Table of Contents

Class StandardGeneticAlgorithm<T, TInput, TOutput>

Namespace
AiDotNet.Genetics
Assembly
AiDotNet.dll
public class StandardGeneticAlgorithm<T, TInput, TOutput> : GeneticBase<T, TInput, TOutput>, IGeneticAlgorithm<T, TInput, TOutput, ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>, ModelParameterGene<T>>

Type Parameters

T
TInput
TOutput
Inheritance
GeneticBase<T, TInput, TOutput>
StandardGeneticAlgorithm<T, TInput, TOutput>
Implements
IGeneticAlgorithm<T, TInput, TOutput, ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>, ModelParameterGene<T>>
Derived
Inherited Members

Constructors

StandardGeneticAlgorithm(Func<IFullModel<T, TInput, TOutput>>, IFitnessCalculator<T, TInput, TOutput>, IModelEvaluator<T, TInput, TOutput>)

public StandardGeneticAlgorithm(Func<IFullModel<T, TInput, TOutput>> modelFactory, IFitnessCalculator<T, TInput, TOutput> fitnessCalculator, IModelEvaluator<T, TInput, TOutput> modelEvaluator)

Parameters

modelFactory Func<IFullModel<T, TInput, TOutput>>
fitnessCalculator IFitnessCalculator<T, TInput, TOutput>
modelEvaluator IModelEvaluator<T, TInput, TOutput>

Methods

CreateIndividual(ICollection<ModelParameterGene<T>>)

Creates a new individual with the specified genes.

public override ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>> CreateIndividual(ICollection<ModelParameterGene<T>> genes)

Parameters

genes ICollection<ModelParameterGene<T>>

The genes to include in the individual.

Returns

ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>

A new individual with the specified genes.

DeserializeIndividual(byte[])

Deserializes an individual from a byte array.

protected override ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>> DeserializeIndividual(byte[] data)

Parameters

data byte[]

The byte array containing the serialized individual.

Returns

ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>

The deserialized individual.

DeserializeModelData(byte[])

Deserializes model-specific data.

protected override void DeserializeModelData(byte[] data)

Parameters

data byte[]

The byte array containing the serialized model data.

DeserializePopulation(byte[])

Deserializes a population from a byte array.

protected override ICollection<ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>> DeserializePopulation(byte[] data)

Parameters

data byte[]

The byte array containing the serialized population.

Returns

ICollection<ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>>

The deserialized population.

GetMetaData()

Gets the metadata for the model.

public override ModelMetadata<T> GetMetaData()

Returns

ModelMetadata<T>

The model metadata.

IndividualToModel(ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>)

Converts an individual to a trained model that can make predictions.

public override IFullModel<T, TInput, TOutput> IndividualToModel(ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>> individual)

Parameters

individual ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>

The individual to convert.

Returns

IFullModel<T, TInput, TOutput>

A model capable of making predictions based on the individual's genes.

InitializePopulation(int, InitializationMethod)

Initializes a new population with random individuals.

public override ICollection<ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>> InitializePopulation(int populationSize, InitializationMethod initializationMethod)

Parameters

populationSize int

The size of the population to create.

initializationMethod InitializationMethod

The method to use for initialization.

Returns

ICollection<ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>>

The newly created population.

MutateGene(ModelParameterGene<T>)

Creates a mutated version of a gene.

protected override ModelParameterGene<T> MutateGene(ModelParameterGene<T> gene)

Parameters

gene ModelParameterGene<T>

The gene to mutate.

Returns

ModelParameterGene<T>

A mutated copy of the gene.

MutateGeneGaussian(ModelParameterGene<T>)

Creates a mutated version of a gene using Gaussian noise.

protected override ModelParameterGene<T> MutateGeneGaussian(ModelParameterGene<T> gene)

Parameters

gene ModelParameterGene<T>

The gene to mutate.

Returns

ModelParameterGene<T>

A mutated copy of the gene.

SerializeIndividual(ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>)

Serializes an individual to a byte array.

protected override byte[] SerializeIndividual(ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>> individual)

Parameters

individual ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>

The individual to serialize.

Returns

byte[]

A byte array containing the serialized individual.

SerializeModelData()

Serializes model-specific data.

protected override byte[] SerializeModelData()

Returns

byte[]

A byte array containing the serialized model data.

SerializePopulation()

Serializes the population to a byte array.

protected override byte[] SerializePopulation()

Returns

byte[]

A byte array containing the serialized population.