/* Copyright 2006 by Sean Luke Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.select; import ec.util.*; import ec.*; /* * BoltzmannSelection.java * * Created: Thu May 14 2009 * By: Jack Compton */ /** * Similar to FitProportionateSelection, but with a Simulated Annealing style twist. BoltzmannSelection picks individuals of a population in * proportion to an adjusted version of their fitnesses instead of their actual fitnesses as returned by fitness(). The adjusted fitness is * calculated by e^(fitness/current_temperature) where current_temperature is a temperature value that decreases by a constant cooling rate as * generations of evolution pass. The current_temperature is calculated by starting-temperature - (cooling-rate * the_current_generation_number). * When the temperature dips below 1.0, annealing ceases and BoltzmannSelection reverts to normal FitProportionateSelection behavior. * *

* Like FitProportionateSelection this is not appropriate for steady-state evolution. * If you're not familiar with the relative advantages of * selection methods and just want a good one, * use TournamentSelection instead. Not appropriate for * multiobjective fitnesses. * *

* Note: Fitnesses must be non-negative. 0 is assumed to be the worst fitness. *

Typical Number of Individuals Produced Per produce(...) call
Always 1.

Parameters
base.starting-temperature
double = some large number (defaults to 1.0)
(the starting temperature for our simulated annealing style adjusted fitness proportions)
base.cooling-rate
double = some smaller number (defaults to 0.0 which causes BoltzmannSelection to behave just as FitProportionateSelection would)
(how slow, or fast, do you want to cool the annealing fitness proportions?)

Default Base
select.boltzmann * * @author Jack Compton * @version 1.0 */ public class BoltzmannSelection extends FitProportionateSelection { /** Default base */ public static final String P_BOLTZMANN = "boltzmann"; /** Starting temperature parameter */ public static final String P_STARTING_TEMPERATURE = "starting-temperature"; /** Cooling rate parameter */ public static final String P_COOLING_RATE = "cooling-rate"; /** Starting temperature **/ private double startingTemperature; /** Cooling rate */ private double coolingRate; public Parameter defaultBase() { return SelectDefaults.base().push(P_BOLTZMANN); } public void setup(final EvolutionState state, final Parameter base) { super.setup(state,base); Parameter def = defaultBase(); coolingRate = state.parameters.getDouble(base.push(P_COOLING_RATE),def.push(P_COOLING_RATE)); // default cooling rate of 1.0 per generation startingTemperature = state.parameters.getDouble(base.push(P_STARTING_TEMPERATURE),def.push(P_STARTING_TEMPERATURE)); // default starting temp is 0.0/completely cooled - will act as normal fit proportionate selection if (coolingRate <= 0) { //Hey! you gotta cool! Set your cooling rate to a positive value! state.output.fatal("Cooling rate should be a positive value.",base.push(P_COOLING_RATE),def.push(P_COOLING_RATE)); } if ((startingTemperature - coolingRate) <= 0) { // C'mon, you should cool slowly if you want boltzmann selection to be effective. state.output.fatal("For best results, try to set your temperature to cool to 0 a more slowly. This can be acheived by increasing your starting-temperature and/or decreasing your cooling rate.\nstarting-temperatire/cooling-rate: " + startingTemperature + " / " + coolingRate); } int total_generations = state.numGenerations; if (total_generations == 0) { //Load from parameter database!! state.output.fatal("Hey now, we gotta load the total_generations from the param DB"); } if ((startingTemperature - (coolingRate * total_generations)) > 0) { //Either your cooling rate is to low, or your starting temp is too high, because at this rate you will never cool to 0! (kind of essential to reaping the benefits of boltzmann selection) state.output.warning("If you want BoltzmannnSelection to be effective, your temperature should cool to 0 before all generations have passed. Make sure that (starting-temperature - (cooling-rate * generations)) <= 0."); } } // completely override FitProportionateSelection.prepareToProduce public void prepareToProduce(final EvolutionState s, final int subpopulation, final int thread) { // load fitnesses fitnesses = new float[s.population.subpops[subpopulation].individuals.length]; for(int x=0;x