Getting "nan" error
Opened this issue · 1 comments
I am trying to implement a simple example with scaled conjugate gradient. This is my code
`
dataset = [Instance( [0,0], [0] ), Instance( [1,0], [1] ), Instance( [0,1], [1] ), Instance( [1,1], [0] )]
settings = {
"n_inputs" : 2,
"layers" : [ (2, sigmoid_function), (1, sigmoid_function) ]
}
network = NeuralNet( settings )
training_set = dataset
test_set = dataset
cost_function = cross_entropy_cost
scaled_conjugate_gradient(
# Required parameters
network, # the neural network instance to train
training_set, # the training dataset
test_set, # the test dataset
cost_function, # the cost function to optimize
# Optional parameters
ERROR_LIMIT = 1e-3, # Error tolerance when terminating the learning
max_iterations = (), # Regardless of the achieved error, terminate after max_iterations epochs. Default: infinite
print_rate = 1000, # The epoch interval to print progression statistics
save_trained_network = False # Whether to ask the user if they would like to save the network after training
)
`
The output at each epoch looks something like this:
[training] Current error: nan Epoch: 1000
It never changed from nan and I can't figure out why
I'm recently working on this and found the same issue while working on the scaled conjugate gradient. I have modified the library with Python3 and also made a few updates to the data structure based on my understanding of sklearn library. I've found that it could be because the cost function didn't produce meaningful error according to the outputs and targets in the original binary_cross_entropy_cost
. I've added another cost function to use while predicting the stock price as below:
def mean_squared_error(outputs, targets, derivative=False, epsilon=1e-11 ):
if derivative:
return 2 * (outputs - targets)
else:
return np.mean(np.sum(np.square(outputs - targets), axis=1))
So you might as well check the value calculated in the error function.