How to use operations_index method in localstack

Best Python code snippet using localstack_python

tradeoff_functions.py

Source:tradeoff_functions.py Github

copy

Full Screen

1from functions import functions_util, inference_fcns2import math, sys3def cost_est(model,bits,**kwargs):4 content_ac = model[0]5 cost_add_flt={64:32,32:16,16:8,8:4}6 cost_mult_flt={64:120,32:25,16:5,8:1}7 cost_reg={64:40,32:20,16:10,8:5}8 cost_sram={64:200,32:100,16:50,8:25}9 par_num = sum([1 for ac in content_ac if 'L' in ac]) #Number of parameters10 add_num = sum([1*len(ac.split(' '))-2-1+1 for ac in content_ac if 'O' in ac]) #Number of multiplications11 mult_num = sum([1*len(ac.split(' '))-3-1+1 for ac in content_ac if 'A' in ac]) #Number of additions12 #Feature and cost sensor are 0 by default13 cost_sensors=014 cost_features=015 #Estimate savings from feature-pruning induced model reduction16 print '\n'17 if kwargs:18 if 'pruned_feature' in kwargs:19 #How much would we save if we pruned features in kwargs20 indicator_dict = model[5]21 variable_list = model[6]22 n_mult = len(indicator_dict[variable_list[kwargs['pruned_feature']] + '_0']) + len(23 indicator_dict[variable_list[kwargs['pruned_feature']] + '_1'])24 n_add = n_mult / 225 n_params = len(indicator_dict[variable_list[kwargs['pruned_feature']] + '_0']) + len(26 indicator_dict[variable_list[kwargs['pruned_feature']] + '_1'])27 saved_mul=n_mult28 saved_add=n_add29 saved_params=n_params30 par_num-=saved_params31 add_num-=saved_add32 mult_num-=saved_mul33 print 'Cost savings', saved_params, saved_mul, saved_add34 if 'sensor_dict' in kwargs:35 print 'Sensor costs!'36 sens_dict=kwargs['sensor_dict']37 sensor_c = kwargs['max_cost']*0.1 #Sensor cost is 10% of most expensive AC comp. cost38 feature_set=kwargs['feature_set']39 sensor_occurrence = [sens_dict[f] for f in feature_set if f in feature_set] #Which sensors are active?40 nsensors = len(set(sensor_occurrence))41 print set(sensor_occurrence)42 print 'Sensors number ', nsensors43 cost_sensors=sensor_c*nsensors44 cost_features=len(feature_set)*((30*cost_add_flt[32])+(30*cost_mult_flt[32])) #Each feature requires 30 MAC, features are extracted at 32 bits45 out_cost=(add_num * cost_add_flt[bits]) + (mult_num * cost_mult_flt[bits]) + ((add_num + mult_num) * cost_reg[bits] ) + (par_num * cost_sram[bits])+cost_sensors+cost_features46 #Return list with [total cost with sensors and features, total cost without sensors or features, sensor cost, feature cost]47 return out_cost48def accuracy_estimation(validation_set,indicator_dict,variable_list,obs_var_den,init_weight,49 operations_index,operation,content_ac,classes,obs_var_num,thres,**kwargs):50 correct_count=051 all_ratios=[]52 for test in validation_set:53 if test:54 observation = [int(t) for t in test.split(',')]55 gt = observation[-1]56 #Set indicator values according to observation57 position_neg_den = [indicator_dict[variable_list[var] + '_' + str(value)] for value, var in58 zip(observation, variable_list) if var in obs_var_den ]59 psn_den = [pos for position in position_neg_den for pos in position]60 init_weight_den = [w for w in init_weight]61 for psden in psn_den:62 init_weight_den[psden] = 063 wmc_den, w_den= inference_fcns.performWMC(operations_index, operation, init_weight_den,content_ac)64 w_den+= sys.float_info.min #Avoid division by 065 #Collect num/den ratio66 ratios = []67 nn=[]68 for classv in classes:69 # chnage observation value of class variable70 observation[-1] = classv71 position_neg_num = [indicator_dict[variable_list[var] + '_' + str(value)] for value, var in zip(observation, variable_list) if var in obs_var_num]72 psn_num = [pos for position in position_neg_num for pos in position]73 init_weight_num = [w for w in init_weight]74 for psnum in psn_num:75 init_weight_num[psnum] = 076 wmc_num, w_num= inference_fcns.performWMC(operations_index, operation, init_weight_num,content_ac)77 nn.append(w_num)78 rati = w_num / w_den79 ratios.append(rati)80 all_ratios.append(ratios)81 conditions = [loc for loc, num in enumerate(ratios) if num >= thres]82 if len(conditions) == 1:83 if int(conditions[0]) == gt:84 correct_count += 185 elif len(conditions) > 1:86 if int(conditions.index(max(conditions))) == gt:87 correct_count += 188 accuracy=float(correct_count) / (len(validation_set))89 return accuracy90def metric_est(bench_name,model,dataset,observed_features,bits,sensor_cost,**kwargs):91 content_ac=model[0]92 ce=cost_est(content_ac,64)93 lmap_id=model[1]94 lmap_w=model[2]95 indicator_dict = model[5]96 variable_list=model[6]97 class_num = len(dataset[0].split(','))98 thres=0.599 NodesEv = observed_features+[class_num]100 obs_var_num = NodesEv101 obs_var_den = observed_features102 classes = [0, 1]103 # Initialize weight vector104 init_weight = inference_fcns.init_weight(content_ac, lmap_id, lmap_w)105 operations_index, operation = inference_fcns.extract_operations(content_ac)106 #To verify WMC: w should be 1107 # wmc, w = inference_fcns.performWMC(operations_index, operation, init_weight, content_ac)108 # print 'w is ', w109 acc=accuracy_estimation(dataset, indicator_dict, variable_list, obs_var_den, init_weight,110 operations_index, operation, content_ac, classes, obs_var_num, thres)111 if kwargs:112 if 'featp' in kwargs:113 cost=cost_est(model,bits,pruned_feature=kwargs['featp'])114 elif not kwargs:115 cost = cost_est(model, bits)116 # print 'acc is ', acc117 # print 'cost is ', cost...

