I'm trying to create a Artificial Neural Network to make a evolving AI for a simple game.
But I'm struggling with the math required by it.
I made a neural net in Python, in around 100 lines, but when I tried to port it to c# I'm already at 200 lines of code, and I haven't even begin the back propagation algorithm (the bulk of the code in python).
For instance a simple input normalization in python takes 1 line:
self.input_values = (inputs - np.mean(inputs , axis=0)) / np.std(inputs , axis=0)
While in C# I've to do it step by step:
float[] normalize_input(float[] inputs){
float sum = 0.0f;
for (int i = 0; i < inputs.Length; i++) {
sum += inputs[i] ;
}
float average = sum / inputs.Length;
float[] deviations = new float[inputs.Length];
for (int i = 0; i < inputs.Length; i++) {
deviations[i] = Mathf.Pow(inputs[i] - average,2);
}
float sum_deviation = 0;
for (int i = 0; i < deviations.Length; i++) {
sum_deviation += deviations[i];
}
float variance = sum_deviation / deviations.Length;
float std = Mathf.Sqrt (variance);
for (int i = 0; i < inputs.Length; i++) {
inputs[i] = (inputs[i] - average)/std;
}
return inputs;
}
**Is there any way to have access to this sort of math functions and matrix computation?**
I know I can do it step by step like I'm doing, but it will take a lot longer, and further more, it's very hard to debug once something is off.
↧