Documentation ¶
Index ¶
- type Crossover
- type FullInit
- type GP
- func (gp GP) BestProgram() (Program, error)
- func (gp *GP) Fit(X [][]float64, Y []float64, W []float64, XVal [][]float64, YVal []float64, ...) error
- func (gp GP) Predict(X [][]float64, proba bool) ([]float64, error)
- func (gp GP) PredictPartial(x []float64, proba bool) (float64, error)
- func (gp GP) String() string
- type GPConfig
- type GrowInit
- type HoistMutation
- type Initializer
- type Mutator
- type PointMutation
- type Program
- func (prog Program) Clone() eaopt.Genome
- func (prog *Program) Crossover(prog2 eaopt.Genome, rng *rand.Rand)
- func (prog Program) Evaluate() (float64, error)
- func (prog Program) MarshalJSON() ([]byte, error)
- func (prog *Program) Mutate(rng *rand.Rand)
- func (prog Program) Predict(X [][]float64, proba bool) ([]float64, error)
- func (prog Program) PredictPartial(x []float64, proba bool) (float64, error)
- func (prog Program) String() string
- func (prog *Program) UnmarshalJSON(bytes []byte) error
- type RampedHaldAndHalfInit
- type SubtreeCrossover
- type SubtreeMutation
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Crossover ¶
A Crossover takes two Operators and combines them in order to produce two new Operators.
type GP ¶
type GP struct { GPConfig EvalMetric metrics.Metric LossMetric metrics.Metric Functions []op.Operator Initializer Initializer GA *eaopt.GA PointMutation PointMutation SubtreeMutation SubtreeMutation HoistMutation HoistMutation SubtreeCrossover SubtreeCrossover X [][]float64 Y []float64 W []float64 XVal [][]float64 YVal []float64 WVal []float64 // contains filtered or unexported fields }
An GP links all the different components together and can be used to train Programs on a dataset. You shouldn't instantiate this struct directly; instead you should use the GPConfig struct and call it's NewGP method.
func (GP) BestProgram ¶
BestProgram returns the GP's best obtained Program.
func (*GP) Fit ¶
func (gp *GP) Fit( X [][]float64, Y []float64, W []float64, XVal [][]float64, YVal []float64, WVal []float64, verbose bool, ) error
Fit an GP to a dataset.
func (GP) PredictPartial ¶
PredictPartial is a convenience function on top of Predict to make predictions on a single instance.
type GPConfig ¶
type GPConfig struct { // Learning parameters LossMetric metrics.Metric EvalMetric metrics.Metric ParsimonyCoeff float64 PolishBest bool // Function parameters Funcs string ConstMin float64 ConstMax float64 PConst float64 PFull float64 PLeaf float64 MinHeight uint MaxHeight uint // Genetic algorithm parameters NPopulations uint NIndividuals uint NGenerations uint PHoistMutation float64 PSubtreeMutation float64 PPointMutation float64 PointMutationRate float64 PSubtreeCrossover float64 // Other RNG *rand.Rand }
A GPConfig contains all the information needed to instantiate an GP.
Example ¶
var conf = NewDefaultGPConfig() conf.LossMetric = metrics.F1{} var est, err = conf.NewGP() if err != nil { fmt.Println(err) } fmt.Println(est)
Output: Loss metric: neg_f1 Evaluation metric: f1 Parsimony coefficient: 0 Polish best program: true Functions: add,sub,mul,div Constant minimum: -5 Constant maximum: 5 Constant probability: 0.5 Full initialization probability: 0.5 Terminal probability: 0.3 Minimum height: 3 Maximum height: 5 Number of populations: 1 Number of individuals per population: 100 Number of generations: 30 Hoist mutation probability: 0.1 Subtree mutation probability: 0.1 Point mutation probability: 0.1 Point mutation rate: 0.3 Subtree crossover probability: 0.5
func NewDefaultGPConfig ¶
func NewDefaultGPConfig() GPConfig
NewDefaultGPConfig returns a GPConfig with default values.
type GrowInit ¶
type GrowInit struct {
PLeaf float64
}
GrowInit can generate an Operator who's depth lies in [MinHeight, MaxHeight].
type HoistMutation ¶
type HoistMutation struct {
Weight1, Weight2 func(operator op.Operator, depth uint, rng *rand.Rand) float64
}
HoistMutation replaces an Operator by of it's operands.
type Initializer ¶
type Initializer interface { Apply( minHeight uint, maxHeight uint, newOp func(leaf bool, rng *rand.Rand) op.Operator, rng *rand.Rand, ) op.Operator }
An Initializer generates a random Operator with random operands.
type PointMutation ¶
PointMutation randomly replaces Operators.
type Program ¶
A Program is a thin layer on top of an Operator.
func (Program) MarshalJSON ¶
MarshalJSON serializes a Program.
func (Program) PredictPartial ¶
PredictPartial is a convenience function on top of Predict to make predictions on a single instance.
func (*Program) UnmarshalJSON ¶
UnmarshalJSON parses a Program.
type RampedHaldAndHalfInit ¶
RampedHaldAndHalfInit randomly uses GrowInit and FullInit. If it uses FullInit then it uses a random height.
type SubtreeCrossover ¶
type SubtreeCrossover struct {
Weight func(operator op.Operator, depth uint, rng *rand.Rand) float64
}
SubtreeCrossover applies subtree crossover to two Operators.