/// <summary> /// Trains FF network to solve boolean algebra. /// It shows how to use the TNRNetBuilder (TNRNetBuilder is using its default build controller). /// </summary> private void TNRNetBuilderLearning_DefaultController() { _log.Write("Example of a FF network build using the TNRNetBuilder component with default build controller:"); //Create FF network configuration. FeedForwardNetworkSettings ffNetCfg = CreateFFNetConfig(); _log.Write($"Network configuration xml:"); _log.Write(ffNetCfg.GetXml(true).ToString()); //Collect training data VectorBundle trainingData = CreateTrainingData(); //In our case, testing data is the same as training data VectorBundle testingData = trainingData; //Training //Create builder instance TNRNetBuilder builder = new TNRNetBuilder("Boolean Algebra", //Network name ffNetCfg, //Network configuration TNRNet.OutputType.Real, //Network output is one or more real numbers trainingData, //Training data testingData, //Testing data null, //No specific random generator object to be used null //No specific build controller -> use default ); //Register notification event handler builder.NetworkBuildProgressChanged += OnNetworkBuildProgressChanged; //Build the network _log.Write(string.Empty); _log.Write(" Training"); TNRNet ffNet = builder.Build(); //Training is done _log.Write(string.Empty); //Display the network computation results DisplayNetworkComputations(ffNet.Network); //Finished return; }
//Methods /// <summary> /// Evaluates whether the "candidate" network achieved a better result than the best network so far. /// </summary> /// <param name="candidate">The candidate network to be evaluated.</param> /// <param name="currentBest">The best network so far.</param> private static bool IsBetter(TNRNet candidate, TNRNet currentBest) { return(candidate.CombinedPrecisionError < currentBest.CombinedPrecisionError); }