private double computeELBO() { double elbo = this.vmp.getNodes().parallelStream().filter(node -> node.isActive() && !node.isObserved()).mapToDouble(node -> this.vmp.computeELBO(node)).sum(); elbo += this.vmp.getNodes() .parallelStream() .filter(node -> node.isActive() && node.isObserved()).mapToDouble(node -> { EF_BaseDistribution_MultinomialParents base = (EF_BaseDistribution_MultinomialParents) node.getPDist(); Variable topicVariable = (Variable) base.getMultinomialParents().get(0); Map<Variable, MomentParameters> momentParents = node.getMomentParents(); double localELBO = 0; MomentParameters topicMoments = momentParents.get(topicVariable); int wordIndex = (int) node.getAssignment().getValue(node.getMainVariable())%node.getMainVariable().getNumberOfStates(); for (int i = 0; i < topicMoments.size(); i++) { EF_SparseMultinomial_Dirichlet dist = (EF_SparseMultinomial_Dirichlet)base.getBaseEFConditionalDistribution(i); MomentParameters dirichletMoments = momentParents.get(dist.getDirichletVariable()); localELBO += node.getSufficientStatistics().get(wordIndex)*dirichletMoments.get(wordIndex)*topicMoments.get(i); } return localELBO; }).sum(); return elbo; }
public double[][] getLambdaMomentParameters(){ double[][] out = new double[this.ef_TExpQ.length][maxsize]; for (int i = 0; i < out.length; i++) { for (int j = 0; j < out[i].length; j++) { out[i][j] = this.ef_TExpQ[i][j].getMomentParameters().get(0); } } return out; }
public double[] getLambdaMomentParameters(){ double[] out = new double[this.prior.getNumberOfBaseVectors()]; for (int i = 0; i < out.length; i++) { out[i] = this.ef_TExpQ[i].getMomentParameters().get(0); } return out; }
int wordIndex = (int)node.getAssignment().getValue(node.getMainVariable()); for (int i = 0; i < topicMoments.size(); i++) { EF_SparseMultinomial_Dirichlet dist = (EF_SparseMultinomial_Dirichlet)base.getBaseEFConditionalDistribution(i); MomentParameters dirichletMoments = momentParents.get(dist.getDirichletVariable()); localELBO += node.getSufficientStatistics().get(wordIndex)*dirichletMoments.get(wordIndex)*topicMoments.get(i);
public static double[] computeLocalKLDirichlet(EF_Dirichlet dirichletQ, EF_Dirichlet dirichletP) { double[] localKL = new double[dirichletP.sizeOfSufficientStatistics()]; int nstates = localKL.length; double sumCountsQ = dirichletQ.getNaturalParameters().sum(); double sumCountsP = dirichletP.getNaturalParameters().sum(); for (int i = 0; i < localKL.length; i++) { double alphaQ = dirichletQ.getNaturalParameters().get(i); double alphaP = dirichletP.getNaturalParameters().get(i); double kl = alphaQ - alphaP; kl*=dirichletQ.getMomentParameters().get(i); kl-=(Gamma.logGamma(alphaQ) - Gamma.logGamma(sumCountsQ)/nstates); kl+=(Gamma.logGamma(alphaP) - Gamma.logGamma(sumCountsP)/nstates); localKL[i] = kl; } return localKL; }
lambda[i] = this.ef_TExpQ[i].getMomentParameters().get(0);
for (int i = 0; i < lambda.length; i++) { for (int j = 0; j < lambda[i].length; j++) { lambda[i][j] = this.ef_TExpQ[i][j].getMomentParameters().get(0);