ga

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: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Precission states the fitness precission.
	// e.g. 100 is 2 decimals (default)
	Precission float64 = 100

	// TrainEpochs states how many epochs to train the MLP in the Train operator
	TrainEpochs int = 100

	// MutateRate states the probability of a neuron to be mutated once the Mutate operator is applied
	MutateRate float64 = 1
)

Variables

View Source
var Log = logrus.New()

Log is the logger instance for the GA

Functions

func SortByFitnessAndNeurons

func SortByFitnessAndNeurons(indis []eaopt.Individual)

SortByFitnessAndNeurons First sorts by Fitness and then by number of neurons

func TrainMLP

func TrainMLP(csvdata string) (mlp.MultiLayerNetwork, float64, error)

TrainMLP trains a Multi Layer Perceptron

Types

type MLPClient

type MLPClient struct {
	ServerAddr   string
	Log          *logrus.Logger
	ID           string
	CustomDialer func(s string, dt time.Duration) (net.Conn, error)
	// contains filtered or unexported fields
}

MLPClient is a client to communicate with the GRPC server

func (*MLPClient) Start

func (c *MLPClient) Start() error

Start starts the client on a while loop borrowing, evaluating and returning individuals

func (*MLPClient) StatsFetcher

func (c *MLPClient) StatsFetcher(client *mlp.DistributedEAClient)

StatsFetcher is a thread to ask server about stats {best_fitness, best_neurons, total_evaluations_overall}

type MLPServer

type MLPServer struct {
	Log    *logrus.Logger
	Input  chan eaopt.Individual
	Output chan eaopt.Individual
	Pool   *PoolModel
	// contains filtered or unexported fields
}

MLPServer implements DistributedEA service

func (*MLPServer) BorrowIndividual

func (s *MLPServer) BorrowIndividual(ctx context.Context, e *empty.Empty) (*mlp.MLPMsg, error)

BorrowIndividual implements DistributedEA service

func (*MLPServer) GetProblemDescription

func (s *MLPServer) GetProblemDescription(ctx context.Context, in *empty.Empty) (*mlp.ProblemDescription, error)

GetProblemDescription returs the configuration for the problem execution to the client

func (*MLPServer) GetStats

func (s *MLPServer) GetStats(ctx context.Context, in *empty.Empty) (*mlp.Stats, error)

GetStats returs the statistics of the overall execution on the algorithm

func (*MLPServer) ReturnIndividual

func (s *MLPServer) ReturnIndividual(ctx context.Context, msg *mlp.MLPMsg) (*empty.Empty, error)

ReturnIndividual implements DistributedEA service

type PoolModel

type PoolModel struct {
	Rnd            *rand.Rand
	KeepBest       bool
	SortFunction   func([]eaopt.Individual)
	ExtraOperators []eaopt.ExtraOperator
	EarlyStop      func(*PoolModel) bool

	// Callbacks
	BestCallback       func(*PoolModel)
	GenerationCallback func(*PoolModel)

	CrossRate float64
	MutRate   float64

	PopSize        int
	MaxEvaluations int
	BestSolution   eaopt.Individual
	// contains filtered or unexported fields
}

PoolModel is a pool-based evolutionary algorithm

func MakePool

func MakePool(popSize int, rnd *rand.Rand) *PoolModel

MakePool Creates a new pool with default configuration

func (*PoolModel) GetAverageFitness

func (mod *PoolModel) GetAverageFitness() float64

GetAverageFitness returns the vaerage fitness of the population

func (*PoolModel) GetTotalEvaluations

func (mod *PoolModel) GetTotalEvaluations() int

GetTotalEvaluations returns the total number of evaluations carried out so far

func (*PoolModel) Minimize

func (mod *PoolModel) Minimize()

Minimize runs the algorithm by connecting the pipes

type Population

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

Population stores individuals

func MakePopulation

func MakePopulation() *Population

MakePopulation returns an empty population

func (*Population) Add

func (pop *Population) Add(indiv eaopt.Individual)

Add an individual

func (*Population) Fold

func (pop *Population) Fold(f func(eaopt.Individual) bool)

Fold applies function f to each individual in the population until the end is reached or f returns false

func (*Population) Length

func (pop *Population) Length() int

Length returns the size of the population

func (*Population) RandIndividual

func (pop *Population) RandIndividual(rnd *rand.Rand) (eaopt.Individual, error)

RandIndividual takes an snapshot of the population and returns a random entry from it

func (*Population) Remove

func (pop *Population) Remove(indiv eaopt.Individual)

Remove an individual

func (*Population) Snapshot

func (pop *Population) Snapshot() map[string]cache.Item

Snapshot returns the state of the population at the moment it was called. TODO: Wrap the cache.Item type to eaopt.Individual

Jump to

Keyboard shortcuts

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