Beispiel #1
0
    def snd_derivative_pdf(self, y, m, s=None):
        s = sigmoid(y * m, self.epsilon)
        # return y * np.square(1 - s) * s - y * np.square(s) * (1 - s)
        res = s * (1-s) * (1 - 2*s)
        # print(np.any(np.isnan(res)))

        return res
Beispiel #2
0
 def fst_derivative_log_pdf(self, y, f, s=None):
     #sigma = sigmoid(f, 1e-10)
     sigma = sigmoid(f)
     A = poisson_link(f)
     res = sigma * (np.divide(y, A) - 1.0)
     res = np.nan_to_num(res)
     #res = np.maximum(res, 1e-8)
     return res
Beispiel #3
0
 def fst_derivative_log_pdf(self, y, m, s=None):
     # ym = y * m
     # print("ym: ", ym.shape)
     # sym = sigmoid(-ym)
     # print("sym: ", sym.shape)
     # res =  y * (1. - sigmoid(y * m))
     # res =  y * sigmoid(y * m)
     res = np.multiply(y, sigmoid(-np.multiply(y, m)))
     return res
Beispiel #4
0
 def snd_derivative_log_pdf(self, y, f, s=None):
     sigma = sigmoid(f)
     A = poisson_link(f)
     temp1 = sigma * (1 - sigma) * (np.divide(y, A) - 1)
     temp2 = y * np.square(sigma) / np.square(A)
     res = temp1 - temp2
     res = np.nan_to_num(res)
     #return np.minimum(0, res)
     return res
Beispiel #5
0
 def fst_derivative_pdf(self, y, m, S=None):
     # pdf * sigmoid * (y/A(f) - 1)
     A    = poisson_link(m)
     pdf  = self.pdf(y, m, S)
     sigm = sigmoid(m)
     assert(sigm.shape == m.shape)
     assert(A.shape == m.shape)
     temp = np.subtract(np.divide(y, A), 1)
     res  = np.multiply(pdf, np.multiply(sigm, temp))
     assert(not np.any(pds.isnull(res)))
     return res
Beispiel #6
0
 def snd_derivative_pdf(self, y, m, s=None):
     pdf = self.pdf(y, poisson_link(m))
     sigm   = sigmoid(m)
     A   = poisson_link(m)
     pmf_prime = self.fst_derivative_pdf(y, m)
     assert(sigm.shape == m.shape)
     assert(A.shape == m.shape)
     # temp1 = (y/A - 1) * (pmf_prime * sigm + sigm*(1-sigm)*pmf)
     # temp2 = pmf * sigm * (-y)/np.square(A) * sigm
     # return 1/factorial(y) * (temp1 + temp2)
     temp1 = np.multiply(pmf_prime, np.multiply(sigm, np.divide(y, A) - 1))
     temp  = np.multiply(-np.divide(y, np.square(A)), np.square(sigm)) \
             + np.multiply(y / A - 1, np.multiply(sigm, 1 - sigm))
     temp2 = np.multiply(pdf, temp)
     res = temp1 + temp2
     assert(not np.any(pds.isnull(res)))
     return res
Beispiel #7
0
 def snd_derivative_log_pdf(self, y, m, s=None):
     # return -np.square(y) * sigmoid(y * m) * sigmoid(-y * m)
     return np.multiply(-sigmoid(np.multiply (y, m)), sigmoid(-np.multiply(y, m)))
Beispiel #8
0
    def fst_derivative_pdf(self, y, m, s=None):
        sigm = sigmoid(np.multiply(y,m), self.epsilon)
        temp = np.multiply(y, sigm)

        res  = np.multiply(temp, np.subtract(1, sigm))
        return res
Beispiel #9
0
 def pdf(self, y, m, s=None):
     res = sigmoid(np.multiply(y, m), self.epsilon)
     # print(res)
     # print(np.any(np.iszero(res)))
     # print(not np.any(res))
     return res
Beispiel #10
0
 def sample(self, m, s=None, k=1):
     return np.random.binomial(1, sigmoid(m), size=k)