private void Button_Click(object sender, RoutedEventArgs e) { int neuronCount = 1000000; int synapsesPerNeuron = 1000; MessageBox.Show("Starting array allocation"); theNeuronArray = new NeuronHandler(); MessageBox.Show("any existing array removed"); theNeuronArray.Initialize(neuronCount); MessageBox.Show("array allocation complete"); int test = theNeuronArray.GetArraySize(); int threads = theNeuronArray.GetThreadCount(); theNeuronArray.SetThreadCount(16); threads = theNeuronArray.GetThreadCount(); theNeuronArray.SetNeuronCurrentCharge(1, 1.4f); theNeuronArray.SetNeuronCurrentCharge(2, 0.9f); theNeuronArray.Fire(); //should transfer current chargest to last float a = theNeuronArray.GetNeuronLastCharge(1); float b = theNeuronArray.GetNeuronLastCharge(2); string s0 = theNeuronArray.GetNeuronLabel(1); theNeuronArray.SetNeuronLabel(1, "Fred"); string s1 = theNeuronArray.GetNeuronLabel(1); theNeuronArray.SetNeuronLabel(1, "George"); string s2 = theNeuronArray.GetNeuronLabel(1); theNeuronArray.AddSynapse(2, 4, .75f, 1, false); List <Synapse> synapses2 = theNeuronArray.GetSynapsesList(2); theNeuronArray.AddSynapse(1, 2, .5f, 0, false); List <Synapse> synapses1 = theNeuronArray.GetSynapsesList(1); theNeuronArray.AddSynapse(1, 3, .6f, 0, false); synapses1 = theNeuronArray.GetSynapsesList(1); theNeuronArray.AddSynapse(1, 4, .75f, 1, false); synapses1 = theNeuronArray.GetSynapsesList(1); theNeuronArray.AddSynapse(2, 4, .75f, 1, false); long count = theNeuronArray.GetTotalSynapses(); List <Synapse> synapses0 = theNeuronArray.GetSynapsesList(0); synapses1 = theNeuronArray.GetSynapsesList(1); List <Synapse> synapsesFrom = theNeuronArray.GetSynapsesFromList(4); NeuronPartial n = theNeuronArray.GetPartialNeuron(1); theNeuronArray.Fire(); long gen = theNeuronArray.GetGeneration(); NeuronPartial n1 = theNeuronArray.GetPartialNeuron(1); NeuronPartial n2 = theNeuronArray.GetPartialNeuron(2); NeuronPartial n3 = theNeuronArray.GetPartialNeuron(3); theNeuronArray.DeleteSynapse(1, 3); theNeuronArray.DeleteSynapse(1, 2); MessageBox.Show("allocating synapses"); Parallel.For(0, neuronCount, x => { //for (int x = 0; x < neuronCount; x++) //{ for (int j = 0; j < synapsesPerNeuron; j++) { int target = x + j; if (target >= theNeuronArray.GetArraySize()) { target -= theNeuronArray.GetArraySize(); } if (target < 0) { target += theNeuronArray.GetArraySize(); } theNeuronArray.AddSynapse(x, target, 1.0f, 0, true); } }); for (int i = 0; i < neuronCount / 100; i++) { theNeuronArray.SetNeuronCurrentCharge(100 * i, 1); } MessageBox.Show("synapses and charge complete"); Stopwatch sw = new Stopwatch(); string msg = ""; for (int i = 0; i < 10; i++) { sw.Start(); theNeuronArray.Fire(); sw.Stop(); msg += "Gen: " + theNeuronArray.GetGeneration() + " FireCount: " + theNeuronArray.GetFiredCount() + " time: " + sw.Elapsed.Milliseconds.ToString() + "\n"; sw.Reset(); } sw.Stop(); MessageBox.Show("Done firing 10x\n" + msg); }
public static bool Load(ref NeuronHandler theNeuronArray, string fileName) { FileStream file = File.Open(fileName, FileMode.Open); XmlSerializer reader1 = new XmlSerializer(typeof(NA));//, GetModuleTypes()); aNeuronArray = (NA)reader1.Deserialize(file); file.Close(); XmlDocument xmldoc = new XmlDocument(); XmlNodeList neuronNodes; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); fs.Close(); int arraySize = aNeuronArray.arraySize; theNeuronArray = new NeuronHandler(); theNeuronArray.Initialize(arraySize); NeuronPartial n1 = theNeuronArray.GetPartialNeuron(1); neuronNodes = xmldoc.GetElementsByTagName("Neuron"); for (int i = 0; i < neuronNodes.Count; i++) { //this is the hard way...we could parse by hand XmlDocument tempDoc = new XmlDocument(); XmlElement neuronNode = (XmlElement)neuronNodes[i]; XmlNode importNode = tempDoc.ImportNode(neuronNode, true); tempDoc.AppendChild(importNode); MemoryStream stream = new MemoryStream(); tempDoc.Save(stream); stream.Flush(); stream.Position = 0; XmlSerializer reader = new XmlSerializer(typeof(N)); //reader.UnknownAttribute += Reader_UnknownAttribute; //reader.UnknownElement += Reader_UnknownElement; //reader.UnknownNode += Reader_UnknownNode; //reader.UnreferencedObject += Reader_UnreferencedObject; N n = (N)reader.Deserialize(stream); if (n != null) { int id = n.Id; theNeuronArray.SetNeuronCurrentCharge(id, n.CurrentCharge); if (n.Label != "") { theNeuronArray.SetNeuronLabel(id, n.Label); } if (n.LeakRate != 0.1f) { theNeuronArray.SetNeuronLeakRate(id, n.LeakRate); } if (n.Model != modelType.Std) { theNeuronArray.SetNeuronModel(id, (int)n.Model); } foreach (S s in n.Synapses) { theNeuronArray.AddSynapse(id, s.TargetNeuron, s.Weight, s.IsHebbian, false); } } //stream.Position = 0; //StreamReader sr = new StreamReader(stream); //string x = sr.ReadToEnd(); } return(true); }