public void setConstraint(Node node){ for ( Constraint constraint : this.constraintMap.get(node.getMainVariable())) { Optional<Node> optional = node.getParents().stream().filter(nodeParent -> eu.amidst.core.constraints.Constraints.match(node.getPDist(), nodeParent.getMainVariable(), constraint)).findFirst(); if (!optional.isPresent()) throw new IllegalStateException("No constraint for the given parameter"); Node nodeParent = optional.get(); nodeParent.setActive(false); eu.amidst.core.constraints.Constraints.fixValue(nodeParent.getQDist(), constraint.getValue()); } } }
for (Node node : plateuNodesTimeT.get(i)) { final int slice = i; node.setParents(node.getPDist().getConditioningVariables().stream().map(var -> this.getNodeOfVarTimeT(var, slice)).collect(Collectors.toList())); node.getPDist().getConditioningVariables().stream().filter(var -> var.isInterfaceVariable()).forEach(var -> node.setVariableToNodeParent(var, this.getNodeOfVarTimeT(var, slice))); node.getPDist().getConditioningVariables().stream().forEach(var -> this.getNodeOfVarTimeT(var, slice).getChildren().add(node));
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; }
.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();
for (Node node : this.plateuStructure.getNonReplictedNodes().collect(Collectors.toList())) { Map<Variable, MomentParameters> momentParents = node.getMomentParents(); kl_q_p0[count] = local_kl((EF_Dirichlet)node.getQDist(),(EF_Dirichlet)node.getPDist()); count++; for (Node node : this.plateuStructure.getNonReplictedNodes().collect(Collectors.toList())) { Map<Variable, MomentParameters> momentParents = node.getMomentParents(); kl_q_pt_1[count] = local_kl((EF_Dirichlet)node.getQDist(),(EF_Dirichlet)node.getPDist()); count++;