gosom

package module
v0.0.0-...-cd12476 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 14 Imported by: 0

README

gosom

Package gosom implements the self organizing map algorithm.

Documentation

Overview

Package gosom implements the self organizing map algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawDimensions

func DrawDimensions(som *SOM, nodeWidth int) []image.Image

DrawDimensions draws the dimensions of the SOM as images.

func DrawUMatrix

func DrawUMatrix(som *SOM, nodeWidth int) image.Image

DrawUMatrix draws the U-Matrix of the SOM as an image.

Types

type Lattice

type Lattice []*Node

A Lattice is a collection of nodes arranged in a two dimensional space.

func NewLattice

func NewLattice(width, height, dimensions int) Lattice

NewLattice returns an initialized lattice.

func (Lattice) Sort

func (l Lattice) Sort(sortFunction func(n1, n2 *Node) bool) Lattice

Sort returns a sorted lattice using the sorting function.

type Matrix

type Matrix struct {
	Data     [][]float64
	Rows     int
	Columns  int
	Minimums []float64
	Maximums []float64
	Minimum  float64
	Maximum  float64
	NaNs     bool
}

A Matrix holds and extends a two dimensional float slice.

func LoadMatrixFromCSV

func LoadMatrixFromCSV(source io.Reader) (*Matrix, error)

LoadMatrixFromCSV reads CSV data and returns a new matrix.

func LoadMatrixFromJSON

func LoadMatrixFromJSON(source io.Reader) (*Matrix, error)

LoadMatrixFromJSON read JSON data and returns a new matrix.

func NewMatrix

func NewMatrix(data [][]float64) *Matrix

NewMatrix will create a new Matrix and work out the meta information. The function expects the float slice to be consistent in columns.

func (*Matrix) Column

func (m *Matrix) Column(col int) []float64

Column returns all values in a column.

func (*Matrix) RandomRow

func (m *Matrix) RandomRow() []float64

RandomRow returns a random row from the matrix.

func (*Matrix) SubMatrix

func (m *Matrix) SubMatrix(start, length int) *Matrix

SubMatrix returns a matrix that holds a subset of the current matrix.

type Node

type Node struct {
	Position []float64
	Weights  []float64
}

A Node is a single neuron in a self organizing map.

func NewNode

func NewNode(x, y, dimensions int) *Node

NewNode returns a new Node.

func (*Node) Adjust

func (n *Node) Adjust(input []float64, influence float64)

Adjust makes the node more alike to the input based on the influence.

Note: Dimensions that include NaNs are ignored.

func (*Node) X

func (n *Node) X() int

X returns the x coordinate of the node.

func (*Node) Y

func (n *Node) Y() int

Y returns the y coordinate of the node.

type SOM

type SOM struct {
	Width                int
	Height               int
	Nodes                Lattice
	CoolingFunction      string
	DistanceFunction     string
	NeighborhoodFunction string
}

SOM holds an instance of a self organizing map.

func LoadSOMFromJSON

func LoadSOMFromJSON(source io.Reader) (*SOM, error)

LoadSOMFromJSON reads data from source and returns a SOM.

func NewSOM

func NewSOM(width, height int) *SOM

NewSOM creates and returns a new self organizing map.

func (*SOM) CF

func (som *SOM) CF(progress float64) float64

CF is a convenience function for calculating cooling factors.

func (*SOM) Classify

func (som *SOM) Classify(input []float64) []float64

Classify returns the classification for input.

func (*SOM) Closest

func (som *SOM) Closest(input []float64) *Node

Closest returns the closest Node to the input.

func (*SOM) D

func (som *SOM) D(from, to []float64) float64

D is a convenience function for calculating distances.

func (*SOM) Dimensions

func (som *SOM) Dimensions() int

Dimensions returns the dimensions of the nodes.

func (*SOM) InitializeWithDataPoints

func (som *SOM) InitializeWithDataPoints(data *Matrix)

InitializeWithDataPoints initializes the nodes with random data points.

Note: Do not use this function if your data set includes null values. Use InitializeWithRandomValues instead.

func (*SOM) InitializeWithRandomValues

func (som *SOM) InitializeWithRandomValues(data *Matrix)

InitializeWithRandomValues initializes the nodes with random values between the calculated minimums and maximums per dimension.

func (*SOM) InitializeWithZeroes

func (som *SOM) InitializeWithZeroes(dimensions int)

InitializeWithZeroes initializes the nodes with zero initialized dimensions.

func (*SOM) Interpolate

func (som *SOM) Interpolate(input []float64, K int) []float64

Interpolate interpolates the input using K neighbors.

func (*SOM) N

func (som *SOM) N(x, y int) *Node

N is a convenience function for accessing nodes.

func (*SOM) NI

func (som *SOM) NI(distance float64) float64

NI is a convenience function for calculating neighborhood influences.

func (*SOM) Neighbors

func (som *SOM) Neighbors(input []float64, K int) []*Node

Neighbors returns the K nearest neighbors to the input.

func (*SOM) SaveAsJSON

func (som *SOM) SaveAsJSON(destination io.Writer) error

SaveAsJSON writes the SOM as a JSON file to destination.

func (*SOM) Step

func (som *SOM) Step(data *Matrix, step int, training *Training)

Step applies one step of learning.

func (*SOM) String

func (som *SOM) String() string

String returns a string matrix of all nodes and weights

func (*SOM) Train

func (som *SOM) Train(data *Matrix, training *Training)

Train trains the SOM from the data.

func (*SOM) WeightMatrix

func (som *SOM) WeightMatrix() *Matrix

WeightMatrix returns a matrix based on the weights of the nodes.

func (*SOM) WeightedInterpolate

func (som *SOM) WeightedInterpolate(input []float64, K int) []float64

WeightedInterpolate interpolates the input using K neighbors by weighting the distance to the input.

type Training

type Training struct {
	SOM                 *SOM
	Steps               int
	InitialLearningRate float64
	FinalLearningRate   float64
	InitialRadius       float64
	FinalRadius         float64
}

A Training holds settings for a SOM training.

func NewTraining

func NewTraining(som *SOM, steps int, ilr, flr, ir, fr float64) *Training

NewTraining returns a new Training.

func (*Training) LearningRate

func (t *Training) LearningRate(step int) float64

LearningRate calculates the current learning rate.

func (*Training) Progress

func (t *Training) Progress(step int) float64

Progress returns the current progress based on step and steps.

func (*Training) Radius

func (t *Training) Radius(step int) float64

Radius calculates the current radius.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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