-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathNeuron.cs
More file actions
62 lines (49 loc) · 1.56 KB
/
Copy pathNeuron.cs
File metadata and controls
62 lines (49 loc) · 1.56 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
using System;
using System.Collections.Generic;
using System.Text;
namespace Bigtree.Algorithm.NeuralNetwork
{
public class Neuron
{
/// <summary>
/// Input values
/// </summary>
public List<Dendrite> InputDendrites { get; set; }
/// <summary>
/// Output pulse
/// </summary>
public double Output { get; set; }
public double Delta { get; set; }
public Neuron()
{
InputDendrites = new List<Dendrite>();
}
public void Fire(NeuralLayer preLayer)
{
Output = Sum(preLayer);
Output = ActivationFunction.Sigmoid(Output);
// Console.WriteLine($"Activation: {Output}");
// Console.WriteLine();
}
public void UpdateWeights(double new_weights)
{
foreach (var terminal in InputDendrites)
{
terminal.Weight = new_weights;
}
}
private double Sum(NeuralLayer preLayer)
{
double computeValue = 0.0f;
for(int i = 0; i < preLayer.Neurons.Count; i++)
{
var neuron = preLayer.Neurons[i];
var dendrite = InputDendrites[i];
computeValue += neuron.Output * dendrite.Weight;
// Console.WriteLine($"{neuron.Output} * {neuron.InputDendrites[0].Weight} = {neuron.Output * neuron.InputDendrites[0].Weight}");
}
// Console.WriteLine($"Sum = {computeValue}");
return computeValue;
}
}
}