Skip to content

Instantly share code, notes, and snippets.

@abelsiqueira
Created March 6, 2020 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsiqueira/d2e7f9719773059b99814a735cabb09f to your computer and use it in GitHub Desktop.
Save abelsiqueira/d2e7f9719773059b99814a735cabb09f to your computer and use it in GitHub Desktop.
using NLPModelsJuMP, JSOSolvers, JuMP
function example()
model = Model()
N = 10
# Fake solution
β_opt = [1.0; 2.0]
# Fake data
x = rand(N)
y = rand(N)
C = rand(N)
z = rand(N)
R = [(C[i] - β_opt[1] * z[i]) / ( (C[i] - β_opt[1] * z[i])^2 * (β_opt[2] - 1) + 1) for i = 1:N]
data = β_opt[1] * x + R .* y + 0.01 * randn(N)
β0 = [20.0; 10.0]
@variable(model, β[i=1:2] ≥ 1, start=β0[i])
@NLexpression(model, F[i=1:N], data[i] - β[1] * x[i] - y[i] * (C[i] - β[1] * z[i]) / ( (C[i] - β[1] * z[i])^2 * (β[2] - 1) + 1))
nls = MathProgNLSModel(model, F)
output = tron(nls, max_eval=10_000)
println(output)
end
nls = example()
[deps]
JSOSolvers = "10dff2fc-5484-5881-a0e0-c90441020f8a"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
NLPModelsJuMP = "792afdf1-32c1-5681-94e0-d7bf7a5df49e"
[compat]
JSOSolvers = "0.2.0"
JuMP = "0.18"
NLPModelsJuMP = "0.5.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment