Ejemplo n.º 1
0
    def forward(self, inputs):
        logit, x = inputs
        self.retain_inputs((0, 1))
        xp = backend.get_array_module(x)
        y = logit * (x - 1) - xp.log(xp.exp(-logit) + 1)
        y = utils.force_array(y)

        # extreme logit
        logit_isinf = xp.isinf(logit)
        self.logit_ispinf = xp.bitwise_and(logit_isinf, logit > 0)
        self.logit_isminf = xp.bitwise_and(logit_isinf, logit <= 0)
        with numpy.errstate(divide='ignore', invalid='raise'):
            y = xp.where(self.logit_ispinf, xp.log(x), y)
            y = xp.where(self.logit_isminf, xp.log(1 - x), y)

        if self.binary_check:
            self.invalid = utils.force_array(xp.bitwise_and(x != 0, x != 1))
            y[self.invalid] = - xp.inf

        return utils.force_array(y, logit.dtype),
Ejemplo n.º 2
0
    def forward(self, inputs):
        logit, x = inputs
        self.retain_inputs((0, 1))
        xp = backend.get_array_module(x)
        y = logit * (x - 1) - xp.log(xp.exp(-logit) + 1)
        y = utils.force_array(y)

        # extreme logit
        logit_isinf = xp.isinf(logit)
        self.logit_ispinf = xp.bitwise_and(logit_isinf, logit > 0)
        self.logit_isminf = xp.bitwise_and(logit_isinf, logit <= 0)
        with numpy.errstate(divide='ignore', invalid='raise'):
            y = xp.where(self.logit_ispinf, xp.log(x), y)
            y = xp.where(self.logit_isminf, xp.log(1 - x), y)

        if self.binary_check:
            self.invalid = utils.force_array(xp.bitwise_and(x != 0, x != 1))
            y[self.invalid] = -xp.inf

        return utils.force_array(y, logit.dtype),
Ejemplo n.º 3
0
    def forward(self, inputs):
        logit, x = inputs
        self.retain_inputs((0, 1))
        xp = cuda.get_array_module(x)
        y = logit * (x - 1) - xp.log(xp.exp(-logit) + 1)
        y = utils.force_array(y)

        self.invalid = utils.force_array(xp.bitwise_and(x != 0, x != 1))
        y[self.invalid] = - xp.inf

        # extreme logit
        logit_isinf = xp.isinf(logit)
        self.to_zero = xp.bitwise_and(
            logit_isinf, xp.sign(x-0.5) == xp.sign(logit))
        self.to_m_inf = xp.bitwise_and(
            logit_isinf, xp.sign(x-0.5) != xp.sign(logit))
        y[self.to_zero] = 0.
        y[self.to_m_inf] = - xp.inf

        return utils.force_array(y, logit.dtype),