eevee3

package
v0.0.0-...-07e8d1b Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

README

eevee3 SDK

This directory represents the path to import all eevee3 types

Documentation

Index

Constants

View Source
const (
	PredicateReasonPopulationWasEmpty          = "population is empty"
	PredicateReasonPopulationAllScoresSame     = "all scores were equal"
	PredicateReasonPopulationAllSolutionsEqual = "all solutions were equal"
	PredicateReasonScoreWasHit                 = "defined score threshold was hit"
)

Variables

View Source
var (
	RecordEverything = &RecorderConfig{
		ExperimentStart:   true,
		InitialPopulation: true,
		Generation:        true,
		Crossover:         true,
		Mutate:            true,
		Selection:         true,
		Terminate:         true,
	}
)

Functions

func CrossoverSliceByMidpoint

func CrossoverSliceByMidpoint[T any](s1, s2 []T)

CrossoverSliceByMidpoint performs an in-place crossover on an exact mid-point split of both slices. It is the caller's responsibility to ensure that the input slices are safe to be mutated.

This function panics if len(s1) != len(s2)

func CrossoverSliceByRandomPoint

func CrossoverSliceByRandomPoint[T any](s1, s2 []T)

CrossoverSliceByRandomPoint performs an in-place crossover on a random point-of-split of both slices. The point-of-split is randomly decided, but is guaranteed to be within the bounds of both slices. It is the caller's responsibility to ensure that the input slices are safe to be mutated.

This function panics if len(s1) != len(s2)

func MutateRandomIndex

func MutateRandomIndex[T any](slice []T, changeFunc func(T) T)

Types

type ConsistentSizeSliceSolution

type ConsistentSizeSliceSolution[E comparable] struct {
	Slice []E
}

func NewConsistentSizeSliceSolution

func NewConsistentSizeSliceSolution[E comparable](initialValue []E) *ConsistentSizeSliceSolution[E]

func (*ConsistentSizeSliceSolution[E]) Clone

func (c *ConsistentSizeSliceSolution[E]) Clone() Solution[[]E]

func (*ConsistentSizeSliceSolution[E]) Describe

func (c *ConsistentSizeSliceSolution[E]) Describe() string

func (*ConsistentSizeSliceSolution[E]) Equals

func (c *ConsistentSizeSliceSolution[E]) Equals(other Solution[[]E]) bool

func (*ConsistentSizeSliceSolution[E]) Score

func (c *ConsistentSizeSliceSolution[E]) Score() float64

func (*ConsistentSizeSliceSolution[E]) String

func (c *ConsistentSizeSliceSolution[E]) String() string

func (*ConsistentSizeSliceSolution[E]) Value

func (c *ConsistentSizeSliceSolution[E]) Value() []E

type Controller

type Controller[T any] struct {
	Recorder Recorder[T]

	// GenerationCycles is the number of generation cycles
	// to run the experiment for
	GenerationCycles int

	// PopulationSize represents the number of solutions
	// in each generation corpus
	PopulationSize int

	// MutationProbability is the probability that
	// each solutions has to mutate on each generation cycle
	MutationProbability float64

	// CrossoverProbability is the probability that
	// each pair of solutions has to crossover together
	CrossoverProbability float64

	// CrossoverSelectionStrategy is the strategy used to select pairs
	// for crossover
	CrossoverSelectionStrategy PairwiseSelectionStrategy[T]

	// NextGenerationSelectionStrategy is the strategy used in each iteration
	// to select the next corpus of solutions
	NextGenerationSelectionStrategy SubgroupSelectionStrategy[T]

	// TerminationConditions allows for input of conditions
	// that may allow for early termination of the experiment
	TerminationConditions []PopulationPredicate[T]
}

Controller represents inner structure data about the experiment, as well as strategies for handling experiment execution.

type Crossover

type Crossover[TUnderlying any] interface {
	// Cross takes 2 solutions instances and performs a crossover on them
	Cross(solution1, solution2 Solution[TUnderlying]) (Solution[TUnderlying], Solution[TUnderlying])
}

type Handler

type Handler[TUnderlying any] interface {
	Crossover[TUnderlying]
	Mutation[TUnderlying]

	// NewSolution returns a single solutions instance
	NewSolution() Solution[TUnderlying]
	NewSolutionFrom(innerValue TUnderlying) Solution[TUnderlying]
}

Handler is the interface of the handler used for operating a problem

type IOWriterRecorder

type IOWriterRecorder[T any] struct {
	// contains filtered or unexported fields
}

func NewIOWriterRecorder

func NewIOWriterRecorder[T any](writer io.Writer, config *RecorderConfig) *IOWriterRecorder[T]

NewIOWriterRecorder creates a new IOWriterRecorder

func (*IOWriterRecorder[T]) Crossover

func (r *IOWriterRecorder[T]) Crossover(in1, in2, out1, out2 Solution[T])

func (*IOWriterRecorder[T]) ExperimentStart

func (r *IOWriterRecorder[T]) ExperimentStart(controller Controller[T])

func (*IOWriterRecorder[T]) Generation

func (r *IOWriterRecorder[T]) Generation(generation int)

func (*IOWriterRecorder[T]) InitialPopulation

func (r *IOWriterRecorder[T]) InitialPopulation(population []Solution[T])

