-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuron.h
61 lines (52 loc) · 1.63 KB
/
neuron.h
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
//
// Created by Izzat on 11/25/2023.
//
#ifndef FRUIT_CLASSIFIER_WASM_NEURON_H
#define FRUIT_CLASSIFIER_WASM_NEURON_H
#include "nn.h"
class nn::Neuron : public vd_t {
private:
double bias;
public:
/**
* Constructor for the Neuron class.
*
* @param weights Vector of initial weights.
* @param threshold Initial bias for the neuron.
*/
explicit Neuron(vd_t weights, double threshold);
/**
* Getter for the bias of the neuron.
*
* @return The current bias of the neuron.
*/
[[nodiscard]] double getBias() const;
/**
* Adjusts the weights and bias of the neuron.
*
* @param weightDeltas Vector of changes to be applied to each weight.
* @param biasDelta Change applied to the bias.
*/
void adjust(const vd_t &weightDeltas, double biasDelta);
/**
* Uses the gradient and learning rate to calculate all the deltas.
* Then adjust the weights and bias of the neuron.
*
* Gradient value is one that resulted from backpropagation
* in which the given inputs were passed to this neuron.
*
* @param inputs Vector of input values passed to the neuron
* @param gradient Gradient error value
* @param alpha Learning rate
*/
void adjust(const vd_t &inputs, double gradient, double alpha);
/**
* Calculates the weighted sum of inputs and the bias.
* The bias is added (not subtracted) from the weighted sum.
*
* @param inputs Vector of input values.
* @return The weighted sum.
*/
[[nodiscard]] double process(const vd_t &inputs) const;
};
#endif //FRUIT_CLASSIFIER_WASM_NEURON_H