.collect(Collectors.toList()); ef_learningmodel = new EF_LearningBayesianNetwork(dists); this.ef_learningmodel.getListOfParametersVariables().stream().forEach(var -> this.replicatedVariables.put(var, false)); this.ef_learningmodel.getListOfNonParameterVariables().stream().forEach(var -> this.replicatedVariables.put(var, true)); dirichletMixingTopics = ef_learningmodel.getDistribution(topicIndicator).getConditioningVariables().get(0); this.replicatedVariables.put(dirichletMixingTopics, true); ef_learningmodel.getDistribution(dirichletMixingTopics).getNaturalParameters().set(i, MIXING_PRIOR); NaturalParameters vec = this.ef_learningmodel.getDistribution(variable).getNaturalParameters();
/** * Replicates this model. */ @Override public void replicateModel() { //nonReplicatedNodes are the Dirichlet storing topics distributions. nonReplictedNodes = ef_learningmodel.getDistributionList().stream() .filter(dist -> isNonReplicatedVar(dist.getVariable())) .map(dist -> { Node node = new Node(dist); nonReplicatedVarsToNode.put(dist.getVariable(), node); return node; }) .collect(Collectors.toList()); List<Node> allNodes = new ArrayList<>(); allNodes.addAll(this.nonReplictedNodes); this.vmp.setNodes(allNodes); }
/** * {@inheritDoc} */ @Override public DynamicBayesianNetwork getLearntDBN() { return new DynamicBayesianNetwork(this.dag, this.ef_extendedBNTime0.toConditionalDistribution(), this.ef_extendedBNTimeT.toConditionalDistribution()); }
/** * Updates the model at time T using a given list of {@link DynamicDataInstance}s. * @param batch a {@code List} of {@link DynamicDataInstance}s. * @return a {@code double} value. */ private double updateModelTimeT(List<DynamicDataInstance> batch) { this.plateauStructure.setEvidenceTimeT(batch); this.plateauStructure.runInferenceTimeT(); for (Variable var: plateauStructure.getEFLearningBNTimeT().getParametersVariables()){ EF_UnivariateDistribution uni = plateauStructure.getEFParameterPosteriorTimeT(var).deepCopy(); plateauStructure.getEFLearningBNTimeT().setDistribution(var,uni); this.plateauStructure.getNodeOfVarTimeT(var,0).setPDist(uni); } return this.plateauStructure.getLogProbabilityOfEvidenceTimeT(); }
public <E extends UnivariateDistribution> E getParameterPosteriorTimeT(Variable parameter) { if (parameter.isParameterVariable()) { Variable newVar =this.svbTimeT.getPlateuStructure().getEFLearningBN().getParametersVariables().getVariableByName(parameter.getName()); return this.svbTimeT.getParameterPosterior(newVar); }else { Variable newVar =this.dagTimeT.getVariables().getVariableByName(parameter.getName()); return this.svbTimeT.getParameterPosterior(newVar); } }
/** * Sets the dynamic DAG for this this DynamicPlateauStructure. * @param dbnModel a {@link DynamicDAG} object. */ public void setDBNModel(DynamicDAG dbnModel) { this.dbnModel = dbnModel; List<EF_ConditionalDistribution> distTim0 = this.dbnModel.getParentSetsTime0().stream().map(pSet -> pSet.getMainVar().getDistributionType().<EF_ConditionalDistribution>newEFConditionalDistribution(pSet.getParents())).collect(Collectors.toList()); this.setEFBayesianNetworkTime0(new EF_LearningBayesianNetwork(distTim0)); List<EF_ConditionalDistribution> distTimT = this.dbnModel.getParentSetsTimeT().stream().map(pSet -> pSet.getMainVar().getDistributionType().<EF_ConditionalDistribution>newEFConditionalDistribution(pSet.getParents())).collect(Collectors.toList()); this.setEFBayesianNetworkTimeT(new EF_LearningBayesianNetwork(distTimT)); }
@Override public double getPosteriorSampleSize() { double sum = 0; for (Variable variable : this.nonReplicatedVariablesList) { sum+=this.ef_learningmodel.getDistribution(variable).getNaturalParameters().sum(); } return sum; } }
/** * Updates the model at time 0 using a given {@link DynamicDataInstance}. * @param dataInstance a {@link DynamicDataInstance} object. * @return a {@code double} value. */ private double updateModelTime0(DynamicDataInstance dataInstance) { this.plateauStructure.setEvidenceTime0(dataInstance); this.plateauStructure.runInferenceTime0(); for (Variable var: plateauStructure.getEFLearningBNTime0().getParametersVariables()){ EF_UnivariateDistribution uni = plateauStructure.getEFParameterPosteriorTime0(var).deepCopy(); plateauStructure.getEFLearningBNTime0().setDistribution(var, uni); this.plateauStructure.getNodeOfVarTime0(var).setPDist(uni); } return this.plateauStructure.getLogProbabilityOfEvidenceTime0(); }
public <E extends UnivariateDistribution> E getParameterPosteriorTime0(Variable parameter) { if (parameter.isParameterVariable()) { Variable newVar =this.parallelVBTime0.getSVB().getPlateuStructure().getEFLearningBN().getParametersVariables().getVariableByName(parameter.getName()); return this.parallelVBTime0.getParameterPosterior(newVar); }else { Variable newVar =this.dagTime0.getVariables().getVariableByName(parameter.getName()); return this.parallelVBTime0.getParameterPosterior(newVar); } }
nodeDirichletMixingTopics = new Node(ef_learningmodel.getDistribution(dirichletMixingTopics)); tmpNodes.add(nodeDirichletMixingTopics); tmpNodes = new ArrayList<>(); nodeDirichletMixingTopics = new Node(ef_learningmodel.getDistribution(dirichletMixingTopics)); tmpNodes.add(nodeDirichletMixingTopics); nodeTopic = new Node(ef_learningmodel.getDistribution(topicIndicator)); nodeWord = new Node(ef_learningmodel.getDistribution(word)); nodeWord.setAssignment(data.get(i));
.collect(Collectors.toList()); ef_learningmodel = new EF_LearningBayesianNetwork(dists); this.ef_learningmodel.getListOfParametersVariables().stream().forEach(var -> this.replicatedVariables.put(var, false)); this.ef_learningmodel.getListOfNonParameterVariables().stream().forEach(var -> this.replicatedVariables.put(var, true)); dirichletMixingTopics = ef_learningmodel.getDistribution(topicIndicator).getConditioningVariables().get(0); this.replicatedVariables.put(dirichletMixingTopics, true); ef_learningmodel.getDistribution(dirichletMixingTopics).getNaturalParameters().set(i,0.1); NaturalParameters vec = this.ef_learningmodel.getDistribution(variable).getNaturalParameters();
/** * Replicates this model. */ @Override public void replicateModel() { //nonReplicatedNodes are the Dirichlet storing topics distributions. nonReplictedNodes = ef_learningmodel.getDistributionList().stream() .filter(dist -> isNonReplicatedVar(dist.getVariable())) .map(dist -> { Node node = new Node(dist); nonReplicatedVarsToNode.put(dist.getVariable(), node); return node; }) .collect(Collectors.toList()); List<Node> allNodes = new ArrayList<>(); allNodes.addAll(this.nonReplictedNodes); this.vmp.setNodes(allNodes); }
/** * {@inheritDoc} */ @Override public BayesianNetwork getLearntBayesianNetwork() { CompoundVector prior = this.plateuStructure.getPlateauNaturalParameterPrior(); this.updateNaturalParameterPrior(this.plateuStructure.getPlateauNaturalParameterPosterior()); BayesianNetwork learntBN = new BayesianNetwork(this.dag, ef_extendedBN.toConditionalDistribution()); this.updateNaturalParameterPrior(prior); return learntBN; }
nodeDirichletMixingTopics = new Node(ef_learningmodel.getDistribution(dirichletMixingTopics)); tmpNodes.add(nodeDirichletMixingTopics); tmpNodes = new ArrayList<>(); nodeDirichletMixingTopics = new Node(ef_learningmodel.getDistribution(dirichletMixingTopics)); tmpNodes.add(nodeDirichletMixingTopics); nodeTopic = new Node(ef_learningmodel.getDistribution(topicIndicator)); nodeWord = new Node(ef_learningmodel.getDistribution(word)); nodeWord.setAssignment(data.get(i));
parametersNodeTime0 = ef_learningmodelTime0.getDistributionList() .stream() .filter(dist -> dist.getVariable().isParameterVariable()) this.variablesToNodeTime0 = new ConcurrentHashMap<>(); this.nodesTime0 = ef_learningmodelTime0.getDistributionList().stream() .filter(dist -> !dist.getVariable().isParameterVariable()) .map(dist -> {
/** * {@inheritDoc} */ @Override public BayesianNetwork getLearntBayesianNetwork() { CompoundVector prior = this.plateuStructure.getPlateauNaturalParameterPrior(); this.updateNaturalParameterPrior(this.plateuStructure.getPlateauNaturalParameterPosterior()); BayesianNetwork learntBN = new BayesianNetwork(this.dag, ef_extendedBN.toConditionalDistribution()); this.updateNaturalParameterPrior(prior); return learntBN; }
parametersToNodeTimeT = new ConcurrentHashMap<>(); parametersNodeTimeT = ef_learningmodelTimeT.getDistributionList() .stream() .filter(dist -> dist.getVariable().isParameterVariable()) cloneNodesTimeT = ef_learningmodelTimeT.getDistributionList() .stream() .filter(dist -> !dist.getVariable().isParameterVariable()) final int slice = i; Map<Variable, Node> map = new ConcurrentHashMap<>(); List<Node> tmpNodes = ef_learningmodelTimeT.getDistributionList().stream() .filter(dist -> !dist.getVariable().isParameterVariable()) .map(dist -> {