N2CMU Arduino
|
Class representing the N2CMU device. More...
#include <n2cmu.h>
Public Member Functions | |
N2Coprocessor (uint8_t rx=N2CMU_RX_PIN, uint8_t tx=N2CMU_TX_PIN) | |
Constructor for N2Coprocessor class. More... | |
bool | begin () |
Initialize the N2CMU device. More... | |
bool | handshake () |
Perform handshake with the N2CMU device. More... | |
bool | cpuReset () |
Reset the CPU of the N2CMU device. More... | |
void | createNetwork (uint8_t inputCount, uint8_t hiddenCount, uint8_t outputCount) |
Create a neural network with specified input, hidden, and output neuron counts. More... | |
bool | train (float *data, float *output, uint16_t len, float learningRate) |
Train the neural network with provided data and output. More... | |
bool | infer (float *input, float *output) |
Make inference with the neural network using provided input data. More... | |
void | resetNetwork () |
Reset the neural network parameters. More... | |
void | setInputCount (uint8_t inputCount) |
Set the number of input neurons. More... | |
void | setHiddenCount (uint8_t hiddenCount) |
Set the number of hidden neurons. More... | |
void | setOutputCount (uint8_t outputCount) |
Set the number of output neurons. More... | |
void | setEpochCount (uint16_t epoch) |
Set the epoch count for training. More... | |
uint8_t | getInputCount () |
Get the number of input neurons. More... | |
uint8_t | getHiddenCount () |
Get the number of hidden neurons. More... | |
uint8_t | getOutputCount () |
Get the number of output neurons. More... | |
uint16_t | getEpochCount () |
Get the epoch count for training. More... | |
bool | setHiddenNeuron (float *hiddenNeuron) |
Set hidden neuron values. More... | |
bool | setOutputNeuron (float *outputNeuron) |
Set output neuron values. More... | |
bool | setHiddenWeights (float *hiddenWeights) |
Set hidden neuron weights. More... | |
bool | setOutputWeights (float *outputWeights) |
Set output neuron weights. More... | |
bool | setHiddenBias (float *hiddenBias) |
Set hidden neuron biases. More... | |
bool | setOutputBias (float *outputBias) |
Set output neuron biases. More... | |
bool | setHiddenGradient (float *hiddenGrad) |
Set hidden neuron gradients. More... | |
bool | setOutputGradient (float *outputGrad) |
Set output neuron gradients. More... | |
void | getHiddenNeuron (float *hiddenNeuron) |
Get hidden neuron values. More... | |
void | getOutputNeuron (float *outputNeuron) |
Get output neuron values. More... | |
void | getHiddenWeights (float *hiddenWeights) |
Get hidden neuron weights. More... | |
void | getOutputWeights (float *outputWeights) |
Get output neuron weights. More... | |
void | getHiddenBias (float *hiddenBias) |
Get hidden neuron biases. More... | |
void | getOutputBias (float *outputBias) |
Get output neuron biases. More... | |
void | getHiddenGradient (float *hiddenGrad) |
Get hidden neuron gradients. More... | |
void | getOutputGradient (float *outputGrad) |
Get output neuron gradients. More... | |
void | loadFromFile (const char *modelFilename) |
void | saveToFile (const char *modelFilename) |
Class representing the N2CMU device.
The N2Coprocessor class offers an interface for controlling and interacting with the N2CMU shield device. It encapsulates functions for initialization, configuration, training, inference, and parameter manipulation of neural networks.
|
inline |
Constructor for N2Coprocessor class.
Constructs a new N2Coprocessor object with the specified RX and TX pins for serial communication.
rx | Pin number for receiving data from N2CMU. |
tx | Pin number for transmitting data to N2CMU. |
bool N2Coprocessor::begin | ( | ) |
Initialize the N2CMU device.
This function initializes the N2CMU device by establishing communication and performing necessary setup operations. It must be called before any other operations are performed on the N2CMU device.
bool N2Coprocessor::cpuReset | ( | ) |
Reset the CPU of the N2CMU device.
This function resets the CPU of the N2CMU device, restoring it to a known state. It can be useful for recovering from unexpected errors or initializing the device before starting a new operation.
void N2Coprocessor::createNetwork | ( | uint8_t | inputCount, |
uint8_t | hiddenCount, | ||
uint8_t | outputCount | ||
) |
Create a neural network with specified input, hidden, and output neuron counts.
This function creates a neural network model with the specified number of input, hidden, and output neurons. It initializes the network architecture for subsequent training and inference tasks.
inputCount | Number of input neurons. |
hiddenCount | Number of hidden neurons. |
outputCount | Number of output neurons. |
uint16_t N2Coprocessor::getEpochCount | ( | ) |
Get the epoch count for training.
This function retrieves the number of training epochs currently set for the neural network.
void N2Coprocessor::getHiddenBias | ( | float * | hiddenBias | ) |
Get hidden neuron biases.
This function retrieves the biases of the hidden neurons in the neural network. It allows obtaining the current biases of the hidden neurons during or after training or inference.
hiddenBias | Array to store hidden neuron biases. |
uint8_t N2Coprocessor::getHiddenCount | ( | ) |
Get the number of hidden neurons.
This function retrieves the number of hidden neurons currently set for the neural network.
void N2Coprocessor::getHiddenGradient | ( | float * | hiddenGrad | ) |
Get hidden neuron gradients.
This function retrieves the gradients of the hidden neurons in the neural network. It allows obtaining the current gradients of the hidden neurons during or after training.
hiddenGrad | Array to store hidden neuron gradients. |
void N2Coprocessor::getHiddenNeuron | ( | float * | hiddenNeuron | ) |
Get hidden neuron values.
This function retrieves the values of the hidden neurons in the neural network. It allows obtaining the current state of the hidden neurons during or after training or inference.
hiddenNeuron | Array to store hidden neuron values. |
void N2Coprocessor::getHiddenWeights | ( | float * | hiddenWeights | ) |
Get hidden neuron weights.
This function retrieves the weights of the connections between input and hidden neurons in the neural network. It allows obtaining the current weights of these connections during or after training or inference.
hiddenWeights | Array to store hidden neuron weights. |
uint8_t N2Coprocessor::getInputCount | ( | ) |
Get the number of input neurons.
This function retrieves the number of input neurons currently set for the neural network.
void N2Coprocessor::getOutputBias | ( | float * | outputBias | ) |
Get output neuron biases.
This function retrieves the biases of the output neurons in the neural network. It allows obtaining the current biases of the output neurons during or after training or inference.
outputBias | Array to store output neuron biases. |
uint8_t N2Coprocessor::getOutputCount | ( | ) |
Get the number of output neurons.
This function retrieves the number of output neurons currently set for the neural network.
void N2Coprocessor::getOutputGradient | ( | float * | outputGrad | ) |
Get output neuron gradients.
This function retrieves the gradients of the output neurons in the neural network. It allows obtaining the current gradients of the output neurons during or after training.
outputGrad | Array to store output neuron gradients. |
void N2Coprocessor::getOutputNeuron | ( | float * | outputNeuron | ) |
Get output neuron values.
This function retrieves the values of the output neurons in the neural network. It allows obtaining the current state of the output neurons during or after training or inference.
outputNeuron | Array to store output neuron values. |
void N2Coprocessor::getOutputWeights | ( | float * | outputWeights | ) |
Get output neuron weights.
This function retrieves the weights of the connections between hidden and output neurons in the neural network. It allows obtaining the current weights of these connections during or after training or inference.
outputWeights | Array to store output neuron weights. |
bool N2Coprocessor::handshake | ( | ) |
Perform handshake with the N2CMU device.
This function performs a handshake with the N2CMU device to ensure proper communication and synchronization. It verifies the connection and readiness of the N2CMU device for subsequent operations.
bool N2Coprocessor::infer | ( | float * | input, |
float * | output | ||
) |
Make inference with the neural network using provided input data.
This function performs inference with the trained neural network using the provided input data. It computes the output of the network based on the input and returns the result.
input | Pointer to the input data array. |
output | Pointer to store the output data array. |
void N2Coprocessor::resetNetwork | ( | ) |
Reset the neural network parameters.
This function resets the parameters of the neural network to their initial values. It clears any previously learned weights, biases, or gradients, effectively resetting the network to its initial state.
void N2Coprocessor::setEpochCount | ( | uint16_t | epoch | ) |
Set the epoch count for training.
This function sets the number of training epochs for the neural network. An epoch represents one complete pass through the entire training dataset.
epoch | Epoch count for training. |
bool N2Coprocessor::setHiddenBias | ( | float * | hiddenBias | ) |
Set hidden neuron biases.
This function sets the biases of the hidden neurons in the neural network. It allows specifying the initial biases of the hidden neurons before training or inference.
hiddenBias | Array of hidden neuron biases. |
void N2Coprocessor::setHiddenCount | ( | uint8_t | hiddenCount | ) |
Set the number of hidden neurons.
This function sets the number of hidden neurons for the neural network. It allows dynamically configuring the hidden layer of the network to adjust its capacity and complexity.
hiddenCount | Number of hidden neurons. |
bool N2Coprocessor::setHiddenGradient | ( | float * | hiddenGrad | ) |
Set hidden neuron gradients.
This function sets the gradients of the hidden neurons in the neural network. It allows specifying the initial gradients of the hidden neurons before training or inference.
hiddenGrad | Array of hidden neuron gradients. |
bool N2Coprocessor::setHiddenNeuron | ( | float * | hiddenNeuron | ) |
Set hidden neuron values.
This function sets the values of the hidden neurons in the neural network. It allows specifying the initial values of the hidden neurons before training or inference.
hiddenNeuron | Array of hidden neuron values. |
bool N2Coprocessor::setHiddenWeights | ( | float * | hiddenWeights | ) |
Set hidden neuron weights.
This function sets the weights of the connections between input and hidden neurons in the neural network. It allows specifying the initial weights of these connections before training or inference.
hiddenWeights | Array of hidden neuron weights. |
void N2Coprocessor::setInputCount | ( | uint8_t | inputCount | ) |
Set the number of input neurons.
This function sets the number of input neurons for the neural network. It allows dynamically configuring the input layer of the network to match the requirements of the input data.
inputCount | Number of input neurons. |
bool N2Coprocessor::setOutputBias | ( | float * | outputBias | ) |
Set output neuron biases.
This function sets the biases of the output neurons in the neural network. It allows specifying the initial biases of the output neurons before training or inference.
outputBias | Array of output neuron biases. |
void N2Coprocessor::setOutputCount | ( | uint8_t | outputCount | ) |
Set the number of output neurons.
This function sets the number of output neurons for the neural network. It allows dynamically configuring the output layer of the network to match the requirements of the output data.
outputCount | Number of output neurons. |
bool N2Coprocessor::setOutputGradient | ( | float * | outputGrad | ) |
Set output neuron gradients.
This function sets the gradients of the output neurons in the neural network. It allows specifying the initial gradients of the output neurons before training or inference.
outputGrad | Array of output neuron gradients. |
bool N2Coprocessor::setOutputNeuron | ( | float * | outputNeuron | ) |
Set output neuron values.
This function sets the values of the output neurons in the neural network. It allows specifying the initial values of the output neurons before training or inference.
outputNeuron | Array of output neuron values. |
bool N2Coprocessor::setOutputWeights | ( | float * | outputWeights | ) |
Set output neuron weights.
This function sets the weights of the connections between hidden and output neurons in the neural network. It allows specifying the initial weights of these connections before training or inference.
outputWeights | Array of output neuron weights. |
bool N2Coprocessor::train | ( | float * | data, |
float * | output, | ||
uint16_t | len, | ||
float | learningRate | ||
) |
Train the neural network with provided data and output.
This function trains the neural network using the provided input data and corresponding output. It adjusts the network parameters based on the training data to improve its performance and accuracy.
data | Pointer to the input data array. |
output | Pointer to the output data array. |
len | Length of the data arrays. |
learningRate | Learning rate for training. |