Package pycv :: Package cs :: Package opt :: Module de :: Class DiffEvolver
[hide private]
[frames] | no frames]

Class DiffEvolver

source code

Minimize a function using differential evolution.

Constructors
------------
DiffEvolver(func, pop0, args=(), crossover_rate=0.5, scale=None,
    strategy=('rand', 2, 'bin'), eps=1e-6)
  func -- function to minimize
  pop0 -- sequence of initial vectors
  args -- additional arguments to apply to func
  crossover_rate -- crossover probability [0..1] usually 0.5 or so
  scale -- scaling factor to apply to differences [0..1] usually > 0.5
    if None, then calculated from pop0 using a heuristic
  strategy -- tuple specifying the differencing/crossover strategy
    The first element is one of 'rand', 'best', 'rand-to-best' to specify
    how to obtain an initial trial vector.
    The second element is either 1 or 2 (or only 1 for 'rand-to-best') to
    specify the number of difference vectors to add to the initial trial.
    The third element is (currently) 'bin' to specify binomial crossover.
  eps -- if the maximum and minimum function values of a given generation are
    with eps of each other, convergence has been achieved.

DiffEvolver.frombounds(func, lbound, ubound, npop, crossover_rate=0.5,
    scale=None, strategy=('rand', 2, 'bin'), eps=1e-6)
  Randomly initialize the population within given rectangular bounds.
  lbound -- lower bound vector
  ubound -- upper bound vector
  npop -- size of population

Public Methods
--------------
solve(newgens=100)
  Run the minimizer for newgens more generations. Return the best parameter
  vector from the whole run.

Public Members
--------------
best_value -- lowest function value in the history
best_vector -- minimizing vector
best_val_history -- list of best_value's for each generation
best_vec_history -- list of best_vector's for each generation
population -- current population
pop_values -- respective function values for each of the current population
generations -- number of generations already computed
func, args, crossover_rate, scale, strategy, eps -- from constructor



Instance Methods [hide private]
 
__init__(self, func, pop0, args=(), crossover_rate=0.5, scale=None, strategy=('rand', 2, 'bin'), eps=1e-006) source code
 
clear(self) source code
 
calculate_scale(self) source code
 
bin_crossover(self, oldgene, newgene) source code
 
select_samples(self, candidate, nsamples) source code
 
diff1(self, candidate) source code
 
diff2(self, candidate) source code
 
choose_best(self, candidate) source code
 
choose_rand(self, candidate) source code
 
choose_rand_to_best(self, candidate) source code
 
get_trial(self, candidate) source code
 
refine(self, trial)
Refine the current trial (e.g.
source code
 
converged(self) source code
 
solve(self, newgens=100)
Run for newgens more generations.
source code
Class Methods [hide private]
 
frombounds(cls, func, lbound, ubound, npop, crossover_rate=0.5, scale=None, strategy=('rand', 2, 'bin'), eps=1e-006) source code
Method Details [hide private]

refine(self, trial)

source code 
Refine the current trial (e.g. constrain it)
Parameters:
  • trial (array) - a trial whose content is to be refined

solve(self, newgens=100)

source code 

Run for newgens more generations.

Return best parameter vector from the entire run.