Skip to content

Commit e8611d9

Browse files
committed
Added CorticalColumn and COrticalColumnInput modules
Added F5 for run/stop and F10 for pause/single step Hide synapse bar graphs is weight is 0.2 Made synapse animations speed proportional to engine speed Fixed undo of synapse moves Added synapse type to synapse lists in neuron context menu Added "lastfired" to neuron context menu Set default Refractory Delay to 4 Added Learn synapse type Changed colors of Learn and Gate synape displays Corrected handling of Gate and Learn synapses Fixed bug with cut/paste neurons left invisible traces
1 parent 88a2bd7 commit e8611d9

23 files changed

+644
-135
lines changed

BrainSimulator/BrainSimulator.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,4 @@
423423
</None>
424424
</ItemGroup>
425425

426-
<Target Name="PostBuild" AfterTargets="Build">
427-
<ItemGroup>
428-
<NativeFiles Include="..\x64\$(Configuration)\neuronengine.*" />
429-
</ItemGroup>
430-
<Message Importance="high" Text="Copying native files: @(NativeFiles)" />
431-
<Copy SourceFiles="@(NativeFiles)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
432-
</Target>
433-
434426
</Project>

BrainSimulator/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
<ComboBoxItem>Hebbian2</ComboBoxItem>
375375
<ComboBoxItem>Hebbian3</ComboBoxItem>
376376
<ComboBoxItem>Gate</ComboBoxItem>
377+
<ComboBoxItem>Learn</ComboBoxItem>
377378
</ComboBox>
378379
<Label Width="10"></Label>
379380
<CheckBox x:Name="SynapseUpdate" VerticalAlignment="Center" IsChecked="True">Update from click</CheckBox>

BrainSimulator/MainWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public partial class MainWindow : Window
4949
public static bool useServers = false;
5050

5151
private static int engineDelay = 500; //wait after each cycle of the engine, 0-1000
52+
public static int EngineDelay { get => engineDelay; set => engineDelay = value; }
5253

5354
//timer to update the neuron values
5455
readonly private DispatcherTimer displayUpdateTimer = new DispatcherTimer();
@@ -519,6 +520,7 @@ static public void UpdateDisplayLabel(float zoomLevel)
519520
}
520521

