Compare commits
1 commit
master
...
repair_dat
Author | SHA1 | Date | |
---|---|---|---|
9a05ae3841 |
3 changed files with 27 additions and 11 deletions
|
@ -27,6 +27,7 @@ typedef struct _neural_data {
|
||||||
|
|
||||||
Neural_Network *neural_new(size_t, size_t, size_t);
|
Neural_Network *neural_new(size_t, size_t, size_t);
|
||||||
void neural_free(Neural_Network *);
|
void neural_free(Neural_Network *);
|
||||||
|
void neural_populate_sequential(Neural_Network *);
|
||||||
void neural_randomize(Neural_Network *);
|
void neural_randomize(Neural_Network *);
|
||||||
float *neural_loadData(Neural_Network *, const char *);
|
float *neural_loadData(Neural_Network *, const char *);
|
||||||
float *neural_process(Neural_Network *, float *);
|
float *neural_process(Neural_Network *, float *);
|
||||||
|
|
4
src/cx.c
4
src/cx.c
|
@ -183,7 +183,7 @@ cx_nninit(Neural_Network **nn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate the neural network with sensible values.
|
// Populate the neural network with sensible values.
|
||||||
neural_randomize(*nn);
|
neural_populate_sequential(*nn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,8 @@ cx_run(CX_Context *ctx) {
|
||||||
|
|
||||||
pthread_join(tg[1]->group_manager->thread, &neural_xml);
|
pthread_join(tg[1]->group_manager->thread, &neural_xml);
|
||||||
|
|
||||||
|
printf("%s\n", neural_xml);
|
||||||
|
|
||||||
ctx->gl_ctx->master_lock = 0;
|
ctx->gl_ctx->master_lock = 0;
|
||||||
|
|
||||||
neural_getMesh(ctx->nn_ctx->nn, ctx->gl_ctx->mr);
|
neural_getMesh(ctx->nn_ctx->nn, ctx->gl_ctx->mr);
|
||||||
|
|
33
src/neural.c
33
src/neural.c
|
@ -67,6 +67,22 @@ neural_free(Neural_Network *self) {
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
neural_populate_sequential(Neural_Network *self) {
|
||||||
|
Neural_Layer *nl;
|
||||||
|
|
||||||
|
for (int i = 0; i < self->layer_count; i++) {
|
||||||
|
nl = self->layers[i];
|
||||||
|
int populator = 0;
|
||||||
|
for (int j = 0; j < nl->layer_size; j++) {
|
||||||
|
for (int k = 0; k < nl->layer_size_next; k++) {
|
||||||
|
nl->neurons[j].synapses[k] = (float)populator;
|
||||||
|
populator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
neural_randomize(Neural_Network *self) {
|
neural_randomize(Neural_Network *self) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -222,6 +238,10 @@ neural_data_new(int layer_size, int layer_size_next) {
|
||||||
* sizeof(float));
|
* sizeof(float));
|
||||||
self->mat_len = layer_size_next;
|
self->mat_len = layer_size_next;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
self->synapse_matrix = NULL;
|
||||||
|
self->mat_len = 0;
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,20 +250,13 @@ neural_getData(Neural_Network *self, size_t layer) {
|
||||||
Neural_Layer *nl;
|
Neural_Layer *nl;
|
||||||
Neural_Data *retval;
|
Neural_Data *retval;
|
||||||
|
|
||||||
|
|
||||||
nl = self->layers[layer];
|
nl = self->layers[layer];
|
||||||
|
|
||||||
retval = neural_data_new(nl->layer_size, nl->layer_size_next);
|
retval = neural_data_new(nl->layer_size, nl->layer_size_next);
|
||||||
|
if (retval->mat_len) {
|
||||||
retval->vect_len = nl->layer_size;
|
|
||||||
if (!nl->layer_size_next) {
|
|
||||||
retval->synapse_matrix = NULL;
|
|
||||||
retval->mat_len = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (int i = 0; i < nl->layer_size; i++) {
|
for (int i = 0; i < nl->layer_size; i++) {
|
||||||
for (int j = 0; j < nl->layer_size_next; j++) {
|
for (int j = 0; j < nl->layer_size_next; j++) {
|
||||||
retval->synapse_matrix[i*j+i] = nl->neurons[i].synapses[j];
|
retval->synapse_matrix[i+(nl->layer_size*j)] = nl->neurons[i].synapses[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +394,7 @@ neural_getXML(Neural_Network *nn) {
|
||||||
line_prep = strcat(line_prep, "[ ");
|
line_prep = strcat(line_prep, "[ ");
|
||||||
for (int k = 0; k < nd->vect_len; k++) {
|
for (int k = 0; k < nd->vect_len; k++) {
|
||||||
|
|
||||||
strfromf(number_buffer, 32, "%.2f ", nd->synapse_matrix[k+j*nd->mat_len]);
|
strfromf(number_buffer, 32, "%.4f ", nd->synapse_matrix[k+(j*nd->vect_len)]);
|
||||||
line_prep = strcat(line_prep, number_buffer);
|
line_prep = strcat(line_prep, number_buffer);
|
||||||
if (k < nd->vect_len - 1) {
|
if (k < nd->vect_len - 1) {
|
||||||
line_prep = strcat(line_prep, ", ");
|
line_prep = strcat(line_prep, ", ");
|
||||||
|
|
Loading…
Reference in a new issue