I have the following code:
float w[n][n] = {
{0, 0, 0.5, -1, 0, 0, 0},
{0, 0, 1.5, -2, 0, 0, 0},
{0, 0, 0, 0, 1, -1, 0},
{0, 0, 0, 0, 3, -4, 0},
{0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, -3}
};
float x[ne] = {2, -1};
float d = 1;
float alpha = 0.1;
float in[n];
float delta[n];
float a[n];
float sum;
for(j = ne; j <= n; j++) {
for(i = 0; i <= n; i++) {
in[j] += w[i][j] * a[i];
}
a[j] = g(in[j]);
}
for(i = 0; i < n; i++) {
printf("a[%d] = %.3f\n", i+1, a[i]);
}
delta[n-1] = d - a[n-1];
for(i = n-2; i >= ne; i--) {
for(j = 0; j <= n; j++) {
sum += w[i][j] * delta[j];
}
delta[i] = g(in[i]) * (1 - g(in[i])) * sum;
printf("delta[%d] = %.3f\n", i+1, delta[i]);
sum = 0;
}
printf("\n\n");
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
if (w[i][j] != 0) {
w[i][j] = w[i][j] + alpha * a[i] * delta[j];
printf("w[%d][%d] = %.3f\n", i+1, j+1, w[i][j]);
}
}
}
I keep getting some variation of this output:
a[1] = 2.000
a[2] = -1.000
a[3] = 0.378
a[4] = 0.500
a[5] = 0.867
a[6] = 0.085
a[7] = 0.649
delta[6] = -1.#QO
delta[5] = -1.#QO
delta[4] = -1.#QO
delta[3] = -1.#QO
w[1][3] = -1.#QO
w[1][4] = -1.#QO
w[2][3] = -1.#QO
w[2][4] = -1.#QO
w[3][5] = -1.#QO
w[3][6] = -1.#QO
w[4][5] = -1.#QO
w[4][6] = -1.#QO
w[5][7] = 1.030
w[6][7] = -2.997
It shows up in different places everytime I compile, knowing that the first time it was giving me the right answer, I'm not sure what went wrong?