eda

package
v0.0.0-...-b9e61c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(opts ...Option) func(Model)

And can be used to chain together multiple settings in order to prepackage common settings among several algorithms. Consider: should this be called Cons?

func AttemptsAfterBest

func AttemptsAfterBest(i int) func(Model)

AttemptsAfterBest terminates an EDA if it fails to improve on its best model after i iterations

func BaseValue

func BaseValue(bv float64) func(Model)

BaseValue is an option which sets the starting environment values

func BitStringBivariate

func BitStringBivariate(samples []*env.F, a, b int) (float64, float64)

BitStringBivariate returns the probabilities p(a|b=t) and p(a|b=f)

func ConditionedBSEnv

func ConditionedBSEnv(senv, tenv, fenv *env.F, a int) *env.F

ConditionedBSEnv returns either tenv or fenv depending on the value at senv[a]

func DefContinue

func DefContinue(m Model) bool

DefContinue is the Default Continue function

func DefReport

func DefReport(m Model)

DefReport is the Default Report function

func FMutator

func FMutator(mtr mut.FloatMutator) func(Model)

FMutator sets a model's float mutator

func FitnessFunc

func FitnessFunc(f Fitness) func(Model)

FitnessFunc is an option which sets the fitness function

func GetSample

func GetSample(e *env.F) *env.F

GetSample returns an environment candidate where each input element is treated as a percent from 0 to 1 inclusive, and each output is each input randomized to either 1 or 0.

func GoalFitness

func GoalFitness(gf int) func(Model)

GoalFitness is an option which sets the goal fitness

func LMutator

func LMutator(mtr mut.FloatMutator) func(Model)

LMutator sets a model's learning rate mutator

func LearningRate

func LearningRate(lr float64) func(Model)

LearningRate is an option which sets the learning rate

func LearningSamples

func LearningSamples(l int) func(Model)

LearningSamples sets the number of learning samples the algorithm will use. learning samples should be less than samples.

func Length

func Length(l int) func(Model)

Length is an option which sets the environment length

func MaxIterations

func MaxIterations(j int) func(Model)

MaxIterations sets the maximum number of iterations the algorithm will evolve before preemptively stopping

func MemberEnvs

func MemberEnvs(mem []pop.Individual) []*env.F

MemberEnvs converts a set of EnvInd members to a smaple array

func MutationRate

func MutationRate(mr float64) func(Model)

MutationRate is an option which sets the mutation rate

func NSamples

func NSamples(n int, senv *env.F) []*env.F

NSamples returns an array of n samples from calling GetSample

func Name

func Name(s string) func(Model)

Name sets the name of the model / test being run, for reporting

func PopEnvs

func PopEnvs(p *pop.Population) []*env.F

PopEnvs converts a population of EnvInd members to a sample array

func Randomize

func Randomize(r bool) func(Model)

Randomize is an option which will randomize initial environment values

func ReportFunc

func ReportFunc(r func(Model)) func(Model)

func SampleFitnesses

func SampleFitnesses(m Model, samples []*env.F) ([]int, []*env.F)

SampleFitnesses returns a sorted list of fitnesses for the given samples in model m, and sorts samples so that the fitness of samples[i] is in fitnesses[i]

func Samples

func Samples(s int) func(Model)

Samples sets the number of samples the algorithm will use.

func SelectionMethod

func SelectionMethod(sm selection.Method) func(Model)

SelectionMethod sets the algorithm's population selection method for algorithms that use selection

func StopCondition

func StopCondition(c func(m Model) bool) func(Model)

StopCondition replaces the default stop condition (goal fitness reached or maximum iteration reached)

func TrackBest

func TrackBest(m Model)

TrackBest sets whether or not the algorithm should keep track of the best model it has found so far

func TrackFitnessRuns

func TrackFitnessRuns(b bool) func(Model)

TrackFitnessRuns tells the model to track how many times it calls its fitness function.

func TrackTime

func TrackTime(m Model)

func UnivariateFromSamples

func UnivariateFromSamples(samples []*env.F, a int) float64

UnivariateFromSamples returns the average value within a given index in a sample set. Used in BMDA for roots.

Types

type BMDA

type BMDA struct {
	Base
	BF      FullBivariateEnv
	LastPop *pop.Population
}

BMDA represents the Bivariate Marginal Distribution Algorithm

func (*BMDA) Adjust

func (bmda *BMDA) Adjust() Model

Adjust on a BMDA is incomplete

func (*BMDA) BMDAPop

func (bmda *BMDA) BMDAPop(roots []int, children [][]int) []*env.F

BMDAPop creates a population from the forest generated by a BMDA So we pick random (all) roots and go down through all of their children using their parents as the elements they are dependant on

func (*BMDA) ChiSquared

func (bmda *BMDA) ChiSquared(a, b int) float64

