Class StandardGeneticAlgorithm<T, TInput, TOutput>
public class StandardGeneticAlgorithm<T, TInput, TOutput> : GeneticBase<T, TInput, TOutput>, IGeneticAlgorithm<T, TInput, TOutput, ModelIndividual<T, TInput, TOutput, ModelParameterGene<T>>, ModelParameterGene<T>>
Type Parameters
TTInputTOutput
- 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
modelFactoryFunc<IFullModel<T, TInput, TOutput>>fitnessCalculatorIFitnessCalculator<T, TInput, TOutput>modelEvaluatorIModelEvaluator<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
genesICollection<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
databyte[]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
databyte[]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
databyte[]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
individualModelIndividual<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
populationSizeintThe size of the population to create.
initializationMethodInitializationMethodThe 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
geneModelParameterGene<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
geneModelParameterGene<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
individualModelIndividual<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.