def iteration(agents, agent_number, iteration_times): cardinality = [] P_choosing_best = [] #an = agent_number #sn = proposition_number N = iteration_times iteration = 0 # iteration time count while iteration < N: reward = bnfc.get_reward(agents, Q) iteration = iteration + 1 square_rank = bnfc.get_sq_rank(reward) index1 = bnfc.pick_agent(agents, square_rank) index2 = bnfc.pick_agent(agents, square_rank) #t = agents [index1] #s = agents [index2] Intersection = agents[index1] & agents[index2] Union = agents[index1] | agents[index2] #distance = hammingdis(s,t) # check if overlap exists if (Intersection == set()): agents[index1] = Union agents[index2] = Union else: agents[index1] = Intersection #intersect if not agents[index2] = Intersection cardinality.append(bnfc.cal_card(agents)) proportion = bnfc.get_proportion(grid, agents) P_choosing_best.append(proportion[1]) return agents, P_choosing_best, cardinality
#correct = 0 for i in range(11): print(i) for j in range(11): print(j) times = 0 Q = {'H0': i, 'H1': j} Quality0.append(i) Quality1.append(j) bestPstore = [] Pstore = [] while times < N: #print(times) agents = bnfc.random_initialise_toss(agent_number, grid) #print(agents) rd = bnfc.get_reward(agents, Q) agents, P1, cardinality = iteration(agents, len(agents), iter, Q) proportion = bnfc.get_proportion(grid, agents) Pstore.append(proportion) bestPstore.append(P1[-1]) times = times + 1 sumP = np.sum(bestPstore) stdP = np.std(bestPstore) aveP = sumP / len(bestPstore) propP1.append(aveP) #print(Ave_P) font = { 'family': 'serif', #'sans-serif':['Computer Modern Sans serif'],#Times New Roman',