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).
Public Member Functions | List of all members
Neuron Class Reference

Represents a single neuron within a neural network layer. More...

#include <Neuron.hpp>

Public Member Functions

 Neuron (unsigned numOutputs, unsigned myIdx)
 Constructs a Neuron with a specified number of outputs. More...
 
void setOutputVal (double val)
 Sets the neuron's output value. More...
 
double getOutputVal () const
 Retrieves the neuron's output value. More...
 
void feedForward (const Layer &prevLayer)
 Feeds the input values forward through the neuron. More...
 
void calcOutputGradients (double targetVal)
 Calculates the gradient for output layer neurons. More...
 
void calcHiddenGradients (const Layer &nextLayer)
 Calculates gradients for hidden layer neurons. More...
 
void updateInputWeights (Layer &prevLayer)
 Updates the weights of connections from the previous layer. More...
 

Detailed Description

Represents a single neuron within a neural network layer.

The Neuron class handles the neuron's output value, weights for connections to subsequent neurons, and methods for updating weights and calculating gradients.

Constructor & Destructor Documentation

◆ Neuron()

Neuron::Neuron ( unsigned  numOutputs,
unsigned  myIdx 
)

Constructs a Neuron with a specified number of outputs.

Constructor for the Neuron class.

Initializes a neuron with a certain number of connections (outputs) and an index within its layer.

Parameters
numOutputsThe number of connections from this neuron to the next layer.
myIdxThe index of this neuron in its layer.

Initializes a neuron with a specified number of outputs and index. Each output connection is initialized with a random weight.

Parameters
numOutputsThe number of connections from this neuron to the next layer.
myIdxThe index of this neuron in its layer.

Member Function Documentation

◆ calcHiddenGradients()

void Neuron::calcHiddenGradients ( const Layer nextLayer)

Calculates gradients for hidden layer neurons.

Computes the gradient for hidden neurons based on the sum of weights and gradients from the next layer and the derivative of the transfer function.

Parameters
nextLayerThe next layer of neurons, used to compute the gradient.

◆ calcOutputGradients()

void Neuron::calcOutputGradients ( double  targetVal)

Calculates the gradient for output layer neurons.

Uses the difference between the target and actual output values, adjusted by the derivative of the transfer function, to set the gradient.

Parameters
targetValThe target value for the output neuron.

◆ feedForward()

void Neuron::feedForward ( const Layer prevLayer)

Feeds the input values forward through the neuron.

Calculates the neuron's output by summing the products of inputs and weights, then applies the transfer function.

Parameters
prevLayerThe previous layer of neurons, used as inputs to this neuron.

Calculates the neuron's output by summing the products of inputs and weights, and then applies the transfer function to the result.

Parameters
prevLayerThe previous layer of neurons, used as inputs to this neuron.

◆ getOutputVal()

double Neuron::getOutputVal ( ) const
inline

Retrieves the neuron's output value.

Returns
The output value of the neuron.

◆ setOutputVal()

void Neuron::setOutputVal ( double  val)
inline

Sets the neuron's output value.

Parameters
valThe output value to be set.

◆ updateInputWeights()

void Neuron::updateInputWeights ( Layer prevLayer)

Updates the weights of connections from the previous layer.

Adjusts each weight based on the neuron's gradient and learning parameters (eta and alpha).

Parameters
prevLayerThe layer of neurons from which the current neuron receives inputs.

The documentation for this class was generated from the following files: