mlp

package
v0.0.0-...-e06ad40 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const ScalingFactor float64 = 0.0000000000001 // TODO: Check if this is really useful

ScalingFactor is Scaling factor for float64 generated random values

Variables

View Source
var (
	ErrInvalidLengthMlp = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowMlp   = fmt.Errorf("proto: integer overflow")
)

Log is the logger for the MLP

View Source
var Logger *logrus.Logger

Logger for MLP

View Source
var TransferFunc_name = map[int32]string{
	0: "SIGMOIDAL",
}
View Source
var TransferFunc_value = map[string]int32{
	"SIGMOIDAL": 0,
}

Functions

func AddNeuron

func AddNeuron(in eaopt.Genome, rng *rand.Rand) eaopt.Genome

AddNeuron is intended to perform incremental learning: it starts with a small structure and increments it, if neccesary, by adding new hidden units TODO: 2 veces probabilidad de eliminar y poner limite de tamaño

func BackPropagate

func BackPropagate(mlp *MultiLayerNetwork, s *mn.Pattern, o []float64, tFunc TransferF, tFuncD TransferF, options ...int) (r float64)

BackPropagate algorithm for assisted learning. Convergence is not guaranteed and very slow. Use as a stop criterion the average between previous and current errors and a maximum number of iterations. [mlp:MultiLayerNetwork] input value [s:Pattern] input value (scaled between 0 and 1) [o:[]float64] expected output value (scaled between 0 and 1) return [r:float64] delta error between generated output and expected output

func Execute

func Execute(mlp *MultiLayerNetwork, s *mn.Pattern, tFunc TransferF, options ...int) (r []float64)

Execute a multi layer Perceptron neural network. [mlp:MultiLayerNetwork] multilayer perceptron network pointer, [s:Pattern] input value It returns output values by network

func KFoldValidation

func KFoldValidation(mlp *MultiLayerNetwork, patterns []mn.Pattern, epochs int, k int, shuffle int, mapped []string) ([]float64, float64)

func NewRandMLP

func NewRandMLP(rng *rand.Rand) eaopt.Genome

NewRandMLP creates a randomly initialized MLP

func PredictN

func PredictN(mlp *MultiLayerNetwork, input []mn.Pattern) (out [][]float64)

PredictN the output for a set of patterns

func RandomNeuronInit

func RandomNeuronInit(neuron *NeuronUnit, dim int)

RandomNeuronInit initialize neuron weight, bias and learning rate using NormFloat64 random value.

func RegisterDistributedEAServer

func RegisterDistributedEAServer(s *grpc.Server, srv DistributedEAServer)

func RemoveNeuron

func RemoveNeuron(in eaopt.Genome, rng *rand.Rand) eaopt.Genome

RemoveNeuron eliminates one hidden neuron at random

func SubstituteNeuron

func SubstituteNeuron(in eaopt.Genome, rng *rand.Rand) eaopt.Genome

SubstituteNeuron replaces one hiddenlayer neuron at random with a new one, initialized with random weights

func Train

func Train(in eaopt.Genome, rng *rand.Rand) eaopt.Genome

Train is used to train the individual-net for a certain number of generations, using BP algorithm.

func Training

func Training(mlp *MultiLayerNetwork, patterns []mn.Pattern, mapped []string, epochs int, bp ...bool)

Training a mlp MultiLayerNetwork with BackPropagation algorithm for assisted learning.

Types

type DistributedEAClient

type DistributedEAClient interface {
	GetProblemDescription(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ProblemDescription, error)
	GetStats(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Stats, error)
	BorrowIndividual(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*MLPMsg, error)
	ReturnIndividual(ctx context.Context, in *MLPMsg, opts ...grpc.CallOption) (*empty.Empty, error)
}

DistributedEAClient is the client API for DistributedEA service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewDistributedEAClient

func NewDistributedEAClient(cc *grpc.ClientConn) DistributedEAClient

type DistributedEAServer

type DistributedEAServer interface {
	GetProblemDescription(context.Context, *empty.Empty) (*ProblemDescription, error)
	GetStats(context.Context, *empty.Empty) (*Stats, error)
	BorrowIndividual(context.Context, *empty.Empty) (*MLPMsg, error)
	ReturnIndividual(context.Context, *MLPMsg) (*empty.Empty, error)
}

