Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions include/cneuron/cneuron.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,21 @@ void vector_apply_activation(const float *a, float *b, size_t length, float (*ac
*/
void hadamard_product(const float *restrict a, const float *restrict b, float *restrict c, size_t length);

/**
* @brief Represents a single layer in a neural network.
*/
typedef struct layer {
float *delta; /**< Error delta for backpropagation. */
float *weighted_input; /**< Weighted input values for the layer. */
float *weights; /**< Weights of the layer in column-major format. */
float *bias; /**< Bias values for the layer. */
float *output; /**< Output values from the layer. */
size_t length; /**< Number of neurons in this layer. */
} layer;

/**
* @brief Represents a neural network with multiple layers.
*/
typedef struct {
layer *layers; /**< Array of struct to layers in the network. */
size_t length; /**< Number of layers in the network. */
size_t inputs_length; /**< Number of inputs to the network. */
size_t *layer_lengths; /**< Number of neuron in each layer. */
size_t *prev_lengths_sums; /**< Number of neuron from all previous layer. */
size_t *prev_weights_sums; /**< Number of weights from all previous layer. */
float (*activation_function)(float, bool); /**< Pointer to the activation function used in the network. */
float *delta; /**< Error delta for backpropagation. */
float *weighted_input; /**< Weighted input values for the layer. */
float *output; /**< Output values from the layer. */
float *bias; /**< Bias values for the layer. */
float *weights; /**< Weights of the layer in column-major format. */
} neural_network;

/**
Expand Down
20 changes: 8 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,17 @@ int main(int argc, char **argv) {

dataset *train_dataset = get_mnist(false);
dataset *test_dataset = get_mnist(true);
size_t network_length = 3;
size_t *layers_length = malloc(sizeof(size_t) * network_length);
layers_length[0] = 100;
layers_length[1] = 16;
layers_length[2] = 10;
const size_t network_length = 3;
const size_t layer_lengths[] = {100, 16, 10};

neural_network *nn = get_neural_network(network_length, layers_length, train_dataset->inputs_length, &sigmoid);
neural_network *nn = get_neural_network(network_length, layer_lengths, train_dataset->inputs_length, &sigmoid);

// Parameters
float learn_rate = 1.5f;
size_t batch_size = 30;
int learn_amount = 4800000;
int batch_amount = learn_amount / batch_size;
int log_amount = 1000; // Log once reached a number of batch
const float learn_rate = 1.5f;
const size_t batch_size = 30;
const int learn_amount = 50000000;
const int batch_amount = learn_amount / batch_size;
const int log_amount = 1000; // Log once reached a number of batch

char cmd[100];
FILE *fp;
Expand Down Expand Up @@ -225,6 +222,5 @@ int main(int argc, char **argv) {
free(train_dataset);
free(test_dataset);
free(nn);
free(layers_length);
return 0;
}
Loading
Loading