xinber / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Patch for /trunk/Sources/Genetic/Fitness Functions/SymbolicRegressionFitness.cs #346

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Added support for multiple input/feature variables. Previously 
SymbolicRegressionFitness only accepted one input variable and multiple 
constants, now it supports multiple variables and multiple constants. It is 
still backwards compatible, so existing code should not break.

Test code:

    double[] constants = new double[] { 3, 11 };
    int constantCount = constants.Length;

    int exampleCount = 100;
    int featureCount = 3;
    double[,] data = new double[exampleCount, featureCount + 1];

    Random rnd = new Random();
    for (int i = 0; i < exampleCount; i++)
    {
        double x = data[i, 0] = rnd.NextDouble() * 100;
        double y = data[i, 1] = rnd.NextDouble() * 100;
        double z = data[i, 2] = rnd.NextDouble() * 100;
        data[i, 3] = constants[0] * x + constants[1] * x * y + x * y / z;
    }

    Population population = new Population(
        100,
        new GPTreeChromosome(new SimpleGeneFunction(featureCount + constantCount)),
        new SymbolicRegressionFitness(data, constants),
        new EliteSelection()
        );

    do
    {
        population.RunEpoch();
        Console.WriteLine(population.BestChromosome + " -> " + population.BestChromosome.Fitness);
    } while (population.BestChromosome.Fitness < 95);

    Console.ReadLine();

Original issue reported on code.google.com by andre.ch...@gmail.com on 9 May 2013 at 11:04

Attachments: