You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorials/dynamic_optimization.md
+88-1Lines changed: 88 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ The `tf` mapping in the parameter map is treated as an initial guess.
101
101
Please note that, at the moment, free final time problems cannot support constraints defined at definite time values, like `x(3) ~ 2`.
102
102
103
103
!!! warning
104
-
104
+
105
105
The Pyomo collocation methods (LagrangeRadau, LagrangeLegendre) currently are bugged for free final time problems. Strongly suggest using BackwardEuler() for such problems when using Pyomo as the backend.
106
106
107
107
When declaring the problem in this case we need to provide the number of steps, since dt can't be known in advanced. Let's solve plot our final solution and the controller for the block, using InfiniteOpt as the backend:
@@ -126,3 +126,90 @@ axislegend(ax1)
126
126
axislegend(ax2)
127
127
fig
128
128
```
129
+
130
+
### Parameter estimation
131
+
132
+
The dynamic optimization framework can also be used for parameter estimation. In this approach, we treat unknown parameters as tunable variables and minimize the difference between model predictions and observed data.
133
+
134
+
Let's demonstrate this with the Lotka-Volterra equations. First, we'll generate some synthetic data by solving the system with known parameter values:
Now we'll set up the parameter estimation problem. We use `EvalAt` to evaluate the state at specific time points and construct a least-squares cost function:
159
+
160
+
```@example dynamic_opt
161
+
costs_pe = [abs2(EvalAt(ti)(x_pe) - data_pe[i]) for (i, ti) in enumerate(ts_pe)]
When using `EvalAt` for parameter estimation, different backends handle the case when evaluation times don't align with collocation points differently:
197
+
198
+
- **JuMP**: Will throw an error asking you to adjust `dt` if evaluation times don't match collocation points exactly.
199
+
- **CasADi**: Uses linear interpolation between collocation points for cost evaluations at intermediate times.
200
+
- **InfiniteOpt**: Automatically adds support points for the evaluation times, handling mismatched grids gracefully.
201
+
202
+
For example, InfiniteOpt can use a different `dt` than what the data spacing requires:
203
+
204
+
```@example dynamic_opt
205
+
# With InfiniteOpt, dt doesn't need to match the data points:
This flexibility makes InfiniteOpt particularly convenient for parameter estimation when your data points don't naturally align with a uniform collocation grid.
# JuMP variables and Symbolics variables never compare equal. When tracing through dynamics, a function argument can be either a JuMP variable or A Symbolics variable, it can never be both.
0 commit comments