ml

package
v0.0.0-...-e2be882 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyScaledDotProductAttention

func ApplyScaledDotProductAttention(queries [][]float64, keys [][]float64, values [][]float64, softmax [][]float64, scale float64) []float64

ApplyScaledDotProductAttention computes the scaled dot-product attention given queries, keys, and values

func CalculateLossMatrix

func CalculateLossMatrix(predictedOutput [][]float64, targetOutput [][]float64) [][]float64

CalculateLossMatrix calculates the loss as a matrix given the predicted output and the target output

func ClipMatByNorm

func ClipMatByNorm(gradients [][]float64, maxNorm float64)

ClipMatByNorm clips gradients based on their global L2 norm.

func ClipVecByNorm

func ClipVecByNorm(gradients []float64, maxNorm float64)

ClipVecByNorm clips gradients based on their global L2 norm.

func Forest

func Forest(file string) error

func NewRandomForest

func NewRandomForest(size, features int) *ensemble.RandomForest

func NormalizeMat

func NormalizeMat(tensor [][]float64) [][]float64

NormalizeMat normalizes the input tensor across the feature dimension

func NormalizeVec

func NormalizeVec(tensor []float64) []float64

NormalizeVec normalizes the input tensor across the feature dimension

func PreProcessAttributes

func PreProcessAttributes(iris *base.DenseInstances) (*base.LazilyFilteredInstances, error)

func RandomForestPredict

func RandomForestPredict(tree base.Classifier, fileName string, template *base.DenseInstances, debug bool) (base.FixedDataGrid, error)

func RandomForestTrain

func RandomForestTrain(tree base.Classifier, fileName string, size, features int, debug bool) (base.Classifier, *base.DenseInstances, float64, error)

func ResidualConnectionMat

func ResidualConnectionMat(input, output [][]float64) [][]float64

ResidualConnectionMat adds a residual connection between two tensors

func ResidualConnectionVec

func ResidualConnectionVec(input, output []float64) []float64

ResidualConnectionVec adds a residual connection between two tensors

Types

type AttentionHead

type AttentionHead struct {
	// contains filtered or unexported fields
}

type Cluster

type Cluster struct {
	Size int
	Avg  float64
}

type DecoderLayer

type DecoderLayer struct {
	// contains filtered or unexported fields
}

func (*DecoderLayer) Decode

func (layer *DecoderLayer) Decode(input [][]float64, encoderOutput [][]float64) [][]float64

Decode applies the Transformer decoder layer to decode input sequences

type EncoderLayer

type EncoderLayer struct {
	// contains filtered or unexported fields
}

func (*EncoderLayer) Encode

func (layer *EncoderLayer) Encode(input [][]float64) [][]float64

Encode applies the Transformer encoder layer to encode input sequences

type FeedForward

type FeedForward struct {
	// contains filtered or unexported fields
}

func NewFeedForward

func NewFeedForward(meta meta, in, out int) *FeedForward

func (*FeedForward) BackProp

func (ffn *FeedForward) BackProp(loss [][]float64, learningRate float64)

BackProp computes the gradients of the loss function and updates the parameters of the feedforward layer

func (*FeedForward) Decode

func (ffn *FeedForward) Decode(inputSequence [][]float64) [][]float64

func (*FeedForward) Encode

func (ffn *FeedForward) Encode(inputSequence [][]float64) [][]float64

type GRU

type GRU struct {
	// contains filtered or unexported fields
}

func NewGRU

func NewGRU(inputSize, hiddenSize, outputSize int) *GRU

func (*GRU) Load

func (gru *GRU) Load(filename string) error

func (*GRU) Save

func (gru *GRU) Save(filename string) error

func (*GRU) Step

func (gru *GRU) Step(input []float64, prevHidden []float64) ([]float64, []float64)

func (*GRU) Train

func (gru *GRU) Train(learningRate float64, threshold float64, maxEpochs int, in, out [][]float64) (epochs int, err []float64)

Train trains the gru network, NOTE : we assume in and out has the same size

type KMeans

type KMeans struct {
	// contains filtered or unexported fields
}

func NewKMeans

func NewKMeans(pair string, dim int, iterations int) *KMeans

func (*KMeans) Predict

func (k *KMeans) Predict(x []float64, leadingThreshold int) (int, float64, Metadata, error)

func (*KMeans) Train

func (k *KMeans) Train(x []float64, y float64, train bool) (Metadata, error)

type Metadata

type Metadata struct {
	Samples  int
	Clusters map[int]Cluster
	Features []float64
	Accuracy float64
	Loss     []float64
}

func NewMetadata

func NewMetadata() Metadata

type MultiHeadAttention

type MultiHeadAttention struct {
	// contains filtered or unexported fields
}

func NewMultiHeadAttention

func NewMultiHeadAttention(numHeads int, in, out int) *MultiHeadAttention

func (*MultiHeadAttention) BackProp

func (attention *MultiHeadAttention) BackProp(loss [][]float64, learningRate float64)

BackProp computes the gradients of the loss function and updates the parameters of the multi-head attention mechanism

func (*MultiHeadAttention) Decode

func (attention *MultiHeadAttention) Decode(input [][]float64, encoderOutput [][]float64) [][]float64

func (*MultiHeadAttention) Encode

func (attention *MultiHeadAttention) Encode(input [][]float64) [][]float64

type Transformer

type Transformer struct {
	// contains filtered or unexported fields
}

func NewTransformer

func NewTransformer(numHeads, numLayers int, dim ...int) *Transformer

func (*Transformer) BackProp

func (model *Transformer) BackProp(loss [][]float64, learningRate float64)

BackProp function for backpropagation

func (*Transformer) Decode

func (model *Transformer) Decode(input [][]float64, encoderOutput [][]float64) [][]float64

func (*Transformer) Encode

func (model *Transformer) Encode(input [][]float64) [][]float64

func (*Transformer) Forward

func (model *Transformer) Forward(inputSequence [][]float64) [][]float64

func (*Transformer) Train

func (model *Transformer) Train(learningRate float64, epochs int, inputSequence [][]float64, targetSequence [][]float64)

Jump to

Keyboard shortcuts

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