Example #1
0
        /// <summary>
        /// Creates a deep copy
        /// </summary>
        public INonRecurrentNetwork DeepClone()
        {
            ParallelPerceptron clone = new ParallelPerceptron(NumOfInputValues, Gates, Resolution);

            clone.SetWeights(_flatWeights);
            return(clone);
        }
Example #2
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="net">The PP 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 PDeltaRuleTrainer(ParallelPerceptron net,
                                 List <double[]> inputVectorCollection,
                                 List <double[]> outputVectorCollection,
                                 PDeltaRuleTrainerSettings cfg,
                                 Random rand
                                 )
        {
            //Parameters
            _cfg                    = (PDeltaRuleTrainerSettings)cfg.DeepClone();
            MaxAttempt              = _cfg.NumOfAttempts;
            MaxAttemptEpoch         = _cfg.NumOfAttemptEpochs;
            _net                    = net;
            _rand                   = rand;
            _inputVectorCollection  = inputVectorCollection;
            _outputVectorCollection = outputVectorCollection;
            _resSquashCoeff         = _net.ResSquashCoeff;
            _acceptableError        = 1d / (2d * _resSquashCoeff);
            _marginSignificance     = 1;
            _clearMargin            = 0.05;
            _minM                   = _acceptableError * _resSquashCoeff;
            _maxM                   = 4d * _minM;
            //Parallel workers / batch ranges preparation
            _workerRangeCollection = new List <WorkerRange>();
            int numOfWorkers = Math.Min(Environment.ProcessorCount, _inputVectorCollection.Count);

            numOfWorkers = Math.Max(1, numOfWorkers);
            int workerBatchSize = _inputVectorCollection.Count / numOfWorkers;

            for (int workerIdx = 0, fromRow = 0; workerIdx < numOfWorkers; workerIdx++, fromRow += workerBatchSize)
            {
                int toRow = 0;
                if (workerIdx == numOfWorkers - 1)
                {
                    toRow = _inputVectorCollection.Count - 1;
                }
                else
                {
                    toRow = (fromRow + workerBatchSize) - 1;
                }
                WorkerRange workerRange = new WorkerRange(fromRow, toRow, _net.NumOfWeights);
                _workerRangeCollection.Add(workerRange);
            }
            InfoMessage = string.Empty;
            //Start training attempt
            Attempt = 0;
            NextAttempt();
            return;
        }