lab

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: BSD-2-Clause Imports: 10 Imported by: 0

README

ev7ab / lab

Package lab is engine of genetic algorithm.

Documentation

go.dev reference

Usage

First of all you need to implement Producer interface. Than create lab instance, add project layout and run examine, like this:

l := lab.New(&producer{})
l.ProjectAdd(project)
l.Run()

But this example does not work as expected because lab.Run() execute goroutine.

App package is an example for using lab package.

Documentation

Overview

Package lab is engine of genetic algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexOfMax

func IndexOfMax(v []float64) int

IndexOfMax returns index of element has maximum value of slice.

func IndexOfMaxExcluded

func IndexOfMaxExcluded(v []float64, excl []int) int

IndexOfMaxExcluded returns index of element has maximum value of slice, excluding some indexes.

func SetAggregator

func SetAggregator(code string, aggr Aggregator)

SetAggregator adds or sets custom aggregation function to functions map. To activate custom aggregation function need to set value of code to Config.Aggr and pass Config to Lab.Setup. May be used to overwrite builtin functions.

func SetProcessor

func SetProcessor(code string, proc Processor)

SetProcessor adds or sets custom processor function to functions map. To activate custom processor function need to set value of code to Config.Proc and pass Config to Lab.Setup. May be used to overwrite builtin functions.

Types

type Aggregator

type Aggregator func([]float64) float64

Aggregator provides function that aggregates values from out of the node.

type Config

type Config struct {
	// Size is maximum size of generation pool and every evolution method.
	Size int
	// Aggr is code of Aggregator lab function.
	// Builtin functions is "sum", "avg", "min", "max".
	// Default is "avg".
	Aggr string
	// Proc is code of Processor lab function.
	// Builtin functions is "linear", "binary", "relu", "lrelu", "silu", "sigmoid", "softplus", "softsign", "tanh", "arctan", "sinusoid", "gaussian".
	// Default is "linear".
	Proc string
	// Goal option if true, than Lab will stop examine when target is reached.
	Goal bool
	// Duel option if true, than Lab will use challenge mode when produce result.
	Duel bool
}

Config provides Lab configuration.

type Lab

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

Lab provides Lab data.

func New

func New(prod Producer) *Lab

New returns new *Lab.

func (*Lab) Export

func (l *Lab) Export() ([]byte, error)

Export returns current state of Lab encoded by gob.

func (*Lab) GetConfig

func (l *Lab) GetConfig() Config

GetConfig returns current Config of Lab.

func (*Lab) GetExec

func (l *Lab) GetExec() bool

GetExec returns exec state of Lab.

func (*Lab) GetProjects

func (l *Lab) GetProjects() []int

GetProjects returns slice of projects id.

func (*Lab) Import

func (l *Lab) Import(data []byte) error

Import used for importing data created by Export function.

func (*Lab) ProjectActivate

func (l *Lab) ProjectActivate(id int)

ProjectActivate activate project by id.

func (*Lab) ProjectAdd

func (l *Lab) ProjectAdd(layout [][]Node) int

ProjectAdd adds new project. Returns id of new project.

func (*Lab) ProjectDeactivate

func (l *Lab) ProjectDeactivate(id int)

ProjectDeactivate deactivate project by id.

func (*Lab) ProjectDelete

func (l *Lab) ProjectDelete(id int)

ProjectDelete delete project by id.

func (*Lab) ProjectLayout

func (l *Lab) ProjectLayout(id int) [][]Node

ProjectLayout returns layout project by id.

func (*Lab) ProjectSet

func (l *Lab) ProjectSet(id int, layout [][]Node)

ProjectSet updates project layout by id. Reset all data of project when update layout.

func (*Lab) ProjectStat

func (l *Lab) ProjectStat(id int) (int, int, int, string, bool)

ProjectStat returns current stats of project: generated count, evoluted count, age, best, goal state

func (*Lab) ProjectStatus

func (l *Lab) ProjectStatus(id int) bool

ProjectStatus status of project.

func (*Lab) ProjectValue

func (l *Lab) ProjectValue(id int, in []float64) []float64

ProjectValue returns out node values of top entity project selected by id.

func (*Lab) Run

func (l *Lab) Run()

Run used for run Lab examine.

func (*Lab) Setup

func (l *Lab) Setup(c Config) error

Setup applies new Config to Lab.

func (*Lab) Stop

func (l *Lab) Stop()

Stop used for soft stop Lab examine.

func (*Lab) Value

func (l *Lab) Value(in []float64) []float64

Value returns out node values of goal entity.

func (*Lab) Volume

func (l *Lab) Volume(in []float64) [][]float64

Volume returns out node values of goal entities all projects.

type Next

type Next func([]float64) []float64

Next provides wrapper function that returns value of last node after execution. This is a service type, usually used in Producer.Produce.

type Node

type Node struct {
	// Src is a slice of links to source nodes.
	Src [][2]int
	// Out is a size of node.
	Out int
}

Node provides interchange of node settings between Lab and external module.

type Processor

type Processor func(float64) float64

Processor provides function that processed values from out of the last node.

type Producer

type Producer interface {
	// Load used for loading and prepare data for producing. Settings map is optional.
	Load(map[string]string) error
	// Setup used for change settings of producer in runtime.
	Setup(string, string) error
	// Produce returns result for first entity.
	// Uses second entity like opponent and previous result when Config.Duel is true.
	Produce(Next, Next, []float64) []float64
	// Validate returns proper state of entity.
	Validate([]float64) bool
	// Compare return true if first result better than second. Used for sort and filter entities.
	Compare([]float64, []float64) bool
	// Best returns formatted string of best result.
	Best([]float64) string
	// Goal returns goal state. If true, lab is reached target.
	Goal([]float64) bool
}

Producer provides prepare and control lab examine.

Jump to

Keyboard shortcuts

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