/// <summary> /// Read a an object. /// </summary> public Object Read(Stream mask0) { var result = new HopfieldNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.Weights = NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Weights])); result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Output]))); result.NeuronCount = EncogFileSection.ParseInt(p, PersistConst.NeuronCount); } } return result; }
private void ValidateHopfield(HopfieldNetwork network) { Assert.AreEqual(4, network.NeuronCount); Assert.AreEqual(4, network.CurrentState.Count); Assert.AreEqual(16, network.Weights.Length); Assert.AreEqual(1.0, network.GetWeight(1, 1)); }
/// <summary> /// Read a an object. /// </summary> public Object Read(Stream mask0) { var result = new HopfieldNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("PARAMS")) { IDictionary <String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("NETWORK")) { IDictionary <String, String> p = section.ParseParams(); result.Weights = NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Weights])); result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Output]))); result.NeuronCount = EncogFileSection.ParseInt(p, PersistConst.NeuronCount); } } return(result); }
public void Execute(IExampleInterface app) { this.app = app; // Create the neural network. BasicLayer hopfield; var network = new HopfieldNetwork(4); // This pattern will be trained bool[] pattern1 = {true, true, false, false}; // This pattern will be presented bool[] pattern2 = {true, false, false, false}; IMLData result; var data1 = new BiPolarMLData(pattern1); var data2 = new BiPolarMLData(pattern2); var set = new BasicMLDataSet(); set.Add(data1); // train the neural network with pattern1 app.WriteLine("Training Hopfield network with: " + FormatBoolean(data1)); network.AddPattern(data1); // present pattern1 and see it recognized result = network.Compute(data1); app.WriteLine("Presenting pattern:" + FormatBoolean(data1) + ", and got " + FormatBoolean(result)); // Present pattern2, which is similar to pattern 1. Pattern 1 // should be recalled. result = network.Compute(data2); app.WriteLine("Presenting pattern:" + FormatBoolean(data2) + ", and got " + FormatBoolean(result)); }
public void TestPersistSerial() { HopfieldNetwork network = new HopfieldNetwork(4); network.SetWeight(1, 1, 1); SerializeObject.Save(SERIAL_FILENAME.ToString(), network); HopfieldNetwork network2 = (HopfieldNetwork)SerializeObject.Load(SERIAL_FILENAME.ToString()); ValidateHopfield(network2); }
public void TestPersistEG() { HopfieldNetwork network = new HopfieldNetwork(4); network.SetWeight(1, 1, 1); network.SetProperty("x", 10); EncogDirectoryPersistence.SaveObject(EG_FILENAME, network); HopfieldNetwork network2 = (HopfieldNetwork)EncogDirectoryPersistence.LoadObject((EG_FILENAME)); ValidateHopfield(network2); }
/// <summary> /// Generate the Hopfield neural network. /// </summary> /// /// <returns>The generated network.</returns> public IMLMethod Generate() { var logic = new HopfieldNetwork(_neuronCount); return logic; }
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(@"----------------------"); } }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; IDictionary<string, string> dictionary2; HopfieldNetwork network = new HopfieldNetwork(); goto Label_00F0; Label_000D: if (section.SectionName.Equals("HOPFIELD") || (0 != 0)) { goto Label_0031; } Label_0022: if ((section = helper.ReadNextSection()) != null) { if (section.SectionName.Equals("HOPFIELD")) { if (0 != 0) { goto Label_0031; } if (3 != 0) { if (0xff == 0) { goto Label_0022; } if (section.SubSectionName.Equals("PARAMS")) { IDictionary<string, string> source = section.ParseParams(); if (0 == 0) { EngineArray.PutAll<string, string>(source, network.Properties); } } } } goto Label_000D; } return network; Label_0031: if (section.SubSectionName.Equals("NETWORK")) { dictionary2 = section.ParseParams(); } else { goto Label_0022; } network.Weights = NumberList.FromList(CSVFormat.EgFormat, dictionary2["weights"]); if (0 == 0) { network.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, dictionary2["output"])); network.NeuronCount = EncogFileSection.ParseInt(dictionary2, "neurons"); goto Label_0022; } if (3 != 0) { goto Label_000D; } Label_00F0: helper = new EncogReadHelper(mask0); goto Label_0022; }