/** * Sets the evidence at time 0. * @param data a {@link DynamicDataInstance} object. */ public void setEvidenceTime0(DynamicDataInstance data) { this.vmpTime0.setEvidence(data); }
/** * {@inheritDoc} */ @Override public <E extends UnivariateDistribution> E getPredictivePosterior(Variable var, int nTimesAhead) { if (timeID==-1){ this.vmpTime0.setEvidence(null); this.vmpTime0.runInference(); this.vmpTime0.getNodes().stream().filter(node -> !node.isObserved()).forEach(node -> { Variable temporalClone = this.model.getDynamicVariables().getInterfaceVariable(node.getMainVariable()); moveNodeQDist(this.vmpTimeT.getNodeOfVar(temporalClone), node); }); this.moveWindow(nTimesAhead-1); E resultQ = this.getFilteredPosterior(var); this.vmpTime0.resetQs(); this.vmpTimeT.resetQs(); return resultQ; }else { Map<Variable, EF_UnivariateDistribution> map = new HashMap<>(); //Create at copy of Qs this.vmpTimeT.getNodes().stream().filter(node -> !node.isObserved()).forEach(node -> map.put(node.getMainVariable(), node.getQDist().deepCopy())); this.moveWindow(nTimesAhead); E resultQ = this.getFilteredPosterior(var); //Come to the original state map.entrySet().forEach(e -> this.vmpTimeT.getNodeOfVar(e.getKey()).setQDist(e.getValue())); return resultQ; } }
this.vmpTime0.setEvidence(null); this.vmpTime0.runInference(); this.timeID=0; this.vmpTime0.setEvidence(this.assignment); this.vmpTime0.runInference(); this.timeID=0; this.vmpTimeT.setEvidence(this.assignment); this.vmpTimeT.runInference(); this.vmpTimeT.getNodes().stream()
/** * Moves the window ahead for a given number of time steps. * @param nsteps an {@link int} that represents a given number of time steps. */ private void moveWindow(int nsteps){ //The first step we need to manually move the evidence from master to clone variables. HashMapDynamicAssignment newassignment = null; if (this.assignment!=null) { newassignment=new HashMapDynamicAssignment(this.model.getNumberOfDynamicVars()); for (Variable var : this.model.getDynamicVariables()) { newassignment.setValue(this.model.getDynamicVariables().getInterfaceVariable(var), this.assignment.getValue(var)); newassignment.setValue(var, Utils.missingValue()); } } for (int i = 0; i < nsteps; i++) { this.vmpTimeT.setEvidence(newassignment); this.vmpTimeT.runInference(); this.vmpTimeT.getNodes().stream() .filter(node -> !node.getMainVariable().isInterfaceVariable()) .filter(node -> !node.isObserved()) .forEach(node -> { Variable temporalClone = this.model.getDynamicVariables().getInterfaceVariable(node.getMainVariable()); moveNodeQDist(this.vmpTimeT.getNodeOfVar(temporalClone), node); }); newassignment=null; } }