def choose_action_phase2(self, stage, prev_data): maxratio = 0 astars = [] selector = { 'a': world.possible_actions_phase2a, 'b': world.possible_actions_phase2b } possible_actions = selector[stage]() for a in possible_actions: dt = world.make_forced_action(a, True) df = world.make_forced_action(a, False) pt = model.p_data_action(dt, a, prev_data) pf = model.p_data_action(df, a, prev_data) print a, pt, pf, pt / pf this_ratio = pt / pf if this_ratio > maxratio: astars = [a] maxratio = this_ratio elif this_ratio == maxratio: astars.append(a) #print astars choice = random.choice(astars) return choice
def success_probability(self, action, prev_data=[]): data_no, data_yes = world.possible_data(action) p_yes = model.p_data_action(data_yes, action, prev_data) p_no = model.p_data_action(data_no, action, prev_data) return p_yes / (p_yes + p_no)
def success_probability(self, action, prev_data=[]): data_no, data_yes=world.possible_data(action) p_yes=model.p_data_action(data_yes, action, prev_data) p_no=model.p_data_action(data_no, action, prev_data) return p_yes/(p_yes+p_no)
def choose_action_phase2(self, stage, prev_data): maxratio=0 astars=[] selector={'a': world.possible_actions_phase2a, 'b': world.possible_actions_phase2b} possible_actions=selector[stage]() for a in possible_actions: dt=world.make_forced_action(a,True) df=world.make_forced_action(a,False) pt=model.p_data_action(dt,a,prev_data) pf=model.p_data_action(df,a,prev_data) print a, pt, pf, pt/pf this_ratio=pt/pf if this_ratio > maxratio: astars=[a] maxratio=this_ratio elif this_ratio == maxratio: astars.append(a) #print astars choice=random.choice(astars) return choice
# print 't: {0}, p: {1}, ppost: {2}'.format(t, model.p_theory(t),\ # model.p_theory_data(t,d0)\ # ) d0p=Datapoint.Datapoint((t1,m0), True) d1=Datapoint.Datapoint((t1,m1), True) #for h in model.singleh_space: #print model.p_data_action(d0p, (t1,m0), []), model.p_data_action(d0p, (t1,m0), d0) action=(t2,m1) n1=0 n2=0 p1s=[] p2s=[] d0[0].display() print action for dat in world.possible_data(action): p1=model.p_data_action(dat, (t2,m1), []) p2=model.p_data_action(dat, (t2,m1), d0) n1+=p1 n2+=p2 p1s.append(p1) p2s.append(p2) print [p/n1 for p in p1s] print [p/n2 for p in p2s]
lposc = [0] * 12 hposc = [0] * 12 lposs = [0] * 12 hposs = [0] * 12 lposi = [0] * 12 hposi = [0] * 12 data = Data.Data() data.read(astext=False) dind = data.data[data.get_kids()[3]] [d.display() for d in dind] # dind[-1].active=False print low_model.p_data_action(dind[0], world.possible_actions()[3]) print high_model.p_data_action(dind[0], world.possible_actions()[3]) dind[0].active = True print low_model.p_data_action(dind[0], world.possible_actions()[3]) print high_model.p_data_action(dind[0], world.possible_actions()[3]) norm = True lostart = time.clock() for t in range(12): lposc[t] = low_model.p_theory_data(t, dcol, normalized=norm) lposs[t] = low_model.p_theory_data(t, dsha, normalized=norm) lposi[t] = low_model.p_theory_data(t, dind, normalized=norm)
lposc = [0] * 12 hposc = [0] * 12 lposs = [0] * 12 hposs = [0] * 12 lposi = [0] * 12 hposi = [0] * 12 data = Data.Data() data.read(astext=False) dind = data.data[data.get_kids()[3]] [d.display() for d in dind] #dind[-1].active=False print low_model.p_data_action(dind[0], world.possible_actions()[3]) print high_model.p_data_action(dind[0], world.possible_actions()[3]) dind[0].active = True print low_model.p_data_action(dind[0], world.possible_actions()[3]) print high_model.p_data_action(dind[0], world.possible_actions()[3]) norm = True lostart = time.clock() for t in range(12): lposc[t] = low_model.p_theory_data(t, dcol, normalized=norm) lposs[t] = low_model.p_theory_data(t, dsha, normalized=norm) lposi[t] = low_model.p_theory_data(t, dind, normalized=norm) # l=[]
# for t in model.t_space: # print 't: {0}, p: {1}, ppost: {2}'.format(t, model.p_theory(t),\ # model.p_theory_data(t,d0)\ # ) d0p = Datapoint.Datapoint((t1, m0), True) d1 = Datapoint.Datapoint((t1, m1), True) #for h in model.singleh_space: #print model.p_data_action(d0p, (t1,m0), []), model.p_data_action(d0p, (t1,m0), d0) action = (t2, m1) n1 = 0 n2 = 0 p1s = [] p2s = [] d0[0].display() print action for dat in world.possible_data(action): p1 = model.p_data_action(dat, (t2, m1), []) p2 = model.p_data_action(dat, (t2, m1), d0) n1 += p1 n2 += p2 p1s.append(p1) p2s.append(p2) print[p / n1 for p in p1s] print[p / n2 for p in p2s]