Orderbook Simulation
OrderbookSim is a C++ application simulating a financial market order book. It efficiently manages and matches buy and sell orders while calculating the Volume-Weighted Average Price (VWAP).
Neuron.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <vector>
13 #include <random>
14 #include "Connection.hpp"
15 
20 typedef std::vector<Neuron> Layer;
21 
29 class Neuron {
30 public:
40  Neuron(unsigned numOutputs, unsigned myIdx);
41 
47  void setOutputVal(double val) { _outputVal = val; }
48 
54  double getOutputVal() const { return _outputVal; }
55 
64  void feedForward(const Layer& prevLayer);
65 
74  void calcOutputGradients(double targetVal);
75 
84  void calcHiddenGradients(const Layer& nextLayer);
85 
94  void updateInputWeights(Layer& prevLayer);
95 
96 private:
97  static double eta;
98  static double alpha;
99 
105  static double randomWeight() { return rand() / double(RAND_MAX); }
106 
107  double _outputVal;
108  std::vector<Connection> _outputWeights;
109  unsigned _myIdx;
110  double _gradient;
111 
120  static double transferFunction(double x);
121 
131  static double transferFunctionDerivative(double x);
132 
142  double sumDOW(const Layer& nextLayer) const;
143 };
std::vector< Neuron > Layer
Represents a layer of neurons in the neural network.
Definition: Neuron.hpp:20
Represents a single neuron within a neural network layer.
Definition: Neuron.hpp:29
void updateInputWeights(Layer &prevLayer)
Updates the weights of connections from the previous layer.
Definition: Neuron.cpp:35
void setOutputVal(double val)
Sets the neuron's output value.
Definition: Neuron.hpp:47
void feedForward(const Layer &prevLayer)
Feeds the input values forward through the neuron.
Definition: Neuron.cpp:126
void calcHiddenGradients(const Layer &nextLayer)
Calculates gradients for hidden layer neurons.
Definition: Neuron.cpp:74
double getOutputVal() const
Retrieves the neuron's output value.
Definition: Neuron.hpp:54
Neuron(unsigned numOutputs, unsigned myIdx)
Constructs a Neuron with a specified number of outputs.
Definition: Neuron.cpp:144
void calcOutputGradients(double targetVal)
Calculates the gradient for output layer neurons.
Definition: Neuron.cpp:87