Jump to content

Component: Neuron (Calculation)

From Flowcode Help
Author Matrix TSL
Version 1.3
Category Calculation


Neuron component

Performs a single-neuron calculation of Z = W · X + B. Sums weight * input for each input, adds bias, then optionally applies an activation function (Linear, ReLU, Sigmoid, Tanh or Leaky ReLU). Use SetWeights / SetWeight and SetBias to configure, set inputs with SetInput or pass an array to Calculate / CalculateSingle. Use CalculateLoss or CalculateLossFromResult to measure error against a target value.

Detailed description

No detailed description exists yet for this component

Examples

No additional examples

Macro reference

Calculate

Calculate
Calculates Z = sum(Weight[i] * Input[i]) + Bias, then applies the selected activation. Returns the activated output and also stores it in Result. 
- FLOAT InputArray
Array of input values (one per input) 
- FLOAT Return


CalculateLoss

CalculateLoss
Calculates loss between a predicted value and a target value using the Loss Type property. MSE = (Predicted - Target)^2. MAE = abs(Predicted - Target). Binary Cross Entropy = -(Target * log(Predicted) + (1 - Target) * log(1 - Predicted)). Stores the value in Loss and returns it. 
- FLOAT Predicted
Predicted / output value 
- FLOAT Target
Expected / target value 
- FLOAT Return


CalculateSingle

CalculateSingle
Convenience for a single-input neuron: Z = Weight[0] * X + Bias, then activation. Uses only input index 0. Ideal when Number of Inputs is 1. 
- FLOAT X
Single input value 
- FLOAT Return


CalculateStored

CalculateStored
Same as Calculate, but uses the inputs previously stored with SetInput. Useful when filling inputs one at a time. 
- FLOAT Return


Initialise

Initialise
Clears all weights, inputs, bias, result and loss to 0.0. 
- VOID Return


SetBias

SetBias
Sets the bias offset constant B used in Z = W · X + B. 
- FLOAT Value
Bias value 
- VOID Return


SetInput

SetInput
Stores a single input value for later use by CalculateStored. Index range: 0 to (Number of Inputs - 1). 
- BYTE Index
Input index (0 based) 
- FLOAT Value
Input value to store 
- VOID Return


SetWeight

SetWeight
Sets a single weight value by index. Index range: 0 to (Number of Inputs - 1). 
- BYTE Index
Weight index (0 based) 
- FLOAT Value
Weight value to store 
- VOID Return


SetWeights

SetWeights
Copies an array of weight values into the neuron. The array must contain at least Number of Inputs elements. 
- FLOAT WeightArray
Array of weight values (one per input) 
- VOID Return


Property reference

Properties
Number of Inputs
Number of inputs (and weights) used by the neuron. Range: 1 to 32. 
Activation
Activation applied after Z = W · X + B. Linear returns Z unchanged. ReLU returns max(0, Z). Sigmoid returns 1 / (1 + exp(-Z)). Tanh returns (2 / (1 + exp(-2Z))) - 1. Leaky ReLU returns Z when Z > 0, otherwise Leak Slope * Z. 
Loss Type
Error / loss function used by CalculateLoss and CalculateLossFromResult. MSE = (Predicted - Target)^2. MAE = abs(Predicted - Target). Binary Cross Entropy is intended for Sigmoid outputs in the range 0 to 1. 

Component Source Code

Please click here to download the component source project: FC_Comp_Source_Neuron.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_Neuron.fcfx