Skip to content

Commit df73e06

Browse files
committed
Added synapse animation and saving of checkbox to network file
Corrected handling of "ALWAYS" model neurons. Improved display of special values within neuron circles Fixed race condition in neuron engine Added Hebbian3 model which works acording to STDP rule Changed Hebbian2 model so it handles the number of firing vs non-firing inputs Update language version for Neuron ENgine to C++20 Replaced HebbianSynapses network to be compatible with ne synapse models
1 parent ade26a8 commit df73e06

18 files changed

+1904
-1647
lines changed

BrainSimulator/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
<Label Visibility="Hidden" Width="5"></Label>
330330
<CheckBox x:Name="checkBox" Content="All Synapses" Height="18" VerticalAlignment="Center" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
331331
<Label Visibility="Hidden" Width="30"></Label>
332-
<CheckBox x:Name="checkBoxAnimate" Content="Animate" Height="18" VerticalAlignment="Center" />
332+
<CheckBox x:Name="checkBoxAnimate" Content="Animate Synapses" Height="18" VerticalAlignment="Center" Checked="Animate_Checked" Unchecked="Animate_Unchecked" />
333333
<Label Visibility="Hidden" Width="30"></Label>
334334
<Button x:Name="buttonInit" FontSize="20" FontFamily="Segoe MDL2 Assets" Content="&#xEB9E;" Foreground="#FF00539C" VerticalAlignment="Top" Click="ButtonInit_Click" ToolTip="Reset all modules" Grid.Column="2" >
335335
<!--<Image Source="/resources/Rewind.png" Height="20"></Image>-->

BrainSimulator/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,5 @@ public void UpdateFreeMem()
576576
ulong availablePhysicalMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().AvailablePhysicalMemory;
577577
MainWindow.thisWindow.SetStatus(4, "Available Memory: " + availablePhysicalMemory.ToString("##,#"), 0);
578578
}
579-
580579
}
581580
}

BrainSimulator/MainWindowEventHandlers.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,22 @@ private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
641641
theNeuronArray.ShowSynapses = false;
642642
Update();
643643
}
644+
private void Animate_Unchecked(object sender, RoutedEventArgs e)
645+
{
646+
theNeuronArray.animateSynapses = false;
647+
Update();
648+
}
649+
650+
private void Animate_Checked(object sender, RoutedEventArgs e)
651+
{
652+
theNeuronArray.animateSynapses = true;
653+
Update();
654+
}
644655

645656
public void SetShowSynapsesCheckBox(bool showSynapses)
646657
{
647658
checkBox.IsChecked = showSynapses;
659+
checkBoxAnimate.IsChecked = theNeuronArray.animateSynapses;
648660
}
649661

650662
private void MenuItemProperties_Click(object sender, RoutedEventArgs e)

BrainSimulator/Networks/HebbianSynapse OLDs.xml

Lines changed: 1689 additions & 0 deletions
Large diffs are not rendered by default.

BrainSimulator/Networks/HebbianSynapses.xml

Lines changed: 54 additions & 1587 deletions
Large diffs are not rendered by default.

BrainSimulator/NeuronArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public partial class NeuronArray : NeuronHandler
2121
public bool EngineIsPaused = false;
2222
public int arraySize;
2323
public int rows;
24+
public int refractoryDelay = 0;
25+
public bool animateSynapses = false;
2426

2527
public int lastFireCount = 0;
2628
internal List<ModuleView> modules = new List<ModuleView>();
@@ -85,8 +87,6 @@ public List<int> GetKeysFromLabelCache()
8587
return labelCache.Keys.ToList();
8688
}
8789

88-
89-
private int refractoryDelay = 0;
9090
public int RefractoryDelay
9191
{ get => refractoryDelay; set { refractoryDelay = value; SetRefractoryDelay(refractoryDelay); } }
9292

BrainSimulator/NeuronArrayView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:BrainSimulator"
77
mc:Ignorable="d"
8-
d:DesignHeight="100" d:DesignWidth="100" Background="Gray" MouseWheel="theCanvas_MouseWheel" MouseEnter="theCanvas_MouseEnter" >
8+
d:DesignHeight="100" d:DesignWidth="100" Background="DimGray" MouseWheel="theCanvas_MouseWheel" MouseEnter="theCanvas_MouseEnter" >
99
<Grid >
1010
<Canvas HorizontalAlignment="Stretch" Background="DimGray" VerticalAlignment="Stretch" Name="theCanvas"
1111
MouseWheel="theCanvas_MouseWheel" MouseDown="theCanvas_MouseDown" MouseUp="theCanvas_MouseUp" MouseMove="theCanvas_MouseMove"

