Ejemplo n.º 1
0
 @Override
 protected double supportEvidenceAndCalculateLogWeight() {
   // TODO modify to block sampling
   BLOGUtil.setBasicVars(evidence, curWorld);
   BlockInstantiatingEvalContextImpl context = new BlockInstantiatingEvalContextImpl(curWorld);
   BLOGUtil.ensureDetAndSupported(evidence.getEvidenceVars(), context);
   return evidence.getEvidenceLogProb(curWorld);
 }
Ejemplo n.º 2
0
  @Override
  public void nextSample() {
    WorldWithBlock curWorld = (WorldWithBlock) getBaseWorld();
    if (curWorld == null) {
      curWorld = new WorldWithBlock(model, evidence, intBound, depthBound);
      Util.debug("Creating initial possible world");
    }
    this.curWorld = curWorld;
    double logWeight = Double.NEGATIVE_INFINITY;
    latestSampleLogWeight = 0;
    while (!isCurWorldSufficient(curWorld)) {
      VarWithDistrib var = curWorld.getNextUninstVar();
      if (var != null) {
        if (var.canSample(curWorld)) {
          logWeight = sampleAndComputeLogWeight(var, curWorld);
        } else {
          curWorld.putBackVarWithDistrib(var);
        }
      } else {
        System.out.println(
            "World is not complete, but no basic random "
                + "variable is supported.  Please check for "
                + "a possible cycle in your model.");
      }
      latestSampleLogWeight += logWeight;
    }

    if (!evidence.isTrue(curWorld)) latestSampleLogWeight = Double.NEGATIVE_INFINITY;
    BLOGUtil.ensureDetAndSupported(queryVars, curWorld);

    // FIXME: remove duplication with LWSampler
    ++totalNumSamples;
    ++numSamplesThisTrial;
    if (latestSampleLogWeight > NEGLIGIBLE_LOG_WEIGHT) {
      ++totalNumConsistent;
      ++numConsistentThisTrial;
    }
    logSumWeightsThisTrial = Util.logSum(logSumWeightsThisTrial, latestSampleLogWeight);
  }