Пример #1
0
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
Пример #2
0
Pstore = []
cardstore = []
#correct = 0
while times < N:
    agents = bnfc.random_initialise_toss(agent_number, grid)
    #plot(agents,get_proportion(grid,agents))
    ##print (agents)
    ##print(get_reward(agents,Q))
    ##reward = get_reward(agents,Q)
    ##print(pick_agent(agents,reward))
    #agents,P1 = iteration(agents,len(agents),500)
    #plot(agents,get_proportion(grid,agents))
    #agents,P2 = iteration(agents,len(agents),500)
    #plot(agents,get_proportion(grid,agents))
    agents, P1, cardinality = iteration(agents, len(agents), iter)
    proportion = bnfc.get_proportion(grid, agents)
    Pstore.append(proportion)
    bestPstore.append(P1)
    cardstore.append(cardinality)
    times = times + 1
#print(Ave_P)
sumcard = np.sum(cardstore, axis=0)
stdcard = np.std(cardstore, axis=0)
ave_card = sumcard / N

sumPbest = np.sum(bestPstore, axis=0)
stdPbest = np.std(bestPstore, axis=0)
#index = list(range(0,3000))
ave_pbest = sumPbest / N

sumP = np.sum(Pstore, axis=0)