I'd like to use Matlab to train my neural network, using the weights calculated by Matlab in my own program, written in Go. It seems like this should be pretty straightforward but I have not been able to get the same results.
My application is regression with 21 numeric inputs, all with different ranges, and a single answer that will range between about 25 and 100. I have lots of training data, over 8000 records. I should be able to get good results and, indeed, if I stay completely in Matlab I get very high R scores.
This has been my approach so far:
- Linearly scale all of my inputs and target values to between 0 and 1 and import to Matlab
- Use the Matlab Neural Network gui to to set up and train a network, mostly using defaults
- Run further tests inside Matlab with very good results
- Write the network's weights and biases to .csv files using net.IW, net.LW, and net.b
- Apply these weights and biases to my own network written in Go.
My own network operates how I understand that it should, but I am new to this so it's possible I'm missing something important. Using the weights and biases from Matlab, I get outputs that range from around -50 to +200 which I'm expecting. The results do seem to respond to the inputs in the correct direction, I just get answers from a much wider range than I'm expecting.
My network operates like so:
- Each hidden-layer node sums up each input times the weight for that input-node pair from IW
- Each hidden-layer node adds its bias to the sum
- Each hidden-layer node "activates" with f(sum) = tanh(sum)
- The output node sums up all of the hidden-layer outputs times the appropriate weight from LW
- The output node adds its bias
- The output node activates with f(sum) = sum
- Multiply the output by the scale value (100)
I understand that I can get better results by normalizing my data and/or using different activation functions. My concern right now isn't to achieve the best performance.
All I want to do right now is get my network behaving the same as Matlab's. There's something I'm missing. Maybe Matlab does its own normalization on the training data.
Has anyone been able to do this successfully?