@@ -1115,38 +1115,38 @@ function get_optim_functions(
1115
1115
nx̂, nym, nŷ, nu, He = estim. nx̂, estim. nym, model. ny, model. nu, estim. He
1116
1116
nV̂, nX̂, ng, nZ̃ = He* nym, He* nx̂, length (con. i_g), length (estim. Z̃)
1117
1117
Nc = nZ̃ + 3
1118
- Z̃_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nZ̃), Nc)
1119
- V̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nV̂), Nc)
1120
- g_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), Nc)
1121
- X̂_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nX̂), Nc)
1122
- x̄_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nx̂), Nc)
1123
- û_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nu), Nc)
1124
- ŷ_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nŷ), Nc)
1118
+ Z̃_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nZ̃), Nc)
1119
+ V̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nV̂), Nc)
1120
+ g_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), Nc)
1121
+ X̂0_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nX̂), Nc)
1122
+ x̄_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nx̂), Nc)
1123
+ û0_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nu), Nc)
1124
+ ŷ0_cache :: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nŷ), Nc)
1125
1125
function Jfunc (Z̃tup:: T... ):: T where {T <: Real }
1126
1126
Z̃1 = Z̃tup[begin ]
1127
1127
Z̃, g = get_tmp (Z̃_cache, Z̃1), get_tmp (g_cache, Z̃1)
1128
1128
for i in eachindex (Z̃tup)
1129
1129
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability
1130
1130
end
1131
- V̂, X̂ = get_tmp (V̂_cache, Z̃1), get_tmp (X̂_cache , Z̃1)
1132
- û, ŷ = get_tmp (û_cache , Z̃1), get_tmp (ŷ_cache , Z̃1)
1133
- V̂, X̂ = predict! (V̂, X̂, û, ŷ , estim, model, Z̃)
1131
+ V̂, X̂0 = get_tmp (V̂_cache, Z̃1), get_tmp (X̂0_cache , Z̃1)
1132
+ û0, ŷ0 = get_tmp (û0_cache , Z̃1), get_tmp (ŷ0_cache , Z̃1)
1133
+ V̂, X̂0 = predict! (V̂, X̂0, û0, ŷ0 , estim, model, Z̃)
1134
1134
g = get_tmp (g_cache, Z̃1)
1135
- g = con_nonlinprog! (g, estim, model, X̂ , V̂, Z̃)
1135
+ g = con_nonlinprog! (g, estim, model, X̂0 , V̂, Z̃)
1136
1136
x̄ = get_tmp (x̄_cache, Z̃1)
1137
1137
return obj_nonlinprog! (x̄, estim, model, V̂, Z̃):: T
1138
1138
end
1139
1139
function gfunc_i (i, Z̃tup:: NTuple{N, T} ):: T where {N, T <: Real }
1140
1140
Z̃1 = Z̃tup[begin ]
1141
1141
Z̃, g = get_tmp (Z̃_cache, Z̃1), get_tmp (g_cache, Z̃1)
1142
1142
if any (new != = old for (new, old) in zip (Z̃tup, Z̃)) # new Z̃tup, update predictions:
1143
- V̂, X̂ = get_tmp (V̂_cache, Z̃1), get_tmp (X̂_cache , Z̃1)
1144
- û, ŷ = get_tmp (û_cache , Z̃1), get_tmp (ŷ_cache , Z̃1)
1143
+ V̂, X̂0 = get_tmp (V̂_cache, Z̃1), get_tmp (X̂0_cache , Z̃1)
1144
+ û0, ŷ0 = get_tmp (û0_cache , Z̃1), get_tmp (ŷ0_cache , Z̃1)
1145
1145
for i in eachindex (Z̃tup)
1146
1146
Z̃[i] = Z̃tup[i] # Z̃ .= Z̃tup seems to produce a type instability
1147
1147
end
1148
- V̂, X̂ = predict! (V̂, X̂, û, ŷ , estim, model, Z̃)
1149
- g = con_nonlinprog! (g, estim, model, X̂ , V̂, Z̃)
1148
+ V̂, X̂0 = predict! (V̂, X̂0, û0, ŷ0 , estim, model, Z̃)
1149
+ g = con_nonlinprog! (g, estim, model, X̂0 , V̂, Z̃)
1150
1150
end
1151
1151
return g[i]
1152
1152
end
0 commit comments