Exemple #1
0
        public static RnnTrainRec TrainRnn(Mat input, Vec output, Chromosome chrom, MakeRnnTrainRecFunc makeResult, Func <bool> canceled = null)
        {
            Func <int, LayerSpec> logisticSigmoidRecurrent = nodeCount =>
                                                             new LayerSpec(nodeCount, true, ActivationType.LogisticSigmoid);

            var layers = new List <LayerSpec> {
                logisticSigmoidRecurrent(chrom.RnnLayer1NodeCount),
                logisticSigmoidRecurrent(chrom.RnnLayer2NodeCount),
                new LayerSpec(1, false, ActivationType.Linear)
            };
            var epochMax = chrom.RnnTrainingEpochs;

            var numInputs      = input.RowCount;
            var rnnWeightCount = RNN.GetWeightCount(layers, numInputs);
            var initialWeights = RNN.MakeRandomWeights(rnnWeightCount);
            var trainResult    = RNN.TrainSCG(layers, initialWeights, epochMax, input, output, canceled);

            return(makeResult(initialWeights, MRnnSpec.FromRnnSpec(trainResult.RNNSpec), trainResult.CostHistory));
        }
Exemple #2
0
        public static RnnTrainResult TrainSCGMulti(List <LayerSpec> layers, double epoch_max, Mat trainingData, Vec outputData,
                                                   int numTrials)
        {
            object theLock    = new object();
            var    candidates = new List <RnnTrainResult>();
            Action trainOne   = () => {
                int numWeights      = GetWeightCount(layers, trainingData.RowCount);
                Vec initialWeights  = RNN.MakeRandomWeights(numWeights);
                var candidateResult = TrainSCG(layers, initialWeights, epoch_max, trainingData, outputData);
                lock (theLock) { candidates.Add(candidateResult); }
            };

            //Parallel.For(0, numTrials, n => trainOne());
            for (int i = 0; i < numTrials; i++)
            {
                trainOne();
            }
            return(candidates.OrderBy(r => r.Cost).First());
        }