Esempio n. 1
0
    def objective_function(self, reps, collapse_z=False):
        assert len(reps) == self.nterms

        fobj = 0.
        m = np.zeros(self.nfea)
        S = np.zeros((self.nfea, self.nfea))
        for estimator, rep in zip(self.estimators, reps):
            # E[log P(u|U)]
            fobj += estimator.expected_log_prob(rep)

            # H(q)
            fobj += rep.entropy()

            # sufficient statistics
            m += np.dot(estimator.A.T, rep.expected_value())
            S += misc.mult([estimator.A.T, rep.covariance(), estimator.A])

        Lambda_N = np.linalg.inv(self.Sigma_N)

        fobj += -0.5 * self.nfea * np.log(2 * np.pi) - 0.5 * misc.logdet(
            self.Sigma_N)
        diff = self.x - m
        fobj += -0.5 * np.dot(np.dot(diff, Lambda_N), diff)
        fobj += -0.5 * np.sum(S * Lambda_N)

        return fobj
    def objective_function(self, reps, collapse_z=False):
        assert len(reps) == self.nterms

        fobj = 0.
        m = np.zeros(self.nfea)
        S = np.zeros((self.nfea, self.nfea))
        for estimator, rep in zip(self.estimators, reps):
            # E[log P(u|U)]
            fobj += estimator.expected_log_prob(rep)
            
            # H(q)
            fobj += rep.entropy()
            
            # sufficient statistics
            m += np.dot(estimator.A.T, rep.expected_value())
            S += misc.mult([estimator.A.T, rep.covariance(), estimator.A])

        Lambda_N = np.linalg.inv(self.Sigma_N)

        fobj += -0.5 * self.nfea * np.log(2*np.pi) - 0.5 * misc.logdet(self.Sigma_N)
        diff = self.x - m
        fobj += -0.5 * np.dot(np.dot(diff, Lambda_N), diff)
        fobj += -0.5 * np.sum(S * Lambda_N)

        return fobj
 def value(self):
     return misc.mult([child.value() for child in self.children])