Nested Sum in NLObjective -

Hi, I am totally new to both Julia and Optimization and I am trying to define a non linear objective that requires nested sums. I found some examples that I am trying to replicate, but I get an error. This is how I set my nested NLObjective

@NLobjective(my_model, :Min, Sum(Sum((Sum( m[i]* exp((X[j]-x[i])^2/gamma^2) * exp((Y[k]-y[i])^2/gamma^2) for i=1:np) - C[j,k])^2 for j in eachindex(X)) for k in eachindex(Y)))

Where m, x and y are my arrays of variables and X, Y and C are arrays of predefined parameters.

I am getting the following error and eBay help is hugely appreciated:

LoadError: Unsupported generator :Sum
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] _parse_generator_expression(code::Expr, x::Expr, operators::Set{Tuple{Symbol, Int64}})
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:2008
[3] _parse_nonlinear_expression_inner(code::Expr, x::Expr, operators::Set{Tuple{Symbol, Int64}})
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:1968
[4] _parse_nonlinear_expression(model::Expr, x::Expr)
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:1876
[5] var"@NLobjective"(source::LineNumberNode, module::Module, model::Any, sense::Any, x::Any)
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:2393
in expression starting at /Users/Greg/Documents/OneDrive/Documents/Julia Code/Scalar points optimizer:41
in expression starting at /Users/Greg/Documents/OneDrive/Documents/Julia Code/Scalar points optimizer:41

Try it with a lowercase s, i.e. sum, not Sum.

1 Like

Hey Abel, thank you so much. it all works. Sometimes, things are so big that you cannot see them. You have a great rest of your day. Cheers, Greg

1 Like