/// <summary> /// Deep copy constructor /// </summary> /// <param name="source">Source instance</param> public RPropTrainerSettings(RPropTrainerSettings source) { NumOfAttempts = source.NumOfAttempts; NumOfAttemptEpochs = source.NumOfAttemptEpochs; ZeroTolerance = source.ZeroTolerance; PositiveEta = source.PositiveEta; NegativeEta = source.NegativeEta; IniDelta = source.IniDelta; MinDelta = source.MinDelta; MaxDelta = source.MaxDelta; return; }
//Constructor /// <summary> /// Instantiates the RPropTrainer /// </summary> /// <param name="net">The FF network to be trained.</param> /// <param name="inputVectorCollection">The input vectors (input).</param> /// <param name="outputVectorCollection">The output vectors (ideal).</param> /// <param name="cfg">The configuration of the trainer.</param> /// <param name="rand">The random object to be used.</param> public RPropTrainer(FeedForwardNetwork net, List <double[]> inputVectorCollection, List <double[]> outputVectorCollection, RPropTrainerSettings cfg, Random rand ) { if (!net.Finalized) { throw new InvalidOperationException($"Can´t create trainer. Network structure was not finalized."); } _cfg = cfg; MaxAttempt = _cfg.NumOfAttempts; MaxAttemptEpoch = _cfg.NumOfAttemptEpochs; _net = net; _rand = rand; _inputVectorCollection = inputVectorCollection; _outputVectorCollection = outputVectorCollection; _weigthsGradsAcc = new double[_net.NumOfWeights]; _weigthsPrevGradsAcc = new double[_net.NumOfWeights]; _weigthsPrevDeltas = new double[_net.NumOfWeights]; _weigthsPrevChanges = new double[_net.NumOfWeights]; //Parallel gradient workers (batch ranges) preparation int numOfWorkers = Math.Max(1, Math.Min(Environment.ProcessorCount - 1, _inputVectorCollection.Count)); _gradientWorkerDataCollection = new GradientWorkerData[numOfWorkers]; int workerBatchSize = _inputVectorCollection.Count / numOfWorkers; for (int workerIdx = 0, fromRow = 0; workerIdx < numOfWorkers; workerIdx++, fromRow += workerBatchSize) { GradientWorkerData gwd = new GradientWorkerData ( fromRow: fromRow, toRow: (workerIdx == numOfWorkers - 1 ? _inputVectorCollection.Count - 1 : (fromRow + workerBatchSize) - 1), numOfWeights: _net.NumOfWeights ); _gradientWorkerDataCollection[workerIdx] = gwd; } InfoMessage = string.Empty; //Start training attempt Attempt = 0; NextAttempt(); return; }