Skip to content

PFalkowski/SimpleML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleML.GeneticAlgorithm

CI NuGet version NuGet downloads Quality Gate Status License: MIT Buy Me a Coffee

A simple, extensible Genetic Algorithm implementation for .NET 8.

Install

dotnet add package SimpleML.GeneticAlgorithm

Usage

// Implement IFitnessFunction for your problem
public class MyFitness : IFitnessFunction
{
    public double Evaluate(Genotype genotype) => /* compute fitness */;
    public Task<double> EvaluateAsync(Genotype genotype) => Task.FromResult(Evaluate(genotype));
}

// Configure and run
var settings = new GeneticAlgorithmSettings(new MyFitness(), problemSize: 100)
{
    PopulationSize = 5000,
    SurvivalRate = 0.1,
    MutationRate = 0.05,
    StopFunction = new BasicStopFunction { MaxEpochs = 500, MinFitness = 95 }
};

var ga = new GeneticAlgorithm(settings);
await ga.Run();

Console.WriteLine($"Best fitness: {ga.RunInfo.BestFitnessSoFar}");

Key types

Type Description
GeneticAlgorithm Orchestrates the evolution loop
GeneticAlgorithmSettings Population size, survival/mutation rates, stop condition
Population Gene pool management, selection, and breeding
Genotype Individual solution encoded as a boolean array
BasicStopFunction Stops after max epochs, target fitness, or fitness plateau
EliteSelection Keeps the top N organisms
BinaryTournamentSelection Random pairwise tournament selection

The idea of the project is to implement various popular ML algorithms in a simple yet efficient way, conforming to best patterns and practices of modern OO programming. PRs are very welcome.

About

No description or website provided.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages