-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyNetwork.cs
91 lines (77 loc) · 2.45 KB
/
MyNetwork.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
namespace DigitsNet
{
class MyNetwork
{
public InputLayer inLayer;
public OutputLayer outLayer;
public List<HiddenLayer> hiddenLayers = new List<HiddenLayer>();
public MyNetwork(int noInputs,int noOutputs,int noHiddenLayers,List<int> sizeOfHiddenLayers)
{
inLayer = new InputLayer(noInputs);
hiddenLayers.Add(new HiddenLayer(inLayer.inputs, sizeOfHiddenLayers[0]));
for (int i = 1; i < noHiddenLayers; i++)
{
hiddenLayers.Add(new HiddenLayer(hiddenLayers[i-1].outputs, sizeOfHiddenLayers[i]));
}
}
}
class InputLayer
{
//public List<double> inputs = new List<double>();
//public Matrix<double> inputs;
public Vector<double> inputs;
public InputLayer(int noInputs)
{
for(int i = 0; i < noInputs; i++)
{
//inputs = Matrix<double>.Build.Random(noInputs, 1);
inputs = Vector<double>.Build.Dense(noInputs);
}
}
}
class OutputLayer
{
}
class HiddenLayer
{
//private InputLayer inLayer;
public List<Neuron> neurons = new List<Neuron>();
public Vector<double> outputs;
public HiddenLayer(Vector<double> layerIn, int sizeOfLayer)
{
outputs = Vector<double>.Build.Dense(sizeOfLayer);
for (int i = 0; i < sizeOfLayer; i++)
{
neurons.Add(new Neuron(layerIn));
outputs[i] = neurons[i].result(layerIn);
}
}
}
class Neuron
{
//public List<double> inputs = new List<double>();
//public InputLayer inputs;
//public List<double> weights = new List<double>();
Vector<double> weights;
public double bias;
public Neuron(Vector<double> inLayer)
{
//inputs = inLayer;
weights = Vector<double>.Build.Random(inLayer.Count);
Random rand = new Random();
bias = rand.NextDouble();
}
public double result(Vector<double> inLayer)
{
double res = inLayer.DotProduct(weights) + bias;
return res;
}
}
}