This problem stems from my lack of understanding of how Hopfield Artificial Neural Networks (this applies to my understanding of all artificial neural networks) work. I think I have the concept behind "learning" down (for the most part), but when it comes to using the "trained" matrix to recognize a pattern, that's where I'm falling on my face.
I've attached the files as links to make it easier for some:
http://bin.cakephp.org/view/1255828170
http://bin.cakephp.org/view/873169308
http://bin.cakephp.org/view/908185693
http://bin.cakephp.org/view/152716718
The main method:
namespace artificialneuralnetwork
{
class MainClass
{
public static string FormatBoolean(bool [] b)
{
System.Text.StringBuilder result = new System.Text.StringBuilder();
result.Append ('[');
for (int i = 0; i < b.Length; i++)
{
if (b)
{
result.Append ("T");
}
else
{
result.Append ("F");
}
if (i != b.Length - 1)
{
result.Append (",");
}
}
result.Append (']');
return result.ToString();
}
public static void Main (string[] args)
{
// create a neural network.
HopfieldNetwork network = new HopfieldNetwork(4);
// this pattern will be trained.
//bool [] pattern1 = {true, true, false, false};
bool [] pattern1 = {false, true, false, true};
// this pattern will be represented.
//bool [] pattern2 = {true, false, false, false};
bool [] pattern2 = {true, true, false, true};
bool [] result;
// train the neural network with pattern1.
System.Console.WriteLine("Training Hopfield network with: "
+ FormatBoolean(pattern1));
network.Train(pattern1);
// present pattern1 and see it recognized.
System.Console.WriteLine("Presenting pattern: "
+ FormatBoolean(pattern1));
// present pattern2, which is similar to pattern1.
// pattern1 should be recalled.
result = network.Present(pattern2);
System.Console.WriteLine ("Presenting pattern: "
+ FormatBoolean(pattern1) + ", and got "
+ FormatBoolean(result) + " .");
// present pattern2, which is similar to pattern1. Pattern1 should be
// recalled.
result = network.Present (pattern2);
System.Console.WriteLine("Presenting pattern: "
+ FormatBoolean(pattern2) + ", and got "
+ FormatBoolean(result) + " .");
// let's write more code, not less.
System.Threading.Thread.Sleep(100000);
}
}
}
I'm still debugging and trying to figure what's going on, but I'd really love some help on trying to wrap my mind around this concept.