521522
static bool fullUpdateNeeded = false;
523+
522524
public static void Update()
523525
{
524526
if (thisWindow.IsEngineSuspended())

BrainSimulator/MainWindowEventHandlers.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
109109
}
110110
NeuronArrayView.StopInsertingModule();
111111
}
112+
if (e.Key == Key.System && e.SystemKey == Key.F10)
113+
{
114+
ButtonSingle_Click(null, null);
115+
e.Handled = true;
116+
}
117+
if (e.Key == Key.F5)
118+
{
119+
PlayPause_Click(buttonPlay, null);
120+
}
112121
if (e.Key == Key.F1)
113122
{
114123
MenuItemHelp_Click(null, null);

BrainSimulator/ModuleViewMenu.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ private static void Mi_Click(object sender, RoutedEventArgs e)
470470
Neuron n = MainWindow.theNeuronArray.GetNeuron(Id);
471471
foreach (Synapse s in n.Synapses)
472472
{
473-
if (s.model != Synapse.modelType.Fixed)
473+
if (s.model == Synapse.modelType.Hebbian1 ||
474+
s.model == Synapse.modelType.Hebbian2 ||
475+
s.model == Synapse.modelType.Hebbian3 )
474476
{
475477
//TODO: Add some UI for this:
476478
//s.model = Synapse.modelType.Hebbian2;
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
//
2+
// Copyright (c) [Name]. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using System.Windows;
12+
using System.Windows.Controls;
13+
using System.Windows.Media;
14+
using System.Xml.Serialization;
15+
16+
namespace BrainSimulator.Modules
17+
{
18+
public class ModuleCorticalColumn : ModuleBase
19+
{
20+
//any public variable you create here will automatically be saved and restored with the network
21+
//unless you precede it with the [XmlIgnore] directive
22+
//[XlmIgnore]
23+
//public theStatus = 1;
24+
25+
26+
//set size parameters as needed in the constructor
27+
//set max to be -1 if unlimited
28+
public ModuleCorticalColumn()
29+
{
30+
minHeight = 15;
31+
maxHeight = 20;
32+
minWidth = 1;
33+
maxWidth = 1;
34+
}
35+
36+
37+
//fill this method in with code which will execute
38+
//once for each cycle of the engine
39+
public override void Fire()
40+
{
41+
Init(); //be sure to leave this here
42+
43+
//if you want the dlg to update, use the following code whenever any parameter changes
44+
// UpdateDialog();
45+
}
46+
47+
//fill this method in with code which will execute once
48+
//when the module is added, when "initialize" is selected from the context menu,
49+
//or when the engine restart button is pressed
50+
public override void Initialize()
51+
{
52+
AddSynapses();
53+
}
54+
55+
56+
private void AddSynapses()
57+
{
58+
//rows with hard-coded functionality
59+
int inputRow = 6;
60+
int outputRow = 8;
61+
int thisCol = 9;
62+
int recur = 10;
63+
int isa = 11;
64+
int has_inst = 12;
65+
int has_a = 13;
66+
int part_of = 14;
67+
68+
Init();
69+
//ClearNeurons(false);
70+
71+
mv.Color = Utils.ColorToInt(Colors.DarkGray);
72+
int colNum = 0;
73+
foreach (var module in theNeuronArray.modules)
74+
{
75+
if (module.Label=="CorticalColumn" && module.FirstNeuron < mv.FirstNeuron)
76+
colNum++;
77+
}
78+
79+
mv.GetNeuronAt(0, 0).Label = "Col" + colNum;
80+
Neuron n = theNeuronArray.GetNeuron("Request");
81+
if (n != null)
82+
n.AddSynapse(mv.GetNeuronAt(0, 0).id, 1);
83+
84+
mv.GetNeuronAt(0, 0).AddSynapse(mv.GetNeuronAt(0, 1).id, .2f, Synapse.modelType.Hebbian3);
85+
mv.GetNeuronAt(0, 0).AddSynapse(mv.GetNeuronAt(0, 2).id, 1);
86+
mv.GetNeuronAt(0, 1).Model = Neuron.modelType.LIF;
87+
mv.GetNeuronAt(0, 1).LeakRate = 0.3f;
88+
mv.GetNeuronAt(0, 1).AddSynapse(mv.GetNeuronAt(0, 2).id, -1);
89+
mv.GetNeuronAt(0, 1).AddSynapse(mv.GetNeuronAt(0, 3).id, -1);
90+
mv.GetNeuronAt(0, 2).AddSynapse(mv.GetNeuronAt(0, 3).id, 1);
91+
mv.GetNeuronAt(0, 3).AddSynapse(mv.GetNeuronAt(0, 4).id, 1);
92+
93+
foreach (var module in theNeuronArray.modules)
94+
{
95+
if (module.ModuleTypeStr.Contains("CorticalColumn") && module.FirstNeuron > mv.FirstNeuron)
96+
{
97+
mv.GetNeuronAt(0, 3).AddSynapse(module.FirstNeuron + 4, -1);
98+
}
99+
}
100+
101+
mv.GetNeuronAt(0, 4).Label = "Act" + colNum;
102+
mv.GetNeuronAt(0, 4).Model = Neuron.modelType.Burst;
103+
mv.GetNeuronAt(0, 4).AxonDelay = 7;
104+
mv.GetNeuronAt(0, 4).LeakRate = 4;
105+
106+
mv.GetNeuronAt(0, 4).AddSynapse(mv.GetNeuronAt(0, 0).id, 1);
107+
mv.GetNeuronAt(0, 4).AddSynapse(mv.GetNeuronAt(0, 1).id, 1);
108+
mv.GetNeuronAt(0, 4).AddSynapse(mv.GetNeuronAt(0, 6).id, 1, Synapse.modelType.Learn);
109+
mv.GetNeuronAt(0, 4).AddSynapse(mv.GetNeuronAt(0, 7).id, 1, Synapse.modelType.Learn);
110+
111+
mv.GetNeuronAt(5).Label = "De" + colNum;
112+
mv.GetNeuronAt(5).Model = Neuron.modelType.Burst;
113+
mv.GetNeuronAt(5).AxonDelay = 5;
114+
mv.GetNeuronAt(5).LeakRate = 4;
115+
mv.GetNeuronAt(5).AddSynapse(mv.GetNeuronAt(1).id, -1, Synapse.modelType.Learn);
116+
mv.GetNeuronAt(5).AddSynapse(mv.GetNeuronAt(6).id, -1, Synapse.modelType.Learn);
117+
mv.GetNeuronAt(5).AddSynapse(mv.GetNeuronAt(7).id, -1, Synapse.modelType.Learn);
118+
mv.GetNeuronAt(5).AddSynapse(mv.GetNeuronAt(8).id, -1, Synapse.modelType.Learn);
119+
120+
mv.GetNeuronAt(6).Label = "In" + colNum;
121+
mv.GetNeuronAt(6).Model = Neuron.modelType.LIF;
122+
mv.GetNeuronAt(6).LeakRate = .3f;
123+
n = theNeuronArray.GetNeuron("in-fired");
124+
if (n != null)
125+
mv.GetNeuronAt(6).AddSynapse(n.id, 1);
126+
for (int i = thisCol; i < part_of; i++)
127+
if (i != recur)
128+
mv.GetNeuronAt(inputRow).AddSynapse(mv.GetNeuronAt(i).id, 1);
129+
mv.GetNeuronAt(7).AddSynapse(mv.GetNeuronAt(recur).id, 1);
130+
mv.GetNeuronAt(8).AddSynapse(mv.GetNeuronAt(recur).id, 1);
131+
132+
mv.GetNeuronAt(7).Label = "In" + colNum+"*";
133+
mv.GetNeuronAt(7).Model = Neuron.modelType.LIF;
134+
mv.GetNeuronAt(7).LeakRate = .3f;
135+
mv.GetNeuronAt(7).AddSynapse(mv.GetNeuronAt(8).id, 1, Synapse.modelType.Learn);
136+
137+
mv.GetNeuronAt(8).Label = "Out" + colNum;
138+
mv.GetNeuronAt(8).Model = Neuron.modelType.LIF;
139+
mv.GetNeuronAt(8).LeakRate = .3f;
140+
n = theNeuronArray.GetNeuron("out-fired");
141+
if (n != null)
142+
mv.GetNeuronAt(8).AddSynapse(n.id, 1);
143+
144+
//find all neurons in theNeuronArray with labels starting with "
145+
string labelPrefix = "\""; // Replace with desired prefix
146+
147+
for (int i = 0; i < theNeuronArray.arraySize; i++)
148+
{
149+
Neuron neuron = theNeuronArray.GetNeuron(i);
150+
if (neuron != null && neuron.Label != null && neuron.Label.StartsWith(labelPrefix))
151+
{
152+
neuron.AddSynapse(mv.GetNeuronAt(6).id, .2f, Synapse.modelType.Hebbian3);
153+
Neuron neuron2 = theNeuronArray.GetNeuron(i + 2*theNeuronArray.rows);
154+
neuron2.AddSynapse(mv.GetNeuronAt(7).id, .2f, Synapse.modelType.Hebbian3);
155+
Neuron neuron3 = theNeuronArray.GetNeuron(i + 4 * theNeuronArray.rows);
156+
mv.GetNeuronAt(8).AddSynapse(neuron3.id, .2f, Synapse.modelType.Hebbian3);
157+
}
158+
}
159+
160+
161+
//this relationship...transfer input to output
162+
Neuron nThis = theNeuronArray.GetNeuron("this");
163+
if (nThis == null) return;
164+
nThis.AddSynapse(mv.GetNeuronAt(thisCol).id, 1, Synapse.modelType.Gate);
165+
mv.GetNeuronAt(thisCol).AddSynapse(mv.GetNeuronAt(8).id, 1);
166+
167+
//recur relationship...transfer output to input
168+
Neuron nRecur = theNeuronArray.GetNeuron("recur");
169+
if (nRecur == null) return;
170+
nRecur.AddSynapse(mv.GetNeuronAt(recur).id, 1, Synapse.modelType.Gate);
171+
mv.GetNeuronAt(recur).AddSynapse(mv.GetNeuronAt(6).id, 1);
172+
173+
//Isa Relationships
174+
bool flowControl = AddFixedRelationshipRow(outputRow, has_inst, "has-inst");
175+
if (!flowControl)
176+
return;
177+
flowControl = AddFixedRelationshipRow(outputRow, has_a, "has-a");
178+
if (!flowControl)
179+
return;
180+
flowControl = AddFixedRelationshipRow(outputRow, isa, "is-a");
181+
if (!flowControl)
182+
return;
183+
184+
//handle part-of relationships
185+
Neuron nSource = theNeuronArray.GetNeuron("part-of");
186+
if (nSource is null) return;
187+
nSource.AddSynapse(mv.GetNeuronAt(part_of).id, 1, Synapse.modelType.Gate);
188+
mv.GetNeuronAt(part_of).AddSynapse(mv.GetNeuronAt(outputRow).id, 1);
189+
190+
foreach (var module in theNeuronArray.modules)
191+
{
192+
if (module.Label== "CorticalColumn" && module.FirstNeuron != mv.FirstNeuron)
193+
{
194+
Neuron nTest = module.GetNeuronAt(inputRow);
195+
nTest.AddSynapse(mv.GetNeuronAt(part_of).id,.2f, Synapse.modelType.Hebbian2);
196+
}
197+
}
198+
}
199+
200+
private bool AddFixedRelationshipRow(int thisOut, int row, string sourceLabel)
201+
{
202+
Neuron nSource = theNeuronArray.GetNeuron(sourceLabel);
203+
if (nSource is null) return false;
204+
nSource.AddSynapse(mv.GetNeuronAt(row).id, 1, Synapse.modelType.Gate);
205+
206+
foreach (var module in theNeuronArray.modules)
207+
{
208+
if (module.Label =="CorticalColumn" && module.FirstNeuron != mv.FirstNeuron)
209+
{
210+
mv.GetNeuronAt(row).AddSynapse(module.GetNeuronAt(thisOut).id, .2f, Synapse.modelType.Hebbian3);
211+
}
212+
}
213+
214+
return true;
215+
}
216+
217+
218+
219+
//the following can be used to massage public data to be different in the xml file
220+
//delete if not needed
221+
public override void SetUpBeforeSave()
222+
{
223+
}
224+
public override void SetUpAfterLoad()
225+
{
226+
}
227+
228+
public override MenuItem CustomContextMenuItems()
229+
{
230+
Button clearButton = new Button { Content = "Clear Neurons", };
231+
clearButton.Click += ClrButton_Click;
232+
MenuItem mi = new MenuItem { Header = clearButton };
233+
return mi;
234+
}
235+
236+
private void ClrButton_Click(object sender, RoutedEventArgs e)
237+
{
238+
foreach (Neuron n in mv.Neurons)
239+
{
240+
foreach (Synapse s in n.synapses)
241+
n.DeleteSynapse(s.targetNeuron);
242+
}
243+
MainWindow.arrayView.Update();
244+
}
245+
246+
247+
//called whenever the size of the module rectangle changes
248+
//for example, you may choose to reinitialize whenever size changes
249+
//delete if not needed
250+
public override void SizeChanged()
251+
{
252+
if (mv == null) return;
253+
AddSynapses();
254+
}
255+
}
256+
}

0 commit comments

Comments
 (0)