lt_model.py 文件源码

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

项目:latenttrees 作者: kaltwang 项目源码 文件源码
def init_distrib_idx(self, distrib, idx=None):
        assert isinstance(distrib, DistribGauss)
        x = distrib.get_mu()
        if idx is None:
            # initialize prior and thus average over all cases
            mu = np.nanmean(x, axis=0, keepdims=True)
        else:
            # select cases idx
            mu = x[idx, :]
            idx_nan = np.isnan(mu)
            if np.any(idx_nan):
                # we need to randomly select new values for all NaNs
                idx_good = np.ones_like(idx, dtype=bool)
                idx_good[idx, :] = False
                idx_good[np.isnan(x)] = False
                x_good = x[idx_good, :]
                num_nan = np.count_nonzero(idx_nan)
                mu[idx_nan] = np.random.choice(x_good, num_nan, replace=False)
            mu = np.copy(mu)  # make sure to not overwrite data

        std = np.empty_like(mu)
        std.fill(np.asscalar(np.nanstd(x)))
        self.init_data(mu, std)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号