#include <CscNeuralNetwork.h>
|
| | CscNeuralNetwork (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit) |
| |
| | CscNeuralNetwork (CscNeuralNetworkType neuralNetworkType, NeuralNetworkHyperparameters *neuralNetworkHyperparametersInit, TrainingHyperparameters *trainingHyperparametersInit, float **weightsLoadedFromModel, float **biasesLoadedFromModel) |
| |
| virtual | ~CscNeuralNetwork () |
| |
| CscNeuralNetworkType | getNeuralNetworkType () const |
| |
| CscNeuralNetwork::NeuralNetworkHyperparameters * | getNeuralNetworkHyperparameters () const |
| |
| CscNeuralNetwork::TrainingHyperparameters * | getTrainingHyperparameters () const |
| |
| virtual ResultTraining | trainNeuralNetwork (const int nbEpochs, const int nbMiniBatchs, DataSet *trainingDataSet, DataSet *validationDataSet, const bool debugMode=false)=0 |
| | Trains the neural network using the provided input and target data. More...
|
| |
|
| static float *** | adaptDataForMiniBatches (float **dataToTransform, const int minibatchSize, const int dataSetSize) |
| | Prepares the dataset for minibatch processing by dividing it into smaller batches. More...
|
| |
| static void | normalizeDataAutoRange (float **data, size_t size, int nbInputsOrOutputs, CscNormalizationType normalizationType) |
| |
| static void | normalizeDataCustomRange0to1 (float **data, size_t size, int nbInputsOrOutputs, float *minValue, float *maxValue) |
| |
| static void | normalizeDataCustomRangeMinus1to1 (float **data, size_t size, int nbInputsOrOutputs, float *minValue, float *maxValue) |
| |
| static void | normalizeData (float **data, size_t size, int rowData, float newMin, float newMax, float minValue, float maxValue) |
| |
| static void | deleteAllDataMiniBatches (float ***dataMiniBatches, const int nbMiniBatches, const int nbDataPerMinibatch) |
| | Frees the memory allocated for the mini-batches of data. More...
|
| |
| static void | initializeWeights (float *weightsToInitialize, int size, CscInitializationWeightsStrategy strategy, int fanIn, int fanOut=0, float *weightsLoaded=nullptr) |
| | Initializes the weights of the neural network according to a specified initialization strategy. More...
|
| |
| static void | initializeBias (float *biasToInitialize, int size, CscInitializationBiasStrategy strategy, float *biasLoaded=nullptr) |
| |
◆ CscNeuralNetwork() [1/2]
◆ CscNeuralNetwork() [2/2]
◆ ~CscNeuralNetwork()
| conscience_core::ai::nn::CscNeuralNetwork::~CscNeuralNetwork |
( |
| ) |
|
|
virtual |
◆ adaptDataForMiniBatches()
| float *** conscience_core::ai::nn::CscNeuralNetwork::adaptDataForMiniBatches |
( |
float ** |
dataToTransform, |
|
|
const int |
minibatchSize, |
|
|
const int |
dataSetSize |
|
) |
| |
|
static |
Prepares the dataset for minibatch processing by dividing it into smaller batches.
This method organizes input data into a structure suitable for minibatch training. Each minibatch consists of a subset of the input data, allowing for more efficient memory usage and potentially faster convergence of the neural network due to more frequent updates.
- Parameters
-
| dataToTransform | Pointer to the original dataset to be divided into minibatches. |
| minibatchSize | The size of each minibatch. |
| dataSetSize | The total number of samples in the dataset. |
- Returns
- A 3D array where the first dimension corresponds to the minibatch index, the second dimension indexes into a specific sample within a minibatch, and the third dimension represents the data of that sample.
- Warning
- The new tabs created must be deleted after they have been used for training.
◆ calculateLimitGlorot()
| float conscience_core::ai::nn::CscNeuralNetwork::calculateLimitGlorot |
( |
int |
fanIn, |
|
|
int |
fanOut |
|
) |
| |
|
staticprotected |
◆ calculateStddevGlorot()
| float conscience_core::ai::nn::CscNeuralNetwork::calculateStddevGlorot |
( |
int |
fanIn, |
|
|
int |
fanOut |
|
) |
| |
|
staticprotected |
◆ calculateStddevHe()
| float conscience_core::ai::nn::CscNeuralNetwork::calculateStddevHe |
( |
int |
fanIn | ) |
|
|
staticprotected |
◆ calculateStddevLeCun()
| float conscience_core::ai::nn::CscNeuralNetwork::calculateStddevLeCun |
( |
int |
fanIn | ) |
|
|
staticprotected |
◆ createNeuralNetwork()
◆ deleteAllDataMiniBatches()
| void conscience_core::ai::nn::CscNeuralNetwork::deleteAllDataMiniBatches |
( |
float *** |
dataMiniBatches, |
|
|
const int |
nbMiniBatches, |
|
|
const int |
nbDataPerMinibatch |
|
) |
| |
|
static |
Frees the memory allocated for the mini-batches of data.
This function iterates through each mini-batch of data, and for each mini-batch, it iterates through each data point. It frees the memory allocated for each data point and then frees the memory allocated for the mini-batch itself. Finally, it frees the memory allocated for the array of pointers to the mini-batches.
- Parameters
-
| dataMiniBatches | A pointer to an array of pointers to arrays of pointers. Each element in the first array represents a mini-batch. Each element in a mini-batch represents a single data point. The memory for each data point, each mini-batch, and the array of mini-batches itself is dynamically allocated and needs to be freed. |
| nbMiniBatches | The number of mini-batches in dataMiniBatches. This is the size of the first array. |
| nbDataPerMinibatch | The number of data points in each mini-batch. This is the size of each second-level array. |
◆ getNeuralNetworkHyperparameters()
◆ getNeuralNetworkType()
◆ getTrainingHyperparameters()
◆ initializeBias()
| void conscience_core::ai::nn::CscNeuralNetwork::initializeBias |
( |
float * |
biasToInitialize, |
|
|
int |
size, |
|
|
CscInitializationBiasStrategy |
strategy, |
|
|
float * |
biasLoaded = nullptr |
|
) |
| |
|
static |
◆ initializeWeights()
| void conscience_core::ai::nn::CscNeuralNetwork::initializeWeights |
( |
float * |
weightsToInitialize, |
|
|
int |
size, |
|
|
CscInitializationWeightsStrategy |
strategy, |
|
|
int |
fanIn, |
|
|
int |
fanOut = 0, |
|
|
float * |
weightsLoaded = nullptr |
|
) |
| |
|
static |
Initializes the weights of the neural network according to a specified initialization strategy.
This method initializes the weights of the neural network using one of four supported initialization strategies: He, GlorotUniform, GlorotNormal, or LeCunNormal. Each strategy has its characteristics and is chosen based on the specific needs of the network's architecture. Proper weight initialization is crucial for the successful learning and convergence of the neural network.
- Parameters
-
| weightsToInitialize | Pointer to the array of weights to be initialized. This array must be pre-allocated with enough size to hold all the weights. |
| size | The number of weights to initialize in the array. |
| strategy | The CscInitializationWeightsStrategy enumeration specifying the initialization strategy to use for the weights. |
| fanIn | The number of incoming units to the node for which the weights are being initialized, used in the calculation for some strategies. |
| fanOut | The number of outgoing units from the node for which the weights are being initialized, used in the calculation for some strategies. |
- Note
- The function uses specific distributions based on the chosen strategy to initialize the weights. For
He, a normal distribution is used with a standard deviation calculated based on fanIn. For GlorotUniform, a uniform distribution is used with limits calculated based on fanIn and fanOut. GlorotNormal uses a normal distribution similar to GlorotUniform but with a different standard deviation. LeCunNormal uses a normal distribution with a standard deviation calculated solely based on fanIn.
◆ initNormal()
| void conscience_core::ai::nn::CscNeuralNetwork::initNormal |
( |
float * |
weights, |
|
|
int |
size, |
|
|
mt19937 & |
gen, |
|
|
double |
stddev |
|
) |
| |
|
staticprotected |
◆ initUniform()
| void conscience_core::ai::nn::CscNeuralNetwork::initUniform |
( |
float * |
weights, |
|
|
int |
size, |
|
|
mt19937 & |
gen, |
|
|
float |
limit |
|
) |
| |
|
staticprotected |
◆ normalizeData()
| void conscience_core::ai::nn::CscNeuralNetwork::normalizeData |
( |
float ** |
data, |
|
|
size_t |
size, |
|
|
int |
rowData, |
|
|
float |
newMin, |
|
|
float |
newMax, |
|
|
float |
minValue, |
|
|
float |
maxValue |
|
) |
| |
|
static |
Normalizes the elements of a given float array to a specified new range.
This method adjusts the values within the array so that they fit within a new range, defined by newMin and newMax. The normalization is done based on a given range of values in the array, specified by the parameters minValue and maxValue. The method scales each element of the array from its original range (minValue to maxValue) to the new range (newMin to newMax). If the array's size is zero, or if newMin is equal to or greater than newMax, the method logs an error and returns without modifying the array.
- Parameters
-
| data | Pointer to the first element of the array of float values to be normalized. |
| size | The number of elements in the array. |
| newMin | The minimum value of the new range to which the data should be normalized. |
| newMax | The maximum value of the new range to which the data should be normalized. |
| minValue | The minimum value in the original range of the data. This parameter is used directly in the normalization calculation and is not modified by the method. |
| maxValue | The maximum value in the original range of the data. This parameter is used directly in the normalization calculation and is not modified by the method. |
◆ normalizeDataAutoRange()
| void conscience_core::ai::nn::CscNeuralNetwork::normalizeDataAutoRange |
( |
float ** |
data, |
|
|
size_t |
size, |
|
|
int |
nbInputsOrOutputs, |
|
|
CscNormalizationType |
normalizationType |
|
) |
| |
|
static |
◆ normalizeDataCustomRange0to1()
| void conscience_core::ai::nn::CscNeuralNetwork::normalizeDataCustomRange0to1 |
( |
float ** |
data, |
|
|
size_t |
size, |
|
|
int |
nbInputsOrOutputs, |
|
|
float * |
minValue, |
|
|
float * |
maxValue |
|
) |
| |
|
static |
◆ normalizeDataCustomRangeMinus1to1()
| void conscience_core::ai::nn::CscNeuralNetwork::normalizeDataCustomRangeMinus1to1 |
( |
float ** |
data, |
|
|
size_t |
size, |
|
|
int |
nbInputsOrOutputs, |
|
|
float * |
minValue, |
|
|
float * |
maxValue |
|
) |
| |
|
static |
◆ shuffleMinibatchData()
| void conscience_core::ai::nn::CscNeuralNetwork::shuffleMinibatchData |
( |
float *** |
minibatchDataInputs, |
|
|
float *** |
minibatchDataTargets, |
|
|
const int |
numberOfBatches, |
|
|
const int |
minibatchSize |
|
) |
| |
|
protected |
Shuffles the data within each minibatch as well as between minibatches.
This method performs an in-place shuffle of the minibatch data, both the inputs and the targets. The shuffling is performed within each minibatch and across minibatches to ensure that the model does not learn any unintended patterns from the order of the data.
- Parameters
-
| minibatchDataInputs | A 3D array containing the input data divided into minibatches. |
| minibatchDataTargets | A 3D array containing the target data divided into minibatches. |
| numberOfBatches | The total number of minibatches. |
| minibatchSize | The size of each minibatch. |
◆ trainNeuralNetwork()
| virtual ResultTraining conscience_core::ai::nn::CscNeuralNetwork::trainNeuralNetwork |
( |
const int |
nbEpochs, |
|
|
const int |
nbMiniBatchs, |
|
|
DataSet * |
trainingDataSet, |
|
|
DataSet * |
validationDataSet, |
|
|
const bool |
debugMode = false |
|
) |
| |
|
pure virtual |
Trains the neural network using the provided input and target data.
This method trains the neural network over a specified number of epochs and mini-batches, using the TensorFlow C API. It initializes the session and model parameters, shuffles the data for each epoch (except the first one), processes each mini-batch by executing the graph, and updates the weights and biases according to the cost function. It also provides optional debugging information, including logging the progress of training and the change in weights and biases.
- Parameters
-
| nbEpochs | The number of epochs to train the neural network for. |
| nbMiniBatchs | The number of mini-batches to divide the input data into. |
| debugMode | A boolean flag that, when true, enables logging of debugging information during training. |
- Returns
- The mean of the loss/cost function over the mini-batches in the final epoch of training.
- Note
- This function requires TensorFlow C API setup and assumes that the session, graph, and status are correctly initialized and available globally or within the class.
- Warning
- The method does not handle the creation and destruction of the TensorFlow session, graph, and status objects. These should be appropriately managed outside this method.
- Attention
- This method assumes that the neural network, its variables (weights and biases), and the cost function are already defined in the TensorFlow graph.
Implemented in conscience_core::ai::nn::CscNeuralNetworkTensorFlow.
◆ logger
| unique_ptr<CscLogger> conscience_core::ai::nn::CscNeuralNetwork::logger |
|
protected |
◆ neuralNetworkHyperparameters
◆ neuralNetworkType
◆ trainingHyperparameters
The documentation for this class was generated from the following files: