Documentation ¶
Index ¶
- func LayerToIndex(layer Layer) int
- type BatchNormCache
- type BatchNormShift
- type BatchnormLayer
- func (layer *BatchnormLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *BatchnormLayer) FromBytes(bytes []byte)
- func (layer *BatchnormLayer) Initialize(n_inputs int)
- func (layer *BatchnormLayer) NumOutputs() int
- func (layer *BatchnormLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *BatchnormLayer) PrettyPrint() string
- func (layer *BatchnormLayer) ToBytes() []byte
- type CacheType
- type Conv2DLayer
- func (layer *Conv2DLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *Conv2DLayer) FromBytes(bytes []byte)
- func (layer *Conv2DLayer) Initialize(numInputs int)
- func (layer *Conv2DLayer) NumOutputs() int
- func (layer *Conv2DLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *Conv2DLayer) PrettyPrint() string
- func (layer *Conv2DLayer) ToBytes() []byte
- type FlattenLayer
- func (layer *FlattenLayer) Back(_ CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *FlattenLayer) FromBytes(bytes []byte)
- func (layer *FlattenLayer) Initialize(n_inputs int)
- func (layer *FlattenLayer) NumOutputs() int
- func (layer *FlattenLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *FlattenLayer) PrettyPrint() string
- func (layer *FlattenLayer) ToBytes() []byte
- type InputCache
- type KernelShift
- type LSTMCache
- type LSTMLayer
- func (layer *LSTMLayer) Back(cache CacheType, frontalPass *mat.Dense) (shift ShiftType, backpass *mat.Dense)
- func (layer *LSTMLayer) FromBytes(bytes []byte)
- func (layer *LSTMLayer) Initialize(totalInputs int)
- func (layer *LSTMLayer) NumOutputs() int
- func (layer *LSTMLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *LSTMLayer) PrettyPrint() string
- func (layer *LSTMLayer) ToBytes() []byte
- type LSTMShift
- type LanhLayer
- func (layer *LanhLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *LanhLayer) FromBytes(bytes []byte)
- func (layer *LanhLayer) Initialize(n_inputs int)
- func (layer *LanhLayer) NumOutputs() int
- func (layer *LanhLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *LanhLayer) PrettyPrint() string
- func (layer *LanhLayer) ToBytes() []byte
- type Layer
- type LinearLayer
- func (layer *LinearLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *LinearLayer) FromBytes(bytes []byte)
- func (layer *LinearLayer) Initialize(numInputs int)
- func (layer *LinearLayer) NumOutputs() int
- func (layer *LinearLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *LinearLayer) PrettyPrint() string
- func (layer *LinearLayer) ToBytes() []byte
- type MaxPool2DLayer
- func (layer *MaxPool2DLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *MaxPool2DLayer) FromBytes(bytes []byte)
- func (layer *MaxPool2DLayer) Initialize(n_inputs int)
- func (layer *MaxPool2DLayer) NumOutputs() int
- func (layer *MaxPool2DLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *MaxPool2DLayer) PrettyPrint() string
- func (layer *MaxPool2DLayer) ToBytes() []byte
- type NilShift
- type OutputCache
- type ReluLayer
- func (layer *ReluLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *ReluLayer) FromBytes(bytes []byte)
- func (layer *ReluLayer) Initialize(n_inputs int)
- func (layer *ReluLayer) NumOutputs() int
- func (layer *ReluLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *ReluLayer) PrettyPrint() string
- func (layer *ReluLayer) ToBytes() []byte
- type Shape
- type ShiftType
- type SigmoidLayer
- func (layer *SigmoidLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *SigmoidLayer) FromBytes(bytes []byte)
- func (layer *SigmoidLayer) Initialize(n_inputs int)
- func (layer *SigmoidLayer) NumOutputs() int
- func (layer *SigmoidLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *SigmoidLayer) PrettyPrint() string
- func (layer *SigmoidLayer) ToBytes() []byte
- type SoftmaxLayer
- func (layer *SoftmaxLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *SoftmaxLayer) FromBytes(bytes []byte)
- func (layer *SoftmaxLayer) Initialize(n_inputs int)
- func (layer *SoftmaxLayer) NumOutputs() int
- func (layer *SoftmaxLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *SoftmaxLayer) PrettyPrint() string
- func (layer *SoftmaxLayer) ToBytes() []byte
- type TanhLayer
- func (layer *TanhLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *TanhLayer) FromBytes(bytes []byte)
- func (layer *TanhLayer) Initialize(n_inputs int)
- func (layer *TanhLayer) NumOutputs() int
- func (layer *TanhLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *TanhLayer) PrettyPrint() string
- func (layer *TanhLayer) ToBytes() []byte
- type VariableLinearLayer
- func (layer *VariableLinearLayer) Back(cache CacheType, forwardGradients *mat.Dense) (ShiftType, *mat.Dense)
- func (layer *VariableLinearLayer) FromBytes(bytes []byte)
- func (layer *VariableLinearLayer) Initialize(numInputs int)
- func (layer *VariableLinearLayer) NumOutputs() int
- func (layer *VariableLinearLayer) Pass(input *mat.Dense) (*mat.Dense, CacheType)
- func (layer *VariableLinearLayer) PrettyPrint() string
- func (layer *VariableLinearLayer) ToBytes() []byte
- type WeightShift
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LayerToIndex ¶
Types ¶
type BatchNormCache ¶ added in v1.5.0
type BatchNormShift ¶ added in v1.5.0
type BatchNormShift struct {
// contains filtered or unexported fields
}
func (*BatchNormShift) Apply ¶ added in v1.5.0
func (b *BatchNormShift) Apply(rawlayer Layer, scale float64)
func (*BatchNormShift) Combine ¶ added in v1.5.0
func (b *BatchNormShift) Combine(b2 ShiftType) ShiftType
func (*BatchNormShift) NumMatrices ¶ added in v1.5.0
func (b *BatchNormShift) NumMatrices() int
func (*BatchNormShift) Optimize ¶ added in v1.5.0
func (b *BatchNormShift) Optimize(opt optimizers.Optimizer, index int)
func (*BatchNormShift) Scale ¶ added in v1.5.0
func (b *BatchNormShift) Scale(f float64)
type BatchnormLayer ¶ added in v1.5.0
type BatchnormLayer struct { BatchSize int GradientScale float64 // contains filtered or unexported fields }
func (*BatchnormLayer) FromBytes ¶ added in v1.5.0
func (layer *BatchnormLayer) FromBytes(bytes []byte)
func (*BatchnormLayer) Initialize ¶ added in v1.5.0
func (layer *BatchnormLayer) Initialize(n_inputs int)
func (*BatchnormLayer) NumOutputs ¶ added in v1.5.0
func (layer *BatchnormLayer) NumOutputs() int
func (*BatchnormLayer) PrettyPrint ¶ added in v1.5.0
func (layer *BatchnormLayer) PrettyPrint() string
func (*BatchnormLayer) ToBytes ¶ added in v1.5.0
func (layer *BatchnormLayer) ToBytes() []byte
type CacheType ¶ added in v1.4.0
type CacheType interface{}
This is an interface for allowing layers to designate their own types of caches. For example, on Tanh layers, it is best to cache the output of the layer for backprop as it avoids recalculating tanh values, but for linear layers it is better to cache the inputs.
type Conv2DLayer ¶
type Conv2DLayer struct { InputShape Shape KernelShape Shape NumKernels int FirstLayer bool // contains filtered or unexported fields }
func (*Conv2DLayer) FromBytes ¶
func (layer *Conv2DLayer) FromBytes(bytes []byte)
func (*Conv2DLayer) Initialize ¶
func (layer *Conv2DLayer) Initialize(numInputs int)
func (*Conv2DLayer) NumOutputs ¶
func (layer *Conv2DLayer) NumOutputs() int
func (*Conv2DLayer) PrettyPrint ¶
func (layer *Conv2DLayer) PrettyPrint() string
func (*Conv2DLayer) ToBytes ¶
func (layer *Conv2DLayer) ToBytes() []byte
type FlattenLayer ¶
type FlattenLayer struct {
// contains filtered or unexported fields
}
func (*FlattenLayer) FromBytes ¶
func (layer *FlattenLayer) FromBytes(bytes []byte)
func (*FlattenLayer) Initialize ¶
func (layer *FlattenLayer) Initialize(n_inputs int)
func (*FlattenLayer) NumOutputs ¶
func (layer *FlattenLayer) NumOutputs() int
func (*FlattenLayer) PrettyPrint ¶
func (layer *FlattenLayer) PrettyPrint() string
func (*FlattenLayer) ToBytes ¶
func (layer *FlattenLayer) ToBytes() []byte
type InputCache ¶ added in v1.4.0
type KernelShift ¶
type KernelShift struct {
// contains filtered or unexported fields
}
func (*KernelShift) Apply ¶
func (k *KernelShift) Apply(layer Layer, scale float64)
func (*KernelShift) Combine ¶
func (k *KernelShift) Combine(k2 ShiftType) ShiftType
func (*KernelShift) NumMatrices ¶ added in v1.5.0
func (k *KernelShift) NumMatrices() int
func (*KernelShift) Optimize ¶ added in v1.5.0
func (k *KernelShift) Optimize(opt optimizers.Optimizer, index int)
func (*KernelShift) Scale ¶ added in v1.5.0
func (k *KernelShift) Scale(f float64)
type LSTMLayer ¶ added in v1.4.0
type LSTMLayer struct { Outputs int InputSize int OutputSequence bool ConstantLengthInput bool OutputChunks int // contains filtered or unexported fields }
func (*LSTMLayer) Initialize ¶ added in v1.4.0
func (*LSTMLayer) NumOutputs ¶ added in v1.4.0
func (*LSTMLayer) PrettyPrint ¶ added in v1.4.0
type LSTMShift ¶ added in v1.4.0
type LSTMShift struct {
// contains filtered or unexported fields
}
func (*LSTMShift) NumMatrices ¶ added in v1.5.0
type LanhLayer ¶ added in v1.5.2
type LanhLayer struct { GradientScale float64 // contains filtered or unexported fields }
func (*LanhLayer) Initialize ¶ added in v1.5.2
func (*LanhLayer) NumOutputs ¶ added in v1.5.2
func (*LanhLayer) PrettyPrint ¶ added in v1.5.2
type Layer ¶
type Layer interface { Initialize(int) Pass(*mat.Dense) (*mat.Dense, CacheType) Back(CacheType, *mat.Dense) (ShiftType, *mat.Dense) NumOutputs() int ToBytes() []byte FromBytes([]byte) PrettyPrint() string }
LAYER - The basic interface for all inner layers of an ANN.
Initialize (numInputs int): Tells the layer how many inputs to expect, and sets up everything accordingly.
Pass (*mat.Dense) (*mat.Dense, CacheType): Passes the input through the layer to get an output, and cache necessary information to do backprop.
Back (cache CacheType, forwardGradients *mat.Dense) (shift ShiftType, backwardsGradients *mat.Dense): Takes the partial derivatives from the layers in front, calculates the gradient for itself, and passes it back to the last layer.
func IndexToLayer ¶
This allows for mapping between layer types and ints for the sake of saving to files and reconstructing.
type LinearLayer ¶
Linear (or Dense) layer type
func (*LinearLayer) FromBytes ¶
func (layer *LinearLayer) FromBytes(bytes []byte)
func (*LinearLayer) Initialize ¶
func (layer *LinearLayer) Initialize(numInputs int)
func (*LinearLayer) NumOutputs ¶
func (layer *LinearLayer) NumOutputs() int
func (*LinearLayer) PrettyPrint ¶
func (layer *LinearLayer) PrettyPrint() string
func (*LinearLayer) ToBytes ¶
func (layer *LinearLayer) ToBytes() []byte
type MaxPool2DLayer ¶
type MaxPool2DLayer struct { PoolShape Shape // contains filtered or unexported fields }
func (*MaxPool2DLayer) FromBytes ¶
func (layer *MaxPool2DLayer) FromBytes(bytes []byte)
func (*MaxPool2DLayer) Initialize ¶
func (layer *MaxPool2DLayer) Initialize(n_inputs int)
func (*MaxPool2DLayer) NumOutputs ¶
func (layer *MaxPool2DLayer) NumOutputs() int
func (*MaxPool2DLayer) PrettyPrint ¶
func (layer *MaxPool2DLayer) PrettyPrint() string
func (*MaxPool2DLayer) ToBytes ¶
func (layer *MaxPool2DLayer) ToBytes() []byte
type NilShift ¶
type NilShift struct{}
func (*NilShift) NumMatrices ¶ added in v1.5.0
type OutputCache ¶ added in v1.4.0
type ReluLayer ¶
type ReluLayer struct {
// contains filtered or unexported fields
}
func (*ReluLayer) Initialize ¶
func (*ReluLayer) NumOutputs ¶
func (*ReluLayer) PrettyPrint ¶
type ShiftType ¶
type ShiftType interface { Apply(Layer, float64) Combine(ShiftType) ShiftType Optimize(optimizers.Optimizer, int) NumMatrices() int Scale(float64) }
This is an interface for carrying all the different gradient steps that will be applied after backprop. The default NilShift is defined here, but most layer specific shift types are defined in their own files.
type SigmoidLayer ¶
type SigmoidLayer struct { GradientScale float64 // contains filtered or unexported fields }
func (*SigmoidLayer) FromBytes ¶
func (layer *SigmoidLayer) FromBytes(bytes []byte)
func (*SigmoidLayer) Initialize ¶
func (layer *SigmoidLayer) Initialize(n_inputs int)
func (*SigmoidLayer) NumOutputs ¶
func (layer *SigmoidLayer) NumOutputs() int
func (*SigmoidLayer) PrettyPrint ¶
func (layer *SigmoidLayer) PrettyPrint() string
func (*SigmoidLayer) ToBytes ¶
func (layer *SigmoidLayer) ToBytes() []byte
type SoftmaxLayer ¶
type SoftmaxLayer struct {
// contains filtered or unexported fields
}
func (*SoftmaxLayer) FromBytes ¶
func (layer *SoftmaxLayer) FromBytes(bytes []byte)
func (*SoftmaxLayer) Initialize ¶
func (layer *SoftmaxLayer) Initialize(n_inputs int)
func (*SoftmaxLayer) NumOutputs ¶
func (layer *SoftmaxLayer) NumOutputs() int
func (*SoftmaxLayer) PrettyPrint ¶
func (layer *SoftmaxLayer) PrettyPrint() string
func (*SoftmaxLayer) ToBytes ¶
func (layer *SoftmaxLayer) ToBytes() []byte
type TanhLayer ¶
type TanhLayer struct { GradientScale float64 // contains filtered or unexported fields }
func (*TanhLayer) Initialize ¶
func (*TanhLayer) NumOutputs ¶
func (*TanhLayer) PrettyPrint ¶
type VariableLinearLayer ¶ added in v1.5.4
type VariableLinearLayer struct { InputSize int OutputSize int ConstantLengthInput bool // contains filtered or unexported fields }
Linear (or Dense) layer type
func (*VariableLinearLayer) FromBytes ¶ added in v1.5.4
func (layer *VariableLinearLayer) FromBytes(bytes []byte)
func (*VariableLinearLayer) Initialize ¶ added in v1.5.4
func (layer *VariableLinearLayer) Initialize(numInputs int)
func (*VariableLinearLayer) NumOutputs ¶ added in v1.5.4
func (layer *VariableLinearLayer) NumOutputs() int
func (*VariableLinearLayer) PrettyPrint ¶ added in v1.5.4
func (layer *VariableLinearLayer) PrettyPrint() string
func (*VariableLinearLayer) ToBytes ¶ added in v1.5.4
func (layer *VariableLinearLayer) ToBytes() []byte
type WeightShift ¶
type WeightShift struct {
// contains filtered or unexported fields
}
ShiftType used by LinearLayers
func (*WeightShift) Apply ¶
func (w *WeightShift) Apply(layer Layer, scale float64)
func (*WeightShift) Combine ¶
func (w *WeightShift) Combine(w2 ShiftType) ShiftType
func (*WeightShift) NumMatrices ¶ added in v1.5.0
func (w *WeightShift) NumMatrices() int
func (*WeightShift) Optimize ¶ added in v1.5.0
func (w *WeightShift) Optimize(opt optimizers.Optimizer, index int)
func (*WeightShift) Scale ¶ added in v1.5.0
func (w *WeightShift) Scale(f float64)