/// <summary>
 /// Deep copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public ElasticRegrTrainerSettings(ElasticRegrTrainerSettings source)
 {
     NumOfAttemptEpochs = source.NumOfAttemptEpochs;
     Lambda             = source.Lambda;
     Alpha = source.Alpha;
     return;
 }
        //Methods
        /// <summary>
        /// See the base.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            ElasticRegrTrainerSettings cmpSettings = obj as ElasticRegrTrainerSettings;

            if (NumOfAttemptEpochs != cmpSettings.NumOfAttemptEpochs ||
                Lambda != cmpSettings.Lambda ||
                Alpha != cmpSettings.Alpha
                )
            {
                return(false);
            }
            return(true);
        }
Example #3
0
        //Constructor
        /// <summary>
        /// Constructs an initialized instance
        /// </summary>
        /// <param name="net">FF network to be trained</param>
        /// <param name="inputVectorCollection">Predictors (input)</param>
        /// <param name="outputVectorCollection">Ideal outputs (the same number of rows as number of inputs)</param>
        /// <param name="settings">Startup parameters of the trainer</param>
        public ElasticRegrTrainer(FeedForwardNetwork net,
                                  List <double[]> inputVectorCollection,
                                  List <double[]> outputVectorCollection,
                                  ElasticRegrTrainerSettings settings
                                  )
        {
            //Check network readyness
            if (!net.Finalized)
            {
                throw new Exception("Can´t create trainer. Network structure was not finalized.");
            }
            //Check network conditions
            if (net.LayerCollection.Count != 1 || !(net.LayerCollection[0].Activation is Identity))
            {
                throw new Exception("Can´t create trainer. Network structure is not complient (single layer having Identity activation).");
            }
            //Check samples conditions
            if (inputVectorCollection.Count == 0)
            {
                throw new Exception("Can´t create trainer. Missing training samples.");
            }
            //Collections
            _inputVectorCollection  = new List <double[]>(inputVectorCollection);
            _outputVectorCollection = new List <double[]>(outputVectorCollection);
            var rangePartitioner = Partitioner.Create(0, _inputVectorCollection.Count);

            _parallelRanges = new List <Tuple <int, int> >(rangePartitioner.GetDynamicPartitions());
            //Parameters
            _settings       = settings;
            MaxAttempt      = _settings.NumOfAttempts;
            MaxAttemptEpoch = _settings.NumOfAttemptEpochs;
            Attempt         = 1;
            AttemptEpoch    = 0;
            _net            = net;
            _gamma          = _settings.Lambda * _settings.Alpha;
            return;
        }