コード例 #1
0
    def initialize(self, alpha, beta, sample_init=True):
        init_mean = np.empty([self.K, self.N])
        init_var = np.empty_like(init_mean)
        init_etrpy = np.empty_like(init_mean)
        alpha = alpha / self.K
        beta = beta * (1 - 1.0 / self.K)

        if sample_init:
            from npbNMF.datatools import sample_init_Z_bernoulli
            for n in range(self.N):
                for k in range(self.K):
                    estimates = sample_init_Z_bernoulli(
                        alpha,
                        beta,
                        n_samples=10,
                    )
                    init_mean[k, n], init_var[k, n] = estimates
                    # leave the entropy, as we refrain from estimating it
        else:
            p_expected = np.full((self.K, self.N), alpha / (beta + alpha))
            init_mean, init_var, init_etrpy = bernoulli_moments(p_expected)

        self.mean = init_mean
        self.var = init_var
        self.etrpy = init_etrpy
        self.mean_sq = mean_sq(self.mean, self.var)
コード例 #2
0
    def moments(self, mu, sigma_sq):
        new_mean, new_var, new_etrpy = trunc_moments(self.lower_bound,
                                                     self.upper_bound, mu,
                                                     sigma_sq)
        new_mean_sq = mean_sq(new_mean, new_var)

        return new_mean, new_var, new_etrpy, new_mean_sq
コード例 #3
0
 def add_new_features(self, expected_param_inv, k_new):
     new_moments = self._initialize_new_features(expected_param_inv, k_new)
     new_mean, new_var, new_etrpy = new_moments
     new_mean_sq = mean_sq(new_mean, new_var)
     self.mean = np.append(self.mean, new_mean, axis=0)
     self.var = np.append(self.var, new_var, axis=0)
     self.mean_sq = np.append(self.mean_sq, new_mean_sq, axis=0)
     self.etrpy = np.append(self.etrpy, new_etrpy, axis=0)
コード例 #4
0
    def initialize(self, expected_param_inv, K_init=1):
        init_mean = np.empty([K_init, self.N])
        init_var = np.empty_like(init_mean)
        init_etrpy = np.zeros_like(init_mean)

        for n in range(self.N):
            for k in range(K_init):
                estimates = self._sample_estimates(expected_param_inv)
                init_mean[k, n], init_var[k, n] = estimates
                # leave the entropy, as we refrain from estimating it

        self.mean = init_mean
        self.var = init_var
        self.etrpy = init_etrpy
        self.mean_sq = mean_sq(self.mean, self.var)
コード例 #5
0
    def initialize(self, expected_param_inv, K_init=1):
        init_mean = np.empty([self.D, K_init])
        init_var = np.empty_like(init_mean)
        init_etrpy = np.zeros_like(init_mean)

        from npbNMF.datatools import sample_init_factor_expon
        for d in range(self.D):
            for k in range(K_init):
                estimates = self._sample_estimates(expected_param_inv)
                init_mean[d, k], init_var[d, k] = estimates
                # leave the entropy, as we refrain from estimating it

        self.mean = init_mean
        self.var = init_var
        self.etrpy = init_etrpy
        self.mean_sq = mean_sq(self.mean, self.var)
コード例 #6
0
    def initialize(self, expected_param):
        init_mean = np.empty([self.K, self.N])
        init_var = np.empty_like(init_mean)
        init_etrpy = np.empty_like(init_mean)

        from npbNMF.datatools import sample_init_factor_expon
        for n in range(self.N):
            for k in range(self.K):
                estimates = self._sample_estimates(expected_param)
                init_mean[k, n], init_var[k, n] = estimates
                # leave the entropy, as we refrain from estimating it

        self.mean = init_mean
        self.var = init_var
        self.etrpy = init_etrpy
        self.mean_sq = mean_sq(self.mean, self.var)
コード例 #7
0
    def initialize_preset(self, init_mean, init_var):

        self.mean = init_mean
        self.var = init_var
        self.mean_sq = mean_sq(self.mean, self.var)
コード例 #8
0
 def moments(self, pi):
     new_mean, new_var, new_etrpy = bernoulli_moments(pi)
     new_mean_sq = mean_sq(new_mean, new_var)
     return new_mean, new_var, new_etrpy, new_mean_sq