예제 #1
0
        /// <summary>
        /// Run the example.
        /// </summary>
        public void Process()
        {
            // read the iris data from the resources
            Assembly assembly = Assembly.GetExecutingAssembly();
            var res = assembly.GetManifestResourceStream("AIFH_Vol1.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, 0, 1);
            ds.NormalizeRange(1, 0, 1);
            ds.NormalizeRange(2, 0, 1);
            ds.NormalizeRange(3, 0, 1);
            IDictionary<String, int> species = ds.EncodeOneOfN(4);

            IList<BasicData> trainingData = ds.ExtractSupervised(0, 4, 4, 3);

            var network = new RBFNetwork(4, 4, 2);
            network.Reset(new MersenneTwisterGenerateRandom());
            IScoreFunction score = new ScoreRegressionData(trainingData);
            var train = new TrainAnneal(network, score);
            PerformIterations(train, 100000, 0.01, true);
            QueryOneOfN(network, trainingData, species);
        }
예제 #2
0
        public void TestIterations()
        {
            var anneal = new TrainAnneal(new TrialAlgo(), new TrialScore(), 10, 400, 0.0001) {Cycles = 10};
            Assert.AreEqual(400, anneal.CoolingSchedule(), AIFH.DefaultPrecision);


            Assert.AreEqual(400, anneal.StartingTemperature, AIFH.DefaultPrecision);
            Assert.AreEqual(0.0001, anneal.EndingTemperature, AIFH.DefaultPrecision);
            Assert.AreEqual(10, anneal.Cycles);

            Assert.AreEqual(0, anneal.CurrentTemperature, AIFH.DefaultPrecision);
            Assert.AreEqual(0, anneal.K);
            Assert.AreEqual(false, anneal.Done);
            Assert.AreEqual(true, double.IsInfinity(anneal.LastError));
            Assert.AreEqual(0, anneal.LastProbability, AIFH.DefaultPrecision);
            anneal.Iteration();

            Assert.AreEqual(true, anneal.LastError > 0);

            Assert.AreEqual(87.46896591546223, anneal.CurrentTemperature, AIFH.DefaultPrecision);
            Assert.AreEqual(1, anneal.K);
            Assert.AreEqual(false, anneal.Done);

            for (int i = 0; i < 9; i++)
            {
                anneal.Iteration();
            }

            Assert.AreEqual(true, anneal.Done);
            Assert.AreEqual(9.999999999999E-5, anneal.CurrentTemperature, AIFH.DefaultPrecision);
            Assert.AreEqual(10, anneal.K);

        }
예제 #3
0
 public void TestRandomize()
 {
     var algo = new TrialAlgo();
     var anneal = new TrainAnneal(algo, new TrialScore());
     anneal.PerformRandomize(algo.LongTermMemory);
     anneal.FinishTraining();
     Assert.AreEqual(0, algo.LongTermMemory[0], AIFH.DefaultPrecision);
 }
예제 #4
0
 public void TestAnneal()
 {
     var anneal = new TrainAnneal(new TrialAlgo(), new TrialScore());
     PerformTest(anneal);
 }
예제 #5
0
 public void TestGetStatus()
 {
     var anneal = new TrainAnneal(new TrialAlgo(), new TrialScore());
     Assert.AreEqual("k=0,kMax=1000,t=0,prob=0", anneal.Status);
 }
예제 #6
0
 public void TestBasic()
 {
     var anneal = new TrainAnneal(new TrialAlgo(), new TrialScore());
     Assert.AreEqual(400, anneal.CoolingSchedule(), AIFH.DefaultPrecision);
 }