public static void Run(string[] args) { // -clusterid $(Cluster) -processid $(Process) -brain Breakout.brain -factor 0.5 int clusterId = 0; int processId = 0; double discountFactor = 0.6; string breakoutBrainFilePath = ""; OptionSet options = new OptionSet() .Add("clusterid=", v => clusterId = Int32.Parse(v)) .Add("processid=", v => processId = Int32.Parse(v)) .Add("factor=", v => discountFactor = Double.Parse(v, CultureInfo.InvariantCulture)) .Add("brain=", v => breakoutBrainFilePath = Path.GetFullPath(v)); try { options.Parse(Environment.GetCommandLineArgs().Skip(1)); } catch (OptionException e) { MyLog.ERROR.WriteLine(e.Message); } MyProjectRunner runner = new MyProjectRunner(MyLogLevel.DEBUG); StringBuilder result = new StringBuilder(); runner.OpenProject(breakoutBrainFilePath); runner.DumpNodes(); runner.SaveOnStop(23, true); for (int i = 0; i < 5; ++i) { runner.RunAndPause(1000, 100); float[] data = runner.GetValues(23, "Bias"); MyLog.DEBUG.WriteLine(data[0]); MyLog.DEBUG.WriteLine(data[1]); result.AppendFormat("{0}: {1}, {2}", i, data[0], data[1]); runner.Set(23, typeof(MyQLearningTask), "DiscountFactor", discountFactor); runner.RunAndPause(1000, 300); data = runner.GetValues(23, "Bias"); MyLog.DEBUG.WriteLine(data[0]); MyLog.DEBUG.WriteLine(data[1]); result.AppendFormat(" --- {0}, {1}", data[0], data[1]).AppendLine(); runner.Reset(); } string resultFilePath = @"res." + clusterId.ToString() + "." + processId.ToString() + ".txt"; File.WriteAllText(resultFilePath, result.ToString()); string brainzFilePath = @"state." + clusterId.ToString() + "." + processId.ToString() + ".brainz"; runner.SaveProject(brainzFilePath); runner.Shutdown(); return; }
public void CreatesAndRunsMNIST() { using (var runner = new MyProjectRunner()) { MyProject project = runner.CreateProject(typeof(MNISTWorld)); var world = project.World as MNISTWorld; var neuralGroup = project.CreateNode <MyNeuralNetworkGroup>(); project.Network.AddChild(neuralGroup); var hiddenLayer = project.CreateNode <MyHiddenLayer>(); neuralGroup.AddChild(hiddenLayer); var outputLayer = project.CreateNode <MyOutputLayer>(); neuralGroup.AddChild(outputLayer); var accumulator = project.CreateNode <MyAccumulator>(); neuralGroup.AddChild(accumulator); // Connect the nodes. project.Connect(project.Network.GroupInputNodes[0], neuralGroup, 0, 0); project.Connect(project.Network.GroupInputNodes[1], neuralGroup, 0, 1); project.Connect(neuralGroup.GroupInputNodes[0], hiddenLayer, 0, 0); project.Connect(neuralGroup.GroupInputNodes[1], outputLayer, 0, 1); project.Connect(hiddenLayer, outputLayer, 0, 0); project.Connect(outputLayer, accumulator, 1, 0); // Setup the nodes. var sendMnistData = world.SendMNISTTrainData; Assert.NotNull(sendMnistData); sendMnistData.ExpositionTime = 1; world.BitmapOrder = ExampleOrderOption.Shuffle; world.OneHot = true; hiddenLayer.Neurons = 40; accumulator.ApproachValue.ApproachMethod = MyAccumulator.MyApproachValueTask.SequenceType.Momentum; accumulator.ApproachValue.Delta = 0.1f; accumulator.ApproachValue.Target = 0; accumulator.ApproachValue.Factor = 0.9f; // Enable tasks. project.World.EnableDefaultTasks(); neuralGroup.EnableDefaultTasks(); neuralGroup.RMS.Enabled = true; hiddenLayer.EnableDefaultTasks(); outputLayer.EnableDefaultTasks(); accumulator.EnableDefaultTasks(); accumulator.ApproachValue.Enabled = true; // Run the simulation. runner.RunAndPause(100); float error = runner.GetValues(accumulator.Id)[0]; Assert.True(error < 0.5f); //runner.SaveProject(@"c:\foobar.brain"); } }
public float[] GetValues(int nodeId, string blockName = "Output") { return(m_projectRunner.GetValues(nodeId, blockName)); }
public void CreatesAndRunsMNIST() { using (var runner = new MyProjectRunner()) { MyProject project = runner.CreateProject(typeof(MyMNISTWorld)); MyWorld world = project.World; var neuralGroup = project.CreateNode <MyNeuralNetworkGroup>(); project.Network.AddChild(neuralGroup); var hiddenLayer = project.CreateNode <MyHiddenLayer>(); neuralGroup.AddChild(hiddenLayer); var outputLayer = project.CreateNode <MyOutputLayer>(); neuralGroup.AddChild(outputLayer); var accumulator = project.CreateNode <MyAccumulator>(); neuralGroup.AddChild(accumulator); // Connect the nodes. project.Connect(project.Network.GroupInputNodes[0], neuralGroup, 0, 0); project.Connect(project.Network.GroupInputNodes[1], neuralGroup, 0, 1); project.Connect(neuralGroup.GroupInputNodes[0], hiddenLayer, 0, 0); project.Connect(neuralGroup.GroupInputNodes[1], outputLayer, 0, 1); project.Connect(hiddenLayer, outputLayer, 0, 0); project.Connect(outputLayer, accumulator, 1, 0); // Setup the nodes. MyTask sendMnistData = world.GetTaskByPropertyName("SendTrainingMNISTData"); Assert.NotNull(sendMnistData); sendMnistData.GetType().GetProperty("RandomEnumerate").SetValue(sendMnistData, true); sendMnistData.GetType().GetProperty("ExpositionTime").SetValue(sendMnistData, 1); world.GetType().GetProperty("Binary").SetValue(world, true); hiddenLayer.Neurons = 40; accumulator.ApproachValue.ApproachMethod = MyAccumulator.MyApproachValueTask.SequenceType.Momentum; accumulator.ApproachValue.Delta = 0.1f; accumulator.ApproachValue.Target = 0; accumulator.ApproachValue.Factor = 0.9f; // Enable tasks. project.World.EnableDefaultTasks(); neuralGroup.EnableDefaultTasks(); neuralGroup.RMS.Enabled = true; hiddenLayer.EnableDefaultTasks(); outputLayer.EnableDefaultTasks(); accumulator.EnableDefaultTasks(); accumulator.ApproachValue.Enabled = true; // Run the simulation. runner.RunAndPause(100); float error = runner.GetValues(accumulator.Id)[0]; Assert.True(error < 0.5f); //runner.SaveProject(@"c:\foobar.brain"); } }