How to use get_value_string method in Slash

Best Python code snippet using slash

Omega2dSimulator.py

Source:Omega2dSimulator.py Github

copy

Full Screen

...92 self.path_tail = [None]*self.path_tail_length93 def load_configs(self, config_file):94 # load some values form the config file95 self.config_reader = ConfigReader(config_file)96 self.x_lb = str2list(self.config_reader.get_value_string("system.states.first_symbol"))97 self.x_ub = str2list(self.config_reader.get_value_string("system.states.last_symbol"))98 self.x_eta = str2list(self.config_reader.get_value_string("system.states.quantizers"))99 self.u_lb = str2list(self.config_reader.get_value_string("system.controls.first_symbol"))100 self.u_ub = str2list(self.config_reader.get_value_string("system.controls.last_symbol"))101 self.u_eta = str2list(self.config_reader.get_value_string("system.controls.quantizers"))102 self.specs_formula = self.config_reader.get_value_string("specifications.ltl_formula")103 self.X_initial = self.config_reader.get_value_string("system.states.initial_set")104 self.X_initial_HR = str2hyperrects(self.X_initial)[0]105 self.SCREEN_WIDTH = int(self.config_reader.get_value_string("simulation.window_width"))106 self.SCREEN_HEIGHT = int(self.config_reader.get_value_string("simulation.window_height"))107 self.title = self.config_reader.get_value_string("simulation.widow_title")108 self.step_time = float(self.config_reader.get_value_string("system.dynamics.step_time"))109 self.skip_aps = self.config_reader.get_value_string("simulation.skip_APs").replace(" ", "").split(",")110 self.visualize_3rd_dim = ( "true" == self.config_reader.get_value_string("simulation.visualize_3rdDim"))111 self.model_image = self.config_reader.get_value_string("simulation.system_image")112 self.model_image_scale = float(self.config_reader.get_value_string("simulation.system_image_scale"))113 self.controller_file = self.config_reader.get_value_string("simulation.controller_file")114 self.use_ODE = ( "true" == self.config_reader.get_value_string("simulation.use_ode"))115 strTmp = self.config_reader.get_value_string("simulation.path_tail_length")116 if strTmp == "" or strTmp == None:117 self.path_tail_length = 0118 else: 119 self.path_tail_length = int(strTmp)120 self.model_dump_file = self.config_reader.get_value_string("simulation.model_dump_file")121 if(self.model_dump_file == "" or self.model_dump_file == None):122 self.use_model_dump = False123 else: 124 self.use_model_dump = True125 self.x_0_str = self.config_reader.get_value_string("simulation.initial_state")126 if self.x_0_str == "center":127 self.x_0 = self.X_initial_HR.get_center_element()128 elif self.x_0_str == "random":129 self.x_0 = self.X_initial_HR.get_random_element()130 else:131 self.x_0 = str2list(self.x_0_str)132 # create a quantizer and an ode solver133 self.qnt_x = Quantizer(self.x_lb, self.x_eta, self.x_ub)134 self.qnt_u = Quantizer(self.u_lb, self.u_eta, self.u_ub)135 if self.use_ODE:136 self.ode = RungeKuttaSolver(self.sys_dynamics, 5)137 # configs for the arena138 self.PADDING = 40139 self.ZERO_BASE_X = self.PADDING140 self.ZERO_BASE_Y = self.PADDING141 self.X_GRID = (self.SCREEN_WIDTH-2*self.PADDING)/self.qnt_x.get_widths()[0]142 self.Y_GRID = (self.SCREEN_HEIGHT-2*self.PADDING)/self.qnt_x.get_widths()[1]143 self.ARENA_WIDTH = (self.qnt_x.get_widths()[0])*self.X_GRID144 self.ARENA_HIGHT = (self.qnt_x.get_widths()[1])*self.Y_GRID145 self.X_SCALE_FACTOR = self.ARENA_WIDTH/(self.x_ub[0] - self.x_lb[0] + self.x_eta[0])146 self.Y_SCALE_FACTOR = self.ARENA_HIGHT/(self.x_ub[1] - self.x_lb[1] + self.x_eta[1])147 self.Z_SCALE_FACTOR = 180.0/math.pi # from rad to deg 148 self.arena_mdl_lb = self.translate_sys_to_arena(self.x_lb)149 self.arena_mdl_ub = self.translate_sys_to_arena(self.x_ub) 150 # others: subsets151 self.subset_names = self.config_reader.get_value_string("system.states.subsets.names").replace(" ","").split(",")152 self.subset_HRs = []153 for subset_name in self.subset_names:154 skip = False155 for skip_ap in self.skip_aps:156 if skip_ap == subset_name:157 skip = True158 if skip:159 continue160 subset_str = self.config_reader.get_value_string("system.states.subsets.mapping_" + subset_name)161 if subset_str == '':162 continue163 HRs = str2hyperrects(subset_str)164 HRs_modified = []165 for HR in HRs:166 conc_lb = HR.get_lb()167 conc_ub = HR.get_ub()168 for i in range(len(self.x_lb)):169 if conc_lb[i] < self.x_lb[i]:170 conc_lb[i] = self.x_lb[i] - self.x_eta[i]/2171 if conc_ub[i] > self.x_ub[i]:172 conc_ub[i] = self.x_ub[i] + self.x_eta[i]/2173 lb = self.translate_sys_to_arena(conc_lb)174 ub = self.translate_sys_to_arena(conc_ub)...

