Hey all,
I can't for the life of me figure out why this is segfaulting... sorry to bother you all with such a lame question. Here's the source:
Code:
#include <stdlib.h>
#include <stdio.h>
//#include <math.h>
#define NUM_IN 2
#define NUM_HIDDEN 3
#define NUM_OUT 1
//double v[3][3]; //the widest line across has 3 neurons, and 3 layers
double w[3][3][3]; //for each connection [line][neuron][connection]
int num[3]={NUM_IN,NUM_HIDDEN,NUM_OUT};
void init_weights() {
int i,j,k;
double t;
for (i=1;i<3;i++) { //layer
for (j=0;j<num[i];j++) { //neurons is layer
for (k=0;k<num[i-1];k++) { //connections per neuron
t=((double)(rand()))/((double)(RAND_MAX));
w[i][j][k]=(t-0.5); //vals -0.5 <= w <= 0.5
printf("Setting for layer %d, neuron %d, input %d: %f\n",
i,j,k,(t-0.5));
}
}
}
}
int main( int argc, char *argv[] ) {
srand(getpid()*time());
init_weights();
return 0;
}
And when I run it:
Code:
[jack@jacklaptop1 neural-net]$ uname -a;id
Linux jacklaptop1.crepinc.com 2.6.15-1.2054_FC5smp #1 SMP Tue Mar 14 16:05:46 EST 2006 i686 i686 i386 GNU/Linux
uid=500(jack) gid=500(jack) groups=500(jack) context=user_u:system_r:unconfined_t
[jack@jacklaptop1 neural-net]$ gcc -o neural1 neural1.c -lm
[jack@jacklaptop1 neural-net]$ ./neural1
Setting for layer 1, neuron 0, input 0: -0.480149
Setting for layer 1, neuron 0, input 1: -0.267299
Setting for layer 1, neuron 1, input 0: -0.104947
Setting for layer 1, neuron 1, input 1: -0.483809
Setting for layer 1, neuron 2, input 0: 0.079405
Setting for layer 1, neuron 2, input 1: 0.422783
Setting for layer 2, neuron 0, input 0: -0.258891
Setting for layer 2, neuron 0, input 1: 0.237996
Setting for layer 2, neuron 0, input 2: 0.243387
Segmentation fault
[jack@jacklaptop1 neural-net]$
Thanks for your help,
-Jack Carrozzo
jack {-@-} crepinc.com