I’m trying to optimize a likelihood function a little different from the traditional ones. I’m going to call this likelihood function of mine “faux”. To show my problem, first see how well this example (I took this example from the Jump tutorial) works:
using Distributions
using JuMP, Ipopt
n = 1_000
data = randn(n)
model = Model(Ipopt.Optimizer)
set_silent(model)
@variable(model, μ, start = 0.0)
@variable(model, σ >= 0.0, start = 1.0)
@NLobjective( model , Max, n / 2 * log(1 / (2 * π * σ^2)) -sum((data[i] - μ)^2 for i in 1:n) / (2 * σ^2) )
optimize!(model)
# declare solution
@show value(μ)
@show value(σ)
As I said, my function is a little more complicated to the point of writing it directly like the example I’m giving. So, as I have faux built out and want to maximize it using the same script as above. For this, assume that
faux(μ,σ) = n / 2 * log(1 / (2 * π * σ^2)) -sum((data[i] - μ)^2 for i in 1:n) / (2 * σ^2)
But, when I do this
n = 1_000
data = randn(n)
model = Model(Ipopt.Optimizer)
set_silent(model)
@variable(model, μ, start = 0.0)
@variable(model, σ >= 0.0, start = 1.0)
@NLobjective( model , Max, faux(μ,σ) )
optimize!(model)
I have an error: Unrecognized function “faux” used in nonlinear expression.
Why is this happening?
Any solution?