ChiSquared on a bmda calculates a chi^2 value where the observed values are the unconditional bivariate probabilities and the expected values are the univariate probabilities multiplied together.

func (*BMDA) GetSample

func (bmda *BMDA) GetSample(tenv, fenv *env.F, roots []int, children [][]int) *env.F

GetSample uses the forest given to create a sample

func (*BMDA) NSamples

func (bmda *BMDA) NSamples(n int, tenv, fenv *env.F, roots []int, children [][]int) []*env.F

NSamples returns a set of samples using bmda.GetSample

func (*BMDA) SetChildSample

func (bmda *BMDA) SetChildSample(senv, tenv, fenv *env.F, children [][]int, parent int)

SetChildSample is used by GetSample to chain through all children in a tree

func (*BMDA) SetChildren

func (bmda *BMDA) SetChildren(samples []*env.F, tenv, fenv *env.F, children [][]int, parent int)

SetChildren is used by BMDAPop to chain through all children in a tree

func (*BMDA) UpdateFromPop

func (bmda *BMDA) UpdateFromPop()

UpdateFromPop regenerates bmda.F and bmda.BF using bmda.LastPop

type BOA

type BOA struct {
	Base
	P *pop.Population
}

BOA represents the Bayesian Optimization Algorithm

func (*BOA) Adjust

func (boa *BOA) Adjust() Model

Adjust on a BOA produces a bayes net from selections of the BOA's population, then replaces part of its population with samples from the bayes net.

func (*BOA) Mutate

func (boa *BOA) Mutate()

Mutate on a BOA mutate's the BOA's population

type Base

type Base struct {
	*env.F
	// contains filtered or unexported fields
}

Base is a struct which all EDA models should be composed of so that they can use generic option functions. Future work: create several kinds of bases, where each base satisfies a Base interface, where all options will call a Set function on the interface, so that models that do not want as many fields as Base provides do not need to have wasted memory in their structs.

func DefaultBase

func DefaultBase(opts ...Option) (Base, error)

DefaultBase initializes some base fields to non-automatic zero values

func (*Base) Adjust

func (b *Base) Adjust() Model

Adjust is the default Adjust method, which is expected to be overwritten

func (*Base) BaseModel

func (b *Base) BaseModel() *Base

BaseModel is a function which is used by all Options to obtain the base from any given model. All models must implement BaseModel.

func (*Base) Continue

func (b *Base) Continue() bool

Continue is a wrapper around b.cont

func (*Base) Fitness

func (b *Base) Fitness() int

Fitness is shorthand for fitness(b.F)

func (*Base) GenIndices

func (b *Base) GenIndices() []int

GenIndices is a utility function to generate a list of ints 0 ... b.length

func (*Base) Mutate

func (b *Base) Mutate()

Mutate is the default mutation function

func (*Base) Pop

func (b *Base) Pop() *pop.Population

Pop generates a population of EnvInds from sampling base.F

func (*Base) ReplaceLowFitnesses

func (b *Base) ReplaceLowFitnesses(p *pop.Population, newMembers []*env.F)

ReplaceLowFitnesses sorts the given population members by fitness and replaces the lowest members of those with the newMembers.

func (*Base) SelectLearning

func (b *Base) SelectLearning(p *pop.Population) []pop.Individual

SelectLearning selects b.learningSamples members from the given population

type BayesNet

type BayesNet struct {
	// contains filtered or unexported fields
}

This bayes net construction code is based on http://www.cleveralgorithms.com/nature-inspired/probabilistic/boa.html

func NewBayesNet

func NewBayesNet(samples []*env.F) *BayesNet

func (*BayesNet) Prob

func (bn *BayesNet) Prob(i int, curSample *env.F, samples []*env.F) float64

func (*BayesNet) Sample

func (bn *BayesNet) Sample(curSamples []*env.F, n int) []*env.F

func (*BayesNet) SampleOrdered

func (bn *BayesNet) SampleOrdered(samples []*env.F, ordered []int) *env.F

func (*BayesNet) Topographical

func (bn *BayesNet) Topographical() []int

func (*BayesNet) TryConnect

func (bn *BayesNet) TryConnect(samples []*env.F, index int) (float64, int)

func (*BayesNet) ViableParents

func (bn *BayesNet) ViableParents(index int) []int

type BestCandidates

type BestCandidates struct {
	Front  *Candidate
	Back   *Candidate
	Length int
	Limit  int
}

BestCandidates represents the top N candidates sampled from an EDA. Todo: This should be a heap, not a linked list, for sufficiently large sizes

func NewBestCandidates

func NewBestCandidates(m Model, bcsLimit int, sFunc func() *env.F) *BestCandidates

NewBestCandidates creates a default BestCandidates with model.samples samples added to the candidate list. if sFunc is not supplied, GetSample on a copy of the model's initial environment will be used.

