typedef struct DataSet_ {
size_t rows;
size_t cols;
float** data;
} DataSet;
The number of rows in the dataset
The number of columns in the dataset
The data held in the dataset, of the aforementioned dimensions
typedef struct Matrix_ {
size_t rows;
size_t cols;
float* data;
} Matrix;
The number of rows in the matrix
The number of columns in the matrix
The data held in the matrix, stored one-dimensionally in row-major order
typedef enum LAYER_TYPE_ {
INPUT,
HIDDEN,
OUTPUT
} LAYER_TYPE;
typedef struct Layer_ {
LAYER_TYPE type;
size_t size;
Activation activation;
Matrix* input;
} Layer;
The type of layer (INPUT, OUTPUT, or HIDDEN)
The number of neurons in the layer
The activation function for the layer
The data currently stored in the layer in the form of a row vector with one entry per neuron in the layer
typedef struct Connection_ {
Layer* from;
Layer* to;
Matrix* weights;
Matrix* bias;
} Connection;
The layer on the input side of the connection
The layer on the output side of the connection
The weights matrix between the "from" and "to" layers, of dimensions "from"->size by "to"->size
The bias vector of the "to" layer, as a row vector of "to"->size
typedef struct Network_ {
size_t numLayers;
Layer** layers;
size_t numConnections;
Connection** connections;
} Network;
The total number of layers in the network
The network's layers, in order
The total number of connections in the network
The network's connections, in order
DataSet* createDataSet(size_t rows, size_t cols, float** data);
The number of rows in the dataset
The number of columns in the dataset
The data, of the aforementioned dimensions, to be put into the dataset
DataSet** createBatches(DataSet* allData, int numBatches);
The overall dataset to be split
The number of batches to split the dataset into
void destroyDataSet(DataSet* dataset);
The dataset to be freed
typedef void (*Activation)(Matrix*);
Applies sigmoid function to layer (for hidden layers)
Applies ReLU function to layer (for hidden layers)
Applies tanh function to layer (for hidden layers)
Applies softmax function to layer (for output layer with CROSS_ENTROPY_LOSS)
Applies linear function to layer (for output layer with MEAN_SQUARED_ERROR)
Matrix* createMatrix(size_t rows, size_t cols, float* data);
The number of rows in the matrix
The number of columns in the matrix
The data, of the aforementioned dimensions, to be put into the matrix
void destroyMatrix(Matrix* matrix);
The matrix to free
Network* createNetwork(size_t numFeatures, size_t numHiddenLayers, size_t*
hiddenSizes, Activation* hiddenActivations, size_t numOutputs,
Activation outputActivation);
The number of neurons in the input layer
The number of hidden layers in the network
The sizes of the hidden layers, provided as a list of sizes in order
The activation functions of the hidden layers, provided as a list of functions, in order
The number of neurons in the output layer
The activation function of the output layer (should be softmax for classification, and linear for regression)
void destroyNetwork(Network* network);
The network to free
typedef enum LOSS_FUNCTION_ {
CROSS_ENTROPY_LOSS,
MEAN_SQUARED_ERROR
} LOSS_FUNCTION;
typedef struct ParameterSet_ {
Network* network;
DataSet* data;
DataSet* classes;
LOSS_FUNCTION lossFunction;
size_t batchSize;
float learningRate;
float searchTime;
float regularizationStrength;
float momentumFactor;
int maxIters;
int shuffle;
int verbose;
} ParameterSet;
The network to optimize
The training data to train the network with
The target values for the training data
The loss function to use when training, should be CROSS_ENTROPY_LOSS for classification and MEAN_SQUARED_ERROR for regression
The size of each batch (provide 1 for SGD, and data->rows for Batch)
The constant factor for initial learning rate
The parameter for "search-then-converge" learning rate annealing that describes when the learning rate will begin slowing down, provide 0 to not use annealing
The constant factor for regularization
The constant factor for simple momentum (adds a fraction of the previous weight update)
The number of epochs to run the optimization algorithm for
If non-zero, will shuffle the data in between epochs (recommended)
If non-zero, will print loss every 100 epochs
void optimize(ParameterSet params);
The set of parameters to use when optimizing
void forwardPass(Network* network, Matrix* input);
The network to use
The data to pass through the network
void forwardPassDataSet(Network* network, DataSet* input);
The network to use
The data to pass through the network
Matrix* getOuput(Network* network);
The network to use
int* predict(Network* network);
The network to use
float accuracy(Network* network, DataSet* data, DataSet* classes)
The network to use
The data to test on
The target data to test accuracy against
void saveNetwork(Network* network, char* path);
The network to save
The file path to where the network is to be saved
Network* readNetwork(char* path);
The file path to where the network had been saved