Esempio n. 1
0
def grad(self, inp, grads):
    """
    
    """
    x, = inp
    gz, = grads
    cst = numpy.asarray(-2. / numpy.sqrt(numpy.pi),
        dtype=upcast(x.type.dtype, gz.type.dtype))
    return gz * (cst + 2. * x * exp(-x * x) * erfcx(x)),
Esempio n. 2
0
    def grad(self, inputs, gout):
        (x, ) = inputs
        (gz, ) = gout
        # rval = x.zeros_like()

        # if rval.type.dtype in discrete_types:
        #     rval = rval.astype(theano.config.floatX)

        return [gz * exp(-1.0 * abs_(x))]
Esempio n. 3
0
 def grad(self, inp, grads):
     x, = inp
     gz, = grads
     if x.type in complex_types:
         raise NotImplementedError()
     elif x.type in float_types:
         cst = numpy.asarray(numpy.sqrt(numpy.pi) / 2.0, dtype=upcast(x.type.dtype, gz.type.dtype))
         return (gz * cst * exp(erfinv(x) ** 2),)
     else:
         return (None,)
Esempio n. 4
0
 def grad(self, inp, grads):
     x, = inp
     gz, = grads
     if x.type in complex_types:
         raise NotImplementedError()
     elif x.type in float_types:
         cst = numpy.asarray(2. / numpy.sqrt(numpy.pi),dtype=upcast(x.type.dtype,gz.type.dtype))
         return - gz * cst * exp(-x*x),
     else:
         return None,
Esempio n. 5
0
class Erf(UnaryScalarOp):
    def impl(self, x):
        return scipy.special.erf(x)

    def grad(self, (x, ), (gz, )):
        if x.type in complex_types:
            raise NotImplementedError()
        elif x.type in float_types:
            return gz * 2. / numpy.sqrt(numpy.pi) * exp(-x * x),
        else:
            return None,
Esempio n. 6
0
    def grad(self, inp, grads):
        x, = inp
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if self(x).type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = numpy.asarray(2.0 / numpy.sqrt(numpy.pi), dtype=upcast(x.type.dtype, gz.type.dtype))
        return (-gz * cst * exp(-x * x),)
Esempio n. 7
0
    def L_op(self, inputs, outputs, grads):
        x, = inputs
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if outputs[0].type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = numpy.asarray(2. / numpy.sqrt(numpy.pi),
                            dtype=upcast(x.type.dtype, gz.type.dtype))
        return -gz * cst * exp(-x * x),
Esempio n. 8
0
    def grad(self, inp, grads):
        x, = inp
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if self(x).type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = numpy.asarray(numpy.sqrt(numpy.pi) / 2.,
                            dtype=upcast(x.type.dtype, gz.type.dtype))
        return -gz * cst * exp(erfcinv(x)**2),
Esempio n. 9
0
    def L_op(self, inputs, outputs, grads):
        x, = inputs
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if outputs[0].type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = np.asarray(np.sqrt(np.pi) / 2.,
                         dtype=upcast(x.type.dtype, gz.type.dtype))
        return gz * cst * exp(erfinv(x)**2),
Esempio n. 10
0
    def L_op(self, inputs, outputs, grads):
        x, = inputs
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if outputs[0].type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = np.asarray(2. / np.sqrt(np.pi),
                         dtype=upcast(x.type.dtype, gz.type.dtype))
        return - gz * cst * exp(-x * x),
Esempio n. 11
0
    def L_op(self, inputs, outputs, grads):
        x, = inputs
        gz, = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if outputs[0].type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=theano.config.floatX)]
            else:
                return [x.zeros_like()]

        cst = numpy.asarray(numpy.sqrt(numpy.pi) / 2.,
                            dtype=upcast(x.type.dtype, gz.type.dtype))
        return gz * cst * exp(erfinv(x) ** 2),
Esempio n. 12
0
    def L_op(self, inputs, outputs, grads):
        (x, ) = inputs
        (gz, ) = grads
        if x.type in complex_types:
            raise NotImplementedError()
        if outputs[0].type in discrete_types:
            if x.type in discrete_types:
                return [x.zeros_like(dtype=config.floatX)]
            else:
                return [x.zeros_like()]

        cst = np.asarray(2.0 / np.sqrt(np.pi),
                         dtype=upcast(x.type.dtype, gz.type.dtype))
        return (-gz * cst * exp(-x * x), )
Esempio n. 13
0
 def grad(self, inputs, gout):
     (x,) = inputs
     (gz,) = gout
     return [gz *sgn_pg2_alpha * exp(-sgn_pg2_beta * abs(x))]