Hello, This is my first post on the forum so I'm not quite sure how it works.
I am working on my project for my Uni course where I am using Arduino to build a neural network. I have been building up the size of the network and I am now trying to use arrays to streamline the process. Everything has bee fine so far and I have used a 2D array to hold the values for my weights.
bool finish = true;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
#include<math.h>
}
void loop() {
// put your main code here, to run repeatedly:
int n, c, count;
// NODES //
float NODE[ ] = {0, 0 ,0};
float OUTPUTS[ ] = {0, 0};
// ERRORS //
float ERRORH[ ] = {0, 0, 0};
float ERRORO[ ] = {0, 0};
int INPUTS[4] = {1, 0, 1, 0};
float WEIGHTH[3][4] =
{
{0.1, 0.9, 0.5, 0.25},
{-0.2, -0.1, 0.8, -0.45},
{0.7, -0.6, -0.3, 0.4}
};
float WEIGHTO[2][3] =
{
{0.75, -0.4, -0.5},
{-0.9, 0.2, 0.3}
};
int TARGET[2] = {1, 0};
while (finish)
{
// HIDDEN LAYER //
for(n = 0; n <= 2; n ++)
{
for (c = 0; c <= 3; c++)
{
NODE[n] = NODE[n] + (INPUTS[c] * WEIGHTH[n][c]);
}
}
// SIGMOID FUNCTION //
for(count = 0; count <=2 ; count++)
{
NODE[count] = 1 / (1 + exp(-NODE[count]));
}
// OUTPUT LAYER //
for(n = 0; n <= 1; n ++)
{
for (c = 0; c <= 2; c++)
{
OUTPUTS[n] = OUTPUTS[n] + (NODE[c] * WEIGHTO[n][c]);
}
}
// SIGMOID FUNCTION //
for(count = 0; count <=2 ; count++)
{
OUTPUTS[count] = 1 / (1 + exp(-OUTPUTS[count]));
}
// Reverse Pass //
// ERRORS //
for(count = 0; count < 2; count++)
{
ERRORO[count] = OUTPUTS[count] * (1 - OUTPUTS[count]) * (TARGET[count] - OUTPUTS[count]);
}
// NEW WEIGHTS //
for(n = 0; n <= 1; n ++)
{
for (c = 0; c <= 2; c++)
{
WEIGHTO[n][c] = WEIGHTO[n][c] + (ERRORO[n] * NODE[c]);
}
}
Serial.println();
Serial.println(WEIGHTO[0][0]);
Serial.println(WEIGHTO[0][1]);
Serial.println(WEIGHTO[0][2]);
Serial.println(WEIGHTO[1][0]);
Serial.println(WEIGHTO[1][1]);
Serial.println(WEIGHTO[1][2]);
finish = false;
}
}
Everything was going fine and I was quite proud I was managing as well as I was, but when I went to print the values for my new weights as a test I was doing after each section, it wont print. I get a couple of squares and some question mark symbols. I would quite like to be checking my values after each step to make sure they match my own calculations, does this mean that the Arduino isn't calculating them or is it just a printing problem?
I have no idea what causes this so hopefully someone has some advice and I am probably missing a very obvious trick!



