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]) ind.getFitness().setValue(prosp[0]); # set the fitness ea.nextIndividual(); # continue print 'done' # Should be something about 2-3000 #fitness = ea.getBestInd().getFitness().getValue(); #print "==== The result is: "+ea.getBestInd().toString()
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 #for j in range(len(vals)): # print 'xxxxxxx testing the value: '+str(vals[j]) # for i in range(runs): # name = base + '_%d'%i; # print '----------------- starting experiment named: '+name # prosp = evalConfiguration(QLambda.DEF_ALPHA,QLambda.DEF_GAMMA,QLambda.DEF_LAMBDA,QLambda.DEF_IMPORTANCE,t,dt,name+"_"+str(vals[j])) # print '----------------- exp named: '+name+' done, the value is '+str(prosp[0])
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()