def _score()

in svinfer/linear_model/logistic_regression.py [0:0]


    def _score(beta, x, y, x_s2, query_runner):
        """
        score(beta) = avg_{i = 1}^{n} (y_i - p_i(beta)) c_i(beta)
        where p_i(beta) = (1 + exp(-c_i(beta)^T beta))^{-1},
        and c_i(beta) = x_i + (y_i - 0.5) diag(x_s2) beta.

        For Jacobian, the element at the i-th row and the j-th column is
        the partial derivative of the i-th component in score(beta)
        with respect to the j-th component in beta.

        jacobian(beta) = avg_{i = 1}^{n} (
            (y_i - p_i(beta)) (y_i - 0.5) diag(x_s2)
            - p_i(beta) (1 - pi(beta)) (y_i - 0.5) c_i(beta) beta^T diag(x_s2)
            - p_i(beta) (1 - pi(beta)) c_i(beta) c_i(beta)^T
        )
        """
        c = x + (y - 0.5).outer(x_s2 * beta)
        score = c * (y - 1.0 / (1.0 + (-c.dot(beta)).exp()))
        p = 1.0 / (1 + (-c.dot(beta)).exp())
        term1_part = (y - p) * (y - 0.5)
        term2_part = c * (p * (1 - p) * (y - 0.5))
        term3_part = (c * (p * (1 - p))).cross(c)
        z = get_result({
            "score": score,
            "term1_part": term1_part,
            "term2_part": term2_part,
            "term3_part": term3_part,
        }, query_runner)
        score = z["score"]
        term1 = z["term1_part"] * np.diag(x_s2)
        term2 = np.outer(z["term2_part"], x_s2 * beta)
        term3 = z["term3_part"]
        jacobian = term1 - term2 - term3
        return score, jacobian