-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuron.cs
More file actions
77 lines (68 loc) · 2.36 KB
/
Copy pathNeuron.cs
File metadata and controls
77 lines (68 loc) · 2.36 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
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyNeuralNetworkProject
{
internal class Neuron
{
// Inputs
private double sepalLength;
private double sepalWidth;
private double petalLength;
private double petalWidth;
private string plantType;
// Weigths
double sepalLengthWeight;
double sepalWidthWeight;
double petalLengthWeight;
double petalWidthWeight;
// Assigning random weights in [0, 1] range
Random random;
public Neuron()
{
random= new Random();
sepalLengthWeight = random.NextDouble();
sepalWidthWeight = random.NextDouble();
petalLengthWeight = random.NextDouble();
petalWidthWeight = random.NextDouble();
}
// Setting inputs
public void setInputs(double sepalLength, double sepalWidth, double petalLength, double petalWidth, string plantType)
{
this.sepalLength = sepalLength;
this.sepalWidth = sepalWidth;
this.petalLength = petalLength;
this.petalWidth = petalWidth;
this.plantType = plantType;
}
// Getter for plantType
public string PlantType
{
get
{
return plantType;
}
}
// Output
public double calculateOutput()
{
return sepalLength * sepalLengthWeight + sepalWidth * sepalWidthWeight + petalLength * petalLengthWeight + petalWidth * petalWidthWeight;
}
public void decreaseWeights(double learningRate)
{
sepalLengthWeight -= learningRate * sepalLength;
sepalWidthWeight -= learningRate * sepalWidth;
petalLengthWeight -= learningRate * petalLength;
petalWidthWeight -= learningRate * petalWidth;
}
public void increaseWeights(double learningRate)
{
sepalLengthWeight += learningRate * sepalLength;
sepalWidthWeight += learningRate * sepalWidth;
petalLengthWeight += learningRate * petalLength;
petalWidthWeight += learningRate * petalWidth;
}
}
}