Documentation
¶
Overview ¶
Package keras implements many functionalities from the popular Keras API which is a deep learning API written in Python, running on top of the machine learning platform TensorFlow. This package was started mainly for fun is still very much under development
Index ¶
- func ColNum(m Matrix) int
- func CrossEntropy(prediction, truth []float64) float64
- func Dimensions(m Matrix) (int, int)
- func ELU(x float64) float64
- func FalseNegatives(predicted, actual []float64) int
- func FalsePositives(predicted, actual []float64) int
- func HeUniform(x float64) float64
- func Max(x, y int) int
- func MeanSqRoot(prediction, truth []float64) float64
- func NumberOfElements(m Matrix) int
- func OnesInitializer(x float64) float64
- func Precision(predicted, actual []float64) int
- func PrintByRows(m Matrix)
- func PrintfMatrix(m Matrix)
- func ReLU(x float64) float64
- func Recall(predicted, actual []float64) int
- func RootMeanSq(prediction, truth []float64) float64
- func RowNum(m Matrix) int
- func Sensitivity(predicted, actual []float64) int
- func Sigmoid(x float64) float64
- func SigmoidPrime(x float64) float64
- func SimpleRandomVector(size int) []float64
- func Specificity(predicted, actual []float64) int
- func Swish(x float64) float64
- func Tanh(x float64) float64
- func ToArray(m Matrix) []float64
- func TrueNegatives(predicted, actual []float64) int
- func TruePositivies(predicted, actual []float64) int
- func Variance(fls []float64) float64
- func ZeroInitializer(x float64) float64
- type BatchNormLayer
- type Biases
- type Callback
- type CallbackHistory
- type Conv2DLayer
- type DenseLayer
- type DropoutLayer
- type EarlyStopper
- type FlattenLayer
- type InputLayer
- type Layer
- type Matrix
- type Metrics
- type Model
- func (m *Model) Add(layer Layer) *Model
- func (m *Model) CallbackList() []Callback
- func (m *Model) Compile(optimizer Optimizer, loss func([]float64, []float64) float64, ms []Metrics)
- func (m *Model) CsvLogger(filename string) error
- func (m *Model) EarlyStopping(index int, patience int, at int, minDdelta float64, mode string)
- func (m *Model) GetLayerByIndex(index int) Layer
- func (m *Model) GetLayerByName(name string) Layer
- func (m *Model) GetMetricsByIndex(index int) Metrics
- func (m *Model) History(filepath string) (*CallbackHistory, error)
- func (m *Model) LearningRateScheduler(fn func(x float64) float64)
- func (m *Model) ModelCheckpoint(filepath string, metrics Metrics, saveWeightsOnly bool) error
- func (m *Model) Predict(values []float64) []float64
- func (m *Model) Summary()
- func (m *Model) Train(trainX, trainY []float64, epochs int) map[string]float64
- type Network
- type Optimizer
- type ReduceLearningRateOnPlateau
- type Shape
- type SoftmaxLayer
- type TrainingLog
- type Vector
- type Weights
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CrossEntropy ¶
CrossEntropy returns the cross entropy loss
func Dimensions ¶
Dimensions returns the number of rows and columns of m.
func ELU ¶
ELUExponential Linear Unit or its widely known name ELU is a function that tend to converge cost to zero faster and produce more accurate results
func FalseNegatives ¶
FalseNegatives returns the number of false negative predicted values.
func FalsePositives ¶
FalsePositives estimates the false positive predicted values
func HeUniform ¶
HeUniform stands for He Initialization or the glorot_unifom for kernel_initialization.
func MeanSqRoot ¶
MeanSqRoot returns the mean squared error between prediction and truth arrays.
func NumberOfElements ¶
NumberOfElements returns the number of elements.
func OnesInitializer ¶
OnesInitializer returns the ones initializer for the bias initialization
func PrintfMatrix ¶
func PrintfMatrix(m Matrix)
PrintfMatrix is a helper function that will print a matrix to stdout.
func ReLU ¶
ReLU or rectified linear activation function is a piecewise linear function that will output the input directly if it is positive, otherwise, it will output zero
func RootMeanSq ¶
Rmse returns the root mean squared error between prediction and truth arrays.
func Sensitivity ¶
Sensitivity returns the sensitivity
func SigmoidPrime ¶
SigmoidPrime calculates the derivative of the Sigmoid
func SimpleRandomVector ¶
RandomVector returns a random valued vector.
func Specificity ¶
Specificity returns the specificity
func Swish ¶
Swish is an activation function proposed byGoogle Brain Team, which is simply f(x) = x · sigmoid(x)
func TrueNegatives ¶
TrueNegative calculates the true negative predicted values
func TruePositivies ¶
TruePositivies returns the number of true positive predicted values.
func ZeroInitializer ¶
ZeroInitializer returns the zeros initializer for the bias initialization
Types ¶
type BatchNormLayer ¶
type BatchNormLayer struct {
// contains filtered or unexported fields
}
BatchNormLayer layer
func (*BatchNormLayer) Call ¶
func (bn *BatchNormLayer) Call() []float64
Call for the batch normalization layer
type CallbackHistory ¶
type CallbackHistory struct {
// contains filtered or unexported fields
}
CallbackHistory struct
func (*CallbackHistory) ReadToStrings ¶
func (ch *CallbackHistory) ReadToStrings() ([]string, error)
ReadToStrings returns history in strings.
type Conv2DLayer ¶
type Conv2DLayer struct { Filters int Inputs, Outputs []float64 Weights Weights Biases Biases Activation func(float64) float64 KernelInit func(float64) float64 BiasInit func(float64) float64 // contains filtered or unexported fields }
DenseLayer defines a fully connected layer.
func Conv2D ¶
func Conv2D(numFilter int, x int, y int, inputs []float64, padding func(x, y int) Weights) Conv2DLayer
Conv2D initializes a Conv2DLayer
func (Conv2DLayer) Call ¶
func (cd Conv2DLayer) Call() []float64
func (Conv2DLayer) GetBiases ¶
func (cd Conv2DLayer) GetBiases() Vector
GetBiases returns the layer's biases.
func (Conv2DLayer) GetWeights ¶
func (cd Conv2DLayer) GetWeights() Matrix
GetWeights returns the layer's weights.
func (Conv2DLayer) TrainableParameters ¶
func (cd Conv2DLayer) TrainableParameters() int
TrainableParameters returns the count of trainable parameters.
type DenseLayer ¶
type DenseLayer struct { Activation func(float64) float64 KernelInit func(float64) float64 BiasInit func(float64) float64 // contains filtered or unexported fields }
DenseLayer defines a fully connected layer.
func Dense ¶
func Dense(units int, inputs []float64, activation func(float64) float64) DenseLayer
Dense fully connected layer initializer
func (DenseLayer) Call ¶
func (d DenseLayer) Call() []float64
Call of the dense layer.Outputs the next tensors.
func (DenseLayer) GetBiases ¶
func (d DenseLayer) GetBiases() Vector
GetBiases returns the layer's biases.
func (DenseLayer) GetWeights ¶
func (d DenseLayer) GetWeights() Matrix
GetWeights returns the layer's weights.
func (*DenseLayer) SetBiases ¶
func (d *DenseLayer) SetBiases(bs Vector)
SetBiases is used for manually defining the bias vector.
func (*DenseLayer) SetWeights ¶
func (d *DenseLayer) SetWeights(Kernels Matrix)
SetWeights is used for manually defining the weight
func (DenseLayer) TrainableParameters ¶
func (d DenseLayer) TrainableParameters() int
TrainableParameters returns the count of trainable parameters.
type DropoutLayer ¶
type DropoutLayer struct {
// contains filtered or unexported fields
}
DropoutLayer layer
type EarlyStopper ¶
type EarlyStopper struct {
// contains filtered or unexported fields
}
EarlyStopper callback
type FlattenLayer ¶
type FlattenLayer struct {
// contains filtered or unexported fields
}
FlattenLayer layer
type InputLayer ¶
type InputLayer struct { Inputs []float64 Weights Weights Biases Biases Trainable bool Name string // contains filtered or unexported fields }
InputLayer layer, much like the keras one.
type Layer ¶
type Layer interface { Call() []float64 GetWeights() Matrix GetBiases() Vector Name() string TrainableParameters() int }
Layer interface given these 5 functions which every layer must have.
type Matrix ¶
type Matrix struct {
Matrix [][]float64
}
Matrix type is a 2D slice of float64 Values.
func RandomMatrix ¶
RandomMatrix will create a new matrix and randomize float64 values.
func (Matrix) ScalarAdition ¶
ScalarAdition adds a scalar to every elements
func (Matrix) ScalarMultiplication ¶
ScalarMultiplication multiplies every element with a scalar
type Model ¶
type Model struct { ConvLayers []Layer Name string Optimizer Optimizer LossFunc func([]float64, []float64) float64 LossValues []float64 Duration time.Duration Settings []Metrics TrainDataX []float64 TrainDataY []float64 Callbacks []Callback Training bool LearningRate float64 TrainingLog TrainingLog }
Model architecure to implement neural network.
func Sequential ¶
Sequential returns a model given layers and a name.
func (*Model) CallbackList ¶
CallbackList returns model's callback list
func (*Model) EarlyStopping ¶
EarlyStopping is much like the keras EarlyStopping callback. Index is the number in the model metrics attribute. Look it up under model.get_metrics()
func (*Model) GetLayerByIndex ¶
GetLayerByIndex returns the ith layer.
func (*Model) GetLayerByName ¶
GetLayerByName returns the layer given its name.
func (*Model) GetMetricsByIndex ¶
GetMetricsByIndex returns the index's model metric
func (*Model) History ¶
func (m *Model) History(filepath string) (*CallbackHistory, error)
History for model checkpointing
func (*Model) LearningRateScheduler ¶
LearningRateScheduler defined by fn
func (*Model) ModelCheckpoint ¶
ModelCheckpoint callback
func (*Model) Summary ¶
func (m *Model) Summary()
Summary prints the layer by layer summaary along with trainable parameters.
func (*Model) Train ¶
Train trains the model given trainX and trainY data and the number of epochs. It keeps track of the defined metrics and prints it every epoch. It also prints the training duration. It returns a map from strings to floats, where strings represent the metrics name and float the metrics value.
type Network ¶
type Network struct {
InputNodes, HiddenNodes, OutputNodes int
WeightsIh, WeightsHo, BiasO, BiasH Matrix
LearningRate float64
}
Network defines a simple neural network architecture.
func InitNetwork ¶
InitNetwork initializes the network with the number of nodes and the learning rate.
type Optimizer ¶
type Optimizer interface {
ApplyGradients()
}
Optimizer interface requires an ApplyGradients function. Pass it to the model compilation.
type ReduceLearningRateOnPlateau ¶
type ReduceLearningRateOnPlateau struct {
// contains filtered or unexported fields
}
ReduceLearningRateOnPlateau callback
func (*ReduceLearningRateOnPlateau) ReduceLr ¶
func (rlr *ReduceLearningRateOnPlateau) ReduceLr(m *Model, at int)
ReduceLr callback
type SoftmaxLayer ¶
type SoftmaxLayer struct {
// contains filtered or unexported fields
}
SoftmaxLayer layer
func Softmax ¶
func Softmax(inputs []float64, classes int) SoftmaxLayer
Softmax returns the softmax layer based on values.
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector type
func (Vector) ApplyMatrix ¶
ApplyMatrix returns the vector through a matrix transformation.
func (Vector) NumberOfElements ¶
NumberOfElements returns the number of elements.
type Weights ¶
Weights struct with the actual Kernels and the kernel initializer function.