Sknn - input size mismatch in second fit

I tried to create a neural network that uses reinforcement training. I chose scikit-neuralnetwork as a library (because it is simple). It seems the installation of the Theano two-time crash.

Here is the simplest code that causes a crash (note that it doesn't matter which layers exist and the learning speed or n_iter):

import numpy as np from sknn.mlp import Classifier, Layer clf = Classifier( layers=[ Layer("Softmax") ], learning_rate=0.001, n_iter=1) clf.fit(np.array([[0.]]), np.array([[0.]])) # Initialize the network for learning X = np.array([[-1.], [1.]]) Y = np.array([[1.], [0.]]) clf.fit(X, Y) # crash 

And here is the error I received:

 ValueError: Input dimension mis-match. (input[0].shape[1] = 2, input[1].shape[1] = 1) Apply node that caused the error: Elemwise{Mul}[(0, 1)](y, LogSoftmax.0) Toposort index: 12 Inputs types: [TensorType(float64, matrix), TensorType(float64, matrix)] Inputs shapes: [(1L, 2L), (1L, 1L)] Inputs strides: [(16L, 8L), (8L, 8L)] Inputs values: [array([[ 1., 0.]]), array([[ 0.]])] Outputs clients: [[Sum{axis=[1], acc_dtype=float64}(Elemwise{Mul}[(0, 1)].0)]] 

Tested in Python 2.7.11

Does sknn not support installation several times, or am I making some kind of idiotic mistake? If this is not the case, how should you implement reinforcement training?

+6
source share
1 answer

I do not use sknn very often, but it is very similar to sklearn , so I could help!

First of all, using the fit method, you reinitialize the scales, if you want to update the scales based on new data, you must use the partial_fit method.

As for the failure, this is because you are an X array - this is a different shape in the first dimension, and not in the second.

 import numpy as np from sknn.mlp import Classifier, Layer clf = Classifier( layers=[ Layer("Softmax") ], learning_rate=0.001, n_iter=1) # Original training data X = np.array([[0.]]) Y = np.array([[0.]]) print X.shape, Y.shape # Data used for second fitting X = np.array([[-1.], [1.]]) Y = np.array([[1.], [0.]]) print X.shape, Y.shape # Use the partial fit method to update weights clf.partial_fit(X, Y) # Initialize the network for learning clf.partial_fit(X, Y) # Update the weights # Multiple training examples by stacking two on top of each other X = np.concatenate((X, X)) Y = np.concatenate((Y, Y)) print X.shape, Y.shape clf.partial_fit(X, Y) 

Outputs:

 (1, 1) (1, 1) (2, 1) (2, 1) (4, 1) (4, 1) 
+1
source

All Articles