Encog.Neural.Thermal.HopfieldNetwork.RunUntilStable C# (CSharp) Method

RunUntilStable() public method

Run the network until it becomes stable and does not change from more runs.
public RunUntilStable ( int max ) : int
max int The maximum number of cycles to run before giving up.
return int
        public int RunUntilStable(int max)
        {
            bool done = false;
            String currentStateStr = (CurrentState.ToString());

            int cycle = 0;
            do
            {
                Run();
                cycle++;

                String lastStateStr = (CurrentState.ToString());

                if (!currentStateStr.Equals(lastStateStr))
                {
                    if (cycle > max)
                    {
                        done = true;
                    }
                }
                else
                {
                    done = true;
                }

                currentStateStr = lastStateStr;
            } while (!done);

            return cycle;
        }

Usage Example

 public void Evaluate(HopfieldNetwork hopfield, String[][] pattern)
 {
     for (int i = 0; i < pattern.Length; i++)
     {
         BiPolarMLData pattern1 = ConvertPattern(pattern, i);
         hopfield.CurrentState = pattern1;
         int cycles = hopfield.RunUntilStable(100);
         BiPolarMLData pattern2 = hopfield.CurrentState;
         Console.WriteLine("Cycles until stable(max 100): " + cycles + ", result=");
         Display(pattern1, pattern2);
         Console.WriteLine(@"----------------------");
     }
 }