wolfe-pack / wolfe

Wolfe Language and Engine
https://wolfe-pack.github.io/wolfe
Apache License 2.0
135 stars 17 forks source link

Single factor for a Seq[Int] sum #93

Closed insperatum closed 9 years ago

insperatum commented 10 years ago

The model below generates only a single factor of degree 5, rather than 4 factors of degree 2. Note that similar models over seqsOfLength(5, bools) will generate the correct factor graph.

def space = seqsOfLength(5, 0 to 3)
@OutputFactorGraph
def model(s:Seq[Int]) =  sum(0 until s.length-1) {
  i:Int => s(i) + s(i+1)
}
val t = argmax(space) {model}
FactorGraphBuffer.get.factors.length == 1 // true

screenshot from 2014-08-13 15 34 01

riedelcastro commented 10 years ago

Haha, this gotta be the most awesomely looking wolfe bug report so far. I will never address this just to leave it open!

riedelcastro commented 10 years ago

Okay, the reason why this fails is because your model is essentially sum(...)(t:T=>Int)).toDouble instead of sum(...)(t:T=>Int).toDouble). You can temporarily fix this by writing

def space = seqsOfLength(5, (0 to 3) map (_.toDouble))

Also, model is now taking Seq[Double] arguments.

Fixing this for good means automatically pushing down the toDouble conversion into the sum which is a little more tedious than it looks.