map* init_map(int sideX, int sideY, int scale){ int x, y; unsigned int i, count = 0; int aux = 0; unsigned int n; void **word_adresses; word *pt_aux = malloc(sizeof(word));; map *_map = malloc(sizeof(map)); _map->latice_size = sideX * sideY; _map->sideX = sideX; _map->sideY = sideY; _map->scale = scale; _map->lattice = malloc(_map->latice_size * sizeof( neuron)); mt_seed (); if ((n = get_list(pt_aux))) { printf("n: %d\n", n); word_adresses = malloc(n * sizeof(void *)); while (pt_aux != NULL) { x = mt_rand() %sideX; y = mt_rand() %sideY; init_neuron(_map->lattice, x, y, pt_aux->frames, pt_aux->n, pt_aux->name); word_adresses[count++] = pt_aux; pt_aux = pt_aux->next; } printf("count: %d\n", count); for (i = 0; i < count; i++) free(word_adresses[i]); free(word_adresses); } return _map; }
void nn_init( int ninput, int noutput, int nhidden, double (*hidden_act)(double), double (*hidden_actp)(double), double (*output_act)(double), double (*output_actp)(double), double learnrate, neural_network_t *out_nn ) { out_nn->nil = ninput; out_nn->nhl = nhidden; out_nn->nol = noutput; out_nn->il = new neuron_t[ninput]; out_nn->hl = new neuron_t[nhidden]; out_nn->ol = new neuron_t[noutput]; out_nn->learn_rate = learnrate; neuron_t *n1,*n2; // TODO: currently bias is always 0, // may want to change this in the // future for ( int i = 0; i < ninput; i++ ) { n1 = &out_nn->il[i]; init_neuron( n1, 0, nhidden ); // do not specify an activation n1->act = 0; n1->actp = 0; n1->b = 0; } for ( int i = 0; i < nhidden; i++ ) { n1 = &out_nn->hl[i]; init_neuron( n1, ninput, noutput ); n1->act = hidden_act; n1->actp = hidden_actp; n1->b = 0; } for ( int i = 0; i < noutput; i++ ) { n1 = &out_nn->ol[i]; init_neuron( n1, nhidden, 0 ); n1->act = output_act; n1->actp = output_actp; n1->b = 0; } // hook up all the neurons for ( int i = 0; i < ninput; i++ ) { n1 = &out_nn->il[i]; for ( int j = 0; j < nhidden; j++ ) { n2 = &out_nn->hl[j]; n1->y[j] = n2; } } for ( int i = 0; i < nhidden; i++ ) { n1 = &out_nn->hl[i]; for ( int j = 0; j < ninput; j++ ) { n2 = &out_nn->il[j]; n1->x[j] = n2; } for ( int j = 0; j < noutput; j++ ) { n2 = &out_nn->ol[j]; n1->y[j] = n2; } } for ( int i = 0; i < noutput; i++ ) { n1 = &out_nn->ol[i]; for ( int j = 0; j < nhidden; j++ ) { n2 = &out_nn->hl[j]; n1->x[j] = n2; } } }