func (*IOWriterRecorder[T]) Mutate

func (r *IOWriterRecorder[T]) Mutate(in, out Solution[T])

func (*IOWriterRecorder[T]) Selection

func (r *IOWriterRecorder[T]) Selection(before, after []Solution[T])

func (*IOWriterRecorder[T]) Terminate

func (r *IOWriterRecorder[T]) Terminate(result Result[T])

type Mutation

type Mutation[TUnderlying any] interface {
	// Mutate takes a single solutions instance and performs a mutation on it
	Mutate(solution Solution[TUnderlying]) Solution[TUnderlying]
}

type PairwiseSelectionStrategy

type PairwiseSelectionStrategy[T any] func(corpus []Solution[T]) [][2]Solution[T]

func SelectBestPairs

func SelectBestPairs[T any]() PairwiseSelectionStrategy[T]

SelectBestPairs returns a k-size slice of pairs of solutions whose scores are elitist, ie. Best and 2nd-best are paired, 3rd-best and 4th-best are paired.

func SelectRandomPairs

func SelectRandomPairs[T any]() PairwiseSelectionStrategy[T]

SelectRandomPairs returns a k-size slice of randomly picked pairs of solutions

type PopulationPredicate

type PopulationPredicate[T any] func([]Solution[T]) (PredicateReason, bool)

func TrueWhenAllScoresSame

func TrueWhenAllScoresSame[T any]() PopulationPredicate[T]

TrueWhenAllScoresSame returns a PopulationPredicate that returns true when all solutions of the input population corpus have the same score

func TrueWhenAllSolutionsEqual

func TrueWhenAllSolutionsEqual[T any]() PopulationPredicate[T]

TrueWhenAllSolutionsEqual returns a PopulationPredicate that returns true when all solutions of the input population corpus are identical

func TrueWhenAtLeastNScores

func TrueWhenAtLeastNScores[T any](n int, scoreThresholdFunc func(float64) bool) PopulationPredicate[T]

TrueWhenAtLeastNScores returns a PopulationPredicate that returns true when at least [n] solutions in the corpus fulfill the [scoreThresholdFunc] (returns true) given.

If n > len(population), the predicate will always return false.

type PredicateReason

type PredicateReason string

type Recorder

type Recorder[T any] interface {
	// ExperimentStart marks the start of the experiment
	ExperimentStart(controller Controller[T])

	// InitialPopulation records the initial population
	InitialPopulation(population []Solution[T])

	// Generation records whenever a new generation cycle begins
	Generation(generation int)

	// Crossover records each crossover event
	Crossover(in1, in2, out1, out2 Solution[T])

	// Mutate records each mutation event
	Mutate(in, out Solution[T])

	// Selection records the selection process at the end of each cycle
	Selection(before, after []Solution[T])

	// Terminate records a termination
	Terminate(result Result[T])
}

Recorder is a logger interface for visibility into the iteration process. All method implementations must be concurrent-safe.

type RecorderConfig

type RecorderConfig struct {
	ExperimentStart   bool
	InitialPopulation bool
	Generation        bool
	Crossover         bool
	Mutate            bool
	Selection         bool
	Terminate         bool
}

type Result

type Result[T any] struct {
	Population             []Solution[T] `json:"population"`
	TerminatedAtGeneration int           `json:"terminatedAtGeneration"`
	TerminationReason      string        `json:"terminationReason"`
}

Result is the output of a single experiment run

func Run

func Run[T any](handler Handler[T], controller *Controller[T]) *Result[T]

func RunN

func RunN[T any](handler Handler[T], controller *Controller[T], n int) *Result[T]

RunN is similar to Run, but only returns the top (by score) n solutions in the final population corpus

func RunSingle

func RunSingle[T any](handler Handler[T], controller *Controller[T]) *Result[T]

RunSingle is a helper for RunN(handler, controller, 1)

func (*Result[T]) Describe

func (r *Result[T]) Describe() string

type Solution

type Solution[TUnderlying any] interface {
	fmt.Stringer

	// Score returns the solutions's individual score
	Score() float64

	// Value returns the underlying value backing the solutions
	Value() TUnderlying

	// Equals returns true if the solutions is
	// identical to the given other solutions
	Equals(Solution[TUnderlying]) bool

	// Clone returns a clone that has no shared memory references
	// with the original
	Clone() Solution[TUnderlying]

	// Describe returns textual information describing the solutions.
	// This may be information to be presented at the end of a run, etc.
	Describe() string
}

Solution is a standard interface for a potential solutions in each corpus

type SolutionPredicate

type SolutionPredicate[T any] func(solution Solution[T]) (PredicateReason, bool)

type SubgroupSelectionStrategy

type SubgroupSelectionStrategy[T any] func(corpus []Solution[T]) []Solution[T]

func SelectBestAndWorstSubgroup

func SelectBestAndWorstSubgroup[T any](bestRatio float64) SubgroupSelectionStrategy[T]

func SelectBestSubgroup

func SelectBestSubgroup[T any]() SubgroupSelectionStrategy[T]

func SelectRandomSubgroup

func SelectRandomSubgroup[T any]() SubgroupSelectionStrategy[T]

Jump to

Keyboard shortcuts

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