added values for each neuron

This commit is contained in:
vik 2024-11-28 12:28:34 -06:00
parent 46710ca382
commit 7a5197285e

8
snn.c
View File

@ -34,9 +34,10 @@ typedef struct Layer {
gsl_matrix* weights; // make a matrix of size m x n, where m is the number of neurons in the gsl_matrix* weights; // make a matrix of size m x n, where m is the number of neurons in the
// next layer while n is the number of neurons in the current layer // next layer while n is the number of neurons in the current layer
// -> exploit BLAS to matmul and get the results of the next layer // -> exploit BLAS to matmul and get the results of the next layer
gsl_matrix* values; // the layer's values
} Layer; } Layer;
Layer* createlayer(Layer* lprev, Layer* lnext, int neurons) { Layer* createlayer(Layer* lprev, Layer* lnext, int neurons, gsl_matrix* nvalues) {
Layer* self = (Layer*) calloc(1, sizeof(Layer)); Layer* self = (Layer*) calloc(1, sizeof(Layer));
if (self == NULL) return NULL; if (self == NULL) return NULL;
self->previous = lprev; self->previous = lprev;
@ -44,6 +45,9 @@ Layer* createlayer(Layer* lprev, Layer* lnext, int neurons) {
// number of neurons MUST be more than zero sigma // number of neurons MUST be more than zero sigma
self->neurons = neurons; self->neurons = neurons;
assert((neurons == nvalues->size2) && (nvalues->size1 == lnext->neurons));
self->values = nvaules;
// setup the weights matrix // setup the weights matrix
assert(lnext != NULL); assert(lnext != NULL);
self->weights = gsl_matrix_calloc(lnext->neurons, neurons); self->weights = gsl_matrix_calloc(lnext->neurons, neurons);
@ -54,10 +58,10 @@ Layer* createlayer(Layer* lprev, Layer* lnext, int neurons) {
void freelayer(Layer* layer) { void freelayer(Layer* layer) {
assert(layer != NULL); assert(layer != NULL);
if (layer->weights != NULL) gsl_matrix_free(layer->weights); if (layer->weights != NULL) gsl_matrix_free(layer->weights);
if (layer->values != NULL) gsl_matrix_free(layer->values);
free(layer); free(layer);
} }
void forwardprop(Layer* layer) { void forwardprop(Layer* layer) {
} }