示例#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
        static void SetupBPNetwork(Agent reasoner)
        {
            //Chunks for the whales, tuna, and bears
            DeclarativeChunk TunaChunk  = World.NewDeclarativeChunk("Tuna");
            DeclarativeChunk WhaleChunk = World.NewDeclarativeChunk("Whale");
            DeclarativeChunk BearChunk  = World.NewDeclarativeChunk("Bear");

            //The 2 properties (as DV pairs)
            DimensionValuePair livesinwater = World.NewDimensionValuePair("lives in", "water");
            DimensionValuePair eatsfish     = World.NewDimensionValuePair("eats", "fish");

            //The BP network to be used in the bottom level of the NACS
            BPNetwork net = AgentInitializer.InitializeAssociativeMemoryNetwork(reasoner, BPNetwork.Factory);

            //Adds the properties (as inputs) and chunks (as outputs) to the BP network
            net.Input.Add(livesinwater);
            net.Input.Add(eatsfish);
            net.Output.Add(TunaChunk);
            net.Output.Add(WhaleChunk);
            net.Output.Add(BearChunk);

            reasoner.Commit(net);

            //Adds the chunks to the GKS
            reasoner.AddKnowledge(TunaChunk);
            reasoner.AddKnowledge(WhaleChunk);
            reasoner.AddKnowledge(BearChunk);

            //Initializes a trainer to use to train the BP network
            GenericEquation trainer = ImplicitComponentInitializer.InitializeTrainer(GenericEquation.Factory, (Equation)trainerEQ);

            //Adds the properties (as inputs) and chunks (as outputs) to the trainer
            trainer.Input.Add(livesinwater);
            trainer.Input.Add(eatsfish);
            trainer.Output.Add(TunaChunk);
            trainer.Output.Add(WhaleChunk);
            trainer.Output.Add(BearChunk);

            trainer.Commit();

            //Sets up data sets for each of the 2 properties
            List <ActivationCollection> sis = new List <ActivationCollection>();
            ActivationCollection        si  = ImplicitComponentInitializer.NewDataSet();

            si.Add(livesinwater, 1);
            sis.Add(si);

            si = ImplicitComponentInitializer.NewDataSet();
            si.Add(eatsfish, 1);
            sis.Add(si);

            Console.Write("Training AMN...");
            //Trains the BP network to report associative knowledge between the properties and the chunks
            ImplicitComponentInitializer.Train(net, trainer, sis, ImplicitComponentInitializer.TrainingTerminationConditions.SUM_SQ_ERROR);
            Console.WriteLine("Finished!");
        }
示例#3
0
        static void DoTraining(BPNetwork target, FoodDrive foodDr)
        {
            DriveEquation trainer = ImplicitComponentInitializer.InitializeTrainer(DriveEquation.Factory, foodDr);

            trainer.Commit();

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

            data.Add(ImplicitComponentInitializer.NewDataSet());

            foreach (var i in foodDr.Input)
            {
                ImplicitComponentInitializer.AddRange(i.WORLD_OBJECT, 0, 1, .25);
                data[0].Add(i);
            }

            Console.WriteLine("Performing Pre-Training (see the trace log for results)");

            ImplicitComponentInitializer.Train(target, trainer, data, ImplicitComponentInitializer.TrainingTerminationConditions.BOTH, numTrials);
        }