gonn

package module
v0.0.0-...-02ddbf2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 9 Imported by: 0

README

gonn

This package currently contains a generalized dropout feed-forward neural network implementation. Any future neural network models I create will be added to this library. The code was originally generated through OpenAI's ChatGPT, which was further debugged and enriched by my own analysis.

Installation

To use this package, run the following command in the directory containing your go.mod file:

go get -t -u github.com/syhv-git/gonn

This package is not currently thread-safe tested

Usage

Refer to the test file for proper usage. I have also added some documentation for important public methods. The epochs are managed by the user and it is up to the user on whether the dropout rate is set only once or every epoch when training.

The Dropout rate must be set to 0 when performing validation and predictions on new data

Only binary classification problems have a validator implemented in this package. Any other types of analysis must be implemented by the user for proper validation. If private variables are required to properly validate the data, submit your method implementation as a pull request.

Issues

If there are any bugs, or further functionality is requested, please make a pull request with suitable information for reproducibility.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeakyReLU

func LeakyReLU(x float64) float64

func LoadCSVData

func LoadCSVData(src string, inputLen, targetLen int, names bool) ([][]float64, [][]float64)

LoadCSVData loads training data from source and returns two float64 matrices containing the training data and the target outcome.

inputLen determines how many fields contain the input data.

outputLen determines the number of targets.

names signifies if the first entry in the CSV contains field names.

func MAE

func MAE(predicted, target float64) float64

func MAEPrime

func MAEPrime(predicted, target float64) float64

func MSE

func MSE(predicted, target float64) float64

func MSEPrime

func MSEPrime(predicted, target float64) float64

func NoActivation

func NoActivation(x float64) float64

func ReLU

func ReLU(x float64) float64

func ReLUPrime

func ReLUPrime(x float64) float64

func Sigmoid

func Sigmoid(x float64) float64

func SigmoidPrime

func SigmoidPrime(x float64) float64

func Softplus

func Softplus(x float64) float64

func SoftplusPrime

func SoftplusPrime(x float64) float64

func Tanh

func Tanh(x float64) float64

func TanhPrime

func TanhPrime(x float64) float64

Types

type ActivationFunc

type ActivationFunc func(float64) float64

type DNN

type DNN struct {
	Rate float64
	// contains filtered or unexported fields
}

func NewDNN

func NewDNN(sizes []int, learningRate float64, hiddenActivation, hiddenVariance, outputActivation, outputVariance ActivationFunc, loss, lossPrime LossFunc) *DNN

NewDNN creates a new Dropout Multilayer Perceptron

sizes contains the sizes of each layer in the network

learningRate is the scaling hyperparameter for gradient descent

activation defines the normalization function applied to the output

variance defines the derivative of the activation function used

func (*DNN) Predict

func (nn *DNN) Predict(inputs []float64) []float64

func (*DNN) SetDropout

func (nn *DNN) SetDropout(rate []float64)

SetDropout sets the dropout rate for the network.

rate defines the dropout rate for the network. It can contain one value for the whole network or specific values for each layer in the network.

** The dropout rate must be set before training, and then set to 0 before predicting new data **

func (*DNN) Train

func (nn *DNN) Train(inputs, targets []float64)

Train performs one iteration of prediction and backpropagation learning

func (*DNN) ValidateBinaryClassification

func (nn *DNN) ValidateBinaryClassification(inputs, targets [][]float64) int

type FFNN

type FFNN struct {
	Rate float64
	// contains filtered or unexported fields
}

func NewFFNN

func NewFFNN(sizes []int, learningRate float64, hiddenActivation, hiddenVariance, outputActivation, outputVariance ActivationFunc, loss, lossPrime LossFunc) *FFNN

func (*FFNN) Predict

func (nn *FFNN) Predict(inputs []float64) []float64

func (*FFNN) Train

func (nn *FFNN) Train(inputs, targets []float64)

func (*FFNN) ValidateBinaryClassification

func (nn *FFNN) ValidateBinaryClassification(inputs, targets [][]float64) int

type LossFunc

type LossFunc func(float64, float64) float64

Jump to

Keyboard shortcuts

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