Ejemplo n.º 1
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!");
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            Agent reasoner = World.NewAgent();

            InitializeWorld(reasoner);

            //Adds all of the declarative chunks to the GKS
            foreach (DeclarativeChunk dc in chunks)
            {
                reasoner.AddKnowledge(dc);
            }

            //Initializes the Hopfield network in the bottom level of the NACS
            HopfieldNetwork net = AgentInitializer.InitializeAssociativeMemoryNetwork
                                      (reasoner, HopfieldNetwork.Factory);

            //Species all of the dimension-value pairs as nodes for the Hopfield network
            net.Nodes.AddRange(dvs);

            //Commits the Hopfield network
            reasoner.Commit(net);

            //Encodes the patterns into the Hopfield network
            EncodeHopfieldNetwork(net);

            //Sets up the rules in the top level of the NAS
            SetupRules(reasoner);

            //Specifies that the NACS should perform 2 reasoning iterations
            reasoner.NACS.Parameters.REASONING_ITERATION_COUNT = 2;
            //Sets the conclusion threshold to 1
            //(indicating that only fully matched conclusions should be returned)
            reasoner.NACS.Parameters.CONCLUSION_THRESHOLD = 1;

            //Initiates reasoning and outputs the results
            DoReasoning(reasoner);

            //Kills the reasoning agent
            reasoner.Die();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            Agent reasoner = World.NewAgent();

            InitializeWorld(reasoner);

            //Adds all of the declarative chunks to the GKS
            foreach (DeclarativeChunk dc in chunks)
            {
                reasoner.AddKnowledge(dc);
            }

            //Initializes the Hopfield network in the bottom level of the NACS
            HopfieldNetwork net = AgentInitializer.InitializeAssociativeMemoryNetwork
                                      (reasoner, HopfieldNetwork.Factory);

            //Species all of the dimension-value pairs as nodes for the Hopfield network
            net.Nodes.AddRange(dvs);

            //Commits the Hopfield network
            reasoner.Commit(net);

            //Encodes the patterns into the Hopfield network
            EncodeHopfieldNetwork(net);

            //Specifies that the NACS should perform 2 reasoning iterations
            reasoner.NACS.Parameters.REASONING_ITERATION_COUNT = 1;
            //Sets the conclusion threshold to 1
            //(indicating that only fully matched conclusions should be returned)
            reasoner.NACS.Parameters.CONCLUSION_THRESHOLD = 1;

            // Add Some Action Chunks for the ACS
            World.NewExternalActionChunk("Yes");
            World.NewExternalActionChunk("No");
            ReasoningRequestActionChunk think = World.NewReasoningRequestActionChunk("DoReasoning");

            think.Add(NonActionCenteredSubsystem.RecognizedReasoningActions.NEW, 1, false);

            World.NewDimensionValuePair("state", 1);
            World.NewDimensionValuePair("state", 2);
            World.NewDimensionValuePair("state", 3);

            // Add ACS Rule to use chunks
            RefineableActionRule yes = AgentInitializer.InitializeActionRule(reasoner, RefineableActionRule.Factory, World.GetActionChunk("Yes"));

            yes.GeneralizedCondition.Add(World.GetDeclarativeChunk(1), true);
            reasoner.Commit(yes);

            RefineableActionRule no = AgentInitializer.InitializeActionRule(reasoner, RefineableActionRule.Factory, World.GetActionChunk("No"));

            no.GeneralizedCondition.Add(World.GetDeclarativeChunk(0), true, "altdim");
            no.GeneralizedCondition.Add(World.GetDeclarativeChunk(2), true, "altdim");
            no.GeneralizedCondition.Add(World.GetDeclarativeChunk(3), true, "altdim");
            no.GeneralizedCondition.Add(World.GetDeclarativeChunk(4), true, "altdim");
            reasoner.Commit(no);

            RefineableActionRule doReasoning = AgentInitializer.InitializeActionRule(reasoner, RefineableActionRule.Factory, World.GetActionChunk("DoReasoning"));

            doReasoning.GeneralizedCondition.Add(World.GetDimensionValuePair("state", 1));
            reasoner.Commit(doReasoning);

            RefineableActionRule doNothing = AgentInitializer.InitializeActionRule(reasoner, RefineableActionRule.Factory, ExternalActionChunk.DO_NOTHING);

            doNothing.GeneralizedCondition.Add(World.GetDimensionValuePair("state", 2));
            reasoner.Commit(doNothing);

            reasoner.ACS.Parameters.PERFORM_RER_REFINEMENT            = false;
            reasoner.ACS.Parameters.FIXED_BL_LEVEL_SELECTION_MEASURE  = 0;
            reasoner.ACS.Parameters.FIXED_RER_LEVEL_SELECTION_MEASURE = 1;
            reasoner.ACS.Parameters.FIXED_IRL_LEVEL_SELECTION_MEASURE = 0;
            reasoner.ACS.Parameters.FIXED_FR_LEVEL_SELECTION_MEASURE  = 0;
            reasoner.ACS.Parameters.LEVEL_SELECTION_METHOD            = ActionCenteredSubsystem.LevelSelectionMethods.STOCHASTIC;
            reasoner.ACS.Parameters.LEVEL_SELECTION_OPTION            = ActionCenteredSubsystem.LevelSelectionOptions.FIXED;
            reasoner.ACS.Parameters.NACS_REASONING_ACTION_PROBABILITY = 1;
            reasoner.ACS.Parameters.EXTERNAL_ACTION_PROBABILITY       = 1;
            reasoner.NACS.Parameters.REASONING_ITERATION_TIME         = 3000;

            //Initiates the simulation and outputs the results
            Run(reasoner);

            //Kills the reasoning agent
            reasoner.Die();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }