public ANN UpdateCache(ANN Net) { int count = PreviousData.Count; if (count > 2 && HighPos > -1) { int Pos = HighPos; double[] NewInput = PreviousData[Pos].GetInput(); double[] SingleTarget = PreviousData[Pos].GetTarget(); double[] result = Net.feedForward(NewInput); HighError = Net.LearnError(SingleTarget, result); double ErrorLevel; int CheckCount = 1; do { Net.Learn(SingleTarget, result, NewLearnRate); result = Net.feedForward(NewInput); CheckCount--; ErrorLevel = Net.LearnError(SingleTarget, result); } while (ErrorLevel > LowError && CheckCount > 0); } return(Net); }
public double[] FeedForward(double[] ID) { double[] temp; temp = Net.feedForward(ID); return(temp); }
public void EnhancedLearn(ANN Net, double[] NewInput, double [] SingleTarget) { double ErrorLevel; double[] result = Net.feedForward(NewInput); ErrorLevel = Net.LearnError(SingleTarget, result); double SetLevel = ErrorLevel * 0.9; //if (SetLevel < 0.05) //{ //SetLevel = 0.05; //} int CheckCount = 10; do { result = Net.feedForward(NewInput); Net.Learn(SingleTarget, result, NewLearnRate); CheckCount--; ErrorLevel = Net.LearnError(SingleTarget, result); } while (ErrorLevel > SetLevel || CheckCount > 0); }
public ANN CacheLearn(PastData NewEntry, ANN Net) { int OneCount = 0; int TwoCount = 0; int ThreeCount = 0; // LowPos = -1; // HighPos = -1; LowError = double.MaxValue; HighError = double.MinValue; LastEntry = NewEntry; double ErrorLevel = 0; double[] NewInput = NewEntry.GetInput(); double[] SingleTarget = NewEntry.GetTarget(); double[] result = Net.feedForward(NewInput); Net.Learn(SingleTarget, result, NewLearnRate); // ErrorLevel = Net.LearnError(SingleTarget, result); // add a bit that only addes bad ones! // if (ErrorLevel > 0.25) // { PreviousData.Add(NewEntry); // Console.WriteLine("hello"); // } // Console.WriteLine("ADDING ENTRY : " + PreviousData.Count); if (PreviousData.Count > CacheSize) { PreviousData.RemoveAt(LowPos); LowError = double.MaxValue; LowPos = -1; } for (int a = 0; a < PreviousData.Count(); a++) { ErrorLevel = 0; NewInput = PreviousData[a].GetInput(); SingleTarget = PreviousData[a].GetTarget(); if (EnhancedLearning > 0) { EnhancedLearn(Net, NewInput, SingleTarget); } ///// // Store Type Makeup if (PreviousData[a].GetTypeCode() == 1) { OneCount++; } if (PreviousData[a].GetTypeCode() == 2) { TwoCount++; } if (PreviousData[a].GetTypeCode() == 3) { ThreeCount++; } result = Net.feedForward(NewInput); TypeData = "" + OneCount + " ," + TwoCount + "," + ThreeCount + "," + (OneCount + TwoCount + ThreeCount); ErrorLevel = Net.LearnError(SingleTarget, result); if (ErrorLevel < LowError) { LowError = ErrorLevel; LowPos = a; } if (ErrorLevel > HighError) { HighError = ErrorLevel; HighPos = a; } // } } if (EnhancedLearning > 0) { EnhancedLearning--; } return(Net); }