GeneticAlgorithm

scalation.optimization.GeneticAlgorithm
class GeneticAlgorithm(f: FunctionV2S, rands: Array[Variate]) extends Minimizer, MonitorEpochs

The GA class solves unconstrained Non-Linear Programming (NLP) problems using a genetic algorithm approach. Given a function 'f' and a set of random variables based on the dimensionality of the search space, and the domain of the search space, the GA will evolve a pool of candidate solutions using evolutionary concepts such as crossover and mutation. The random variables are used to create random candidate solutions for the solution pool. The algorithm iterates until it converges or has reached a maximum number of generations.

minimize f(x)

Value parameters

f

the vector-to-scalar objective function

rands

random variables used to create the initial 'gene' pool. There is one r.v. per dimension, and should reflect the domain of the search space.

Attributes

Graph
Supertypes
trait Minimizer
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def cross(x1: VectorD, x2: VectorD): VectorD

Calculate the crossover of two solutions.

Calculate the crossover of two solutions.

Value parameters

x1

the first solution for the crossover

x2

the second solution for the crossover

Attributes

def findMin(i: Int): Int

Find

Find

Attributes

def initPool(seeds: Array[VectorD] = ...): Unit

Create the initial pool of candidate solutions.

Create the initial pool of candidate solutions.

Value parameters

seeds

a (possibly null) array of initial candidates provided by the user.

Attributes

def lineSearch(x: VectorD, dir: VectorD, step: Double = ...): Double

Perform an exact, e.g., GoldenSectionLS or inexact, e.g., WolfeLS line search. Search in direction dir, returning the distance z to move in that direction.

Perform an exact, e.g., GoldenSectionLS or inexact, e.g., WolfeLS line search. Search in direction dir, returning the distance z to move in that direction.

Value parameters

dir

the direction to move in

step

the initial step size

x

the current point

Attributes

def mutate(x: VectorD): Unit

Perform a mutation on a solution.

Perform a mutation on a solution.

Value parameters

x

the solution on which to perform the mutation

Attributes

def nextGen(): Unit

Calculate the next generation of solutions. The top four solutions are kept and the rest of the pool size is filled out by evolving new solutions with crossover and mutation.

Calculate the next generation of solutions. The top four solutions are kept and the rest of the pool size is filled out by evolving new solutions with crossover and mutation.

Attributes

def printPool(n: Int = ...): Unit

Utility method to print the current solution pool.

Utility method to print the current solution pool.

Value parameters

n

the number of solutions from the pool to include in the print the default is set to 5

Attributes

def solve(x0: VectorD, step: Double = ..., toler: Double = ...): FuncVec

Solve the Non-Linear Programming (NLP) problem by starting at x0 and iteratively moving down in the search space to a minimal point. Return the optimal point/vector x and its objective function value.

Solve the Non-Linear Programming (NLP) problem by starting at x0 and iteratively moving down in the search space to a minimal point. Return the optimal point/vector x and its objective function value.

Value parameters

step

the initial step size (may default to STEP)

toler

the tolerance (may default to TOL)

x0

the starting point

Attributes

def solve2(seeds: Array[VectorD] = ...): FuncVec

Solve the optimization problem.

Solve the optimization problem.

Value parameters

seeds

an array of initial candidates provided by the user.

Attributes

def sortPool(): Unit

Sort the pool by the objective function value of the candidate solutions.

Sort the pool by the objective function value of the candidate solutions.

Attributes

Inherited methods

def fg(x: VectorD): Double

The objective function f plus a weighted penalty based on the constraint function g. Override for constrained optimization and ignore for unconstrained optimization.

The objective function f plus a weighted penalty based on the constraint function g. Override for constrained optimization and ignore for unconstrained optimization.

Value parameters

x

the coordinate values of the current point

Attributes

Inherited from:
Minimizer
def lossPerEpoch(): ArrayBuffer[Double]

Return the loss function for each epoch.

Return the loss function for each epoch.

Attributes

Inherited from:
MonitorEpochs
def plotLoss(): Unit

Attributes

Inherited from:
MonitorEpochs
def resolve(n: Int, step_: Double = ..., toler: Double = ...): FuncVec

Solve the following Non-Linear Programming (NLP) problem: min { f(x) | g(x) <= 0 }. To use explicit functions for gradient, replace gradient (fg, x._1 + s) with gradientD (df, x._1 + s). This method uses multiple random restarts.

Solve the following Non-Linear Programming (NLP) problem: min { f(x) | g(x) <= 0 }. To use explicit functions for gradient, replace gradient (fg, x._1 + s) with gradientD (df, x._1 + s). This method uses multiple random restarts.

Value parameters

n

the dimensionality of the search space

step_

the initial step size

toler

the tolerance

Attributes

Inherited from:
Minimizer

Inherited fields

protected val epochLoss: ArrayBuffer[Double]

Attributes

Inherited from:
MonitorEpochs