Example #1
0
        static void SerializeDriveComponent()
        {
            World.LoggingLevel = TraceLevel.Warning;
            Agent     John = World.NewAgent("John");
            BPNetwork net;
            FoodDrive foodDr = AgentInitializer.InitializeDrive(John, FoodDrive.Factory, .5);;

            if (load && File.Exists(componentLoadFile))
            {
                Console.WriteLine("Deserializing the drive component");
                SerializationPlugin.DeserializeDriveComponent(foodDr, componentLoadFile, out net);
            }
            else
            {
                Console.WriteLine("Initializing the drive component");
                net = AgentInitializer.InitializeDriveComponent(foodDr, BPNetwork.Factory);
                net.Input.AddRange(Drive.GenerateTypicalInputs(foodDr));

                net.Parameters.LEARNING_RATE = .2;
                net.Parameters.MOMENTUM      = .05;
                foodDr.Commit(net);
            }

            John.Commit(foodDr);

            DoTraining(net, foodDr);

            Console.WriteLine("Serializing the drive component");
            SerializationPlugin.Serialize(net, componentLoadFile);

            John.Die();
        }
Example #2
0
        static void SerializeWorld()
        {
            Agent     John;
            BPNetwork net;
            FoodDrive foodDr;

            if (load && File.Exists(worldLoadFile))
            {
                Console.WriteLine("Deserializing the world");
                SerializationPlugin.DeserializeWorld(worldLoadFile);
                John   = World.GetAgent("John");
                foodDr = (FoodDrive)John.GetInternals(Agent.InternalContainers.DRIVES).First();
                net    = (BPNetwork)foodDr.DriveComponent;
            }
            else
            {
                Console.WriteLine("Initializing the world");
                World.LoggingLevel = TraceLevel.Warning;
                John = World.NewAgent("John");

                foodDr = AgentInitializer.InitializeDrive(John, FoodDrive.Factory, .5);

                net = AgentInitializer.InitializeDriveComponent(foodDr, BPNetwork.Factory);
                net.Input.AddRange(Drive.GenerateTypicalInputs(foodDr));

                net.Parameters.LEARNING_RATE = .2;
                net.Parameters.MOMENTUM      = .05;
                foodDr.Commit(net);
                John.Commit(foodDr);
            }

            DoTraining(net, foodDr);

            Console.WriteLine("Serializing the world");
            SerializationPlugin.SerializeWorld(worldLoadFile);

            John.Die();
        }
Example #3
0
        public static void InitializeAgent(Groups gr)
        {
            Participant = World.NewAgent();

            BPNetwork idn = AgentInitializer.InitializeImplicitDecisionNetwork(Participant, BPNetwork.Factory);

            idn.Input.AddRange(dvs);

            idn.Output.AddRange(acts);

            Participant.Commit(idn);

            foreach (DeclarativeChunk t in tools)
            {
                RefineableActionRule a = AgentInitializer.InitializeActionRule(Participant, RefineableActionRule.Factory, World.GetActionChunk("Tool"));
                foreach (DimensionValuePair dv in t)
                {
                    a.GeneralizedCondition.Add(dv, true);
                }
                Participant.Commit(a);
            }

            foreach (DeclarativeChunk g in guns)
            {
                RefineableActionRule a = AgentInitializer.InitializeActionRule(Participant, RefineableActionRule.Factory, World.GetActionChunk("Gun"));
                foreach (DimensionValuePair dv in g)
                {
                    a.GeneralizedCondition.Add(dv, true);
                }
                Participant.Commit(a);
            }

            Participant.ACS.Parameters.PERFORM_RER_REFINEMENT            = false;
            Participant.ACS.Parameters.PERFORM_DELETION_BY_DENSITY       = false;
            Participant.ACS.Parameters.FIXED_BL_LEVEL_SELECTION_MEASURE  = 1;
            Participant.ACS.Parameters.FIXED_RER_LEVEL_SELECTION_MEASURE = 1;
            Participant.ACS.Parameters.FIXED_IRL_LEVEL_SELECTION_MEASURE = 0;
            Participant.ACS.Parameters.FIXED_FR_LEVEL_SELECTION_MEASURE  = 0;
            Participant.ACS.Parameters.B = 1;

            HonorDrive honor = AgentInitializer.InitializeDrive(Participant, HonorDrive.Factory, r.NextDouble());

            GenericEquation hd = AgentInitializer.InitializeDriveComponent(honor, GenericEquation.Factory, (Equation)TangentEquation);

            var ins = Drive.GenerateTypicalInputs(honor);

            ParameterChangeActionChunk pac = World.NewParameterChangeActionChunk();

            pac.Add(Participant.ACS, "MCS_RER_SELECTION_MEASURE", .5);

            hd.Input.AddRange(ins);

            hd.Parameters.MAX_ACTIVATION = 5;

            honor.Commit(hd);

            honor.Parameters.DRIVE_GAIN = (gr == Groups.PRIVATE) ? .1 / 5 : .2 / 5;

            Participant.Commit(honor);

            ParameterSettingModule lpm = AgentInitializer.InitializeMetaCognitiveModule(Participant, ParameterSettingModule.Factory);

            ACSLevelProbabilitySettingEquation lpe = AgentInitializer.InitializeMetaCognitiveDecisionNetwork(lpm, ACSLevelProbabilitySettingEquation.Factory, Participant);

            lpe.Input.Add(honor.GetDriveStrength());

            lpm.Commit(lpe);

            Participant.Commit(lpm);

            lpm.Parameters.FIXED_BL_LEVEL_SELECTION_MEASURE  = 1;
            lpm.Parameters.FIXED_RER_LEVEL_SELECTION_MEASURE = 0;

            //Pre-train the IDN in the ACS
            PreTrainACS(idn);
        }
Example #4
0
        static void Main(string[] args)
        {
            //Initialize the task
            Console.WriteLine("Initializing the Full Hello World Task");

            int CorrectCounter = 0;
            int NumberTrials   = 20000;

            Random rand = new Random();

            World.LoggingLevel = TraceLevel.Off;

            int progress = 0;

            TextWriter   orig = Console.Out;
            StreamWriter sw   = File.CreateText("HelloWorldFull.txt");

            DimensionValuePair hi  = World.NewDimensionValuePair("Salutation", "Hello");
            DimensionValuePair bye = World.NewDimensionValuePair("Salutation", "Goodbye");

            ExternalActionChunk sayHi  = World.NewExternalActionChunk("Hello");
            ExternalActionChunk sayBye = World.NewExternalActionChunk("Goodbye");

            GoalChunk salute      = World.NewGoalChunk("Salute");
            GoalChunk bidFarewell = World.NewGoalChunk("Bid Farewell");

            //Initialize the Agent
            Agent John = World.NewAgent("John");

            SimplifiedQBPNetwork net = AgentInitializer.InitializeImplicitDecisionNetwork(John, SimplifiedQBPNetwork.Factory);

            net.Input.Add(salute, "goals");
            net.Input.Add(bidFarewell, "goals");

            net.Input.Add(hi);
            net.Input.Add(bye);

            net.Output.Add(sayHi);
            net.Output.Add(sayBye);

            net.Parameters.LEARNING_RATE = 1;

            John.Commit(net);

            John.ACS.Parameters.VARIABLE_BL_BETA  = .5;
            John.ACS.Parameters.VARIABLE_RER_BETA = .5;
            John.ACS.Parameters.VARIABLE_IRL_BETA = 0;
            John.ACS.Parameters.VARIABLE_FR_BETA  = 0;

            RefineableActionRule.GlobalParameters.SPECIALIZATION_THRESHOLD_1 = -.6;
            RefineableActionRule.GlobalParameters.GENERALIZATION_THRESHOLD_1 = -.1;
            RefineableActionRule.GlobalParameters.INFORMATION_GAIN_OPTION    = RefineableActionRule.IGOptions.PERFECT;

            AffiliationBelongingnessDrive ab = AgentInitializer.InitializeDrive(John, AffiliationBelongingnessDrive.Factory, rand.NextDouble(), (DeficitChangeProcessor)HelloWorldFull_DeficitChange);

            DriveEquation abd = AgentInitializer.InitializeDriveComponent(ab, DriveEquation.Factory);

            ab.Commit(abd);

            John.Commit(ab);

            AutonomyDrive aut = AgentInitializer.InitializeDrive(John, AutonomyDrive.Factory, rand.NextDouble(), (DeficitChangeProcessor)HelloWorldFull_DeficitChange);

            DriveEquation autd =
                AgentInitializer.InitializeDriveComponent(aut, DriveEquation.Factory);

            aut.Commit(autd);

            John.Commit(aut);

            GoalSelectionModule gsm =
                AgentInitializer.InitializeMetaCognitiveModule(John, GoalSelectionModule.Factory);

            GoalSelectionEquation gse =
                AgentInitializer.InitializeMetaCognitiveDecisionNetwork(gsm, GoalSelectionEquation.Factory);

            gse.Input.Add(ab.GetDriveStrength());
            gse.Input.Add(aut.GetDriveStrength());

            GoalStructureUpdateActionChunk su = World.NewGoalStructureUpdateActionChunk();
            GoalStructureUpdateActionChunk bu = World.NewGoalStructureUpdateActionChunk();

            su.Add(GoalStructure.RecognizedActions.SET_RESET, salute);
            bu.Add(GoalStructure.RecognizedActions.SET_RESET, bidFarewell);

            gse.Output.Add(su);
            gse.Output.Add(bu);

            gsm.SetRelevance(su, ab, 1);
            gsm.SetRelevance(bu, aut, 1);

            gsm.Commit(gse);

            John.Commit(gsm);

            John.MS.Parameters.CURRENT_GOAL_ACTIVATION_OPTION =
                MotivationalSubsystem.CurrentGoalActivationOptions.FULL;

            //Run the task
            Console.WriteLine("Running the Full Hello World Task");
            Console.SetOut(sw);

            SensoryInformation si;

            ExternalActionChunk chosen;

            for (int i = 0; i < NumberTrials; i++)
            {
                si = World.NewSensoryInformation(John);

                si[AffiliationBelongingnessDrive.MetaInfoReservations.STIMULUS, typeof(AffiliationBelongingnessDrive).Name] = 1;
                si[AutonomyDrive.MetaInfoReservations.STIMULUS, typeof(AutonomyDrive).Name] = 1;

                //Randomly choose an input to perceive.
                if (rand.NextDouble() < .5)
                {
                    //Say "Hello"
                    si.Add(hi, John.Parameters.MAX_ACTIVATION);
                    si.Add(bye, John.Parameters.MIN_ACTIVATION);
                }
                else
                {
                    //Say "Goodbye"
                    si.Add(hi, John.Parameters.MIN_ACTIVATION);
                    si.Add(bye, John.Parameters.MAX_ACTIVATION);
                }

                //Perceive the sensory information
                John.Perceive(si);

                //Choose an action
                chosen = John.GetChosenExternalAction(si);

                //Deliver appropriate feedback to the agent
                if (chosen == sayHi)
                {
                    //The agent said "Hello".
                    if (si[hi] == John.Parameters.MAX_ACTIVATION)
                    {
                        //The agent responded correctly
                        Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was correct");
                        //Record the agent's success.
                        CorrectCounter++;
                        //Give positive feedback.
                        John.ReceiveFeedback(si, 1.0);
                    }
                    else
                    {
                        //The agent responded incorrectly
                        Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was incorrect");
                        //Give negative feedback.
                        John.ReceiveFeedback(si, 0.0);
                    }
                }
                else
                {
                    //The agent said "Goodbye".
                    if (si[bye] == John.Parameters.MAX_ACTIVATION)
                    {
                        //The agent responded correctly
                        Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was correct");
                        //Record the agent's success.
                        CorrectCounter++;
                        //Give positive feedback.
                        John.ReceiveFeedback(si, 1.0);
                    }
                    else
                    {
                        //The agent responded incorrectly
                        Trace.WriteLineIf(World.LoggingSwitch.TraceWarning, "John was incorrect");
                        //Give negative feedback.
                        John.ReceiveFeedback(si, 0.0);
                    }
                }

                Console.SetOut(orig);
                progress           = (int)(((double)(i + 1) / (double)NumberTrials) * 100);
                Console.CursorLeft = 0;
                Console.Write(progress + "% Complete..");
                Console.SetOut(sw);
            }

            //Report Results

            Console.WriteLine("Reporting Results for the Full Hello World Task");
            Console.WriteLine("John got " + CorrectCounter + " correct out of " + NumberTrials + " trials (" +
                              (int)Math.Round(((double)CorrectCounter / (double)NumberTrials) * 100) + "%)");

            Console.WriteLine("At the end of the task, John had learned the following rules:");
            foreach (var i in John.GetInternals(Agent.InternalContainers.ACTION_RULES))
            {
                Console.WriteLine(i);
            }

            sw.Close();
            Console.SetOut(orig);
            Console.CursorLeft = 0;
            Console.WriteLine("100% Complete..");
            //Kill the agent to end the task
            Console.WriteLine("Killing John to end the program");
            John.Die();
            Console.WriteLine("John is Dead");

            Console.WriteLine("The Full Hello World Task has finished");
            Console.WriteLine("The results have been saved to \"HelloWorldFull.txt\"");
            Console.Write("Press any key to exit");
            Console.ReadKey(true);
        }