utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:diamond 作者: stitchfix 项目源码 文件源码
def _l2_clogistic_gradient_IL(X, alpha, beta, offset=None, **kwargs):
    """ Helper function for calculating the cumulative logistic gradient. \
        The inverse logit of alpha[j + X*beta] is \
        ubiquitous in gradient and Hessian calculations \
        so it's more efficient to calculate it once and \
        pass it around as a parameter than to recompute it every time

    Args:
        X : array_like. design matrix
        alpha : array_like. intercepts. must have shape == one less than the number of columns of `Y`
        beta : array_like. parameters. must have shape == number of columns of X
        offset : array_like, optional. Defaults to 0
        n : int, optional.\
        You must specify the number of rows if there are no main effects
    Returns:
        array_like. n x J-1 matrix where entry i,j is the inverse logit of (alpha[j] + X[i, :] * beta)
    """
    J = len(alpha) + 1
    if X is None:
        n = kwargs.get("n")
    else:
        n = X.shape[0]
    if X is None or beta is None:
        Xb = 0.
    else:
        Xb = dot(X, beta) + (0 if offset is None else offset)
    IL = np.zeros((n, J - 1))
    for j in range(J - 1):
        IL[:, j] = expit(alpha[j] + Xb)
    return IL
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号