Exemple #1
0
def properSelection(Agents,AgentScores,numSurvivors,maxScore):
    surAgents  = []
    surAgents = bs.sort_rev(AgentScores,Agents)
    lenAg = len(surAgents)
    normScores = surAgents
    accumScores = []
    normScore = 0
    #Step 1 - Normalise The Results, so they add up to 1.
    for score in AgentScores:
        normScore = normScore + score
    for agentId in range(lenAg):
        normScores[agentId] = float(AgentScores[agentId] / normScore)

    #print(normScores)

    #Step 2 - Sort Agents (They are already sorted)
    #Step 3 - Accumulated Results
    accumScores = normScores
    for i in range(1,len(normScores)):
        accumScores[i] = accumScores[i-1] + normScores[i]
    #print(accumScores)
    return Agents
Exemple #2
0
    movieResults = []
    for movie in data:
        movieId = movieId + 1
        agentId = -1
        AgentResults = []
        for agent in Agents:
            agentId = agentId + 1
            result = (nn.runThroughNetworkOnce(movie, agent, layoutOfNetwork))
            AgentScores[agentId] = AgentScores[agentId] + nn.workOutResult(
                fullData, resultPos, endFireFactor, movieId, result)
            AgentResults.append(nn.getActualResult(endFireFactor, result))
        movieResults.append(
            [fullData[movieId][resultPos], movieId, AgentResults])

    #Sort Agents First
    Agents = bs.sort_rev(AgentScores, Agents)

    #Kill off poor performing Agents
    [Agents, cut, acScores] = ga.properSelection(Agents, AgentScores,
                                                 len(data), minC, maxC)
    numBreed = int(ga.numToBreed(numAgents, len(Agents)))
    numRandomAgents = numAgents - len(Agents) - 2 * numBreed
    bestAgent = Agents[0:2]

    #Unsort the Agents
    Agents = ga.bs.unsort(Agents, numSwaps)

    #Surviving Agents Breed to create more
    cutPoint = int(random.random() * ((maxCut - minCut) + minCut) *
                   len(Agents[0]))
    Agents = ga.singleCrossover(Agents, numBreed, cutPoint)
Exemple #3
0
def naturalSelection(Agents,AgentScores,numSurvivors):
    survivingAgents = []
    survivingAgents = bs.sort_rev(AgentScores,Agents)[0:numSurvivors]
    return survivingAgents
Exemple #4
0
def naturalSelection(Agents, AgentScores, numSurvivors):
    """Literally only Keep agents in the Agent array from index 0 to numSurvivors"""
    survivingAgents = []
    survivingAgents = bs.sort_rev(AgentScores, Agents)[0:numSurvivors]
    return survivingAgents