Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </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>
        public ElasticRegrTrainer(FeedForwardNetwork net,
                                  List <double[]> inputVectorCollection,
                                  List <double[]> outputVectorCollection,
                                  ElasticRegrTrainerSettings cfg
                                  )
        {
            //Check network readyness
            if (!net.Finalized)
            {
                throw new InvalidOperationException($"Can´t create trainer. Network structure was not finalized.");
            }
            //Check network conditions
            if (net.LayerCollection.Count != 1 || !(net.LayerCollection[0].Activation is AFAnalogIdentity))
            {
                throw new InvalidOperationException($"Can´t create trainer. Network structure is not complient (single layer having Identity activation).");
            }
            //Check samples conditions
            if (inputVectorCollection.Count == 0)
            {
                throw new InvalidOperationException($"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
            _cfg            = cfg;
            MaxAttempt      = _cfg.NumOfAttempts;
            MaxAttemptEpoch = _cfg.NumOfAttemptEpochs;
            Attempt         = 1;
            AttemptEpoch    = 0;
            _net            = net;
            _gamma          = _cfg.Lambda * _cfg.Alpha;
            return;
        }