model_average.py 文件源码

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

项目:skggm 作者: skggm 项目源码 文件源码
def _random_weights(n_features, lam, lam_perturb, prng):
    """Generate a symmetric random matrix with zeros along the diagnoal and
    non-zero elements take the value {lam * lam_perturb, lam / lam_perturb}
    with probability 1/2.
    """
    weights = np.zeros((n_features, n_features))
    n_off_diag = int((n_features ** 2 - n_features) / 2)
    berns = prng.binomial(1, 0.5, size=n_off_diag)
    vals = np.zeros(berns.shape)
    vals[berns == 0] = 1. * lam * lam_perturb
    vals[berns == 1] = 1. * lam / lam_perturb
    weights[np.triu_indices(n_features, k=1)] = vals
    weights[weights < 0] = 0
    weights = weights + weights.T
    return weights
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号