Documentation
¶
Index ¶
- func CalcHeight(op Operator) (d uint)
- func Count(op Operator, condition func(Operator) bool) (n uint)
- func CountConsts(op Operator) uint
- func CountDistinctVars(op Operator) uint
- func CountLeaves(op Operator) uint
- func CountOps(op Operator) uint
- func CountVars(op Operator) uint
- func GetConsts(op Operator) []float64
- func GetVars(op Operator) []uint
- type Abs
- func (abs Abs) Arity() uint
- func (abs Abs) Diff(i uint) Operator
- func (abs Abs) Eval(X [][]float64) []float64
- func (abs Abs) Name() string
- func (abs Abs) Operand(i uint) Operator
- func (abs Abs) SetOperand(i uint, op Operator) Operator
- func (abs Abs) Simplify() Operator
- func (abs Abs) String() string
- type Add
- func (add Add) Arity() uint
- func (add Add) Diff(i uint) Operator
- func (add Add) Eval(X [][]float64) []float64
- func (add Add) Name() string
- func (add Add) Operand(i uint) Operator
- func (add Add) SetOperand(i uint, op Operator) Operator
- func (add Add) Simplify() Operator
- func (add Add) String() string
- type CodeDisplay
- type Const
- func (c Const) Arity() uint
- func (c Const) Diff(i uint) Operator
- func (c Const) Eval(X [][]float64) []float64
- func (c Const) Name() string
- func (c Const) Operand(i uint) Operator
- func (c Const) SetOperand(i uint, op Operator) Operator
- func (c Const) Simplify() Operator
- func (c Const) String() string
- type Cos
- func (cos Cos) Arity() uint
- func (cos Cos) Diff(i uint) Operator
- func (cos Cos) Eval(X [][]float64) []float64
- func (cos Cos) Name() string
- func (cos Cos) Operand(i uint) Operator
- func (cos Cos) SetOperand(i uint, op Operator) Operator
- func (cos Cos) Simplify() Operator
- func (cos Cos) String() string
- type DirDisplay
- type Displayer
- type Div
- func (div Div) Arity() uint
- func (div Div) Diff(i uint) Operator
- func (div Div) Eval(X [][]float64) []float64
- func (div Div) Name() string
- func (div Div) Operand(i uint) Operator
- func (div Div) SetOperand(i uint, op Operator) Operator
- func (div Div) Simplify() Operator
- func (div Div) String() string
- type GraphvizDisplay
- type If
- type Inv
- func (inv Inv) Arity() uint
- func (inv Inv) Diff(i uint) Operator
- func (inv Inv) Eval(X [][]float64) []float64
- func (inv Inv) Name() string
- func (inv Inv) Operand(i uint) Operator
- func (inv Inv) SetOperand(i uint, op Operator) Operator
- func (inv Inv) Simplify() Operator
- func (inv Inv) String() string
- type Max
- func (max Max) Arity() uint
- func (max Max) Diff(i uint) Operator
- func (max Max) Eval(X [][]float64) []float64
- func (max Max) Name() string
- func (max Max) Operand(i uint) Operator
- func (max Max) SetOperand(i uint, op Operator) Operator
- func (max Max) Simplify() Operator
- func (max Max) String() string
- type Min
- func (min Min) Arity() uint
- func (min Min) Diff(i uint) Operator
- func (min Min) Eval(X [][]float64) []float64
- func (min Min) Name() string
- func (min Min) Operand(i uint) Operator
- func (min Min) SetOperand(i uint, op Operator) Operator
- func (min Min) Simplify() Operator
- func (min Min) String() string
- type Mul
- func (mul Mul) Arity() uint
- func (mul Mul) Diff(i uint) Operator
- func (mul Mul) Eval(X [][]float64) []float64
- func (mul Mul) Name() string
- func (mul Mul) Operand(i uint) Operator
- func (mul Mul) SetOperand(i uint, op Operator) Operator
- func (mul Mul) Simplify() Operator
- func (mul Mul) String() string
- type Neg
- func (neg Neg) Arity() uint
- func (neg Neg) Diff(i uint) Operator
- func (neg Neg) Eval(X [][]float64) []float64
- func (neg Neg) Name() string
- func (neg Neg) Operand(i uint) Operator
- func (neg Neg) SetOperand(i uint, op Operator) Operator
- func (neg Neg) Simplify() Operator
- func (neg Neg) String() string
- type Operator
- func ParseFunc(name string) (Operator, error)
- func ParseFuncs(names, sep string) ([]Operator, error)
- func ParseOp(serial SerialOp) (Operator, error)
- func Replace(op Operator, when func(Operator) bool, how func(Operator) Operator, ...) Operator
- func ReplaceAt(op Operator, pos uint, with Operator) Operator
- func Sample(op Operator, weight func(op Operator, depth uint, rng *rand.Rand) float64, ...) (Operator, uint)
- func Select(op Operator, pos uint) Operator
- func SetConsts(op Operator, values []float64) Operator
- type SerialOp
- type Sin
- func (sin Sin) Arity() uint
- func (sin Sin) Diff(i uint) Operator
- func (sin Sin) Eval(X [][]float64) []float64
- func (sin Sin) Name() string
- func (sin Sin) Operand(i uint) Operator
- func (sin Sin) SetOperand(i uint, op Operator) Operator
- func (sin Sin) Simplify() Operator
- func (sin Sin) String() string
- type Square
- func (square Square) Arity() uint
- func (square Square) Diff(i uint) Operator
- func (square Square) Eval(X [][]float64) []float64
- func (square Square) Name() string
- func (square Square) Operand(i uint) Operator
- func (square Square) SetOperand(i uint, op Operator) Operator
- func (square Square) Simplify() Operator
- func (square Square) String() string
- type Sub
- func (sub Sub) Arity() uint
- func (sub Sub) Diff(i uint) Operator
- func (sub Sub) Eval(X [][]float64) []float64
- func (sub Sub) Name() string
- func (sub Sub) Operand(i uint) Operator
- func (sub Sub) SetOperand(i uint, op Operator) Operator
- func (sub Sub) Simplify() Operator
- func (sub Sub) String() string
- type Var
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcHeight ¶
CalcHeight returns the height of an Operator. The height of an Operator is the height of it's root node. The height of a node is the number of edges on the longest path between the node and a leaf.
func CountConsts ¶
CountConsts returns the number of Consts in an Operator.
func CountDistinctVars ¶
CountDistinctVars returns the number of distinct Vars in an Operator.
func CountLeaves ¶
CountLeaves returns the number of leaves in an Operator.
Types ¶
type Abs ¶
type Abs struct {
Op Operator
}
The Abs operator.
func (Abs) SetOperand ¶
SetOperand replaces Abs's operand if i is equal to 0.
type Add ¶
type Add struct {
Left, Right Operator
}
The Add operator.
func (Add) SetOperand ¶
SetOperand replaces one of Add's operands if i is equal to 0 or 1.
type CodeDisplay ¶
type CodeDisplay struct{}
CodeDisplay outputs an code-like representation of an Operator.
Example ¶
var ( op = Cos{Add{Const{42}, Var{0}}} disp = CodeDisplay{} ) fmt.Println(disp.Apply(op))
Output: cos(add(42, x0))
func (CodeDisplay) Apply ¶
func (displayer CodeDisplay) Apply(op Operator) string
Apply CodeDisplay.
type Const ¶
type Const struct {
Value float64
}
The Const operator always returns the same value.
func (Const) SetOperand ¶
SetOperand returns the Const without any modifications.
type Cos ¶
type Cos struct {
Op Operator
}
The Cos operator.
func (Cos) SetOperand ¶
SetOperand replaces Cos's operand if i is equal to 0.
type DirDisplay ¶
type DirDisplay struct {
TabSize int
}
DirDisplay outputs a directory like representation of an Operator.
Example ¶
var ( op = Cos{Add{Const{42}, Var{0}}} disp = DirDisplay{TabSize: 4} ) fmt.Println(disp.Apply(op))
Output: cos add 42 x0
type Div ¶
type Div struct {
Left, Right Operator
}
The Div operator.
func (Div) SetOperand ¶
SetOperand replaces one of Div's operands if i is equal to 0 or 1.
type GraphvizDisplay ¶
type GraphvizDisplay struct{}
GraphvizDisplay outputs a Graphviz representation of an Operator. Each branch is indexed with a global counter and is labelled with the Operator's Name method.
Example ¶
var ( op = Cos{Add{Const{42}, Var{0}}} disp = GraphvizDisplay{} ) fmt.Println(disp.Apply(op))
Output: digraph G { 0 [label="cos"]; 0 -> 1; 1 [label="add"]; 1 -> 2; 2 [label="42"]; 1 -> 3; 3 [label="x0"]; }
func (GraphvizDisplay) Apply ¶
func (displayer GraphvizDisplay) Apply(op Operator) string
Apply Graphviz display.
type If ¶
The If operator.
func (If) SetOperand ¶
SetOperand replaces If's operand if i is equal to 0.
type Inv ¶
type Inv struct {
Op Operator
}
The Inv operator.
func (Inv) SetOperand ¶
SetOperand replaces Inv's operand if i is equal to 0.
type Max ¶
type Max struct {
Left, Right Operator
}
The Max operator.
func (Max) SetOperand ¶
SetOperand replaces one of Max's operands if i is equal to 0 or 1.
type Min ¶
type Min struct {
Left, Right Operator
}
The Min operator.
func (Min) SetOperand ¶
SetOperand replaces one of Min's operands if i is equal to 0 or 1.
type Mul ¶
type Mul struct {
Left, Right Operator
}
The Mul operator.
func (Mul) SetOperand ¶
SetOperand replaces one of Mul's operands if i is equal to 0 or 1.
type Neg ¶
type Neg struct {
Op Operator
}
The Neg operator.
func (Neg) SetOperand ¶
SetOperand replaces Neg's operand if i is equal to 0.
type Operator ¶
type Operator interface { Eval(X [][]float64) []float64 Arity() uint Operand(i uint) Operator SetOperand(i uint, op Operator) Operator Simplify() Operator Diff(i uint) Operator Name() string String() string }
An Operator is a mathematical operator. It has operands that are themselves Operators.
func ParseFuncs ¶
ParseFuncs parses a string into a slice of Operators.
func Replace ¶
func Replace( op Operator, when func(Operator) bool, how func(Operator) Operator, stopAtFirst bool, ) Operator
Replace replaces an Operator if a given condition is met.
func Sample ¶
func Sample( op Operator, weight func(op Operator, depth uint, rng *rand.Rand) float64, rng *rand.Rand, ) (Operator, uint)
Sample returns a random suboperator.
type SerialOp ¶
type SerialOp struct { Type string `json:"type"` Value string `json:"value"` Operands []SerialOp `json:"operands"` }
func SerializeOp ¶
type Sin ¶
type Sin struct {
Op Operator
}
The Sin operator.
func (Sin) SetOperand ¶
SetOperand replaces Sin's operand if i is equal to 0.
type Square ¶
type Square struct {
Op Operator
}
The Square operator.
func (Square) SetOperand ¶
SetOperand replaces Square's operand if i is equal to 0.
type Sub ¶
type Sub struct {
Left, Right Operator
}
The Sub operator.
func (Sub) SetOperand ¶
SetOperand replaces one of Sub's operands if i is equal to 0 or 1.
type Var ¶
type Var struct {
Index uint
}
The Var operator.
func (Var) Diff ¶
Diff computes the following derivative: x' = 1. However if i not equal to the Var's Index then a 0 Const is returned.
func (Var) SetOperand ¶
SetOperand returns the Const without any modifications.