public NetData(NetData data) { this.time = data.time; this.epoch = data.epoch; this.avgErr = data.avgErr; this.errChange = data.errChange; this.seconds = data.seconds; }
public NetData LearnInt(MainForm parentForm) { int currInput, currIndex; this.parent = parentForm; this.era = 0; this.avgErr = int.MaxValue; this.currErr = 0; double currAbsErr = 0; this.eta = maxEta; this.AllocMem(); this.InitWeights(); this.PreGenerateInputOutput(); //speed up, memory down DateTime start = DateTime.Now; NetData data = NetData.Empty; do { if (!this.parent.GetState()) { break; } currErr = 0; for (int i = 0; i < NumOfInputs; i++) { inputIndecies.Add(i); } while (inputIndecies.Count > 0) { currIndex = r.Next(inputIndecies.Count - 1); currInput = inputIndecies[currIndex]; inputIndecies.RemoveAt(currIndex); GenerateIntInput(currInput); GenerateIntOutput(currInput); ForwardPass(); currErr += CountCurrentError(); //if (this.error.Max() < this.config.minError) //continue; BackwardPass(); Application.DoEvents(); } this.lastAvgError = this.avgErr; this.avgErr = CountAverageError(); this.era++; currAbsErr = Math.Abs(this.avgErr); this.eta /= 1.01; } while (currAbsErr > config.minError && Math.Abs(lastAvgError - avgErr) > config.minErrorChange && this.era < config.maxEpoch); data.time = DateTime.Now.Subtract(start); data.avgErr = this.avgErr; data.epoch = this.Epoch; data.errChange = this.lastAvgError - this.avgErr; return(data); }
private void DoFullLearning() { Random rand = new Random(); var dataForCurrentCount = new List <NetData>(); NetData avgData = NetData.Empty; int candidate = 0; if (this.MinFixedCount == 0) //for 0 fixed neurons { for (int n = 0; n < AttemptsOnCurrentIndex && running; n++) { this.SetState(n + 1, this.AttemptsOnCurrentCount); dataForCurrentCount.Add(this.net.LearnInt(this)); } foreach (var t in dataForCurrentCount) { avgData.time += t.time; avgData.epoch += t.epoch; avgData.errChange += t.errChange; avgData.avgErr += t.avgErr; } if (!running) { return; } avgData.avgErr /= dataForCurrentCount.Count; avgData.epoch /= dataForCurrentCount.Count; avgData.errChange /= dataForCurrentCount.Count; avgData.seconds = avgData.time.TotalSeconds / dataForCurrentCount.Count; dataForCurrentCount.Clear(); var e = new Experiment { fixedNeurons = new List <int>(0), name = "Unfixed", data = avgData }; this.graph.AddExperiment(e); if (logger.isRunning) { logger.Log(e.ToExtendedString()); } avgData = NetData.Empty; } for (int i = MinFixedCount == 0 ? 1 : MinFixedCount; i <= MaxFixedCount; i++) //fixed neurons { avgData = NetData.Empty; var exp = new Experiment(); exp.name = String.Format("Fixed count: {0}", i); exp.fixedNeurons = new List <int>(); for (int j = 0; j < AttemptsOnCurrentCount && running; j++) //on current fixed count { //this.net.LearnInt(this); //without fixing exp.fixedNeurons.Clear(); for (int l = 0; l < i && running; l++) //get random fixed index { do { candidate = rand.Next(0, this.config.NumHidden); }while (exp.fixedNeurons.Count(x => x == candidate) > 0); //check if candidate has not been fixed exp.fixedNeurons.Add(candidate); } for (int k = 0; k < AttemptsOnCurrentIndex && running; k++) //on current fixed index { if (!this.running) { this.DoStop(); return; } this.SetState(i, exp.fixedNeurons, j + 1, k + 1); this.net.LearnInt(this); this.net.Fix(exp.fixedNeurons); dataForCurrentCount.Add(this.net.LearnInt(this)); this.net.Unfix(); } } if (!running) { return; } foreach (var t in dataForCurrentCount) { avgData.time += t.time; avgData.epoch += t.epoch; avgData.errChange += t.errChange; avgData.avgErr += t.avgErr; } avgData.avgErr /= dataForCurrentCount.Count; avgData.epoch /= dataForCurrentCount.Count; avgData.errChange /= dataForCurrentCount.Count; avgData.seconds = avgData.time.TotalSeconds / dataForCurrentCount.Count; dataForCurrentCount.Clear(); exp.data = avgData; graph.AddExperiment(exp); if (logger.isRunning) { logger.Log(exp.ToExtendedString()); } } }
private void DoBatchLearning() { for (int i = 0; i < this.exps.Count && running; i++) { if (this.clbExperiments.GetItemChecked(i)) //user can check it manually for skipping { continue; } var allData = new List <NetData>(); NetData avgData = NetData.Empty; this.clbExperiments.SelectedIndex = i; for (int j = 0; j < this.exps[i].repeats && running; j++) { if (this.exps[i].fixedNeurons.Count > 0) { this.SetState(j + 1, this.exps[i].repeats, i + 1, this.exps.Count, this.exps[i].fixedNeurons); } else { this.SetState(j + 1, this.exps[i].repeats); } if (this.exps[i].fixedNeurons.Count > 0) //just if we have fixed { this.net.LearnInt(this); this.net.Fix(this.exps[i].fixedNeurons); } allData.Add(this.net.LearnInt(this)); this.net.Unfix(); } if (!running) { return; } foreach (var t in allData) { avgData.time += t.time; avgData.epoch += t.epoch; avgData.errChange += t.errChange; avgData.avgErr += t.avgErr; } avgData.avgErr /= allData.Count; avgData.epoch /= allData.Count; avgData.errChange /= allData.Count; avgData.seconds = avgData.time.TotalSeconds / allData.Count; this.exps[i].data = avgData; this.clbExperiments.SetItemChecked(i, true); graph.AddExperiment(this.exps[i]); if (logger.isRunning) { logger.Log(exps[i].ToExtendedString()); } } }