Full Screen

Full Screen

pmml.py

Source:pmml.py Github

copy

Full Screen

...3"""convert LightGBM model to pmml"""4from __future__ import absolute_import5from sys import argv6from itertools import count7def get_value_string(line):8 return line[line.find('=') + 1:]9def get_array_strings(line):10 return get_value_string(line).split()11def get_array_ints(line):12 return [int(token) for token in get_array_strings(line)]13def get_field_name(node_id, prev_node_idx, is_child):14 idx = leaf_parent[node_id] if is_child else prev_node_idx15 return feature_names[split_feature[idx]]16def get_threshold(node_id, prev_node_idx, is_child):17 idx = leaf_parent[node_id] if is_child else prev_node_idx18 return threshold[idx]19def print_simple_predicate(tab_len, node_id, is_left_child, prev_node_idx, is_leaf):20 if is_left_child:21 op = 'equal' if decision_type[prev_node_idx] == 1 else 'lessOrEqual'22 else:23 op = 'notEqual' if decision_type[prev_node_idx] == 1 else 'greaterThan'24 out_('\t' * (tab_len + 1) + ("<SimplePredicate field=\"{0}\" " + " operator=\"{1}\" value=\"{2}\" />").format(25 get_field_name(node_id, prev_node_idx, is_leaf), op, get_threshold(node_id, prev_node_idx, is_leaf)))26def print_nodes_pmml(node_id, tab_len, is_left_child, prev_node_idx):27 if node_id < 0:28 node_id = ~node_id29 score = leaf_value[node_id]30 recordCount = leaf_count[node_id]31 is_leaf = True32 else:33 score = internal_value[node_id]34 recordCount = internal_count[node_id]35 is_leaf = False36 out_('\t' * tab_len + ("<Node id=\"{0}\" score=\"{1}\" " + " recordCount=\"{2}\">").format(37 next(unique_id), score, recordCount))38 print_simple_predicate(tab_len, node_id, is_left_child, prev_node_idx, is_leaf)39 if not is_leaf:40 print_nodes_pmml(left_child[node_id], tab_len + 1, True, node_id)41 print_nodes_pmml(right_child[node_id], tab_len + 1, False, node_id)42 out_('\t' * tab_len + "</Node>")43# print out the pmml for a decision tree44def print_pmml():45 # specify the objective as function name and binarySplit for46 # splitCharacteristic because each node has 2 children47 out_("\t\t\t\t<TreeModel functionName=\"regression\" splitCharacteristic=\"binarySplit\">")48 out_("\t\t\t\t\t<MiningSchema>")49 # list each feature name as a mining field, and treat all outliers as is,50 # unless specified51 for feature in feature_names:52 out_("\t\t\t\t\t\t<MiningField name=\"%s\"/>" % (feature))53 out_("\t\t\t\t\t</MiningSchema>")54 # begin printing out the decision tree55 out_("\t\t\t\t\t<Node id=\"{0}\" score=\"{1}\" recordCount=\"{2}\">".format(56 next(unique_id), internal_value[0], internal_count[0]))57 out_("\t\t\t\t\t\t<True/>")58 print_nodes_pmml(left_child[0], 6, True, 0)59 print_nodes_pmml(right_child[0], 6, False, 0)60 out_("\t\t\t\t\t</Node>")61 out_("\t\t\t\t</TreeModel>")62if len(argv) != 2:63 raise ValueError('usage: pmml.py <input model file>')64# open the model file and then process it65with open(argv[1], 'r') as model_in:66 # ignore first 6 and empty lines67 model_content = iter([line for line in model_in.read().splitlines() if line][6:])68feature_names = get_array_strings(next(model_content))69feature_infos = get_array_strings(next(model_content))70segment_id = count(1)71with open('LightGBM_pmml.xml', 'w') as pmml_out:72 def out_(string):73 pmml_out.write(string + '\n')74 out_(75 "<PMML version=\"4.3\" \n" +76 "\t\txmlns=\"http://www.dmg.org/PMML-4_3\"\n" +77 "\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +78 "\t\txsi:schemaLocation=\"http://www.dmg.org/PMML-4_3 http://dmg.org/pmml/v4-3/pmml-4-3.xsd\">")79 out_("\t<Header copyright=\"Microsoft\">")80 out_("\t\t<Application name=\"LightGBM\"/>")81 out_("\t</Header>")82 # print out data dictionary entries for each column83 out_("\t<DataDictionary numberOfFields=\"%d\">" % len(feature_names))84 # not adding any interval definition, all values are currently85 # valid86 for feature in feature_names:87 out_("\t\t<DataField name=\"" + feature + "\" optype=\"continuous\" dataType=\"double\"/>")88 out_("\t</DataDictionary>")89 out_("\t<MiningModel functionName=\"regression\">")90 out_("\t\t<MiningSchema>")91 # list each feature name as a mining field, and treat all outliers92 # as is, unless specified93 for feature in feature_names:94 out_("\t\t\t<MiningField name=\"%s\"/>" % (feature))95 out_("\t\t</MiningSchema>")96 out_("\t\t<Segmentation multipleModelMethod=\"sum\">")97 # read each array that contains pertinent information for the pmml98 # these arrays will be used to recreate the traverse the decision tree99 while True:100 tree_start = next(model_content, '')101 if not tree_start.startswith('Tree'):102 break103 out_("\t\t\t<Segment id=\"%d\">" % next(segment_id))104 out_("\t\t\t\t<True/>")105 tree_no = tree_start[5:]106 num_leaves = int(get_value_string(next(model_content)))107 split_feature = get_array_ints(next(model_content))108 split_gain = next(model_content) # unused109 threshold = get_array_strings(next(model_content))110 decision_type = get_array_ints(next(model_content))111 left_child = get_array_ints(next(model_content))112 right_child = get_array_ints(next(model_content))113 leaf_parent = get_array_ints(next(model_content))114 leaf_value = get_array_strings(next(model_content))115 leaf_count = get_array_strings(next(model_content))116 internal_value = get_array_strings(next(model_content))117 internal_count = get_array_strings(next(model_content))118 shrinkage = get_value_string(next(model_content))119 has_categorical = get_value_string(next(model_content))120 unique_id = count(1)121 print_pmml()122 out_("\t\t\t</Segment>")123 out_("\t\t</Segmentation>")124 out_("\t</MiningModel>")...

