Beispiel #1
0
    def calc_Hess(B):
        weights = [ lc.calc_weight(x,B) for x in X ]
        oneMinusW = [ 1 - w for w in weights ]

        d_elem = [None] * N
        for j in range(len(weights)):
            d_elem[j] = np.asscalar(m[j]) * weights[j] * oneMinusW[j]

        D = np.diagflat(np.array(d_elem))

        hess = X.T * D * X

        return hess
Beispiel #2
0
def gen_D_mat(X, y, m, B):

    (N, P) = np.shape(X)

    weights = [lc.calc_weight(x, B) for x in X]
    oneMinusW = [1 - w for w in weights]

    d_elem = [None] * N
    for j in range(len(weights)):
        d_elem[j] = np.asscalar(m[j]) * weights[j] * oneMinusW[j]

    D = np.matrix(np.diagflat(np.array(d_elem)))
    return D
Beispiel #3
0
def calc_llh_point_contribution(B, x, y, m):
    """
    Calculates the contribution to the total likelihood of the selected sample point

    B: (cvector) -- Current guess for beta
    x: (cvector) -- Predictors of a single sample point
    y: (scalar)  -- Response of sample point
    m: (scalar)  -- Number of trials on this sample point, m_i
    """

    # -L_i(B) = y_i \log(w_i) + (m_i - y_i) \log(1 - w_i)

    w = lc.calc_weight(x.T, B)

    return -np.asscalar(y * math.log(w) + (m - y) * math.log(1 - w))