pyglmnet.py 文件源码

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

项目:pyglmnet 作者: glm-tools 项目源码 文件源码
def _logL(distr, y, y_hat):
    """The log likelihood."""
    if distr in ['softplus', 'poisson']:
        eps = np.spacing(1)
        logL = np.sum(y * np.log(y_hat + eps) - y_hat)
    elif distr == 'gaussian':
        logL = -0.5 * np.sum((y - y_hat)**2)
    elif distr == 'binomial':
        # analytical formula
        logL = np.sum(y * np.log(y_hat) + (1 - y) * np.log(1 - y_hat))

        # but this prevents underflow
        # z = beta0 + np.dot(X, beta)
        # logL = np.sum(y * z - np.log(1 + np.exp(z)))
    elif distr == 'probit':
        logL = np.sum(y * np.log(y_hat) + (1 - y) * np.log(1 - y_hat))
    elif distr == 'gamma':
        # see
        # https://www.statistics.ma.tum.de/fileadmin/w00bdb/www/czado/lec8.pdf
        nu = 1.  # shape parameter, exponential for now
        logL = np.sum(nu * (-y / y_hat - np.log(y_hat)))
    return logL
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号