How to use get_parameters method in Slash

Best Python code snippet using slash

utils.py

Source:utils.py Github

copy

Full Screen

...5 validate_fact_type,6 validate_month,7 validate_number,8)9def get_validated_get_parameters(get_parameters: QueryDict) -> dict:10 response = {11 "number": "random",12 "fact_type": None,13 "date": None,14 "error": None,15 }16 # Validate number17 if "number" in get_parameters:18 number = get_parameters["number"]19 if validate_number(number) == False:20 response[21 "error"22 ] = "Inform a valid number option: an integer or the word random"23 return response24 response["number"] = number25 # Validate fact type26 if "fact_type" in get_parameters:27 fact_type = get_parameters["fact_type"]28 if validate_fact_type(fact_type) == False:29 response[30 "error"31 ] = "Invalid fact type. Should be one of: trivia, math, date or year"32 return response33 response["fact_type"] = fact_type34 # Validate date request, which should have valid 'day' and 'month' parameters,35 # paired with the "date" 'fact_type' parameter36 if "month" in get_parameters:37 if "day" in get_parameters:38 month = get_parameters["month"]39 if validate_month(month) == False:40 response["error"] = "Invalid month. Should be a number from 1-12"41 return response42 day = get_parameters["day"]43 if validate_day(day) == False:44 response["error"] = "Invalid day. Should be a number from 1-31"45 return response46 date = f"{month}/{day}"47 if validate_date(date) == False:48 response["error"] = "Invalid date. Should be a valid month/day pair"49 return response50 if date is not None and response["fact_type"] != "date":51 response[52 "error"53 ] = "Invalid date/fact type pair. Should be a valid month/day paired with the fact_type 'date'"54 return response55 response["number"] = date56 return response57def join_numbersapi_get_parameters(get_parameters: QueryDict) -> str:58 # Always appends json as a default get parameter59 response = "?json"60 if "fragment" in get_parameters:61 response += "&fragment"62 if "notfound" in get_parameters:63 response += f"&notfound={get_parameters['notfound']}"64 if "default" in get_parameters:65 response += f"&default={get_parameters['default']}"66 if "min" in get_parameters:67 if "max" in get_parameters:68 if get_parameters["min"] != "" and get_parameters["max"] != "":69 response += f"&min={get_parameters['min']}&max={get_parameters['max']}"70 return response71def join_numbersapi_get_url(get_parameters: dict) -> str:...

Full Screen

Full Screen

nnds.py

Source:nnds.py Github

copy

Full Screen

...14 def forward(self, q_Xt, q_At):15 Xt, At = q_Xt.sample()[0], q_At.sample()[0]16 return util.map_network(self.network)(T.concatenate([Xt, At], -1))17 def get_dynamics(self):18 return self.network.get_parameters()19 def __getstate__(self):20 state = super(NNDS, self).__getstate__()21 state['architecture'] = self.architecture22 state['weights'] = T.get_current_session().run(self.get_parameters())23 return state24 def __setstate__(self, state):25 network = pickle.loads(state.pop('architecture'))26 weights = state.pop('weights')27 self.__init__(state['ds'], state['da'], network=network)28 T.get_current_session().run([T.core.assign(a, b) for a, b in zip(self.get_parameters(), weights)])29 def get_parameters(self):30 return self.network.get_parameters()31 def kl_divergence(self, q_X, q_A, _):32 # q_Xt - [N, H, ds]33 # q_At - [N, H, da]34 if (q_X, q_A) not in self.cache:35 q_Xt = q_X.__class__([36 q_X.get_parameters('regular')[0][:, :-1],37 q_X.get_parameters('regular')[1][:, :-1],38 ])39 q_At = q_A.__class__([40 q_A.get_parameters('regular')[0][:, :-1],41 q_A.get_parameters('regular')[1][:, :-1],42 ])43 p_Xt1 = self.forward(q_Xt, q_At)44 q_Xt1 = q_X.__class__([45 q_X.get_parameters('regular')[0][:, 1:],46 q_X.get_parameters('regular')[1][:, 1:],47 ])48 rmse = T.sqrt(T.sum(T.square(q_Xt1.get_parameters('regular')[1] - p_Xt1.get_parameters('regular')[1]), axis=-1))49 model_stdev = T.sqrt(p_Xt1.get_parameters('regular')[0])50 encoding_stdev = T.sqrt(q_Xt1.get_parameters('regular')[0])51 self.cache[(q_X, q_A)] = T.sum(stats.kl_divergence(q_Xt1, p_Xt1), axis=-1), {'rmse': rmse, 'encoding-stdev': encoding_stdev, 'model-stdev': model_stdev}52 return self.cache[(q_X, q_A)]53 def next_state(self, state, action, t):54 state_action = T.concatenate([state, action], -1)55 sigma, delta_mu = self.network(state_action).get_parameters('regular')56 return stats.Gaussian([57 sigma,58 delta_mu + state,59 ])60 def kl_gradients(self, q_X, q_A, kl, num_data):61 return T.grad(kl, self.get_parameters())62 def is_filtering_prior(self):...

Full Screen

Full Screen

train.py

Source:train.py Github

copy

Full Screen

1from client import MLPClient2if __name__ == "__main__":3 model = MLPClient(split="all", l2=1e-3)4 loss, _, accuracy = model.evaluate(model.get_parameters())5 print(f"loss: {loss:.3f}, accuracy: {accuracy['accuracy']}")6 model.fit(model.get_parameters(), epochs=250)7 loss, _, accuracy = model.evaluate(model.get_parameters())8 print(f"loss: {loss:.3f}, accuracy: {accuracy['accuracy']}")9 model.fit(model.get_parameters(), epochs=350)10 loss, _, accuracy = model.evaluate(model.get_parameters())11 print(f"loss: {loss:.3f}, accuracy: {accuracy['accuracy']}")12 model.fit(model.get_parameters(), epochs=450)13 loss, _, accuracy = model.evaluate(model.get_parameters())14 print(f"loss: {loss:.3f}, accuracy: {accuracy['accuracy']}")15 model.fit(model.get_parameters(), epochs=550)16 loss, _, accuracy = model.evaluate(model.get_parameters())17 print(f"loss: {loss:.3f}, accuracy: {accuracy['accuracy']}")18 model.fit(model.get_parameters(), epochs=550)19 loss, _, accuracy = model.evaluate(model.get_parameters())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful