Beispiel #1
0
        /// <summary>
        /// Goes through each record in the training set and displays the ideal output and the actual output.
        /// </summary>
        /// <param name="net">RBF network.</param>
        /// <param name="trainingData"></param>
        /// <param name="specieNames"></param>
        public void QueryEquilateral(GreedyRandom gr, Network net, List <Record> trainingData, Dictionary <string, int> specieNames)
        {
            // invert the specie list
            Dictionary <int, string> invSpecies = new Dictionary <int, string>();

            foreach (string key in specieNames.Keys)
            {
                int value = specieNames[key];
                invSpecies[value] = key;
            }

            Equilateral eq = new Equilateral(specieNames.Count); // create encoding matrix for specie names

            // for each training record
            foreach (Record rec in trainingData)
            {
                double[] output = net.ComputeRegression(rec.Input); // run the record through the RBF network

                int idealIndex  = eq.Decode(rec.Ideals);            // find the ideal specie name for the record
                int actualIndex = eq.Decode(output);                // find the calculated specie name for the record

                Console.WriteLine("Guess: " + invSpecies[actualIndex]
                                  + ", Ideal: " + invSpecies[idealIndex]);
            }

            Console.WriteLine("Final error: " + gr.LastError);
        }
Beispiel #2
0
        /// <summary>
        /// Encodes each header using equilateral encoding.
        /// </summary>
        /// <param name="col">Column to encode.</param>
        /// <returns>Returns dictionary containing specie name and index.</returns>
        public Dictionary <string, int> EncodeEquilateral(int col)
        {
            string name = _headers[col];                              // header name

            Dictionary <string, int> classes = EnumerateClasses(col); // specie name and index
            int classCount = classes.Count;                           // number of species

            InsertColumns(col + 1, classCount - 1);                   // insert additional columns into _data

            Equilateral eq = new Equilateral(classCount);             // create equilateral for number of classes

            // fill _data with encoded species
            foreach (object[] obj in _data)
            {
                int idx = classes[obj[col].ToString()]; // get value for corresponding key

                double[] encoded = eq.Encode(idx);      // encode specie name

                // fill _data with encoded values
                for (int i = 0; i < classCount - 1; i++)
                {
                    obj[col + i] = encoded[i];
                }
            }

            // fill _headers with number of classes
            for (int i = 0; i < classes.Count; i++)
            {
                _headers[col + i] = name + "-" + i;
            }

            return(classes); // return
        }