def random_decision(self, fac, force_list=None): "Creates a decision based on a random list in faction." # decide which list to make decision from decide_list = force_list if force_list is None: decide_list = fac.get_attr_by_type(list) decide_list = self.rand_element(decide_list) attr_list = decide_list[0].attr attr = self.rand_element(attr_list.keys()) # value that we should search for the closest to value_random = random.random() if value_random < 0.333: value = decision.minimum elif value_random < 0.666: value = decision.maximum else: value = self.rand_int(-100, 100) weight = random.random() * 3.0 # possible add decisions on another factor from same list dec = decision.decision(decide_list, attr, value, weight) if random.random() < self.length_change: dec = dec + random_decision(decide_list) return dec
def on_data(self, data): # print data temp = json.loads(data) if temp['coordinates'] != None: coord = temp['coordinates']['coordinates'] t = langDetect.formBaseTweet( temp['text'].encode('utf-8').replace('\n', '')) if temp['user']['lang'].encode('utf-8') == None: print ' user is None' d, flag = decision.decision( temp['user']['lang'].encode('utf-8'), t['text']) if d: t['langAlert'] = flag t['author'] = temp['user']['name'].encode( 'utf-8' ) + ' aka ' + temp['user']['screen_name'].encode('utf-8') t['created_at'] = temp['created_at'] t['userlang'] = temp['user']['lang'].encode('utf-8') # print temp['coordinates']['coordinates'] t['lon'] = temp['coordinates']['coordinates'][0] t['lat'] = temp['coordinates']['coordinates'][1] print locationName, '|', t['userlang'].decode( 'utf-8', 'ignore'), '|', t['detectedLang'].decode( 'utf-8', 'ignore' ), '|', t['langAlert'], '|', t['text'].decode('utf-8') # print '|'.join([str(x).decode('utf-8') for x in [locationName, t['userlang'], t['detectedLang'], t['langAlert'], t['text']]]) SaveToDB.SaveToDB(t, locationName) return True
def run(self): #extracting of command from xml file: cmdCl = TransformXmlToCmd() cmdCl.readXml('cmdCrTest.xml') cmd = cmdCl.getcmd(self.cr.name) #cmd is a list containing objects that contain the indicator and her command # calling the obj_extract class to execute command and extract its result ex=obj_extract() result=ex.extract(self.host,cmd[0],self.cr.name) # definition of fixed threshold of each indicator fixedTh=fixed_thresholds(self.cr) mxAdd=fixedTh.return_maxAdding() mnRem=fixedTh.return_minRemoving() # decision for each indicator d=decision() crDecision=d.optimize(result,mxAdd,mnRem) # saving decision queueLock.acquire() f=open('content.log','a') content=self.cr.name+' , '+crDecision f.write(content) f.close() # saving crDecision queueLock.release()
def __init__(self, fac): self.build_city = lambda reward, resource: action.action( { "to_city" : decision.decision( fac.potential_cities, "area.potential." + resource, decision.decision.maximum ), "from_city" : decision.decision( fac.cities, "area.potential." + resource, decision.decision.minimum ) }, [ action.evaluator( "from_city", city.change, { "population": action.evaluator( "from_city", "population") - 10, "military": action.evaluator( "from_city", "military") - 5 } ), action.evaluator( "to_city", city.change, { "faction_ident": fac.ident, "population": 10, "military": 5 } ) ], { "citizen" : lambda city: create_citizen( fac, city ), "move" : lambda obj, city: action.movement( obj, city.pos, reward=reward), "action" : lambda obj, act: obj.give_action( act ) }, [ ["from_city"], ["citizen", "to_city"], ["citizen", "move"] ] )
def accepted_handler(event: accepted): global pid global finished_paxos acceptedBals[event.ballot] += 1 if acceptedBals[event.ballot] == 2: for process in range(1, 6): if process != pid: sender = threading.Thread( target=send_event, args=[decision(ballotNum, current_transaction), process]) sender.daemon = True sender.start() append_block(current_transaction) finished_paxos = True
def on_data(self, data): # print data temp = json.loads(data) if temp['coordinates']!=None: coord = temp['coordinates']['coordinates'] t = langDetect.formBaseTweet(temp['text'].encode('utf-8').replace('\n','')) if temp['user']['lang'].encode('utf-8')==None: print ' user is None' d, flag = decision.decision(temp['user']['lang'].encode('utf-8'), t['text']) if d: t['langAlert']=flag t['author']=temp['user']['name'].encode('utf-8') + ' aka ' + temp['user']['screen_name'].encode('utf-8') t['created_at']=temp['created_at'] t['userlang']= temp['user']['lang'].encode('utf-8') # print temp['coordinates']['coordinates'] t['lon']= temp['coordinates']['coordinates'][0] t['lat']= temp['coordinates']['coordinates'][1] print locationName , '|', t['userlang'].decode('utf-8','ignore'), '|', t['detectedLang'].decode('utf-8','ignore'), '|', t['langAlert'] , '|', t['text'].decode('utf-8') # print '|'.join([str(x).decode('utf-8') for x in [locationName, t['userlang'], t['detectedLang'], t['langAlert'], t['text']]]) SaveToDB.SaveToDB(t, locationName ) return True
def mk_decision(): a = decision(0, 0, 0, 0, 0, 0, "name") a.name = input("what decision are you going to make ") gh = (input("how happy can you tolerate on 0-100% ")) if (gh.isdigit()): gh = int(gh) if (gh > 0 and gh < 100): a.h = gh if (gh > 100): a.h = 100 if (gh < 0): a.h = 0 else: print("enter a valid number from 1-100") gh = input(" how much happy this decision makes you ") if (gh.isdigit()): gh = int(gh) if (gh > 0 and gh < 100): a.h = gh if (gh > 100): a.h = 100 if (gh < 0): a.h = 0 else: print("enter a valid number from 1-100") gf = input(" how much fear this decision makes you ") if (gf.isdigit()): gf = int(gf) if (gf > 0 and gf < 100): a.f = gf if (gf > 100): a.f = 100 if (gf < 0): a.f = 0 else: print("enter a valid number from 1-100") gs = input(" how much sadness this decision makes you ") if (gs.isdigit()): gs = int(gs) if (gs > 0 and gs < 100): a.s = gs if (gs > 100): a.s = 100 if (gs < 0): a.s = 0 else: print("enter a valid number from 1-100") ga = input(" how much angry this decision makes you ") if (ga.isdigit()): ga = int(ga) if (ga > 0 and ga < 100): a.a = ga if (ga > 100): a.a = 100 if (ga < 0): a.a = 0 else: print("enter a valid number from 1-100") gsu = input(" how much surprise this decision makes you ") if (gsu.isdigit()): gsu = int(gsu) if (gsu > 0 and gsu < 100): a.su = gsu if (gsu > 100): a.su = 100 if (gsu < 0): a.su = 0 else: print("enter a valid number from 1-100") gd = input(" how much disgust this decision makes you ") if (gd.isdigit()): gd = int(gd) if (gd > 0 and gd < 100): a.d = gd if (gd > 100): a.d = 100 if (gd < 0): a.d = 0 else: print("enter a valid number from 1-100") return a
nn_hdim = 3 # number of hidden variables nn_output_dim = 2 # two classes # Initial model model = initialize(nn_input_dim, nn_hdim, nn_output_dim) fig = plt.figure() ax = fig.add_subplot(111) plt.ion() fig.show() fig.canvas.draw() # Train a model reg_lambda = 0.01 epsilon = 0.01 num_passes = 1000 for i in range(0, num_passes): out = forward(model, X, y) z1, a1, probs, yhat = out['z1'], out['a1'], out['probs'], out['yhat'] model = backward(model, X, y, probs, a1, reg_lambda, epsilon) if i % 20 == 0: # Plot the contour and training examples out = decision(X, y, lambda x: predict(model, x)) xx, yy, Z = out["xx"], out["yy"], out["Z"] ax.clear() ax.contourf(xx, yy, Z, cmap=plt.cm.Spectral) ax.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral) plt.pause(0.1)