Documentation ¶
Index ¶
Constants ¶
const ( L1_PENALTY = 0 L2_PENALTY = 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActivationFunction ¶
type ActivationFunction interface { /* Eval computes the value of this activation function at x. Input ===== x : a scalar value Returns ======= the value of this activation function at x */ Eval(x float64) float64 /* Deriv computes the derivative of this activation function at x. Input ===== x : a scalar value Returns ======= the derivative of this activation function at x */ Deriv(x float64) float64 }
ActivationFunction is used to apply a non-linear transformation to the output of a linear function. Activation functions need to be differentiable so that they can be used with gradient descent.
type Function ¶
type Function interface { /* Predict evalutes this function at the point specified by the given vector and returns a scalar value. Input ===== instance : a row vector Returns ======= a scalar value or an error */ Predict(instance mat.MatrixRO) (float64, error) /* PredictM evaluates each row of the specified matrix. Input ===== instances : a matrix where each row corresponds to an input vector Returns ======= a vector containing one prediction for each row vector in instances */ PredictM(instances mat.MatrixRO) (mat.MatrixRO, error) /* InputDims returns the number of dimensions of a valid input vector. Returns ======= the number of dimensions of a valid input vector */ InputDims() int }
Function is a mapping from a vector space to a float64.
type FunctionApproximator ¶
type FunctionApproximator interface { Function /* Fit fits this function approximator to the training data specified by the matrix x and the vector y. Generally this method needs to be called before Predict() can be called. Input ===== x : a matrix where each row is an input vector y : a column vector where each element corresponds to the desired output for the corresponding row of x Returns ======= an error if the fitting process fails */ Fit(x mat.MatrixRO, y mat.MatrixRO) error }
FunctionApproximator is a function that can be trained given a labeled set of input vector, scalar value pairs.
type LinearFunction ¶
type LinearFunction struct { Weights mat.DenseMatrix AFunc ActivationFunction }
LinearFunction is a Function that evaluates input vectors by multiplying them by a weight vector.
func (LinearFunction) InputDims ¶
func (f LinearFunction) InputDims() int
InputDims returns the number of dimensions of a valid input vector.
Returns ======= the number of dimensions of a valid input vector
type SGD ¶
type SGD struct { /* The penalty type to apply (L1_PENALTY or L2_PENALTY). */ PenaltyType int /* The regularization parameter. */ Lambda float64 /* The number of iterations to train for. */ NumIterations int /* The learning rate used during training. */ LearningRate float64 // contains filtered or unexported fields }
SGD performs Stochastic Gradient Descent.
func NewSGD ¶
func NewSGD(penaltyType int, lambda float64, numIterations int, learningRate float64, afunc ActivationFunction) (*SGD, error)
NewSGD constructs a new SGD instance.
Input ===== penaltyType : the type of regularization penalty to user during fitting (either L1_PENALTY or L2_PENALTY) lambda : the regularization parameter (should >= 0) numIterations : the number of iterations to run during fitting. One iteration corresponds to updating with a single sample. learningRate : the constant learning rate parameter to use during training afunc : the activation function to apply to output (nil is interpreted as the identity function)
Returns ======= a pointer to a new (untrained) SGD instance or an error
func (*SGD) NewCopy ¶
NewCopy returns a new instance of *SGD with the same parameters as this instance, but it does not copy any weights. So the new instance can be trained with any (x, y) training samples.
Returns ======= a new instance of *SGD with the same parameters as this instance
func (SGD) Weights ¶
func (self SGD) Weights() mat.DenseMatrix
Weights returns the weight vector obtained during the fitting process. If Fit() has not been executed yet, then the behavior of this method is undefined.
Returns ======= a column vector of weights (including an additional weight for the bias)