Documentation ¶
Index ¶
- func MatrixAve(m Matrix) float64
- func MatrixSum(m Matrix) float64
- type Activation
- type Matrix
- func MatrixAdd(m Matrix, m2 Matrix) (Matrix, error)
- func MatrixMap(m Matrix, f func(x float64) float64) Matrix
- func MatrixMul(m Matrix, m2 Matrix) (Matrix, error)
- func MatrixProduct(m Matrix, m2 Matrix) (Matrix, error)
- func MatrixSub(m Matrix, m2 Matrix) (Matrix, error)
- func MatrixTranspose(m Matrix) Matrix
- func NewColMatrix(arr []float64) Matrix
- func NewMatrix(arr [][]float64) Matrix
- func NewRandom(Rows, Cols int) Matrix
- func NewZeros(Rows, Cols int) Matrix
- func (m *Matrix) Add(a float64)
- func (m *Matrix) AddMat(m2 Matrix) error
- func (m *Matrix) Map(mapFunc func(x float64) float64)
- func (m *Matrix) Mul(a float64)
- func (m *Matrix) MulMat(m2 Matrix) error
- func (m *Matrix) RandomFill()
- func (m *Matrix) Show()
- func (m *Matrix) Sub(a float64)
- func (m *Matrix) SubMat(m2 Matrix) error
- func (m *Matrix) Transpose()
- type Model
- type NeuralNetwork
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Activation ¶
Activation is a simple struct that holds Activation functions for forward progations (F) and back propagation (DF)
func NewSigmoid ¶
func NewSigmoid() *Activation
NewSigmoid returns a pointer to an Activation, set to use Sigmoid
func NewTanh ¶
func NewTanh() *Activation
NewTanh returns a pointer to an Activation, set to use Tanh
type Matrix ¶
Matrix is a struct that represents a mathematical Matrix
func MatrixMap ¶
MatrixMap takes in a Matrix and a function, returns a Matrix created by applying the function to all elements of the Matrix passed in as argument
func MatrixProduct ¶
MatrixProduct takes in two Matrix and returns their Matrix product (Cross product)
func MatrixTranspose ¶
MatrixTranspose takes in a Matrix and returns it's transpose Matrix
func NewColMatrix ¶
NewColMatrix takes in a 1D array of float64 numbers and returns a Matrix (mathematically a vector)
func NewRandom ¶
NewRandom takes in number of rows and column of type int and returns a Matrix of randomly filled values
func NewZeros ¶
NewZeros takes in number of rows and columns of type int and returns a Matrix of Val zero
func (*Matrix) AddMat ¶
AddMat takes in another Matrix as argument and performs element wise addition operation
func (*Matrix) Map ¶
Map takes in a function of type func(x float64) float64 and applies this function to all elements of the matrix
func (*Matrix) MulMat ¶
MulMat takes in another Matrix as argument and performs element wise multiplication operation
func (*Matrix) RandomFill ¶
func (m *Matrix) RandomFill()
RandomFill fills the Matrix with random values
type NeuralNetwork ¶
type NeuralNetwork struct { NumInputNodes int // Num of input nodes on the Neural Network NumOutputNodes int // Num of output nodes on the Neural Network NumHiddenNodes int // Num of hidden nodes on the Neural Network WeightsIH Matrix // weights from input to hidden layer WeightsHO Matrix // weights from hidden to output layer BiasIH Matrix BiasHO Matrix LearningRate float64 // Rate at which the Network would learn/fit data ActivationFunc *Activation // Pointer to an Activation function Epochs int // num of Epochs to loop }
NeuralNetwork is a struct that contains all the values necessary to train a Neural Network model
func Mutate ¶
func Mutate(n NeuralNetwork, mapping func(x float64) float64) NeuralNetwork
Mutate takes in a NeuralNetwork and a function of type func (x float64) float64, and returns the mutation of the NeuralNetwork by applying the function to all Matrix in the NeuralNetwork
func NewNN ¶
func NewNN(inputNodes, hiddenNodes, outputNodes int, LearningRate float64, ActivationFunc string, e int) *NeuralNetwork
NewNN creates and returns a pointers to a NeuralNetwork
Example ¶
nn = NewNN(2, 10, 1, 1, "sgd", 1000) fmt.Println(nn.LearningRate)
Output: 1
func (*NeuralNetwork) Predict ¶
func (n *NeuralNetwork) Predict(input []float64) [][]float64
Predict takes 1D array of input data and returns a One-Hot encoded 2D array
Example ¶
Predicting Output for XOR problem
nn.Predict([]float64{1, 0})
Output:
func (*NeuralNetwork) Train ¶
func (n *NeuralNetwork) Train(input [][]float64, t [][]float64)
Train takes in two 2D arrays of type float64 and trains the NeuralNetwork to fit the data. One arguments should be the input data to the Neural Network and another one should be One Hot encoding of the actual category of the correspoding input data.
Example ¶
Training model to learn XOR problem
var input [][]float64 = [][]float64{{1, 1}, {0, 1}, {0, 0}, {1, 0}} var target [][]float64 = [][]float64{{0}, {1}, {0}, {1}} nn.Train(input, target)
Output: