SAGA_optimize API Reference

This module provides the SAGA class to find the optimal solutions to a set of parameters based on a given energy function with a simulated annealing and genetic algorithm. The ElementDescription class describes a parameter. The Guess class stores a set of ElementDescription instances to a given energy function and the Population class contains a group of Guess instances.

class SAGA_optimize.ElementDescription(low=0, high=0, name='', value=None, mutate=None)[source]

ElementDescription class describes an optimized parameter to a given energy function.

__init__(low=0, high=0, name='', value=None, mutate=None)[source]

ElementDescription initializer.

Parameters:
  • low (double) – minimum value for this element; OPTIONAL if immutable value specified.
  • high (double) – maximum value for this element; OPTIONAL if immutable value specified.
  • name (str) – OPTIONAL - the name of the element.
  • value (double) – OPTIONAL - immutable value for this element.
  • mutate (str) – the method that mutates the element; DEFAULT - mutatePopulationRangedFloat.
class SAGA_optimize.Guess(elementDescriptions, elements, energy=0)[source]

Guess class collects all the optimized parameter values related to a list of ElementDescription instances.

__init__(elementDescriptions, elements, energy=0)[source]

Guess initializer.

Parameters:
  • elementDescriptions (list) – a list of ElementDescription instances.
  • elements (list) – a list of values for the corresponding ElementDescription instances.
  • energy (double) – the energy of the Guess calculated from an energy function.
clone()[source]

Clones everything but the energy.

Returns:the Guess instance.
Return type:Guess
class SAGA_optimize.Population(size, elementDescriptions, energyCalculation, direction=-1, initialPopulation=None)[source]

Population class which contains a group of Guess instances.

__init__(size, elementDescriptions, energyCalculation, direction=-1, initialPopulation=None)[source]
Parameters:
  • size (int) – the number of Guess instances in the population.
  • elementDescriptions (list) – a list of ElementDescription instances in the Guess.
  • energyCalculation – the given energy function.
  • direction (int) – (1 or -1) for determining lowest energy.
  • initialPopulation – an initial Population instance.
class SAGA_optimize.SAGA(stepNumber, startTemperature, temperatureStepSize, alpha, populationSize, energyCalculation, direction=-1, elementDescriptions=None, startPopulation=None, initialPopulation=None, crossoverRate=0.1, crossover=None, acceptedCriteria=None, mutationRate=1, annealMutationRate=1, maxEnergy=None, crossoverProbabilities=None, validGuess=None, bestOperation=None, bestResultsFile=None, allResultsFile=None)[source]

Implements a simulated annealing / genetic algorithm optimization strategy.

__init__(stepNumber, startTemperature, temperatureStepSize, alpha, populationSize, energyCalculation, direction=-1, elementDescriptions=None, startPopulation=None, initialPopulation=None, crossoverRate=0.1, crossover=None, acceptedCriteria=None, mutationRate=1, annealMutationRate=1, maxEnergy=None, crossoverProbabilities=None, validGuess=None, bestOperation=None, bestResultsFile=None, allResultsFile=None)[source]
Parameters:
  • stepNumber (int) – number of simple steps to perform.
  • startTemperature (double) – starting temperature.
  • temperatureStepSize (int) – number of simple steps in a temperature step.
  • alpha (double) – power of annealing rate; 1 is linear.
  • populationSize (int) – size of the population of Guesses.
  • energyCalculation – function to calculate the energy.
  • direction (int) – optimization direction; 1 is maximizing; -1 is minimizing; DEFAULT is -1.
  • elementDescriptions (list) – OPTIONAL - list of ElementDescription instances.
  • startPopulation (Population) – OPTIONAL - Population instance to use as the starting population.
  • initialPopulation (Population) – OPTIONAL - Population instance to initialize with.
  • crossoverRate (double) – fractional rate of crossover versus mutation; DEFAULT is 0.1.
  • mutationRate (int) – number of mutations to perform in creating a new Guess; DEFAULT is 1.
  • annealMutationRate – whether to anneal mutationRate with temperature; DEFAULT is 1.
  • maxEnergy (double) – OPTIONAL - override of maxEnergy for SA calculation.
  • validGuess – function that tests if a Guess instance is valid. DEFAULT is None.
  • bestOperation – function to perform on best Guess instance; DEFAULT is None.
addElementDescriptions(*elementDescriptions)[source]

Add elementDescriptions.

Parameters:elementDescriptions (ElementDescription) – the ElementDescription instance.
optimize()[source]

Performs the optimization.

Returns:Population.