private void ProcessTrain() { if (network == null) { return; } String strMode = GetArg("mode"); String strMinutes = GetArg("minutes"); String strStrategyError = GetArg("strategyerror"); String strStrategyCycles = GetArg("strategycycles"); app.WriteLine("Training Beginning... Output patterns=" + outputCount); double strategyError = double.Parse(strStrategyError); int strategyCycles = int.Parse(strStrategyCycles); var train = new ResilientPropagation(network, training); train.AddStrategy(new ResetStrategy(strategyError, strategyCycles)); if (String.Compare(strMode, "gui", true) == 0) { EncogUtility.TrainDialog(train, network, training); } else { int minutes = int.Parse(strMinutes); EncogUtility.TrainConsole(train, network, training, minutes); } app.WriteLine("Training Stopped..."); }
/// <inheritdoc/> public override void CreateTrainer(OpenCLTrainingProfile profile, bool singleThreaded) { Propagation.Propagation train = new ResilientPropagation(Network, Training, profile, InitialUpdate, MaxStep); if (singleThreaded) { train.NumThreads = 1; } else { train.NumThreads = 0; } foreach (IStrategy strategy in Strategies) { train.AddStrategy(strategy); } Train = train; }
/// <summary> /// Perform an individual job unit, which is a single network to train and /// evaluate. /// </summary> /// /// <param name="context">Contains information about the job unit.</param> public override sealed void PerformJobUnit(JobUnitContext context) { var network = (BasicNetwork)context.JobUnit; BufferedMLDataSet buffer = null; IMLDataSet useTraining = _training; if (_training is BufferedMLDataSet) { buffer = (BufferedMLDataSet)_training; useTraining = (buffer.OpenAdditional()); } // train the neural network double error = Double.PositiveInfinity; for (int z = 0; z < _weightTries; z++) { network.Reset(); Propagation train = new ResilientPropagation(network, useTraining); var strat = new StopTrainingStrategy(0.001d, 5); train.AddStrategy(strat); train.ThreadCount = 1; // force single thread mode for (int i = 0; (i < _iterations) && !ShouldStop && !strat.ShouldStop(); i++) { train.Iteration(); } error = Math.Min(error, train.Error); } if (buffer != null) { buffer.Close(); } if (!ShouldStop) { // update min and max _high = Math.Max(_high, error); _low = Math.Min(_low, error); if (_hidden1Size > 0) { int networkHidden1Count; int networkHidden2Count; if (network.LayerCount > 3) { networkHidden2Count = network.GetLayerNeuronCount(2); networkHidden1Count = network.GetLayerNeuronCount(1); } else { networkHidden2Count = 0; networkHidden1Count = network.GetLayerNeuronCount(1); } int row, col; if (_hidden2Size == 0) { row = networkHidden1Count - _hidden[0].Min; col = 0; } else { row = networkHidden1Count - _hidden[0].Min; col = networkHidden2Count - _hidden[1].Min; } if ((row < 0) || (col < 0)) { Console.Out.WriteLine("STOP"); } _results[row][col] = error; } // report status _currentTry++; UpdateBest(network, error); ReportStatus( context, "Current: " + NetworkToString(network) + "; Best: " + NetworkToString(_bestNetwork)); } }