コード例 #1
0
        /// <summary>
        /// Creates the instance and initialize it from given xml element.
        /// This is the preferred way to instantiate reservoir settings.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing parallel perceptron settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public ParallelPerceptronSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.PP.ParallelPerceptronSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement parallelPerceptronSettingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            NumOfGates = int.Parse(parallelPerceptronSettingsElem.Attribute("gates").Value, CultureInfo.InvariantCulture);
            Resolution = int.Parse(parallelPerceptronSettingsElem.Attribute("resolution").Value, CultureInfo.InvariantCulture);
            XElement pDeltaRuleTrainerElem = parallelPerceptronSettingsElem.Descendants("pDeltaRuleTrainer").FirstOrDefault();

            if (pDeltaRuleTrainerElem != null)
            {
                PDeltaRuleTrainerCfg = new PDeltaRuleTrainerSettings(pDeltaRuleTrainerElem);
            }
            else
            {
                PDeltaRuleTrainerCfg = new PDeltaRuleTrainerSettings();
            }
            return;
        }
コード例 #2
0
 //Constructors
 /// <summary>
 /// Creates an uninitialized instance
 /// </summary>
 public ParallelPerceptronSettings()
 {
     NumOfGates           = 0;
     Resolution           = 0;
     PDeltaRuleTrainerCfg = new PDeltaRuleTrainerSettings();
     return;
 }
コード例 #3
0
 //Constructors
 /// <summary>
 /// Creates an uninitialized instance
 /// </summary>
 public ParallelPerceptronSettings()
 {
     NumOfGates           = 0;
     Resolution           = 0;
     OutputRange          = new Interval(-1, 1);
     PDeltaRuleTrainerCfg = null;
     return;
 }
コード例 #4
0
 /// <summary>
 /// Deep copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public PDeltaRuleTrainerSettings(PDeltaRuleTrainerSettings source)
 {
     IniLR = source.IniLR;
     IncLR = source.IncLR;
     DecLR = source.DecLR;
     MinLR = source.MinLR;
     MaxLR = source.MaxLR;
     return;
 }
コード例 #5
0
 /// <summary>
 /// Deep copy constructor
 /// </summary>
 /// <param name="source">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;
 }
コード例 #6
0
 /// <summary>
 /// The deep copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public ParallelPerceptronSettings(ParallelPerceptronSettings source)
 {
     NumOfGates           = source.NumOfGates;
     Resolution           = source.Resolution;
     PDeltaRuleTrainerCfg = null;
     if (source.PDeltaRuleTrainerCfg != null)
     {
         PDeltaRuleTrainerCfg = source.PDeltaRuleTrainerCfg.DeepClone();
     }
     return;
 }
コード例 #7
0
ファイル: PDeltaRuleTrainer.cs プロジェクト: godtopus/Lean
        //Constructor
        /// <summary>
        /// Constructs a parallel perceptron P-Delta rule trainer
        /// </summary>
        /// <param name="net">PP to be trained</param>
        /// <param name="inputVectorCollection">Predictors (input)</param>
        /// <param name="outputVectorCollection">Ideal outputs (the same number of rows as predictors rows)</param>
        /// <param name="settings">Optional startup parameters of the trainer</param>
        public PDeltaRuleTrainer(ParallelPerceptron net,
                                 List <double[]> inputVectorCollection,
                                 List <double[]> outputVectorCollection,
                                 PDeltaRuleTrainerSettings settings = null
                                 )
        {
            //Parameters
            _settings = settings;
            if (_settings == null)
            {
                //Default parameters
                _settings = new PDeltaRuleTrainerSettings();
            }
            _net = net;
            _inputVectorCollection  = inputVectorCollection;
            _outputVectorCollection = outputVectorCollection;
            _resSquashCoeff         = _net.ResSquashCoeff;
            _acceptableError        = 1d / (2d * _resSquashCoeff);
            _marginSignificance     = 1;
            _clearMargin            = 0.05;
            _minM         = _acceptableError * _resSquashCoeff;
            _maxM         = 4d * _minM;
            _learningRate = _settings.IniLR;
            _prevWeights  = _net.GetWeights();
            _prevMSE      = 0;
            _currMSE      = 0;
            _epoch        = 0;
            //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);
            }
            return;
        }
コード例 #8
0
ファイル: PDeltaRuleTrainer.cs プロジェクト: lulzzz/NET
        //Constructor
        /// <summary>
        /// Constructs a parallel perceptron P-Delta rule trainer
        /// </summary>
        /// <param name="net">PP to be trained</param>
        /// <param name="inputVectorCollection">Predictors (input)</param>
        /// <param name="outputVectorCollection">Ideal outputs (the same number of rows as predictors rows)</param>
        /// <param name="settings">Configuration of the trainer</param>
        /// <param name="rand">Random object to be used</param>
        public PDeltaRuleTrainer(ParallelPerceptron net,
                                 List <double[]> inputVectorCollection,
                                 List <double[]> outputVectorCollection,
                                 PDeltaRuleTrainerSettings settings,
                                 Random rand
                                 )
        {
            //Parameters
            _settings               = (PDeltaRuleTrainerSettings)settings.DeepClone();
            MaxAttempt              = _settings.NumOfAttempts;
            MaxAttemptEpoch         = _settings.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;
        }
コード例 #9
0
        //Methods
        /// <summary>
        /// See the base.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            PDeltaRuleTrainerSettings cmpSettings = obj as PDeltaRuleTrainerSettings;

            if (IniLR != cmpSettings.IniLR ||
                IncLR != cmpSettings.IncLR ||
                DecLR != cmpSettings.DecLR ||
                MinLR != cmpSettings.MinLR ||
                MaxLR != cmpSettings.MaxLR
                )
            {
                return(false);
            }
            return(true);
        }
コード例 #10
0
        /// <summary>
        /// Creates the deep copy instance of this instance
        /// </summary>
        public PDeltaRuleTrainerSettings DeepClone()
        {
            PDeltaRuleTrainerSettings clone = new PDeltaRuleTrainerSettings(this);

            return(clone);
        }