AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Genetic Test Program Problem

The forum is to discuss topics from different artificial intelligence areas, like neural networks, genetic algorithms, machine learning, etc.

Genetic Test Program Problem

Postby fyw » Sat Feb 05, 2011 1:25 pm

I have created a simple test program using your example and I always get a small number as a result when the data values are around 40.
I'm hoping that I have done something stupid and it is easily solved.

Here is my test program:
using System;
using System.IO;
using AForge;
using AForge.Genetic;

namespace GeneticTest {
public class GeneticTest {
public static void Main (string[] args) {
// constants
double[] constants = new double[10] { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23 };
int iterations = 1000;
int predictionSize = 1;
int windowSize = 10;
//
Console.WriteLine ("Processing input file...");
string[] s = File.ReadAllLines (args[0]);
double[] x = new double[s.Length];
for (int j = 0; j < s.Length; j++) {
x[j] = double.Parse (s[j]);
}
Console.WriteLine ("Computing Genetic Prediction ...");
// create population
Population population = new Population (100, new GPTreeChromosome (
new SimpleGeneFunction (windowSize + constants.Length)),
new TimeSeriesPredictionFitness (x, windowSize, predictionSize, constants),
new EliteSelection ());
for(int i = 0; i < iterations; i++) { population.RunEpoch (); }
// just do the prediction
// solution array
int solutionSize = x.Length - windowSize;
double[] input = new double[windowSize + constants.Length];
// prepare input
Array.Copy( constants, 0, input, windowSize, constants.Length );
for (int j = x.Length - 1; j > solutionSize - 1; j--) {
input[x.Length - j] = x[j];
Console.WriteLine("j = {0}, input[j] = {1}", x.Length - j, x[j]);
}
string bestFunction = population.BestChromosome.ToString ();
double y = PolishExpression.Evaluate (bestFunction, input);
Console.WriteLine ("prediction = {0}", y.ToString ("F3"));
Console.WriteLine ("DONE");
}
}
}

My test data has 250 records with values ranging fro 27 -> 43.
I have gotten values of -1.23, 0.0, and 0.077 .. but most of the time I just get zero.

Am I doing something obviously stupid?

Thanks for your help. I love the library.

Frank
fyw
 
Posts: 3
Joined: Sat Feb 05, 2011 1:16 pm

Re: Genetic Test Program Problem

Postby andrew.kirillov » Sat Feb 05, 2011 7:56 pm

Hello,

1) Why are you sure that 1000 iterations is enough for GP to find more or less good solution? Do you ever check fitness function? Do you ever test prediction on test data?
2) What is the point of copying constants array into input array? Constants are just some numbers used to build the expression. They have 0 relation with input and should not be there at all.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Genetic Test Program Problem

Postby fyw » Sat Feb 05, 2011 8:31 pm

1) I will try more iterations and the sample test data.
2) I just copied the technique of the sample program. It copies the constants array to the input data.

Thanks for taking a look :-)

Frank
fyw
 
Posts: 3
Joined: Sat Feb 05, 2011 1:16 pm

Re: Genetic Test Program Problem

Postby andrew.kirillov » Sat Feb 05, 2011 9:21 pm

fyw wrote:2) I just copied the technique of the sample program. It copies the constants array to the input data.

Oh, my bad. Did that sample quite a while ago, so some details went away from my head. And the copy-paste was so tiny, so it does not look like the original sample, which confused me ... Yes, constants should be part of the array together with variables (history of time series).

Did you try putting your data into the original sample? Does it produce anything meaningful?
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Genetic Test Program Problem

Postby fyw » Sat Feb 05, 2011 9:50 pm

I did run the sample data and I had to go to at least 4000 iterations to get a reasonable result. My program does seem to work so, I will see what it takes for me to get a reasonable answer.

Thanks for your help :-) .. onward!

Frank
fyw
 
Posts: 3
Joined: Sat Feb 05, 2011 1:16 pm




Return to Artificial Intelligence