Trait programinduction::GP
[−]
[src]
pub trait GP: Send + Sync + Sized { type Expression: Clone + Send + Sync; type Params; fn genesis<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
pop_size: usize,
tp: &Type
) -> Vec<Self::Expression>; fn mutate<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
prog: &Self::Expression
) -> Self::Expression; fn crossover<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
parent1: &Self::Expression,
parent2: &Self::Expression
) -> Vec<Self::Expression>; fn tournament<'a, R: Rng>(
&self,
rng: &mut R,
tournament_size: usize,
population: &'a [(Self::Expression, f64)]
) -> &'a Self::Expression { ... } fn init<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>
) -> Vec<(Self::Expression, f64)> { ... } fn evolve<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
population: &mut Vec<(Self::Expression, f64)>
) { ... } fn init_and_evolve<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
generations: u32
) -> Vec<(Self::Expression, f64)> { ... } }
A kind of representation suitable for genetic programming.
Implementors of GP
must provide methods for genesis
, mutate
, crossover
. A
Task
provides a fitness function via its oracle
.
Associated Types
type Expression: Clone + Send + Sync
An Expression is a sentence in the representation. Tasks are solved by Expressions.
type Params
Extra parameters for a representation go here.
Required Methods
fn genesis<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
pop_size: usize,
tp: &Type
) -> Vec<Self::Expression>
&self,
params: &Self::Params,
rng: &mut R,
pop_size: usize,
tp: &Type
) -> Vec<Self::Expression>
Create an initial population for a particular requesting type.
fn mutate<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
prog: &Self::Expression
) -> Self::Expression
&self,
params: &Self::Params,
rng: &mut R,
prog: &Self::Expression
) -> Self::Expression
Mutate a single program.
fn crossover<R: Rng>(
&self,
params: &Self::Params,
rng: &mut R,
parent1: &Self::Expression,
parent2: &Self::Expression
) -> Vec<Self::Expression>
&self,
params: &Self::Params,
rng: &mut R,
parent1: &Self::Expression,
parent2: &Self::Expression
) -> Vec<Self::Expression>
Perform crossover between two programs. There must be at least one child.
Provided Methods
fn tournament<'a, R: Rng>(
&self,
rng: &mut R,
tournament_size: usize,
population: &'a [(Self::Expression, f64)]
) -> &'a Self::Expression
&self,
rng: &mut R,
tournament_size: usize,
population: &'a [(Self::Expression, f64)]
) -> &'a Self::Expression
fn init<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>
) -> Vec<(Self::Expression, f64)>
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>
) -> Vec<(Self::Expression, f64)>
fn evolve<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
population: &mut Vec<(Self::Expression, f64)>
)
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
population: &mut Vec<(Self::Expression, f64)>
)
fn init_and_evolve<R: Rng, O: Sync>(
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
generations: u32
) -> Vec<(Self::Expression, f64)>
&self,
params: &Self::Params,
rng: &mut R,
gpparams: &GPParams,
task: &Task<Self, Self::Expression, O>,
generations: u32
) -> Vec<(Self::Expression, f64)>
Implementors
impl GP for Grammar type Expression = AppliedRule; type Params = GeneticParams;