maze

package
v4.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package maze provides the maze solving experiments based on NEAT methodology with Novelty Search and Fitness based optimization.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutputIsNaN = errors.New("OUTPUT is NAN")

ErrOutputIsNaN to be returned if one of the network output values is NaN

View Source
var NoveltyMetric neatns.NoveltyMetric = func(x, y *neatns.NoveltyItem) float64 {
	diff := histDiff(x.Data, y.Data)
	return diff
}

NoveltyMetric the novelty metric function for maze simulation

Functions

func NewMazeObjectiveEvaluator

func NewMazeObjectiveEvaluator(out string, mazeEnv *Environment, numSpeciesTarget, compatAdjustFreq int) (experiment.GenerationEvaluator, experiment.TrialRunObserver)

NewMazeObjectiveEvaluator allows creating maze solving agent based on Novelty Search optimization. It will use provided MazeEnv to run simulation of the maze environment. The numSpeciesTarget specifies the target number of species to maintain in the population. If the number of species differ from the numSpeciesTarget it will be automatically adjusted with compatAdjustFreq frequency, i.e., at each epoch % compatAdjustFreq == 0

func NewNoveltySearchEvaluator

func NewNoveltySearchEvaluator(out string, mazeEnv *Environment, numSpeciesTarget, compatAdjustFreq int) (experiment.GenerationEvaluator, experiment.TrialRunObserver)

NewNoveltySearchEvaluator allows creating maze solving agent based on Novelty Search optimization. It will use provided MazeEnv to run simulation of the maze environment. The numSpeciesTarget specifies the target number of species to maintain in the population. If the number of species differ from the numSpeciesTarget it will be automatically adjusted with compatAdjustFreq frequency, i.e., at each epoch % compatAdjustFreq == 0

func NewSafeNSEvaluator added in v4.0.2

func NewSafeNSEvaluator(out string, mazeEnv *Environment, objFuncGenome *genetics.Genome, objFuncOpts *neat.Options, numSpeciesTarget, compatAdjustFreq int) (experiment.GenerationEvaluator, experiment.TrialRunObserver)

NewSafeNSEvaluator allows creating maze solving agent using SAFE commensalistic coevolution method. It will use provided MazeEnv to run simulation of the maze environment. The objFuncGenome provided defines the start genome to be used for evolution of population of candidates into objective functions. The numSpeciesTarget specifies the target number of species to maintain in the population. If the number of species differ from the numSpeciesTarget it will be automatically adjusted with compatAdjustFreq frequency, i.e., at each epoch % compatAdjustFreq == 0

Types

type Agent

type Agent struct {
	// The current location
	Location Point
	// The heading direction in degrees
	Heading float64
	// The speed of agent
	Speed float64
	// The angular velocity
	AngularVelocity float64
	// The radius of agent body
	Radius float64
	// The maximal range of range finder sensors
	RangeFinderRange float64

	// The angles of range finder sensors
	RangeFinderAngles []float64
	// The beginning angles for radar sensors
	RadarAngles1 []float64
	// The ending angles for radar sensors
	RadarAngles2 []float64

	// stores radar outputs
	Radar []float64
	// stores rangefinder outputs
	RangeFinders []float64
}

Agent represents the maze navigator agent

func NewAgent

func NewAgent() Agent

NewAgent creates new Agent with default settings

type AgentRecord

type AgentRecord struct {
	// The ID of agent
	AgentID int
	// The agent position at the end of simulation
	X, Y float64
	// The agent fitness
	Fitness float64
	// The flag to indicate whether agent reached maze exit
	GotExit bool
	// The population generation when agent data was collected
	Generation int
	// The novelty value associated
	Novelty float64

	// The ID of species to whom individual belongs
	SpeciesID int
	// The age of species to whom individual belongs at time of recording
	SpeciesAge int
}

AgentRecord is the record holding info about individual maze agent performance at the end of simulation

type Environment

type Environment struct {
	// The maze navigating agent
	Hero Agent
	// The maze line segments
	Lines []Line
	// The maze exit - goal
	MazeExit Point

	// The flag to indicate if exit was found
	ExitFound bool

	// The number of time steps to be executed during maze solving simulation
	TimeSteps int
	// The sample step size to determine when to collect subsequent samples during simulation
	SampleSize int

	// The range around maze exit point to test if agent coordinates is within to be considered as solved successfully (5.0 is good enough)
	ExitFoundRange float64
	// contains filtered or unexported fields
}

Environment the maze environment definition

func ReadEnvironment

func ReadEnvironment(ir io.Reader) (*Environment, error)

ReadEnvironment reads maze environment from the reader

func (*Environment) AgentDistanceToExit

func (e *Environment) AgentDistanceToExit() float64

AgentDistanceToExit used for fitness calculations based on distance of maze Agent to the target maze exit

func (*Environment) ApplyOutputs

func (e *Environment) ApplyOutputs(o1, o2 float64) error

ApplyOutputs transform neural net outputs into angular velocity and speed

func (*Environment) GetInputs

func (e *Environment) GetInputs() ([]float64, error)

GetInputs create neural net inputs from maze agent sensors

func (*Environment) String

func (e *Environment) String() string

Stringer

func (*Environment) Update

func (e *Environment) Update() error

Update does one time step of the simulation

type Line

type Line struct {
	A, B Point
}

Line the simple line segment class, used for maze walls

func NewLine

func NewLine(a, b Point) Line

NewLine creates new line

func ReadLine

func ReadLine(lr io.Reader) (*Line, error)

ReadLine reads line from specified reader

func (Line) Distance

func (l Line) Distance(p Point) float64

Distance is to find distance between line segment and the point

func (Line) Intersection

func (l Line) Intersection(line Line) (bool, Point)

Intersection calculates point of intersection between two line segments if it exists

func (Line) Length

func (l Line) Length() float64

Length calculates the line segment length

func (Line) Midpoint

func (l Line) Midpoint() Point

Midpoint is to find midpoint of the line segment

type Point

type Point struct {
	X, Y float64
}

Point the simple point class

func ReadPoint

func ReadPoint(lr io.Reader) (*Point, error)

ReadPoint reads Point from specified reader

func (Point) Angle

func (p Point) Angle() float64

Angle is to determine angle in degrees of vector defined by (0,0)->This Point. The angle is from 0 to 360 degrees anti-clockwise.

func (Point) Distance

func (p Point) Distance(point Point) float64

Distance is to find distance between this point and another point

func (*Point) Rotate

func (p *Point) Rotate(angle float64, point Point)

Rotate is to rotate this point around another point with given angle in degrees

type RecordStore

type RecordStore struct {
	// The array of agent records
	Records []AgentRecord
	// The array of the solver agent path points
	SolverPathPoints []Point
}

RecordStore the maze agent records storage

func (*RecordStore) Read

func (s *RecordStore) Read(r io.Reader) error

Reads record store data from provided reader

func (*RecordStore) Write

func (s *RecordStore) Write(w io.Writer) error

Writes record store to the provided writer

Jump to

Keyboard shortcuts

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