wolfe-pack / wolfe

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

Bug in differentiating sums where search space appears in range? #145

Open riedelcastro opened 9 years ago

riedelcastro commented 9 years ago

This works:

@domain case class Theta(x:Vect,y:IndexedSeq[Double])
val Thetas = Theta.Values(Vectors(2),Seqs(Doubles,3))
def obj(t:Thetas.Term) = 
  sum(0 until 3) { i => 4.0 * t.y(i) - t.y(i) * t.y(i)} + (t.x dot t.x)
val term = argmax(Thetas)(obj) by adaGrad(AdaGradParameters(50,1))
term()

But this doesn't

@domain case class Theta(x:Vect,y:IndexedSeq[Double])
val Thetas = Theta.Values(Vectors(2),Seqs(Doubles,3))
def obj(t:Thetas.Term) = 
  sum(t.y) { i => 4.0 * i - i * i} + (t.x dot t.x)
val term = argmax(Thetas)(obj) by adaGrad(AdaGradParameters(50,1))
term()

Probably difficult to fix because we need to make the sum range differentiable, not sure how this should work. But need a sensible error message and good instructions.