func (*BestCandidates) Add

func (bc *BestCandidates) Add(f int, c *env.F)

Add appends a new candidate to the best candidates, if it is better than any existing candidate

func (*BestCandidates) Slice

func (bc *BestCandidates) Slice() []*env.F

Slice converts BestCandidates from a linked list to a slice

type BivariateEnv

type BivariateEnv struct {
	// contains filtered or unexported fields
}

BivariateEnv represents the relationship (a|b) for all b in some sample set

func NewBSBivariateEnv

func NewBSBivariateEnv(samples []*env.F, a int) *BivariateEnv

NewBSBivariateEnv returns a bivariate environment from samples and a index a for (a|b)

type CGA

type CGA struct {
	Base
}

CGA is an EDA that implements the Compact Genetic Algorithm adjustment function

func (*CGA) Adjust

func (cga *CGA) Adjust() Model

Adjust on a cga samples from a distribution and obtains the most and least fit results from that distribution, modifying the distribution depending on whether the most and least fit candidates share the same value at each index of their bitstring

type Candidate

type Candidate struct {
	*env.F
	Fitness int
	Next    *Candidate
	Prev    *Candidate
}

Candidate is an individual candidate in a BestCandidates list

type ComplexDiff

type ComplexDiff struct {
	// contains filtered or unexported fields
}

ComplexDiff is a pair of indices and some value representing how valuable the pair is

type ComplexHeap

type ComplexHeap []ComplexDiff

ComplexHeap is a heap of ComplexDiffs, heaped on their gain value

func (ComplexHeap) Len

func (ch ComplexHeap) Len() int

func (ComplexHeap) Less

func (ch ComplexHeap) Less(i, j int) bool

func (*ComplexHeap) Pop

func (ch *ComplexHeap) Pop() interface{}

Pop is boilerplate for popping a heap

func (*ComplexHeap) Push

func (ch *ComplexHeap) Push(x interface{})

Push is boilerplate for pushing to a heap

func (ComplexHeap) Swap

func (ch ComplexHeap) Swap(i, j int)

type ECGA

type ECGA struct {
	Base
	P      *pop.Population
	Blocks [][]int
}

ECGA represents the Extended Compact Genetic Algorithm

func (*ECGA) Adjust

func (ecga *ECGA) Adjust() Model

Adjust for an ecga creates an ecga population based on the ecga's understanding of its building blocks and then refreshes those building blocks

func (*ECGA) BlockComplexity

func (ecga *ECGA) BlockComplexity(envs []*env.F, b []int) float64

BlockComplexity returns the complexity of a given block definition

func (*ECGA) CombinedComplexity

func (ecga *ECGA) CombinedComplexity(envs []*env.F, b []int) float64

CombinedComplexity returns the sum marginal complexity of the block's indices in the sample set

func (*ECGA) ECGAPop

func (ecga *ECGA) ECGAPop() *pop.Population

ECGAPop returns a population where some members are from ecga.P and some are sampled from ecga.Blocks and ecga.P at random. The proportion of new to old members is based on learningRate.

func (*ECGA) MDMModel

func (ecga *ECGA) MDMModel(selected []pop.Individual)

MDMModel refreshes the ecga's building blocks

func (*ECGA) ModelComplexity

func (ecga *ECGA) ModelComplexity(b []int) float64

ModelComplexity punishes blocks exponentially for being long in effect, this means ecgas can't develop building blocks longer than maybe four or five indices.

func (*ECGA) Mutate

func (ecga *ECGA) Mutate()

Mutate on an ecga mutates each element of the ecga population

func (*ECGA) UpdateMDM

func (ecga *ECGA) UpdateMDM()

UpdateMDM updates the building blocks and environment of an ecga

type EDA

type EDA func(...Option) (Model, error)

An EDA is a function which constructs an EDA model from a set of initialization options.

type EnvInd

type EnvInd struct {
	*env.F
}

EnvInd is a wrapper around an environment and serves as the basis for the UMDA population

func NewEnvInd

func NewEnvInd(e *env.F) *EnvInd

NewEnvInd initializes a EnvInd to be a sampling of an env

func (*EnvInd) CanCrossover

func (ei *EnvInd) CanCrossover(other pop.Individual) bool

CanCrossover always returns false for a EnvInd

func (*EnvInd) Crossover

func (ei *EnvInd) Crossover(other pop.Individual) pop.Individual

Crossover is NOP on a EnvInd

func (*EnvInd) Fitness

func (ei *EnvInd) Fitness(input, expected [][]float64) int

Fitness is a dummy function on a EnvInd

func (*EnvInd) Mutate

func (ei *EnvInd) Mutate()

Mutate is a NOP on a EnvInd

func (*EnvInd) Print

func (ei *EnvInd) Print()

Print prints a EnvInd

