Diwa
Lightweight implementation of Artificial Neural Network for resource-constrained environments
Loading...
Searching...
No Matches
Diwa Class Reference

Lightweight Feedforward Artificial Neural Network (ANN) library tailored for microcontrollers. More...

#include <diwa.h>

Public Member Functions

 Diwa ()
 Default constructor for the Diwa class.
 
 ~Diwa ()
 Destructor for the Diwa class.
 
DiwaError initialize (int inputNeurons, int hiddenLayers, int hiddenNeurons, int outputNeurons, bool randomizeWeights=true)
 Initializes the Diwa neural network with specified parameters.
 
double * inference (double *inputs)
 Perform inference on the neural network.
 
void train (double learningRate, double *inputNeurons, double *outputNeurons)
 Train the neural network using backpropagation.
 
DiwaError loadFromFile (std::ifstream &annFile)
 Load neural network model from file in non-Arduino environment.
 
DiwaError saveToFile (std::ofstream &annFile)
 Save neural network model to file in non-Arduino environment.
 

Detailed Description

Lightweight Feedforward Artificial Neural Network (ANN) library tailored for microcontrollers.

The Diwa library is designed to provide a simple yet effective implementation of a Feedforward Artificial Neural Network (ANN) for resource-constrained microcontroller environments such as ESP8266, ESP32, and similar development boards.

Note
This library is primarily intended for lightweight applications. For more intricate tasks, consider using advanced machine learning libraries on more powerful platforms.

Constructor & Destructor Documentation

◆ Diwa()

Diwa::Diwa ( )

Default constructor for the Diwa class.

This constructor initializes a new instance of the Diwa class. It sets up the neural network with default value 0 on parameters.

◆ ~Diwa()

Diwa::~Diwa ( )

Destructor for the Diwa class.

This destructor releases resources associated with the Diwa object upon its destruction. It ensures proper cleanup to prevent memory leaks.

Member Function Documentation

◆ inference()

double * Diwa::inference ( double *  inputs)

Perform inference on the neural network.

Given an array of input values, this method computes and returns an array of output values through the neural network.

Parameters
inputsArray of input values for the neural network.
Returns
Array of output values after inference.

◆ initialize()

DiwaError Diwa::initialize ( int  inputNeurons,
int  hiddenLayers,
int  hiddenNeurons,
int  outputNeurons,
bool  randomizeWeights = true 
)

Initializes the Diwa neural network with specified parameters.

This method initializes the Diwa neural network with the given parameters, including the number of input neurons, hidden layers, hidden neurons per layer, and output neurons. Additionally, it allows the option to randomize the weights in the network if desired.

Parameters
inputNeuronsNumber of input neurons in the neural network.
hiddenLayersNumber of hidden layers in the neural network.
hiddenNeuronsNumber of neurons in each hidden layer.
outputNeuronsNumber of output neurons in the neural network.
randomizeWeightsFlag indicating whether to randomize weights in the network (default is true).
Returns
DiwaError indicating the initialization status.

◆ loadFromFile()

DiwaError Diwa::loadFromFile ( std::ifstream &  annFile)

Load neural network model from file in non-Arduino environment.

This method loads a previously saved neural network model from the specified file in a non-Arduino environment. It reads the model data from the given file stream and initializes the Diwa object with the loaded model parameters and weights.

Parameters
annFileInput file stream representing the neural network model file.
Returns
DiwaError indicating the loading status.

◆ saveToFile()

DiwaError Diwa::saveToFile ( std::ofstream &  annFile)

Save neural network model to file in non-Arduino environment.

This method saves the current state of the neural network model to the specified file in a non-Arduino environment. It writes the model parameters and weights to the given file stream, facilitating storage and retrieval of the trained model.

Parameters
annFileOutput file stream representing the destination file for the model.
Returns
DiwaError indicating the saving status.

◆ train()

void Diwa::train ( double  learningRate,
double *  inputNeurons,
double *  outputNeurons 
)

Train the neural network using backpropagation.

This method facilitates the training of the neural network by adjusting its weights based on the provided input and target output values.

Parameters
learningRateLearning rate for the training process.
inputNeuronsArray of input values for training.
outputNeuronsArray of target output values for training.

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