def calculateELBO(self): """ Compute Evidence Lower Bound """ Wtmp = self.markov_blanket["W"].getExpectations() Ztmp = self.markov_blanket["Z"].getExpectations() W, WW = Wtmp["E"], Wtmp["E2"] Z, ZZ = Ztmp["E"], Ztmp["E2"] zeta = self.params["zeta"] tau = self.markov_blanket["Tau"].getValue() mask = self.getMask() # Precompute terms ZW = Z.dot(W.T) ZZWW = s.square(ZW) - s.dot(s.square(Z), s.square(W).T) + ZZ.dot(WW.T) # term1 = 0.5*tau*(ZW - zeta)**2 term1 = 0.5 * tau * (ZZWW - 2 * ZW * zeta + s.square(zeta)) term2 = (ZW - zeta) * (sigmoid(zeta) * (1. - self.obs / self.ratefn(zeta))) term3 = self.ratefn(zeta) - self.obs * s.log(self.ratefn(zeta)) elbo = -(term1 + term2 + term3) elbo[mask] = 0. # I AM NOT SURE WHY NAs are generated... np.isnan(elbo).sum() elbo[np.isnan(elbo)] = 0. return elbo.sum()
def updateExpectations(self): # Update the pseudodata self.E = self.params["zeta"] - 4.*(sigmoid(self.params["zeta"]) - self.obs) # regress out feature-wise mean from the pseudodata self.means = self.E.mean(axis=0).data self.E -= self.means
def updateExpectations(self): # Update the pseudodata tau = self.markov_blanket["Tau"].getValue() # to-do: not expand # self.E = self.params["zeta"] - sigmoid(self.params["zeta"])*(1-self.obs/self.ratefn(self.params["zeta"]))/tau[None,:] self.E = self.params["zeta"] - sigmoid(self.params["zeta"]) * ( 1 - self.obs / self.ratefn(self.params["zeta"])) / tau self.E[self.mask] = 0.
def updateExpectations(self): # Update the pseudodata tau = self.markov_blanket["Tau"].getValue() self.E = self.params["zeta"] - sigmoid(self.params["zeta"])*(1-self.obs/self.ratefn(self.params["zeta"])) / tau self.E[self.mask] = 0. # regress out feature-wise mean from the pseudodata self.means = self.E.mean(axis=0).data self.E -= self.means
def updateExpectations(self): # Update the pseudodata self.E = self.params["zeta"] - 4. * (sigmoid(self.params["zeta"]) - self.obs) self.means = self.E.mean(axis=0).data self.E -= self.means