python - Theano dmatrix contains newaxis raise dimension mismatch -


the following snippet of definition of theano variable , function rbfnn.

# theano tensor definition     self.x = t.dmatrix('x')     self.y = t.dmatrix('y')     self.centers = t.dmatrix('centers')     self.sigmas = t.dvector('sigmas')      self.w = theano.shared(np.zeros((self.n_centers, self.n_classes)), 'w')     self.b = theano.shared(np.zeros((self.n_classes,)), 'b')      # build graph     self.phi = t.exp(-t.sum(t.square(self.x[:, np.newaxis, :] - self.centers[np.newaxis, :, :]), axis=-1) / (         2 * t.square(self.sigmas)))     self.prob = t.mul(self.phi, self.w) + self.b     self.pred = t.argmax(self.prob, axis=1)     self.loss = t.mean(t.sum(t.square(self.y - self.prob), axis=1))     self.w_grad = t.grad(self.loss, self.w)     self.b_grad = t.grad(self.loss, self.b)     self.updates = [(self.w, self.w - self.learning_rate * self.w_grad),                     (self.b, self.b - self.learning_rate * self.b_grad)]      # build function     self.one_step = theano.function([self.x, self.y, self.centers, self.sigmas], [self.loss], updates=self.updates)     self.compute_prob = theano.function([self.x, self.centers, self.sigmas], [self.prob])     self.compute_pred = theano.function([self.x, self.centers, self.sigmas], [self.pred]) 

then feed data

for in xrange(max_iter):     losses = []     batch in xrange(x.shape[0] / n_batch):         losses.append(self.one_step(x[batch * n_batch:(batch + 1) * n_batch, :], y[batch * n_batch:(batch + 1) * n_batch, :], centers, sigmas) 

where x, y train data , centers , sigmas kmeans centers , std of each centers.

it raise error

valueerror: input dimension mis-match. (input[0].shape[0] = 50, input[2].shape[0] = 10) apply node caused error: elemwise{composite{(i0 - ((i1 * i2) + i3))}}(y, elemwise{composite{exp(((i0 * i1) / i2))}}[(0, 1)].0, w, inplacedimshuffle{x,0}.0) inputs types: [tensortype(float64, matrix), tensortype(float64, matrix), tensortype(float64, matrix), tensortype(float64, row)] inputs shapes: [(50, 2), (50, 10), (10, 2), (1, 2)] inputs strides: [(16, 8), (80, 8), (16, 8), (16, 8)] inputs values: ['not shown', 'not shown', 'not shown', array([[ 0.,  0.]])] debugprint of apply node:  elemwise{composite{(i0 - ((i1 * i2) + i3))}} [@a] <tensortype(float64, matrix)> ''     |y [@b] <tensortype(float64, matrix)>  |elemwise{composite{exp(((i0 * i1) / i2))}}[(0, 1)] [@c] <tensortype(float64, matrix)> ''     | |tensorconstant{(1, 1) of -0.5} [@d] <tensortype(float64, (true, true))>  | |sum{axis=[2], acc_dtype=float64} [@e] <tensortype(float64, matrix)> ''     | | |elemwise{composite{sqr((i0 - i1))}} [@f] <tensortype(float64, 3d)> ''     | |   |inplacedimshuffle{0,x,1} [@g] <tensortype(float64, (false, true, false))> ''     | |   | |x [@h] <tensortype(float64, matrix)>  | |   |inplacedimshuffle{x,0,1} [@i] <tensortype(float64, (true, false, false))> ''     | |     |centers [@j] <tensortype(float64, matrix)>  | |elemwise{sqr,no_inplace} [@k] <tensortype(float64, row)> ''     |   |inplacedimshuffle{x,0} [@l] <tensortype(float64, row)> ''     |     |sigmas [@m] <tensortype(float64, vector)>  |w [@n] <tensortype(float64, matrix)>  |inplacedimshuffle{x,0} [@o] <tensortype(float64, row)> ''       |b [@p] <tensortype(float64, vector)>  storage map footprint:  - inplacedimshuffle{x,0}.0, shape: (1, 2), elemsize: 8 byte(s), totalsize: 16 byte(s)  - tensorconstant{(1,) of 0.001}, shape: (1,), elemsize: 8 byte(s), totalsize: 8 byte(s)  - elemwise{composite{exp(((i0 * i1) / i2))}}[(0, 1)].0, shape: (50, 10), elemsize: 8 byte(s), totalsize: 4000 byte(s)  - x, shape: (50, 4), elemsize: 8 byte(s), totalsize: 1600 byte(s)  - y, shape: (50, 2), elemsize: 8 byte(s), totalsize: 800 byte(s)  - centers, shape: (10, 4), elemsize: 8 byte(s), totalsize: 320 byte(s)  - sigmas, shape: (10,), elemsize: 8 byte(s), totalsize: 80 byte(s)  - b, shape: (2,), elemsize: 8 byte(s), totalsize: 16 byte(s)  - tensorconstant{(1, 1) of -0.002}, shape: (1, 1), elemsize: 8 byte(s), totalsize: 8 byte(s)  - tensorconstant{(1,) of -2.0}, shape: (1,), elemsize: 8 byte(s), totalsize: 8 byte(s)  - tensorconstant{(1, 1) of -0.5}, shape: (1, 1), elemsize: 8 byte(s), totalsize: 8 byte(s)  - w, shape: (10, 2), elemsize: 8 byte(s), totalsize: 160 byte(s) 

did self.x , self.center has shape [50, newaxis, 4] , [newaxis, 10, 4]? why turns out [50, 4] , [10, 4]? tell me how solve it?

you can use test values try , debug issue while building graph.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -