当我尝试运行我的代码时,我只是遇到了以下错误。我不明白我做错了什么。有什么建议么?
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()
}
}