示例#1
1
        public void Run()
        {
            // get iris file from resource stream
            Assembly assembly = Assembly.GetExecutingAssembly();
            var f = assembly.GetManifestResourceStream("HillClimbing.Resources.iris.csv");
            StreamReader sr = new StreamReader(f);

            // load all records into new dataset
            DataSet ds = DataSet.Load(sr);
            sr.Close();

            Dictionary<string, int> species = ds.EncodeOneOfN(4); // encode specie names using one of n encoding

            // get a list of records with data and encoded class name
            List<Record> trainingData = ds.ExtractSupervised(0, 4, 4, 3);

            Network net = new Network(4, 4, 2); // new RBF network
            net.Randomize(); // initialize the networks state
            Scorer score = new Scorer(trainingData); // new scorer
            HillClimb hc = new HillClimb(net, score, 1.2, 1); // new hill climbing training algorithm
            Iterate(hc, 100, 0.01); // iterate through hill climbing algorithm
            QueryOneOfN(net, trainingData, species); // display ideal and actual specie names
        }
示例#2
0
        public void Run()
        {
            // get iris file from resource stream
            Assembly     assembly = Assembly.GetExecutingAssembly();
            var          f        = assembly.GetManifestResourceStream("HillClimbing.Resources.iris.csv");
            StreamReader sr       = new StreamReader(f);

            // load all records into new dataset
            DataSet ds = DataSet.Load(sr);

            sr.Close();

            Dictionary <string, int> species = ds.EncodeOneOfN(4); // encode specie names using one of n encoding

            // get a list of records with data and encoded class name
            List <Record> trainingData = ds.ExtractSupervised(0, 4, 4, 3);

            Network net = new Network(4, 4, 2);                  // new RBF network

            net.Randomize();                                     // initialize the networks state
            Scorer    score = new Scorer(trainingData);          // new scorer
            HillClimb hc    = new HillClimb(net, score, 1.2, 1); // new hill climbing training algorithm

            Iterate(hc, 100, 0.01);                              // iterate through hill climbing algorithm
            QueryOneOfN(net, trainingData, species);             // display ideal and actual specie names
        }
示例#3
0
        /// <summary>
        /// Iterate through a hill climbing algorithm.
        /// Tries to minimize score.
        /// </summary>
        /// <param name="hc">Algorithm to iterate through.</param>
        /// <param name="numIterations">Maximum iterations.</param>
        /// <param name="minScore">Minimum score.</param>
        private void Iterate(HillClimb hc, int numIterations, double minScore)
        {
            int iterationNumber = 0; // number of iterations
            bool done = false; // is the algorithm done?

            // while not done...
            do {
                iterationNumber++; // increase number of iterations
                hc.Iteration(); // run an iteration

                // if iteration reaches limit or score reaches min score
                if(iterationNumber >= numIterations || hc.LastError < minScore) {
                    done = true; // set done = true
                }

                // write out iteration # and score
                Console.WriteLine("Iteration #" + iterationNumber + ", Score=" + hc.LastError + " (Minimize)");
            } while(!done);
        }
示例#4
0
        /// <summary>
        /// Iterate through a hill climbing algorithm.
        /// Tries to minimize score.
        /// </summary>
        /// <param name="hc">Algorithm to iterate through.</param>
        /// <param name="numIterations">Maximum iterations.</param>
        /// <param name="minScore">Minimum score.</param>
        private void Iterate(HillClimb hc, int numIterations, double minScore)
        {
            int  iterationNumber = 0;     // number of iterations
            bool done            = false; // is the algorithm done?

            // while not done...
            do
            {
                iterationNumber++; // increase number of iterations
                hc.Iteration();    // run an iteration

                // if iteration reaches limit or score reaches min score
                if (iterationNumber >= numIterations || hc.LastError < minScore)
                {
                    done = true; // set done = true
                }

                // write out iteration # and score
                Console.WriteLine("Iteration #" + iterationNumber + ", Score=" + hc.LastError + " (Minimize)");
            } while(!done);
        }