Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing/evaluation of NLExpressions #585

Closed
anriseth opened this issue Sep 14, 2015 · 3 comments · Fixed by #638
Closed

Incorrect parsing/evaluation of NLExpressions #585

anriseth opened this issue Sep 14, 2015 · 3 comments · Fixed by #638
Labels
Category: Nonlinear Related to nonlinear programming

Comments

@anriseth
Copy link
Contributor

Using a NLExpr in the definition of another NLExpr does not seem to work correctly all the time.
I've tried to define an expression $v(x)^TAv(x)$, where $v$ is a nonlinear vector field in $x$ and $A$ is a matrix. In the example below, you can see that the evaluation of the functions f2 and f3 are different, while I expect it to be the same.

using JuMP
n = 2
x0 = [2.25, 2.4]
β = [-2 0.15; 0.23 -2.1]
Σ = [0.02 0.007; 0.007 0.014]
x0 = [1.5, 2.0]
m = Model()
@defVar(m, x[i=1:n] >= 0, start=x0[i])

@defNLExpr(f1[i=1:n], prod{x[j]^β[j,i], j = 1:n})
@defNLExpr(f2, sum{Σ[i,j]*f1[i]*f1[j], i=1:n, j=1:n}) # bug
@defNLExpr(f3, sum{Σ[i,j]*prod{x[k]^β[k,i], k = 1:n}*prod{x[k]^β[k,j], k = 1:n}, i=1:n, j=1:n})

println(getValue(f2))
println(getValue(f3))

Output:

0.0021786119842496466
0.008103475980157478
@anriseth anriseth changed the title incorrect parsing of NLExpressions Incorrect parsing/evaluation of NLExpressions Sep 14, 2015
@mlubin
Copy link
Member

mlubin commented Sep 14, 2015

Looks like there's a scoping issue. The j in f1 is the same symbol as the j in f2. Definitely a bug, but the easy workaround is to use a different indexing variable in f1.

@anriseth
Copy link
Contributor Author

Thanks, I didn't think about that. @defNLExpr(f1[i=1:n], prod{x[k]^β[k,i], k = 1:n}) works.

@mlubin mlubin added the Category: Nonlinear Related to nonlinear programming label Sep 15, 2015
@mlubin
Copy link
Member

mlubin commented Dec 30, 2015

Will be fixed by #638, confusion of scope is not possible anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Nonlinear Related to nonlinear programming
Development

Successfully merging a pull request may close this issue.

2 participants