public void TestGeneral() { IList <BasicData> training = BasicData.ConvertArrays(TestInput, TestIdeal); var score = new ScoreRegressionData(training); IErrorCalculation ec = new ErrorCalculationMSE(); score.ErrorCalc = ec; Assert.AreEqual(ec, score.ErrorCalc); }
/// <summary> /// Run the example. /// </summary> public void Process() { // read the iris data from the resources Assembly assembly = Assembly.GetExecutingAssembly(); Stream res = assembly.GetManifestResourceStream("AIFH_Vol2.Resources.iris.csv"); // did we fail to read the resouce if (res == null) { Console.WriteLine("Can't read iris data from embedded resources."); return; } // load the data var istream = new StreamReader(res); DataSet ds = DataSet.Load(istream); istream.Close(); IGenerateRandom rnd = new MersenneTwisterGenerateRandom(); // The following ranges are setup for the Iris data set. If you wish to normalize other files you will // need to modify the below function calls other files. ds.NormalizeRange(0, -1, 1); ds.NormalizeRange(1, -1, 1); ds.NormalizeRange(2, -1, 1); ds.NormalizeRange(3, -1, 1); IDictionary <string, int> species = ds.EncodeOneOfN(4); istream.Close(); var codec = new RBFNetworkGenomeCODEC(4, RbfCount, 3); IList <BasicData> trainingData = ds.ExtractSupervised(0, codec.InputCount, 4, codec.OutputCount); IPopulation pop = InitPopulation(rnd, codec); IScoreFunction score = new ScoreRegressionData(trainingData); var genetic = new BasicEA(pop, score) { CODEC = codec }; genetic.AddOperation(0.7, new Splice(codec.Size / 3)); genetic.AddOperation(0.3, new MutatePerturb(0.1)); PerformIterations(genetic, 100000, 0.05, true); var winner = (RBFNetwork)codec.Decode(genetic.BestGenome); QueryOneOfN(winner, trainingData, species); }
/// <summary> /// Perform the example. /// </summary> public void Process() { var trainingData = BasicData.ConvertArrays(XorInput, XorIdeal); var network = new RBFNetwork(2, 5, 1); var score = new ScoreRegressionData(trainingData); var train = new TrainGreedyRandom(true, network, score); PerformIterations(train, 1000000, 0.01, true); Query(network, trainingData); }
/// <summary> /// Run the example. /// </summary> public void Process() { IList <BasicData> trainingData = GenerateTrainingData(); var poly = new PolynomialFn(3); IScoreFunction score = new ScoreRegressionData(trainingData); var train = new TrainGreedyRandom(true, poly, score); PerformIterations(train, 1000000, 0.01, true); Console.WriteLine(poly.ToString()); }
public void TestRegression() { double[] actual = { 0.0, 1.0, 0.0, 0.0 }; IList <BasicData> training = BasicData.ConvertArrays(TestInput, TestIdeal); var score = new ScoreRegressionData(training); var simple = new SimpleAlgo(actual); double s = score.CalculateScore(simple); Assert.AreEqual(training, score.TrainingData); Assert.AreEqual(0.25, s, AIFH.DefaultPrecision); }
/// <summary> /// Run the example. /// </summary> public void Process() { // read the iris data from the resources Assembly assembly = Assembly.GetExecutingAssembly(); Stream res = assembly.GetManifestResourceStream("AIFH_Vol2.Resources.iris.csv"); // did we fail to read the resouce if (res == null) { Console.WriteLine("Can't read iris data from embedded resources."); return; } // load the data var istream = new StreamReader(res); DataSet ds = DataSet.Load(istream); istream.Close(); IGenerateRandom rnd = new MersenneTwisterGenerateRandom(); // The following ranges are setup for the Iris data set. If you wish to normalize other files you will // need to modify the below function calls other files. ds.NormalizeRange(0, -1, 1); ds.NormalizeRange(1, -1, 1); ds.NormalizeRange(2, -1, 1); ds.NormalizeRange(3, -1, 1); IDictionary <string, int> species = ds.EncodeOneOfN(4); var particles = new RBFNetwork[ParticleCount]; for (int i = 0; i < particles.Length; i++) { particles[i] = new RBFNetwork(4, 4, 3); particles[i].Reset(rnd); } IList <BasicData> trainingData = ds.ExtractSupervised(0, 4, 4, 3); IScoreFunction score = new ScoreRegressionData(trainingData); var train = new TrainPSO(particles, score); PerformIterations(train, 100000, 0.05, true); var winner = (RBFNetwork)train.BestParticle; QueryOneOfN(winner, trainingData, species); }
/// <summary> /// Run the example. /// </summary> public void Process() { // read the iris data from the resources Assembly assembly = Assembly.GetExecutingAssembly(); Stream res = assembly.GetManifestResourceStream("AIFH_Vol2.Resources.iris.csv"); // did we fail to read the resouce if (res == null) { Console.WriteLine("Can't read iris data from embedded resources."); return; } // load the data var istream = new StreamReader(res); DataSet ds = DataSet.Load(istream); istream.Close(); // The following ranges are setup for the Iris data set. If you wish to normalize other files you will // need to modify the below function calls other files. ds.NormalizeRange(0, -1, 1); ds.NormalizeRange(1, -1, 1); ds.NormalizeRange(2, -1, 1); ds.NormalizeRange(3, -1, 1); IDictionary <string, int> species = ds.EncodeOneOfN(4); istream.Close(); var network = new RBFNetwork(4, 4, 3); IList <BasicData> trainingData = ds.ExtractSupervised(0, 4, 4, 3); IScoreFunction score = new ScoreRegressionData(trainingData); var train = new ContinuousACO(network, score, 30); PerformIterations(train, 100000, 0.05, true); train.FinishTraining(); QueryOneOfN(network, trainingData, species); }