示例#1
0
        public static void PreTrainACS(BPNetwork idn)
        {
            Console.Write("Pre-training ACS...");

            pABEBlackGun = abeBlackGun + (((r.NextDouble() * 2) - 1) * abeMaxTemp);
            pABEWhiteGun = abeWhiteGun + (((r.NextDouble() * 2) - 1) * abeMaxTemp);

            List <ActivationCollection> dataSets = new List <ActivationCollection>();

            List <DeclarativeChunk> primes = new List <DeclarativeChunk>();

            primes.AddRange(white_faces);
            primes.AddRange(black_faces);

            List <DeclarativeChunk> targets = new List <DeclarativeChunk>();

            targets.AddRange(guns);
            targets.AddRange(tools);

            foreach (DeclarativeChunk p in primes)
            {
                foreach (DeclarativeChunk t in targets)
                {
                    ActivationCollection ds = ImplicitComponentInitializer.NewDataSet();
                    ds.AddRange(p, 1);
                    ds.AddRange(t, 1);

                    dataSets.Add(ds);
                }
            }

            ImplicitComponentInitializer.Train(idn, trainer, numIterations: numTrainingTrials, randomTraversal: true, dataSets: dataSets.ToArray());

            Console.WriteLine("Finished");
        }
示例#2
0
        /// <summary>
        /// Encodes the patterns into the specified Hopfield network and then tests to make sure they have been successfully encoded
        /// </summary>
        /// <remarks>
        /// <note type="implementnotes">Most of the work that is done by this method is actually also performed by the implicit component initializer's
        /// <see cref="ImplicitComponentInitializer.Encode{T}(T, ImplicitComponentInitializer.EncodeTerminationConditions, int, ActivationCollection[])">
        /// Encode</see> method. However, we must separate the "encode" and "recall" phases in this example since we are using a different
        /// <see cref="HopfieldNetwork.TransmissionOptions">transmission option</see> between these encoding process.</note>
        /// </remarks>
        /// <param name="net">the network where the patterns are to be encoded</param>
        static void EncodeHopfieldNetwork(HopfieldNetwork net)
        {
            //Tracks the accuracy of correctly encoded patterns
            double accuracy = 0;

            //Continue encoding until all of the patterns are successfully recalled
            do
            {
                //Specifies to use the "N spins" transmission option during the encoding phase
                net.Parameters.TRANSMISSION_OPTION =
                    HopfieldNetwork.TransmissionOptions.N_SPINS;

                List <ActivationCollection> sis = new List <ActivationCollection>();
                foreach (DeclarativeChunk dc in chunks)
                {
                    //Gets a new "data set" object (to be used by the Encode method to encode the pattern)
                    ActivationCollection si = ImplicitComponentInitializer.NewDataSet();

                    //Sets up the pattern
                    si.AddRange(dc, 1);

                    sis.Add(si);
                }

                //Encodes the pattern into the Hopfield network
                ImplicitComponentInitializer.Encode(net, sis);


                //Specifies to use the "let settle" transmission option during the testing phase
                net.Parameters.TRANSMISSION_OPTION =
                    HopfieldNetwork.TransmissionOptions.LET_SETTLE;

                //Tests the net to see if it has learned the patterns
                accuracy = ImplicitComponentInitializer.Encode(net, sis, testOnly: true);

                Console.WriteLine(((int)accuracy * 100) + "% of the patterns were successfully recalled.");
            } while (accuracy < 1);
        }