Пример #1
0
ea = RealVectorEA(genomelen, False, maxGens, popSize, minw, maxw)
ea.mutate.setStdev(stDev)
ea.setProbabilities(pMut, pCross)

prevgen = 0

filename = 'prosperities.txt'

# now run the EA, store the course of the prosperity (per time step) only for the first one (best one)
while (ea.wantsEval()):

    if (prevgen != ea.generation()):
        prevgen = ea.generation()
        f = file(filename, 'a+')
        f.write('%1.1f %1.6f %s\n' %
                ((prevgen - 1), ea.getBestInd().getFitness().getValue(),
                 ' '.join(map(str,
                              ea.getBestInd().getGenome().getVector()))))
        f.close()

    ind = ea.getCurrentInd()
    indNo = ea.currentOne()
    val = ind.getGenome().getVector()

    name = base + "g" + str(ea.generation()) + "_i" + str(
        ea.currentOne())  # set the name (for file storing)
    prosp = evalConfiguration(val[0], val[1], val[2], QLambda.DEF_IMPORTANCE,
                              t, dt, name, indNo)  # eval
    print '----------------- exp named: ' + name + ' done, the value is ' + str(
        prosp[0])
Пример #2
0
ea = RealVectorEA(genomelen, False, maxGens, popSize, minw, maxw);
ea.mutate.setStdev(stDev);
ea.setProbabilities(pMut, pCross);

prevgen=0

filename = 'prosperities.txt'

# now run the EA, store the course of the prosperity (per time step) only for the first one (best one)
while(ea.wantsEval()):
    
    if(prevgen!=ea.generation()):
        prevgen=ea.generation()
        f=file(filename,'a+')
        f.write('%1.1f %1.6f %s\n'%((prevgen-1),ea.getBestInd().getFitness().getValue(),' '.join(map(str, ea.getBestInd().getGenome().getVector()))))
        f.close()
    
    ind = ea.getCurrentInd();
    indNo = ea.currentOne();
    val = ind.getGenome().getVector();
    
    name = base+"g"+str(ea.generation())+"_i"+str(ea.currentOne()) # set the name (for file storing)
    prosp = evalConfiguration(val[0],val[1],val[2],QLambda.DEF_IMPORTANCE,t,dt,name,indNo) # eval
    print '----------------- exp named: '+name+' done, the value is '+str(prosp[0])

    ind.getFitness().setValue(prosp[0]);                # set the fitness
    ea.nextIndividual();                                # continue

# Should be something about 2-3000
fitness = ea.getBestInd().getFitness().getValue();
Пример #3
0
# now run the EA (change the models parameters), store the course of the prosperity (per time step) only for the first one (best one)
while(ea.wantsEval()):
    


    alphaIn.setFunctions([ConstantFunction(1,11)])
    evaluated = evaluated+1
    print "----------------------------------- gen: "+str(ea.generation())+" ind: "+str(ea.currentOne())+ "------------ evaluated "+str(evaluated)
    
    if(ea.currentOne()==2): # TODO delete this
        break;
    
    if(prevgen!=ea.generation()):
        prevgen=ea.generation()
        f=file(filename,'a+')
        f.write('%1.1f %1.6f %s\n'%((prevgen-1),ea.getBestInd().getFitness().getValue(),' '.join(map(str, ea.getBestInd().getGenome().getVector()))))
        f.close()
    
    ind = ea.getCurrentInd();
    indNo = ea.currentOne();
    val = ind.getGenome().getVector();
    
    net.reset()
    time.sleep(2)
    net.run(t,dt)
    #name = base+"g"+str(ea.generation())+"_i"+str(ea.currentOne()) # set the name (for file storing)
    #prosp = evalConfiguration(val[0],val[1],val[2],QLambda.DEF_IMPORTANCE,t,dt,name,indNo) # evals
    prosp = rl.getOrigin(QLambda.topicProsperity).getValues().getValues(); # read the prosperity
	
    print '----------------- exp named: '+name+' done, the value is '+str(prosp[0])
Пример #4
0
ea = RealVectorEA(genomelen, False, maxGens, popSize, minw, maxw);
ea.mutate.setStdev(stDev);
ea.setProbabilities(pMut, pCross);

prevgen=0

filename = 'prosperities.txt'

# now run the EA, store the course of the prosperity (per time step) only for the first one (best one)
while(ea.wantsEval()):
    
    if(prevgen!=ea.generation()):
        prevgen=ea.generation()
        f=file(filename,'a+')
        f.write('%1.1f %1.6f %s\n'%((prevgen-1),ea.getBestInd().getFitness().getValue(),' '.join(map(str, ea.getBestInd().getGenome().getVector()))))
        f.close()
    
    ind = ea.getCurrentInd();
    indNo = ea.currentOne();
    val = ind.getGenome().getVector();
    
    name = base+"g"+str(ea.generation())+"_i"+str(ea.currentOne()) # set the name (for file storing)
    prosp = evalConfiguration(val[0],val[1],val[2],QLambda.DEF_IMPORTANCE,t,dt,name,indNo) # eval
    print '----------------- exp named: '+name+' done, the value is '+str(prosp[0])

    ind.getFitness().setValue(prosp[0]);                # set the fitness
    ea.nextIndividual();                                # continue

# Should be something about 2-3000
fitness = ea.getBestInd().getFitness().getValue();