InferByBPLoopy with SampleRankTrainer DiscreteDomain$DiscreteValue cast error

37 views
Skip to first unread message

Eric

unread,
Nov 11, 2015, 8:07:14 PM11/11/15
to Factorie
Hi,

I am new to Factorie.
I am trying to build a graph where a set of template variables are connected with pair factors, similar to Grid.scala. There is also a score the comes from a Random Forest model connected to each of those variables. I ran into an error when running LikelihoodExample(Seq(e), model, InferByBPLoopy) with SampleRankTrainer.

>java.lang.ClassCastException: cc.factorie.variable.DiscreteDomain$DiscreteValue cannot be cast to cc.factorie.variable.CategoricalValue

However, when I change LikelihoodExample to PseudolikelihoodExample, the error goes away, so it seems to be a problem with BP. Am I doing something odd? I also know that it works if I use FeatureVectorVariable instead of CategoricalVariable for my Random Forest score, but I chose to use CategoricalVariable because I don't want to deal with the value[Tensor] used by FeatureVectorVariable. Could someone please shed some light on this?

I attached a simplified version of my script and I copied the error message below.

Thank you!
Eric

Exception in thread "main" java.lang.ClassCastException: cc.factorie.variable.DiscreteDomain$DiscreteValue cannot be cast to cc.factorie.variable.CategoricalValue
    at eric.tryProblem$$anon$3$$anon$2.score(tryProblem.scala:43)
    at cc.factorie.model.Family2$class.valuesScore(Factor2.scala:257)
    at cc.factorie.model.Template2.valuesScore(Template2.scala:28)
    at cc.factorie.model.Family2$Factor.valuesScore(Factor2.scala:235)
    at cc.factorie.infer.BPFactor1Factor2.<init>(BP.scala:229)
    at cc.factorie.infer.BPFactorFactory$.newBPFactor(BP.scala:48)
    at cc.factorie.infer.LoopyBPSummary$$anonfun$apply$2.apply(BP.scala:513)
    at cc.factorie.infer.LoopyBPSummary$$anonfun$apply$2.apply(BP.scala:513)
    at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:91)
    at cc.factorie.infer.LoopyBPSummary$.apply(BP.scala:513)
    at cc.factorie.infer.InferByBPLoopy$.infer(BP.scala:816)
    at cc.factorie.infer.InferByBPLoopy$.infer(BP.scala:812)
    at cc.factorie.optimize.LikelihoodExample.accumulateValueAndGradient(Example.scala:113)
    at cc.factorie.optimize.OnlineTrainer.processExamples(Trainer.scala:96)
    at cc.factorie.optimize.Trainer$class.trainFromExamples(Trainer.scala:36)
    at cc.factorie.optimize.OnlineTrainer.trainFromExamples(Trainer.scala:75)
    at eric.tryProblem$.main(tryProblem.scala:65)
    at eric.tryProblem.main(tryProblem.scala)

tryProblem.scala

Eric

unread,
Nov 13, 2015, 6:05:03 PM11/13/15
to Factorie
I need to make a correction, sorry. The error persists if I use FeatureVectorVariable. It was working previously when I was using DotTemplateWithStatistics2 as the factor. However, I wanted the factor to use DenseTensor1 because I do not want to learn separate parameter values for each score category (I think I don't have enough data for that).

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages