Example #1
0
    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();
    
        # evaluated the last individual in the generatio? write stats
        if (ea.actualOne() == (popsize-1)):
            print 'check: '+repr(ea.generation())
            fit = ea.getBestInd().getFitness().get();
Example #2
0
else: 
    useRecurrent =False
    pMut = 0.6;
    pCross = 1;
    N=5
    popsize = 3;
    maxgen = 1;

# init EA
ea = EA(INdim, OUTdim, N, maxgen,popsize,minw,maxw);
ea.setProbabilities(pMut,pCross);
ea.initPop();

# evolution insert here
while ea.wantsEval():
    print 'gen: '+repr(ea.generation())+' actual ind is ' +repr(ea.actualOne())+ ' best so far: '+repr(ea.getBestFitness());
    print ' '

    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();
    print ea.getActualWeights();

# load the best one found
ind = ea.getIndNo(ea.getBest());
Example #3
0
# 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();

    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();

    # evaluated the last individual in the generatio? write stats
    if (ea.actualOne() == (popsize - 1)):
Example #4
0
    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();        

    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();

    # evaluated the last individual in the generatio? write stats
    if (ea.actualOne() == (popsize-1)):
        print 'check: '+repr(ea.generation())
        fit = ea.getBestInd().getFitness().get();