DistributedEAServer is the server API for DistributedEA service.

type MLP

MLP Implements the eaopt.Genome interface for mlp.MultilayerNetwork

func (*MLP) Clone

func (nn *MLP) Clone() eaopt.Genome

Clone a MLP to produce a new one that points to a different one by doing a deep copy.

func (*MLP) Crossover

func (nn *MLP) Crossover(Y eaopt.Genome, rng *rand.Rand)

Crossover carries out the multipoint cross-over between two chromosome nets, so that two networks are obtained whose hidden layer neurons are a mixture of the hidden layer neurons of both parents: some hidden neurons along with their in and out connections, from each parent make one offspring and the remaining hidden neurons make the other one. The learningrate is swapped between the two nets.

func (*MLP) Evaluate

func (nn *MLP) Evaluate() (float64, error)

Evaluate a MLP by getting its accuracy TODO: Compare also number of neurons

func (*MLP) Mutate

func (nn *MLP) Mutate(rng *rand.Rand)

Mutate modifies the weights of certain neurons, at random, depending on the application rate. dding or subtracting a small random number that follows uniform distribution with the interval [-0.1, 0.1]. The learning rate is modified by adding a small random number that follows uniform distribution in the interval [-0.05, 0.05]

type MLPConfig

type MLPConfig struct {
	Epochs      int
	TrainEpochs int
	Folds       int
	Classes     []string
	TrainingSet []mn.Pattern
	FactoryCfg  MLPFactoryConfig

	// For inside the mutation operator
	MutateRate float64
}

MLPConfig Stores the common variables for training and evaluating all MLPs generated by the EA

var Config MLPConfig

Config stores the configuration for evaluation and creation of new MLP

type MLPFactoryConfig

type MLPFactoryConfig struct {
	// Network topology
	InputLayers      int
	OutputLayers     int
	MinHiddenNeurons int
	MaxHiddenNeurons int
	Tfunc            TransferFunc

	// Training Info configuration
	MaxLR float64
	MinLR float64
}

MLPFactoryConfig is a type to create a factory of MLP randomly initialized

type MLPMsg

type MLPMsg struct {
	Mlp                  *MultiLayerNetwork `protobuf:"bytes,1,opt,name=mlp,proto3" json:"mlp,omitempty"`
	IndividualID         string             `protobuf:"bytes,2,opt,name=individualID,proto3" json:"individualID,omitempty"`
	Evaluated            bool               `protobuf:"varint,3,opt,name=evaluated,proto3" json:"evaluated,omitempty"`
	Fitness              float64            `protobuf:"fixed64,4,opt,name=Fitness,proto3" json:"Fitness,omitempty"`
	ClientID             string             `protobuf:"bytes,5,opt,name=clientID,proto3" json:"clientID,omitempty"`
	XXX_NoUnkeyedLiteral struct{}           `json:"-"`
	XXX_unrecognized     []byte             `json:"-"`
	XXX_sizecache        int32              `json:"-"`
}

func (*MLPMsg) Descriptor

func (*MLPMsg) Descriptor() ([]byte, []int)

func (*MLPMsg) GetClientID

func (m *MLPMsg) GetClientID() string

func (*MLPMsg) GetEvaluated

func (m *MLPMsg) GetEvaluated() bool

func (*MLPMsg) GetFitness

func (m *MLPMsg) GetFitness() float64

func (*MLPMsg) GetIndividualID

func (m *MLPMsg) GetIndividualID() string

func (*MLPMsg) GetMlp

func (m *MLPMsg) GetMlp() *MultiLayerNetwork

func (*MLPMsg) ProtoMessage

func (*MLPMsg) ProtoMessage()

func (*MLPMsg) Reset

func (m *MLPMsg) Reset()

func (*MLPMsg) String

func (m *MLPMsg) String() string

func (*MLPMsg) XXX_DiscardUnknown

func (m *MLPMsg) XXX_DiscardUnknown()

func (*MLPMsg) XXX_Marshal

func (m *MLPMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MLPMsg) XXX_Merge

func (m *MLPMsg) XXX_Merge(src proto.Message)

func (*MLPMsg) XXX_Size

func (m *MLPMsg) XXX_Size() int

