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(); }
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); }