```
typedef struct DataSet_ {
size_t rows;
size_t cols;
float** data;
} DataSet;
```

**rows**

The number of rows in the dataset

**cols**

The number of columns in the dataset

**data**

The data held in the dataset, of the aforementioned dimensions

```
typedef struct Matrix_ {
size_t rows;
size_t cols;
float* data;
} Matrix;
```

**rows**

The number of rows in the matrix

**cols**

The number of columns in the matrix

**data**

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;
```

**type**

The type of layer (INPUT, OUTPUT, or HIDDEN)

**size**

The number of neurons in the layer

**activation**

The activation function for the layer

**input**

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;
```

**from**

The layer on the input side of the connection

**to**

The layer on the output side of the connection

**weights**

The weights matrix between the "from" and "to" layers, of dimensions "from"->size by "to"->size

**bias**

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;
```

**numLayers**

The total number of layers in the network

**layers**

The network's layers, in order

**numConnections**

The total number of connections in the network

**connections**

The network's connections, in order

```
DataSet* createDataSet(size_t rows, size_t cols, float** data);
```

**rows**

The number of rows in the dataset

**cols**

The number of columns in the dataset

**data**

The data, of the aforementioned dimensions, to be put into the dataset

```
DataSet** createBatches(DataSet* allData, int numBatches);
```

**allData**

The overall dataset to be split

**numBatches**

The number of batches to split the dataset into

```
void destroyDataSet(DataSet* dataset);
```

**dataset**

The dataset to be freed

```
typedef void (*Activation)(Matrix*);
```

**sigmoid**

Applies sigmoid function to layer (for hidden layers)

**relu**

Applies ReLU function to layer (for hidden layers)

**tanH**

Applies tanh function to layer (for hidden layers)

**softmax**

Applies softmax function to layer (for output layer with CROSS_ENTROPY_LOSS)

**linear**

Applies linear function to layer (for output layer with MEAN_SQUARED_ERROR)

```
Matrix* createMatrix(size_t rows, size_t cols, float* data);
```

**rows**

The number of rows in the matrix

**cols**

The number of columns in the matrix

**data**

The data, of the aforementioned dimensions, to be put into the matrix

```
void destroyMatrix(Matrix* matrix);
```

**matrix**

The matrix to free

```
Network* createNetwork(size_t numFeatures, size_t numHiddenLayers, size_t*
hiddenSizes, Activation* hiddenActivations, size_t numOutputs,
Activation outputActivation);
```

**numFeatures**

The number of neurons in the input layer

**numHiddenLayers**

The number of hidden layers in the network

**hiddenSizes**

The sizes of the hidden layers, provided as a list of sizes in order

**hiddenActivations**

The activation functions of the hidden layers, provided as a list of functions, in order

**numOutputs**

The number of neurons in the output layer

**outputActivation**

The activation function of the output layer (should be softmax for classification, and linear for regression)

```
void destroyNetwork(Network* 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;
```

**network**

The network to optimize

**data**

The training data to train the network with

**classes**

The target values for the training data

**lossFunction**

The loss function to use when training, should be CROSS_ENTROPY_LOSS for classification and MEAN_SQUARED_ERROR for regression

**batchSize**

The size of each batch (provide 1 for SGD, and data->rows for Batch)

**learningRate**

The constant factor for initial learning rate

**searchTime**

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

**regularizationStrength**

The constant factor for regularization

**momentumFactor**

The constant factor for simple momentum (adds a fraction of the previous weight update)

**maxIters**

The number of epochs to run the optimization algorithm for

**shuffle**

If non-zero, will shuffle the data in between epochs (recommended)

**verbose**

If non-zero, will print loss every 100 epochs

```
void optimize(ParameterSet params);
```

**params**

The set of parameters to use when optimizing

```
void forwardPass(Network* network, Matrix* input);
```

**network**

The network to use

**input**

The data to pass through the network

```
void forwardPassDataSet(Network* network, DataSet* input);
```

**network**

The network to use

**input**

The data to pass through the network

```
Matrix* getOuput(Network* network);
```

**network**

The network to use

```
int* predict(Network* network);
```

**network**

The network to use

```
float accuracy(Network* network, DataSet* data, DataSet* classes)
```

**network**

The network to use

**data**

The data to test on

**classes**

The target data to test accuracy against

```
void saveNetwork(Network* network, char* path);
```

**network**

The network to save

**path**

The file path to where the network is to be saved

```
Network* readNetwork(char* path);
```

**path**

The file path to where the network had been saved