func (*MLPMsg) XXX_Unmarshal

func (m *MLPMsg) XXX_Unmarshal(b []byte) error

type MultiLayerNetwork

type MultiLayerNetwork struct {
	LRate                float64       `protobuf:"fixed64,1,opt,name=LRate,proto3" json:"LRate,omitempty"`
	NeuralLayers         []NeuralLayer `protobuf:"bytes,2,rep,name=NeuralLayers,proto3" json:"NeuralLayers"`
	TFunc                TransferFunc  `protobuf:"varint,3,opt,name=TFunc,proto3,enum=mlp.TransferFunc" json:"TFunc,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func NewPopulatedMultiLayerNetwork

func NewPopulatedMultiLayerNetwork(r randyMlp, easy bool) *MultiLayerNetwork

func PrepareMLPNet

func PrepareMLPNet(l []int, lr float64, tf TransferFunc) (mlp MultiLayerNetwork)

PrepareMLPNet create a multi layer Perceptron neural network. [l:[]int] is an int array with layers neurons number [input, ..., output] [lr:int] is the learning rate of neural network [tr:transferFunction] is a transfer function [tr:transferFunction] the respective transfer function derivative

func (*MultiLayerNetwork) Descriptor

func (*MultiLayerNetwork) Descriptor() ([]byte, []int)

func (*MultiLayerNetwork) Equal

func (this *MultiLayerNetwork) Equal(that interface{}) bool

func (*MultiLayerNetwork) GoString

func (this *MultiLayerNetwork) GoString() string

func (*MultiLayerNetwork) Marshal

func (m *MultiLayerNetwork) Marshal() (dAtA []byte, err error)

func (*MultiLayerNetwork) MarshalTo

func (m *MultiLayerNetwork) MarshalTo(dAtA []byte) (int, error)

func (*MultiLayerNetwork) ProtoMessage

func (*MultiLayerNetwork) ProtoMessage()

func (*MultiLayerNetwork) Reset

func (m *MultiLayerNetwork) Reset()

func (*MultiLayerNetwork) Size

func (m *MultiLayerNetwork) Size() (n int)

func (*MultiLayerNetwork) String

func (this *MultiLayerNetwork) String() string

func (*MultiLayerNetwork) Unmarshal

func (m *MultiLayerNetwork) Unmarshal(dAtA []byte) error

func (*MultiLayerNetwork) XXX_DiscardUnknown

func (m *MultiLayerNetwork) XXX_DiscardUnknown()

func (*MultiLayerNetwork) XXX_Marshal

func (m *MultiLayerNetwork) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MultiLayerNetwork) XXX_Merge

func (m *MultiLayerNetwork) XXX_Merge(src proto.Message)

func (*MultiLayerNetwork) XXX_Size

func (m *MultiLayerNetwork) XXX_Size() int

func (*MultiLayerNetwork) XXX_Unmarshal

func (m *MultiLayerNetwork) XXX_Unmarshal(b []byte) error

type NeuralLayer

type NeuralLayer struct {
	NeuronUnits          []NeuronUnit `protobuf:"bytes,1,rep,name=NeuronUnits,proto3" json:"NeuronUnits"`
	Length               int64        `protobuf:"varint,2,opt,name=Length,proto3" json:"Length,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func NewPopulatedNeuralLayer

func NewPopulatedNeuralLayer(r randyMlp, easy bool) *NeuralLayer

func PrepareLayer

func PrepareLayer(n int, p int) (l NeuralLayer)

PrepareLayer create a NeuralLayer with n NeuronUnits inside [n:int] is an int that specifies the number of neurons in the NeuralLayer [p:int] is an int that specifies the number of neurons in the previous NeuralLayer It returns a NeuralLayer object

func (*NeuralLayer) Descriptor

func (*NeuralLayer) Descriptor() ([]byte, []int)

func (*NeuralLayer) Equal

func (this *NeuralLayer) Equal(that interface{}) bool

func (*NeuralLayer) GoString

func (this *NeuralLayer) GoString() string

func (*NeuralLayer) Marshal

func (m *NeuralLayer) Marshal() (dAtA []byte, err error)

func (*NeuralLayer) MarshalTo

func (m *NeuralLayer) MarshalTo(dAtA []byte) (int, error)

func (*NeuralLayer) ProtoMessage

func (*NeuralLayer) ProtoMessage()

func (*NeuralLayer) Reset

func (m *NeuralLayer) Reset()

func (*NeuralLayer) Size

func (m *NeuralLayer) Size() (n int)

func (*NeuralLayer) String

func (this *NeuralLayer) String() string

func (*NeuralLayer) Unmarshal

func (m *NeuralLayer) Unmarshal(dAtA []byte) error

func (*NeuralLayer) XXX_DiscardUnknown

func (m *NeuralLayer) XXX_DiscardUnknown()

func (*NeuralLayer) XXX_Marshal

func (m *NeuralLayer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NeuralLayer) XXX_Merge

func (m *NeuralLayer) XXX_Merge(src proto.Message)

func (*NeuralLayer) XXX_Size

func (m *NeuralLayer) XXX_Size() int

func (*NeuralLayer) XXX_Unmarshal

func (m *NeuralLayer) XXX_Unmarshal(b []byte) error

type NeuronUnit

type NeuronUnit struct {
	Weights              []float64 `protobuf:"fixed64,1,rep,packed,name=Weights,proto3" json:"Weights,omitempty"`
	Bias                 float64   `protobuf:"fixed64,2,opt,name=Bias,proto3" json:"Bias,omitempty"`
	Lrate                float64   `protobuf:"fixed64,3,opt,name=Lrate,proto3" json:"Lrate,omitempty"`
	Value                float64   `protobuf:"fixed64,4,opt,name=Value,proto3" json:"Value,omitempty"`
	Delta                float64   `protobuf:"fixed64,5,opt,name=Delta,proto3" json:"Delta,omitempty"`
	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
	XXX_unrecognized     []byte    `json:"-"`
	XXX_sizecache        int32     `json:"-"`
}

func NewPopulatedNeuronUnit

func NewPopulatedNeuronUnit(r randyMlp, easy bool) *NeuronUnit

func Remove

func Remove(slice []NeuronUnit, i int) []NeuronUnit

Remove the given index i from the slice of neurons

func (*NeuronUnit) Descriptor

func (*NeuronUnit) Descriptor() ([]byte, []int)

func (*NeuronUnit) Equal

func (this *NeuronUnit) Equal(that interface{}) bool

func (*NeuronUnit) GoString

func (this *NeuronUnit) GoString() string

func (*NeuronUnit) Marshal

func (m *NeuronUnit) Marshal() (dAtA []byte, err error)

func (*NeuronUnit) MarshalTo

func (m *NeuronUnit) MarshalTo(dAtA []byte) (int, error)

func (*NeuronUnit) ProtoMessage

func (*NeuronUnit) ProtoMessage()

func (*NeuronUnit) Reset

func (m *NeuronUnit) Reset()

func (*NeuronUnit) Size

func (m *NeuronUnit) Size() (n int)

func (*NeuronUnit) String

func (this *NeuronUnit) String() string

func (*NeuronUnit) Unmarshal

func (m *NeuronUnit) Unmarshal(dAtA []byte) error

func (*NeuronUnit) XXX_DiscardUnknown

func (m *NeuronUnit) XXX_DiscardUnknown()

func (*NeuronUnit) XXX_Marshal

func (m *NeuronUnit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NeuronUnit) XXX_Merge

func (m *NeuronUnit) XXX_Merge(src proto.Message)

func (*NeuronUnit) XXX_Size

func (m *NeuronUnit) XXX_Size() int

func (*NeuronUnit) XXX_Unmarshal

func (m *NeuronUnit) XXX_Unmarshal(b []byte) error

type ProblemDescription

type ProblemDescription struct {
	ClientID             string   `protobuf:"bytes,1,opt,name=clientID,proto3" json:"clientID,omitempty"`
	Epochs               int64    `protobuf:"varint,2,opt,name=epochs,proto3" json:"epochs,omitempty"`
	Folds                int64    `protobuf:"varint,3,opt,name=folds,proto3" json:"folds,omitempty"`
	TrainDataset         string   `protobuf:"bytes,4,opt,name=trainDataset,proto3" json:"trainDataset,omitempty"`
	Classes              []string `protobuf:"bytes,5,rep,name=classes,proto3" json:"classes,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ProblemDescription) Descriptor

func (*ProblemDescription) Descriptor() ([]byte, []int)

func (*ProblemDescription) GetClasses

func (m *ProblemDescription) GetClasses() []string

func (*ProblemDescription) GetClientID

func (m *ProblemDescription) GetClientID() string

func (*ProblemDescription) GetEpochs

func (m *ProblemDescription) GetEpochs() int64

func (*ProblemDescription) GetFolds

func (m *ProblemDescription) GetFolds() int64

func (*ProblemDescription) GetTrainDataset

func (m *ProblemDescription) GetTrainDataset() string

func (*ProblemDescription) ProtoMessage

func (*ProblemDescription) ProtoMessage()

func (*ProblemDescription) Reset

func (m *ProblemDescription) Reset()

func (*ProblemDescription) String

func (m *ProblemDescription) String() string

func (*ProblemDescription) XXX_DiscardUnknown

func (m *ProblemDescription) XXX_DiscardUnknown()

func (*ProblemDescription) XXX_Marshal

func (m *ProblemDescription) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ProblemDescription) XXX_Merge

func (m *ProblemDescription) XXX_Merge(src proto.Message)

func (*ProblemDescription) XXX_Size

func (m *ProblemDescription) XXX_Size() int

func (*ProblemDescription) XXX_Unmarshal

func (m *ProblemDescription) XXX_Unmarshal(b []byte) error

type Stats

type Stats struct {
	Evaluations          int64    `protobuf:"varint,2,opt,name=evaluations,proto3" json:"evaluations,omitempty"`
	BestFitness          float64  `protobuf:"fixed64,3,opt,name=bestFitness,proto3" json:"bestFitness,omitempty"`
	AvgFitness           float64  `protobuf:"fixed64,4,opt,name=avgFitness,proto3" json:"avgFitness,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Stats) Descriptor

func (*Stats) Descriptor() ([]byte, []int)

func (*Stats) GetAvgFitness

func (m *Stats) GetAvgFitness() float64

func (*Stats) GetBestFitness

func (m *Stats) GetBestFitness() float64

func (*Stats) GetEvaluations

func (m *Stats) GetEvaluations() int64

func (*Stats) ProtoMessage

func (*Stats) ProtoMessage()

func (*Stats) Reset

func (m *Stats) Reset()

func (*Stats) String

func (m *Stats) String() string

func (*Stats) XXX_DiscardUnknown

func (m *Stats) XXX_DiscardUnknown()

func (*Stats) XXX_Marshal

func (m *Stats) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Stats) XXX_Merge

func (m *Stats) XXX_Merge(src proto.Message)

func (*Stats) XXX_Size

func (m *Stats) XXX_Size() int

func (*Stats) XXX_Unmarshal

func (m *Stats) XXX_Unmarshal(b []byte) error

type TransferF

type TransferF = func(float64) float64

TransferF is the tranfer function

type TransferFunc

type TransferFunc int32
const (
	TransferFunc_SIGMOIDAL TransferFunc = 0
)

func (TransferFunc) EnumDescriptor

func (TransferFunc) EnumDescriptor() ([]byte, []int)

func (TransferFunc) String

func (x TransferFunc) String() string

type TransferFunction

type TransferFunction = func(float64) float64

TransferFunction stands for a transfer function

type UnimplementedDistributedEAServer

type UnimplementedDistributedEAServer struct {
}

UnimplementedDistributedEAServer can be embedded to have forward compatible implementations.

func (*UnimplementedDistributedEAServer) BorrowIndividual

func (*UnimplementedDistributedEAServer) BorrowIndividual(ctx context.Context, req *empty.Empty) (*MLPMsg, error)

func (*UnimplementedDistributedEAServer) GetProblemDescription

func (*UnimplementedDistributedEAServer) GetProblemDescription(ctx context.Context, req *empty.Empty) (*ProblemDescription, error)

func (*UnimplementedDistributedEAServer) GetStats

func (*UnimplementedDistributedEAServer) ReturnIndividual

func (*UnimplementedDistributedEAServer) ReturnIndividual(ctx context.Context, req *MLPMsg) (*empty.Empty, error)

Jump to

Keyboard shortcuts

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