Esempio n. 1
0
        public virtual void Train(int epochs, int numSamples, int batchSize,
                                  LearningOptions learningOptions,
                                  CallBackOptions callBackOptions = default)
        {
            LearningBegan?.Invoke(this, new LearningEventArgs());

            for (int epoch = 0; epoch < epochs; epoch++)
            {
                for (int i = 0; i < (numSamples / batchSize); i++)
                {
                    ProcessLearning(Data.ReadNext(new StreamOptions(batchSize, learningOptions.shuffleData)),
                                    learningOptions.learningRate, learningOptions.momentumRate, callBackOptions);
                }

                if (numSamples % batchSize > 0)
                {
                    ProcessLearning(Data.ReadNext(new StreamOptions(numSamples % batchSize, learningOptions.shuffleData)),
                                    learningOptions.learningRate, learningOptions.momentumRate, callBackOptions);
                }

                if (callBackOptions.call == CallTime.EveryEpoch)
                {
                    LearningPerformed?.Invoke(this, new LearningEventArgs());
                }
            }

            LearningEnded?.Invoke(this, new LearningEventArgs());
        }
Esempio n. 2
0
        private void ProcessLearning(Sample[] samples, float eta, float alpha, CallBackOptions callBackOptions)
        {
            foreach (Sample sample in samples)
            {
                Net.ProcessInputs(sample.inputs);
                Net.Learn(sample.outputs, eta, alpha);

                if (callBackOptions.call == CallTime.EverySample)
                {
                    Cost(sample.outputs);
                    LearningPerformed?.Invoke(this, new LearningEventArgs(sample, Net.Prediction, MSE));
                }
            }

            if (callBackOptions.call == CallTime.EveryBatch)
            {
                Cost(samples[samples.Length - 1].outputs);
                LearningPerformed?.Invoke(this, new LearningEventArgs(samples[samples.Length - 1], Net.Prediction, MSE));
            }
        }