-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuron.hpp
More file actions
56 lines (47 loc) · 1.69 KB
/
neuron.hpp
File metadata and controls
56 lines (47 loc) · 1.69 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
//
// Created by Eugene Baek on 2021-04-15.
//
#ifndef NEURALNETWORK_NEURON_HPP
#define NEURALNETWORK_NEURON_HPP
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <fstream>
#include <sstream>
struct Connection {
double weight;
double delta_weight;
};
class Neuron {
public:
//Layer is a vector of Neurons
//the Net will comprise of a 2d vector that contains a vector of layers that each contain a vector of neurons
typedef std::vector<Neuron> Layer;
//to create the neuron's connections to next layer, it only needs to know how many neurons are in next layer
Neuron(unsigned num_of_outputs, unsigned neuron_index);
void setOutputValue(double value) { m_output_value = value; };
double getOutputValue(void) const { return m_output_value; };
void feedForward(const Layer &prev_layer);
void calcOutputGradient(double target_value);
void calcHiddenGradient(const Layer &next_layer);
void updateInputWeight(Layer &prev_layer);
private:
static double transferFunction(double sum);
static double transferFunctionDerivative(double sum);
double sumDOW(const Layer &next_layer) const;
static double randWeight(void) {
std::cout << "rand(): " << rand() << std::endl;
std::cout << "double(RAND_MAX): " << double(RAND_MAX) << std::endl;
return rand() / double(RAND_MAX); };
//output value of neuron
double m_output_value;
//weight of each connection to neurons in next layer
std::vector<Connection> m_output_weights;
unsigned m_neuron_index;
double m_gradient;
static double eta; //[0, 1]
static double alpha; //[0, n]
};
#endif //NEURALNETWORK_NEURON_HPP