예제 #1
0
 /// <summary>
 /// The deep copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public ParallelPerceptronSettings(ParallelPerceptronSettings source)
 {
     Gates                = source.Gates;
     Resolution           = source.Resolution;
     PDeltaRuleTrainerCfg = (PDeltaRuleTrainerSettings)source.PDeltaRuleTrainerCfg.DeepClone();
     return;
 }
예제 #2
0
 /// <summary>
 /// The deep copy constructor.
 /// </summary>
 /// <param name="source">The source instance.</param>
 public PDeltaRuleTrainerSettings(PDeltaRuleTrainerSettings source)
 {
     NumOfAttempts      = source.NumOfAttempts;
     NumOfAttemptEpochs = source.NumOfAttemptEpochs;
     IniLR = source.IniLR;
     IncLR = source.IncLR;
     DecLR = source.DecLR;
     MinLR = source.MinLR;
     MaxLR = source.MaxLR;
     return;
 }
예제 #3
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance
 /// </summary>
 /// <param name="gates">Number of gates</param>
 /// <param name="resolution">Output resolution</param>
 /// <param name="trainerCfg">Trainer configuration</param>
 public ParallelPerceptronSettings(int gates,
                                   int resolution,
                                   PDeltaRuleTrainerSettings trainerCfg
                                   )
 {
     Gates                = gates;
     Resolution           = resolution;
     PDeltaRuleTrainerCfg = (PDeltaRuleTrainerSettings)trainerCfg.DeepClone();
     Check();
     return;
 }
예제 #4
0
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="elem">Xml element containing the initialization settings</param>
        public ParallelPerceptronSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            Gates      = int.Parse(settingsElem.Attribute("gates").Value, CultureInfo.InvariantCulture);
            Resolution = int.Parse(settingsElem.Attribute("resolution").Value, CultureInfo.InvariantCulture);
            XElement pDeltaRuleTrainerElem = settingsElem.Elements("pDeltaRuleTrainer").First();

            PDeltaRuleTrainerCfg = new PDeltaRuleTrainerSettings(pDeltaRuleTrainerElem);
            Check();
            return;
        }
예제 #5
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;
        }