jorgenkg / python-neural-network

This is an efficient implementation of a fully connected neural network in NumPy. The network can be trained by a variety of learning algorithms: backpropagation, resilient backpropagation and scaled conjugate gradient learning. The network has been developed with PYPY in mind.
BSD 2-Clause "Simplified" License
297 stars 98 forks source link

The numeric gradient check failed! #12

Closed Ellebkey closed 8 years ago

Ellebkey commented 8 years ago

Hello I'm checking the library and I got a problem when I set my own data.

I'm creating a network with 48inputs, 30hidden layes and 2 for output. My inputs consist on values between 0-100. When I run the examples with my training data, the programs stops working and I get the error: The numeric gradient check failed!. I printed the diferrents values on gradient() and check_gradient() and I got nan on many values.

Hope you can help me.

jorgenkg commented 8 years ago

Hi! What have you specified as the activation functions? If you're able to post a MVC of your data? If so it'll be even easier to help you out.

Ellebkey commented 8 years ago

I used the same example main.py on the settings I put

settings = {

Required settings

"n_inputs"              : 48,  
"layers"                : [  (30, sigmoid_function), (2, sigmoid_function) ],
"weights_low"           : -1.0,  
"weights_high"          : 1.0,  

}

My entries look like this: Instance([0,0,0,13,5,0,0,0,0,0,0,59,44,0,0,0,0,0,2,99,88,0,0,0,0,0,1,90,80,0,0,0,0,0,0,63,54,0,0,0,0,0,0,44,44,0,0,0], [0,1]) . . . and the same for 100 more entries.

But when I run the code stop on the line: network.check_gradient( training_data, cost_function ) and gives me that error

jorgenkg commented 8 years ago

Ok, it looks like the error was located in the preprocessors. I guess you've used the standarize preprocessor?

If that was the case, both the Github repo and the pip-installable version has been fixed!

Ellebkey commented 8 years ago

Yes, I used this:

preprocess = construct_preprocessor( dataset, [standarize] ) training_data = preprocess( dataset ) test_data = preprocess( dataset )

I'll try to use the new fix

Ellebkey commented 8 years ago

Thanks you so much! It worked

jorgenkg commented 8 years ago

Good to hear! Thank you for making me aware of the issue!