Full Screen

Full Screen

evaluator.py

Source:evaluator.py Github

copy

Full Screen

...43 self.result = const.PASS_STRING44 else:45 self.result = const.FAIL_STRING46 def __repr__(self):47 return "(" + self.get_value_string() + "," + str(self.criterion) + "," + self.result + ")"48 def is_testable(self):49 return self.value is not None and self.criterion.is_testable()50 def get_value_string(self):51 if self.value is None:52 return const.NA_STRING53 return str(self.value)54 def pretty_string(self):55 return "Metric \"%s\" = %s evaluated against range [%s, %s] and resulted in %s\n" \56 % (self.criterion.name,57 self.get_value_string(),58 self.criterion.min_string(),59 self.criterion.max_string(),60 self.result)61# Runs tests on given metrics against a given set of criteria62class QCEvaluator:63 def __init__(self, metrics_file_path, criteria_file_path):64 self._load_metrics(metrics_file_path)65 self._load_criteria(criteria_file_path)66 def _load_metrics(self, filename):67 cols = [const.METRIC_FILE_NAME_COLUMN, const.METRIC_FILE_VALUE_COLUMN]68 self.data = pd.read_csv(69 filename, sep=const.TSV_DELIMITER, names=cols, header=None)70 def _load_criteria(self, filename):71 cols = [const.CRITERIA_METRIC_COLUMN,72 const.CRITERIA_MIN_COLUMN, const.CRITERIA_MAX_COLUMN]73 raw_data = pd.read_csv(74 filename, sep=const.TSV_DELIMITER, names=cols, header=0)75 self.criteria = {}76 for i in range(raw_data.shape[0]):77 name = raw_data.at[i, const.CRITERIA_METRIC_COLUMN]78 min = raw_data.at[i, const.CRITERIA_MIN_COLUMN]79 max = raw_data.at[i, const.CRITERIA_MAX_COLUMN]80 self.criteria[name] = Criterion(name, min=min, max=max)81 def get_tests(self):82 tests = {}83 name_idx = self.data.columns.get_loc(const.METRIC_FILE_NAME_COLUMN)84 val_idx = self.data.columns.get_loc(const.METRIC_FILE_VALUE_COLUMN)85 for row in self.data.iterrows():86 name = row[1][name_idx]87 value = row[1][val_idx]88 if name not in self.criteria:89 tests[name] = Test(Criterion(name), value=value)90 else:91 criterion = self.criteria[name]92 tests[name] = Test(criterion, value=value)93 # Criteria that were defined but there were no metrics for94 missed_tests = [Test(self.criteria[x])95 for x in self.criteria if x not in tests]96 for test in missed_tests:97 name = test.criterion.name98 tests[name] = test99 return tests.values()100 def write_tests(self, filename, tests):101 with open(filename, 'w') as f:102 f.write("#METRIC\tMIN\tMAX\tVALUE\tRESULT\n")103 f.writelines(["\t".join([x.criterion.name, x.criterion.min_string(...

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