La transmisión de Theano es diferente a la de Numpy's
Considere el siguiente ejemplo de radiodifusión numpy:
import numpy as np
import theano
from theano import tensor as T
xval = np.array([[1, 2, 3], [4, 5, 6]])
bval = np.array([[10, 20, 30]])
print xval + bval
Como se esperaba, el vectorbval
se agrega a cada fila de la matrizxval
y la salida es:
[[11 22 33]
[14 25 36]]
Intentando replicar el mismo comportamiento en la versión git de theano:
x = T.dmatrix('x')
b = theano.shared(bval)
z = x + b
f = theano.function([x], z)
print f(xval)
Obtuve el siguiente error:
ValueError: Input dimension mis-match. (input[0].shape[0] = 2, input[1].shape[0] = 1)
Apply node that caused the error: Elemwise{add,no_inplace}(x, <TensorType(int64, matrix)>)
Inputs types: [TensorType(float64, matrix), TensorType(int64, matrix)]
Inputs shapes: [(2, 3), (1, 3)]
Inputs strides: [(24, 8), (24, 8)]
Inputs scalar values: ['not scalar', 'not scalar']
entiendoTensor
objetos comox
tener unbroadcastable
atributo, pero no puedo encontrar una manera de 1) configurar esto correctamente para elshared
objeto o 2) tenerlo inferido correctamente. ¿Cómo puedo volver a implementar el comportamiento de numpy en theano?