ii = 0; INdim = 2; OUTdim = 1; N = 1; minw = 0; maxw = 0.3; popsize = 1; maxgen = 0; t = 5; dt = 0.001; # init EA ea = EA(INdim, OUTdim, N, maxgen,popsize,minw,maxw); ea.initPop(); # evolution insert here while ea.wantsEval(): print 'gen: '+repr(ea.generation())+' actual ind is ' +repr(ea.actualOne()) ind = ea.getInd(); ind.printMatrix(); error = evalInd(ind); #error = 0; print 'Ind: '+repr(ea.actualOne())+' Error is: '+repr(error) +' fitness is: '+repr(ind.getFitness().get()); # poc++ and check end of ea ea.nextIndividual();
# setup INdim = 2 OUTdim = 1 N = 5 minw = -1 maxw = 1 popsize = 5 maxgen = 1 t = 5 dt = 0.001 ea = EA(INdim, OUTdim, N, maxgen, popsize, minw, maxw) ea.initPop() while ea.wantsEval(): print ea.actualOne() ind = ea.getInd() ind.printMatrix() # pass weights as python methods def getI1(w): w = ind.getMatrix().get2DInMatrixNo(0) return w def getI2(w): w = ind.getMatrix().get2DInMatrixNo(1) return w
else: useRecurrent =False pMut = 0.6; pCross = 1; N=5 popsize = 4; maxgen = 10; numRuns=10; for expNo in range(numRuns): print '----------------------- experiment number %d'%expNo # init EA ea = EA(INdim, OUTdim, N, maxgen,popsize,minw,maxw); ea.setProbabilities(pMut,pCross); ea.initPop(); f = open('data/ea_%d.txt'%expNo, 'w'); # evolution insert here while ea.wantsEval(): print 'Gen: '+repr(ea.generation())+'/'+repr(maxgen)+' actual ind is ' +repr(ea.actualOne())+'/'+repr(popsize)+' best so far: '+repr(ea.getBestFitness()); ind = ea.getInd(); #ind.printMatrix(); error = evalInd(ind); ind.getFitness().setError(error); print 'Ind: '+repr(ea.actualOne())+' Error is: '+repr(error) +' fitness is: '+repr(ind.getFitness().get()); print ea.getActualWeights();
popsize = 30 maxgen = 100 N = 4 else: useRecurrent = False pMut = 0.6 pCross = 1 N = 5 popsize = 4 maxgen = 5 # init EA ea = EA(INdim, OUTdim, N, maxgen, popsize, minw, maxw) ea.setProbabilities(pMut, pCross) ea.initPop() expNo = round(1000000 * random.random(), 0) # generate some number for text file data print expNo f = open('data/ea_%d.txt' % expNo, 'w') # evolution insert here while ea.wantsEval(): print 'Gen: ' + repr( ea.generation()) + '/' + repr(maxgen) + ' actual ind is ' + repr( ea.actualOne()) + '/' + repr(popsize) + ' best so far: ' + repr( ea.getBestFitness()) ind = ea.getInd() #ind.printMatrix();