コード例 #1
0
def GA_minimize(function, guess):
    
    result = GA(function,[guess, ], minimize=True) # set to minimize by default
    
    start = timeit.default_timer()
    mem = max(memory_usage((result.learn,(),)))
    stop = timeit.default_timer()
    
    print result.learn() #Comment this out for faster performance, i.e. if used purely for evaluation

    exec_time = stop-start

    print '{0} took {1} seconds'.format('Genetic Algorithm',exec_time)
    print '{0} used {1} megabytes'.format('Genetic Algorithm',mem)
    print
コード例 #2
0
  def experiment1(self):
    l = GA(self.fitnessFunction, self.myNetwork.params[self.indices])
    l.minimize = False
    l.verbose = True
    l.maxLearningSteps = 500
    params, fitness = l.learn()
    self.myNetwork.params[self.indices] = params
    self.metaInfo["numsteps"] = l.maxLearningSteps
    self.metaInfo["fitness"] = fitness
#     self.myNetwork._setParameters(self.originalWeights)
    self.logNet()
コード例 #3
0
ファイル: optimization_suite.py プロジェクト: merhart/ProCK
def GA_minimize(function, guess):
    """
    This function runs the genetic algorithm from PyBrain (http://pybrain.org/docs/api/optimization/optimization.html) on a function, provided with an initial guess.

   | NOTE: Format is **crucial** here or this will not work (blame the authors of PyBrain, sorry):
   | Function must take a **tuple** (**Even** if of only one element (in the form (a, )) and guess **MUST BE A LIST** (even if only with one element)
    """
    
    result = GA(function, guess, minimize=True) # set to minimize by default
    
    start = timeit.default_timer()
    mem = max(memory_usage(-1,interval=.1))
    
    print "The result is: ", result.learn()
    stop = timeit.default_timer()
    
    exec_time = stop-start

    print '{0} took {1} seconds'.format('Genetic Algorithm',exec_time)
    print '{0} used {1} megabytes'.format('Genetic Algorithm',mem)
    print
コード例 #4
0
ファイル: TrainAndRun.py プロジェクト: osurdml/flame2.0
for x in range(0,numberOfAgents):
    weights = initPopulation[0]
    NNetListParams.append(weights)


i = 0
while (i < 50):
    for x in range(0,len(NNetListParams)):
        for k in range(0,len(NNetListParams)):
            NNetList[k]._setParameters(NNetListParams[k])

        workingNN = x
        ga = GA(evaluator,NNetListParams[x],maxEvaluations = 20,initRangeScaling = 2,elitism = False,populationSize = populationSize,initialPopulation = popList[x],mutationProb = 0.1)
        ga.minimize = True
        result = ga.learn()
        NNetListParams[x] = result[0]
        popList[x] = ga.currentpop


    i += 1
    print i




for x in range(0,len(NNetListParams)):
    for k in range(0,len(NNetListParams)):
        NNetList[k]._setParameters(NNetListParams[k])

#with open('12nodeNN-20pop.pkl','wb') as output: