internal BPResponse(BPResponseEstimate estimate,BPEpochResponse[] epochs,TimeSpan bpTime) { Estimate=estimate; Epochs=epochs; BPTime=bpTime; }
internal BPResponse(BPResponseEstimate estimate, BPEpochResponse[] epochs, TimeSpan bpTime) { Estimate = estimate; Epochs = epochs; BPTime = bpTime; }
public BPResponse BP(BPRequest bpr) { Utility.Verify(() => bpr != null, "BP bpr"); Stopwatch StopWatch = new Stopwatch(); StopWatch.Start(); bool trace = this.Inspector != null; if (trace) { Inspector.Trace("Backpropagation start, MaxEpochs={0}, MinEpochs={1}", bpr.MinEpochs.ToString(), bpr.MaxEpochs.ToString()); } BPResponseEstimate estimate = BPResponseEstimate.Unknown; NeuronBase[] output = Structure.Output; List <BPEpochResponse> bper = new List <BPEpochResponse>(bpr.MaxEpochs); for (int i = 0; i < bpr.MaxEpochs; i++) { bool succ = true; if (trace) { Inspector.Trace("Backpropagation- start epoch {0}", (i + 1).ToString()); } TrainingData[] ts = bpr.GetTrainingData().ToArray(); List <double> errors = new List <double>(ts.Length); for (int j = 0; j < ts.Length; j++) { bool testPass = true; if (ts[j].TestingSets != null && ts[j].TestingSets.Any(x => GetPulseError(x, ts[j].Output) > bpr.MaxMSE)) { testPass = false; } double mse = GetPulseError(ts[j].Input, ts[j].Output); errors.Add(mse); if (mse > bpr.MaxMSE || !testPass) { for (var k = 0; k != output.Length; k++) { ((Neuron)output[k]).BP(ts[j].Output[k] - output[k].LastOutputSignal, LearnFactor, Momentum); } succ = false; } } double eps = GetTotalEps(errors.ToArray()); if (trace) { Inspector.Trace("End of epoch {0}, total Eps={1}", (i + 1).ToString(), eps); } bper.Add(new BPEpochResponse(errors.ToArray(), eps)); if (i >= bpr.MinEpochs && succ) { estimate = BPResponseEstimate.Success; break; } if (i >= bpr.MaxEpochs - 1) { if (!succ) { estimate = BPResponseEstimate.Failure; } break; } } StopWatch.Stop(); BPResponse response = new BPResponse(estimate, bper.ToArray(), StopWatch.Elapsed); return(response); }