type FitSample

type FitSample struct {
	// contains filtered or unexported fields
}

FitSample is a tuple of a sample and its fitness

type Fitness

type Fitness func(e *env.F) int

A Fitness function for EDAs return an integer from a given vector of floats

type FullBivariateEnv

type FullBivariateEnv []*BivariateEnv

A FullBivariateEnv represents a 2d array of Bivariate environments where each potential pairing of (a|b) is represented at index [a][b]

func NewFullBSBivariateEnv

func NewFullBSBivariateEnv(samples []*env.F) FullBivariateEnv

NewFullBSBivariateEnv returns a FullBivariateEnv under the assumption that the input samples are bitstrings.

type MIMIC

type MIMIC struct {
	Base
	PTF     *env.F
	Indices []int
}

MIMIC is an EDA of the Mutual information maximizing input clustering algorithm

func (*MIMIC) Adjust

func (mimic *MIMIC) Adjust() Model

Adjust on a MIMIC generates samples from MIMIC's chain model, filters them with a straight greed selection algorithm to get the top-percentile samples and retrains its chain on the top-percentile samples. Todo: would mimic perform way better if it wasn't using a straight greed selection? (the paper doesn't refer to this selection algorithm as a selection algorithm but it totally is)

func (*MIMIC) GetSample

func (mimic *MIMIC) GetSample() *env.F

GetSample on a MIMIC iterates through the marked indices of the model where the first index uses a univariate sampling and each following index is a bivariate sampling based on the result of the previous sampled index.

func (*MIMIC) NSamples

func (mimic *MIMIC) NSamples() []*env.F

NSamples runs mimic.GetSample n times to produce a sample list

func (*MIMIC) UpdateFromSamples

func (mimic *MIMIC) UpdateFromSamples(samples []*env.F)

UpdateFromSamples updates the two floating point vectors that a MIMIC stores, the former for the probability that an element is true given the former in the index list is true, and the latter given the former in the index list is false.

type Model

type Model interface {
	BaseModel() *Base
	Continue() bool
	Adjust() Model
	ToEnv() *env.F
	Mutate()
}

A Model is an iteratively adjusting EDA model

func BMDAModel

func BMDAModel(opts ...Option) (Model, error)

BMDAModel returns an initialized BMDA

func BOAModel

func BOAModel(opts ...Option) (Model, error)

BOAModel returns a BOA EDA

func CGAModel

func CGAModel(opts ...Option) (Model, error)

CGAModel initializes a CGA EDA

func ECGAModel

func ECGAModel(opts ...Option) (Model, error)

ECGAModel returns an initialized ECGA EDA

func Loop

func Loop(eda EDA, opts ...Option) (Model, error)

Loop is the main EDA loop

func MIMICModel

func MIMICModel(opts ...Option) (Model, error)

MIMICModel returns an initialized MIMIC EDA

func PBILModel

func PBILModel(opts ...Option) (Model, error)

PBILModel initializes a PBIL EDA

func SHCLVNDModel

func SHCLVNDModel(opts ...Option) (Model, error)

SHCLVNDModel initializes a SHCLVND EDA

func UMDAModel

func UMDAModel(opts ...Option) (Model, error)

UMDAModel initializes a UMDA EDA

type Option

type Option func(Model)

Option is a functional option type to be passed in variadically to model creation functions. All options will take the base behind a model and set some values on that base or otherwise manipulate the base. Options should be able to be called on a model in any order without the order changing the output model.

type PBIL

type PBIL struct {
	Base
}

PBIL is an EDA built on the Population based incremental learning algorithm

func (*PBIL) Adjust

func (pbil *PBIL) Adjust() Model

Adjust for a PBIL takes the learningSamples best samples from the pbil's distribution and reinforces the distribution in the direction of each of the taken samples by learningRate/learningSamples

type SHCLVND

type SHCLVND struct {
	Base
	Sigma float64
}

SHCLVND represents the Stochastic Hill Climbing with Learning by Vectors of Normal Distributions algorithm.

func (*SHCLVND) Adjust

func (shc *SHCLVND) Adjust() Model

Adjust on a SHCLVND polls learningSamples best samples and creates an average candidate from the collected samples. Then the distribution of the SHCLVND is reinforced closer to the average candidate, and the standard deviation used to generate the samples is reduced.

func (*SHCLVND) SigmaSample

func (shc *SHCLVND) SigmaSample() *env.F

SigmaSample is a way to sample an environment based on a standard deviation spread from an average

type UMDA

type UMDA struct {
	Base
}

UMDA represents the Univariate Marginal Distribution Algorithm

func (*UMDA) Adjust

func (umda *UMDA) Adjust() Model

Adjust on a UMDA creates a population from sampling the umda's distribution, then selects from that population top fitness members, then sets its distribution to be the average of the selected members

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL