Exemplo n.º 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();
        }
Exemplo n.º 2
0
        static void SerializeAgent()
        {
            World.LoggingLevel = TraceLevel.Warning;
            Agent     John;
            BPNetwork net;
            FoodDrive foodDr;

            if (load && File.Exists(agentLoadFile))
            {
                Console.WriteLine("Deserializing John");
                SerializationPlugin.DeserializeWorldObject(agentLoadFile, out John);
                foodDr = (FoodDrive)John.GetInternals(Agent.InternalContainers.DRIVES).First();
                net    = (BPNetwork)foodDr.DriveComponent;
            }
            else
            {
                Console.WriteLine("Initializing John");
                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 John");
            SerializationPlugin.Serialize(John, agentLoadFile);

            John.Die();
        }