BrainSimulator/NeuronArrayView.xaml.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void Update()
321321
{
322322
if (l is Shape s && s.Fill is SolidColorBrush b && b.Color == Colors.White)
323323
lbl.Foreground = new SolidColorBrush(Colors.Black);
324-
if (l is NeuronView.FillableDisc && n.currentCharge == 1)
324+
if (l is NeuronView.FillableDisc && n.CurrentCharge == 1)
325325
lbl.Foreground = new SolidColorBrush(Colors.Black);
326326
lbl.SetValue(ShapeType, shapeType.Neuron);
327327
labelCanvas.Children.Add(lbl);
@@ -499,32 +499,36 @@ public void UpdateNeuronColors()
499499
NeuronOnScreen a = neuronsOnScreen[i];
500500
Neuron n = MainWindow.theNeuronArray.GetNeuronForDrawing(a.neuronIndex);
501501

502-
if (MainWindow.thisWindow.checkBoxAnimate.IsChecked == true )
502+
if (MainWindow.theNeuronArray.animateSynapses)
503503
{
504504
//synapse animation trial
505505
float electronSize = dp.NeuronDisplaySize * .2f;
506506
n.synapses = MainWindow.theNeuronArray.GetSynapsesList(n.id);
507507
Point pStart = dp.pointFromNeuron(n.id);
508-
pStart.X += -electronSize / 2 + dp.NeuronDisplaySize / 2;
509-
pStart.Y += -electronSize / 2 + dp.NeuronDisplaySize / 2;
510-
Vector vOffset = new Vector(0, electronSize/2);
508+
//pstart is the UL corner of the neuron...adjust to the center
509+
pStart.X += dp.NeuronDisplaySize / 2;
510+
pStart.Y += dp.NeuronDisplaySize / 2;
511511
foreach (Synapse synapse in n.synapses)
512512
{
513513
Point pTarget = dp.pointFromNeuron(synapse.targetNeuron);
514-
pTarget.X += -electronSize / 2 + dp.NeuronDisplaySize / 2;
515-
pTarget.Y += -electronSize / 2 + dp.NeuronDisplaySize / 2;
514+
//pTarget is the UL corner of the neuron...adjust to the center
515+
pTarget.X += dp.NeuronDisplaySize / 2;
516+
pTarget.Y += dp.NeuronDisplaySize / 2;
517+
516518
//put the little bar graph in the center of hebbian3 synapses
517-
if (synapse.model == Synapse.modelType.Hebbian3 && dp.NeuronDisplaySize > 75)
519+
if ((synapse.model == Synapse.modelType.Hebbian3 || synapse.model == Synapse.modelType.Hebbian2)
520+
&& dp.NeuronDisplaySize > 75)
518521
{
519-
var graph = SynapseView.GetWeightBargraph(pStart+vOffset, pTarget+vOffset, synapse.weight);
522+
var graph = SynapseView.GetWeightBargraph(pStart, pTarget, synapse.weight);
520523
synapseGraphCanvas.Children.Add(graph);
521524
}
522-
if (n.lastCharge != 1) continue;
525+
if (n.lastCharge < 1) continue;
523526

524527
//animate charges along the axons
525528
var fill = Brushes.Yellow;
526529
if (synapse.weight < 0)
527530
fill = Brushes.DeepPink;
531+
528532
// Create the disk (Ellipse)
529533
Ellipse disk = new Ellipse
530534
{
@@ -533,22 +537,21 @@ public void UpdateNeuronColors()
533537
Fill = fill
534538
};
535539
// Initial position
536-
Canvas.SetLeft(disk, pStart.X);
537-
Canvas.SetTop(disk, pStart.Y);
540+
Canvas.SetLeft(disk, pStart.X - electronSize / 2);
541+
Canvas.SetTop(disk, pStart.Y - electronSize / 2);
538542
animationCanvas.Children.Add(disk);
539543
var animX = new DoubleAnimation
540544
{
541-
From = pStart.X,
542-
To = pTarget.X,
545+
From = pStart.X - electronSize / 2,
546+
To = pTarget.X - electronSize / 2,
543547
Duration = TimeSpan.FromMilliseconds(500)
544-
545548
};
546549
Storyboard.SetTarget(animX, disk);
547550
Storyboard.SetTargetProperty(animX, new PropertyPath("(Canvas.Left)"));
548551
var animY = new DoubleAnimation
549552
{
550-
From = pStart.Y,
551-
To = pTarget.Y,
553+
From = pStart.Y - electronSize / 2,
554+
To = pTarget.Y - electronSize / 2,
552555
Duration = TimeSpan.FromMilliseconds(500)
553556
};
554557
Storyboard.SetTarget(animY, disk);
@@ -691,10 +694,12 @@ private void SetTargetNeuronSymbol()
691694
if (targetNeuronIndex != -1 && scale == 1)
692695
{
693696
Ellipse r = new Ellipse();
697+
float ellipseSize = dp.NeuronDisplaySize * .8f;
698+
float offset = (dp.NeuronDisplaySize - ellipseSize) / 2f;
694699
Point p1 = dp.pointFromNeuron(targetNeuronIndex);
695-
r.Width = r.Height = dp.NeuronDisplaySize;
696-
Canvas.SetTop(r, p1.Y);
697-
Canvas.SetLeft(r, p1.X);
700+
r.Width = r.Height = ellipseSize;
701+
Canvas.SetTop(r, p1.Y+offset);
702+
Canvas.SetLeft(r, p1.X+offset);
698703
r.Fill = new SolidColorBrush(Colors.LightBlue);
699704
targetNeuronCanvas.Children.Clear();
700705
targetNeuronCanvas.Children.Add(r);

BrainSimulator/NeuronArrayViewMouse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public void theCanvas_MouseUp(object sender, MouseButtonEventArgs e)
459459
//we clicked on a neuron...was it a fire or a synapse drag?
460460
if (theCanvas.Cursor == Cursors.UpArrow)
461461
{
462-
//if no synapseshape exists, then were just clicking in a nueron
462+
//if no synapseshape exists, then we're just clicking in a nueron
463463
if (synapseShape == null)
464464
{
465465
NeuronMouseUp(e);

BrainSimulator/NeuronArrayViewMouseActions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ private void NeuronMouseUp(MouseButtonEventArgs e)
8282
if (n.Model == Neuron.modelType.Random || n.model == Neuron.modelType.Always)
8383
{
8484
if (n.LeakRate < 0)
85-
n.LeakRate = -n.LeakRate;
85+
n.LeakRate = 1;
8686
else
8787
{
8888
n.CurrentCharge = 0;
8989
n.LastCharge = 0;
90-
n.LeakRate = -n.LeakRate;
90+
n.LeakRate = -1;
9191
}
9292
}
9393
else if (n.Model != Neuron.modelType.Color)

0 commit comments

Comments
 (0)