-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuron.cs
More file actions
68 lines (60 loc) · 1.65 KB
/
Copy pathNeuron.cs
File metadata and controls
68 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlothNet
{
class Neuron
{
public List<Dendrite> Dendrites { get; set; }
public Pulse Output { get; set; }
public double Error;
public Neuron()
{
Dendrites = new List<Dendrite>();
Output = new Pulse();
}
public void Fire()
{
//Console.WriteLine("PRE-SUM: " + Output.Value);
Output.Value = Sum();
//Console.WriteLine("POST-SUM: " + Output.Value);
Output.Value = Activation(Output.Value);
//Console.WriteLine("POST-ACT: " + Output.Value);
}
public void UpdateWeight(double newWeight)
{
foreach(Dendrite d in Dendrites)
{
d.Weight = newWeight;
}
}
public void AdjustWeight(double err)
{
Error = err;
foreach(Dendrite d in Dendrites)
{
d.Weight += Error * Activation(d.Weight) * 0.2 * Output.Value;
}
}
private double Sum()
{
double computed = 0.0f;
foreach(Dendrite d in Dendrites)
{
computed += d.Input.Value * d.Weight;
}
return computed;
}
private double Activation(double input)
{
double val = 1 / (1 + Math.Exp(-input));
return (val * (1 - val) >= 0.00000000001) ? 1 : 0;
}
public override string ToString()
{
return base.ToString();
}
}
}