Full Screen

Full Screen

inference_fcns.py

Source:inference_fcns.py Github

copy

Full Screen

1import operator2def prod(factors):3 return reduce(operator.mul, factors, 1)4def init_weight(content_ac,content_lmap_parsed_indeces,content_lmap_parsed_weights):5 weight_ac = [None] * len(content_ac)6 for i, ac in enumerate(content_ac):7 if ac[0] == 'L':8 index = int(ac[2:len(ac)])9 # index_weight = indices(content_lmap_parsed_indeces, lambda x: x == index)10 index_weight=[ii for ii,con in enumerate(content_lmap_parsed_indeces) if con==index]11 weight_ac[i] = content_lmap_parsed_weights[index_weight[0]]12 else:13 weight_ac[i] = 014 return (weight_ac)15def extract_operation_numbers(content):16 # spaces = indices(content, lambda x: x.isspace())17 spaces=[ii for ii,con in enumerate(content) if con.isspace()]18 ex_op=[]19 if content[0] == 'A':20 for sp in range(len(spaces) - 1):21 if sp == len(spaces) - 2:22 ex_op.append(content[spaces[sp + 1] + 1:])23 else:24 ex_op.append(content[spaces[sp + 1] + 1:spaces[sp + 2]])25 else:26 for sp in range(len(spaces) - 2):27 if sp == len(spaces) - 3:28 ex_op.append(content[spaces[sp + 2] + 1:])29 else:30 ex_op.append(content[spaces[sp + 2] + 1:spaces[sp + 3]])31 return ex_op,spaces32def generate_operation_set(operations_index,content_ac):33 operation = [[] for _ in range(len(operations_index))]34 for i, op in enumerate(operations_index):35 content=content_ac[operations_index[i]]36 (extracted_op,sp)=extract_operation_numbers(content)37 operation[i]=extracted_op38 return operation39def extract_operations(args):40 k=141 for i, ac in enumerate(args):42 if ac[0]=='L':43 k=k+144 operations_index=[0]*(len(args)-k+1)45 operation_wmc=[0]*(len(args))46 j=047 for i, ac in enumerate(args):48 res=[]49 if ac[0] != 'L':50 operations_index[j]=i51 j=j+152 (op_ex, spaces) = extract_operation_numbers(ac)53 if ac[0]=='O':54 res.append(ac[0:spaces[2]])55 if ac[0]=='A':56 res.append(ac[0:spaces[1]])57 lis=list(map(int, op_ex))58 for l in lis:59 res.append(l)60 operation_wmc[i]=res61 else:62 operation_wmc[i]=ac63 operation=generate_operation_set(operations_index,args)64 return operations_index, operation65def performWMC(operations_index, operation, weight_ac_original, content_ac):66 weight_ac=[w for w in weight_ac_original]67 for i, op in enumerate(operations_index):68 temp = []69 for j in range(len(operation[i])):70 temp.append(weight_ac[int(operation[i][j])])71 if 'A' in content_ac[operations_index[i]][0]:72 weight_ac[operations_index[i]] = prod(temp)73 elif 'O' in content_ac[operations_index[i]][0]:74 weight_ac[operations_index[i]] = sum(temp)75 if content_ac[len(content_ac) - 1][0] != 'L':76 wc = weight_ac[len(content_ac) - 1]77 else:78 for w in range(len(content_ac) - 1, -1, -1):79 if content_ac[w][0] != 'L':80 wc = weight_ac[w]81 break...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1__author__ = 'atulmala'2from django.conf.urls import url3from operations import views4urlpatterns = [5 url(r'^$', views.operations_index, name='operations_index'),6 url(r'^att_summary_school/$', views.att_summary_school, name='att_summary_school'),7 url(r'^att_summary_school_device/$', views.att_summary_school_device, name='att_summary_school_device'),8 url(r'^att_register_class/$', views.AttRegisterClass.as_view(), name='att_register_class'),9 url(r'^test_results/$', views.test_result, name='test_results'),10 url(r'^result_sms/$', views.result_sms, name='test_sms'),11 url(r'^send_message/(?P<school_id>\w+)/$', views.send_message, name='send_message'),12 url(r'^parents_communication_report/$', views.ParentCommunicationReport.as_view(),13 name='parents_communication_report'),14 url(r'^monthly_sms_report/$', views.MonthlySMSReport.as_view(), name='sms_summmary_school'),15 url(r'send_bulk_sms/$', views.send_bulk_sms, name='send_bulk_sms'),16 url(r'commit_bulk_sms/$', views.CommitBulkSMS.as_view(), name='commit_bulk_sms'),17 url(r'commit_failed_sms/$', views.CommitFailedSMS.as_view(), name='commit_failed'),18 url(r'retrieve_sms_history/(?P<parent_mobile>\w+)/$', views.SMSHistoryList.as_view()),19 url(r'send_welcome_sms/$', views.send_welcome_sms, name='send_welcome_sms'),...

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 localstack 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