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
name = 'x' indNo=0 # build the model with default values net = buildSimulation(QLambda.DEF_ALPHA,QLambda.DEF_GAMMA,QLambda.DEF_LAMBDA,QLambda.DEF_IMPORTANCE,name,indNo) rl = net.get("RL_QLambda") importanceIn.setFunctions([ConstantFunction(1,0.5)]) # TODO find some optimal value # 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()
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(); print "==== The result is: "+ea.getBestInd().toString()
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(); print "==== The result is: "+ea.getBestInd().toString() # run the experiment several times, plot average in the matlab
maxw = 1 # range of all parameters ea = RealVectorEA(genomelen, False, maxGens, popSize, minw, maxw); ea.mutate.setStdev(stDev); ea.setProbabilities(pMut, pCross); prevgen=0 filename = 'prosperities.txt' evaluated = 0 # now run the EA, store the course of the prosperity (per time step) only for the first one (best one) while(ea.wantsEval()): evaluated = evaluated+1 print "----------------------------------- gen: "+str(ea.generation())+" ind: "+str(ea.currentOne())+ "------------ evaluated "+str(evaluated) 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])