I’m attempting to minimize an RMSE where the optimized coefficients alpha and beta give a forecasted value (xnext) from the original value (x_k). Initially it did not let me add the square root in the objective function, so I tried using sqrt(msd(xnext, x_k)) as my objective function but since xnext is computed dynamically, it gives me an error. Now, with the square root in the objective function, it give me an INVALID_MODEL error. Any ideas or suggestion will be greatly appreciated. The problem formulation is below and the julia code follows
My code is below
bn = 33
#x_k = EstimatedVoltage;
x_k = [0.996296998; 0.99494058; 0.974948068; 0.969848525; 0.964424502; 0.947913184; 0.944859396; 0.935953084; 0.929733301; 0.920502051; 0.92148015; 0.918334107; 0.917047839; 0.913723332; 0.914563694; 0.914004943; 0.908324472; 0.909002883; 0.991995169; 0.983359984; 0.991156028; 0.98713166; 0.977664579; 0.968545981; 0.965580768; 0.945010536; 0.937951627; 0.925111218; 0.916413078; 0.91718043; 0.909069676; 0.909483012; 0.911058107]
# Initialize a JuMP Optimization Model
fcst = Model(with_optimizer(Ipopt.Optimizer, print_level=0))
# Defining variables
@variable(fcst, 0.001 <= alpha[i in 1:bn] <= 0.99)
@variable(fcst, 0.001 <= beta[i in 1:bn] <= 0.99)
@variable(fcst, a_k[i in 1:bn] )
@variable(fcst, b_k[i in 1:bn])
@variable(fcst, xnext[i in 1:bn])
@variable(fcst, Error[i in 1:bn])
# Objective function
@NLobjective(fcst, Min, sqrt(sum(xnext[i]-x_k[i] for i in 1:bn)^2/bn))
#@objective(fcst, Min, sum(xnext[i]-x_k[i] for i in 1:bn)^2/bn)
#@objective(fcst, Min, sqrt(msd(x_k,x_k)))
bn = 33
for i in 1:bn
if i == 1
apast = x_k[1,1]
bpast = x_k[1,1] - x_k[2,1]
@constraint(fcst, a_k[i] == apast )
@constraint(fcst, b_k[i] == bpast)
@constraint(fcst, xnext[i] == a_k[i] + b_k[i])
else
apast = a_k[i-1]
bpast = b_k[i-1]
@constraint(fcst, a_k[i] == alpha[i]*x_k[i] + (1 - alpha[i]*(apast + bpast)))
@constraint(fcst, b_k[i] == beta[i]*(a_k[i] - apast) + (1 - beta[i]*bpast))
@constraint(fcst, xnext[i] == a_k[i] + b_k[i])
@constraint(fcst, beta[i] <= 0.99*alpha[i])
end
end
# Solve the optimization problem
JuMP.optimize!(fcst)
Alpha = JuMP.value.(alpha)
Beta = JuMP.value.(beta)
Xnext = JuMP.value.(xnext)
Level = JuMP.value.(a_k)
Trend = JuMP.value.(b_k)
# Check that the solver terminated without an error
println("The solver termination status is $(termination_status(fcst))")
# Check the value of the objective function
RMSE = objective_value(fcst)