hopfield

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pattern2Image

func Pattern2Image(p *Pattern, r image.Rectangle) image.Image

Pattern2Image turns pattern p to a *lossy* Gray scaled image. Data to pixel transformation is lossy: non-positive elements are transformed to 0, otherwise 255

Types

type Network

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

Network is Hopfield network

func NewNetwork

func NewNetwork(size int, method string) (*Network, error)

NewNetwork creates new Hopfield network which is trained using the training method and returns it. NewNetwork returns error if either non-positive size is supplied or unsupported training method is supplied.

func (Network) Bias

func (n Network) Bias() mat.Matrix

Bias returns network bias

func (Network) Capacity

func (n Network) Capacity() int

Capacity returns network capacity

func (Network) Energy

func (n Network) Energy(p *Pattern) (float64, error)

Energy calculates Hopfield network energy for a given pattern and returns it It returns error if the supplied pattern is nil or if it does not have the same dimension as number of network neurons.

func (Network) Memorised

func (n Network) Memorised() int

Memorised returns count of memorised patterns

func (*Network) Restore

func (n *Network) Restore(p *Pattern, mode string, iters int) (*Pattern, error)

Restore tries to restore supplied pattern from network through mode restore process and returns it. Mode can be either sync or async. If sync mode is requested, iters parameter is ignored. If async mode is requested network runs for iters iterations and returns the restored pattern. It returns error if invalid patterns is supplied, iters is negative or unsupported mode is supplied.

func (*Network) Store

func (n *Network) Store(patterns []*Pattern) error

Store stores supplied patterns in network. Store returns error if patterns is nil or if any of the patterns do not have the same dimension as number network neurons.

func (Network) Weights

func (n Network) Weights() mat.Matrix

Weights returns network weights

type Pattern

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

Pattern is a data pattern

func AddNoise

func AddNoise(p *Pattern, pcnt int) *Pattern

AddNoise adds random noise to pattern p and returns it. Noise is added by flipping the sign of existing pattern value. It allows to specify the percentage of noise via pcnt parameter. AddNoise modifies the pattern p in place.

func Encode

func Encode(data []float64) *Pattern

Encode encodes data to a pattern of values: +1/-1 as follows: Non-positive data items are set to -1, positive values are set to +1. Encode modifies the data slice in place and returns a pointer to Pattern. It panics if data is nil or zero-length slice!

func Image2Pattern

func Image2Pattern(img image.Image) *Pattern

Image2Pattern transforms img raw data into binary encoded pattern that can be used in Hopfield Network It first turns the image into a Grey scaled image and then encodes its pixels into binary values of -1/+1

func (*Pattern) At

func (p *Pattern) At(i int) float64

At returns valir of patttern on position i

func (*Pattern) Len

func (p *Pattern) Len() int

Len returns the length of the pattern

func (*Pattern) RawData

func (p *Pattern) RawData() []float64

RawData returns pattern raw data

func (*Pattern) Set

func (p *Pattern) Set(i int, val float64) error

Set sets value on position i

func (*Pattern) String

func (p *Pattern) String() string

String implements Stringer interface

func (*Pattern) Vec

func (p *Pattern) Vec() *mat.VecDense

Vec returns internal data vector

Jump to

Keyboard shortcuts

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