Given the following function where:

   - y is a ND array
   - g has one less dimension than y
   - x is a 1D array
   - the result is the same number of dimensions as g

How do I write a Theano operation that wraps this function?  I can get it 
to work for the case where y is a 1D array and g is a scalar (see below). 
However, when y is a 2D array, I get the following error. I understand why 
I'm getting the error, but I'm not clear how to write a more suitably 
polymorphic function that can handle broadcasting. Any pointers would be 
appreciated. 

TypeError: We expected inputs of types '[TensorType(float64, vector), 
TensorType(float64, scalar)]' but got types '[TensorType(float64, matrix), 
TensorType(float64, vector)]' 


class Threshold(theano.Op):
    
    __props__ = ('threshold', 'lower', 'upper', 'step')
    
    itypes = [theano.tensor.dvector, theano.tensor.dscalar]
    otypes = [theano.tensor.dscalar]
    
    def __init__(self, threshold, lower, upper, step):
        self.threshold = threshold
        self.lower = lower
        self.upper = upper
        self.step = step
        self.x = np.arange(lower, upper, step)
        super().__init__()
    
    def perform(self, node, inputs, output_storage):
        y = inputs[0]
        g = inputs[1]
        z = output_storage[0]

        y = norm.ppf(y)-norm.ppf(g)
        fx = lambda y: np.interp([1], y, x)[0]
        z[0] = np.apply_along_axis(fx, 0, y)
   

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to