1

当我尝试运行我的代码时,我只是遇到了以下错误。我不明白我做错了什么。有什么建议么?

com.cra.figaro.algorithm.NotATargetException
    at com.cra.figaro.algorithm.ProbQueryAlgorithm$class.check(ProbQueryAlgorithm.scala:68)
    at com.cra.figaro.algorithm.ProbQueryAlgorithm$class.probability(ProbQueryAlgorithm.scala:138)
    at com.cra.figaro.algorithm.sampling.WeightedSampler.probability(WeightedSampler.scala:25)
    at prob1.BetaBinomial$.runner1(BetaBinomial.scala:24)

我在 SBT 中执行runner1("HHHHTHHHHHHTHHTHHHTHH"),我在 figaro 中有其他代码正在运行,但这个代码不会启动。

package prob1

import com.cra.figaro.library.atomic.continuous.Beta
import com.cra.figaro.library.atomic.discrete.Binomial
import com.cra.figaro.language.Flip
import com.cra.figaro.algorithm.sampling.Importance

object BetaBinomial {
    def runner1(data: String){
      val outcomes = data
      val numTosses = outcomes.length
      val numObservedHeads = outcomes.count((c: Char) => c == 'H')
      val bias = Beta(2,5)
      val numberOfHeads = Binomial(numTosses, bias)
      val nextToss = Flip(bias)

      numberOfHeads.observe(numObservedHeads)
      val algorithm = Importance(bias) 
      algorithm.start()
      Thread.sleep(1000)
      algorithm.stop()
      //This is where i get the error
      val probHeads = algorithm.probability(nextToss, true)
      println("Probability of heads = " + probHeads)
      algorithm.kill()
      numberOfHeads.unobserve()
    }
}
4

1 回答 1

1

我不熟悉 figaro,但查看 的实现ProbQueryAlgorithm.check表明您指定的目标不是queryTargets. 在/的queryTargets构造函数中初始化:ImportanceWeightedSampler

abstract class WeightedSampler(override val universe: Universe, targets: Element[_]*) extends ProbQueryAlgorithm with Sampler {
  lazy val queryTargets = targets.toList
  ...
}

abstract class Importance(universe: Universe, targets: Element[_]*)
  extends WeightedSampler(universe, targets: _*) {
  ...
}

你试过这个吗?

val algorithm = Importance(bias, nextToss)
于 2014-09-19T15:24:10.213 回答