class do_mpc.estimator.MHE(model, p_est_list=[])[source]

Moving horizon estimator.

For general information on moving horizon estimation, please read our background article.

The MHE estimator extends the do_mpc.optimizer.Optimizer base class (which is also used for do_mpc.controller.MPC), as well as the Estimator base class. Use this class to configure and run the MHE based on a previously configured do_mpc.model.Model instance.

The class is initiated by passing a list of the parameters that should be estimated. This must be a subset (or all) of the parameters defined in do_mpc.model.Model. This allows to define parameters in the model that influence the model externally (e.g. weather predictions), and those that are internal e.g. system parameters and can be estimated. Passing an empty list (default) value, means that no parameters are estimated.


Parameters are influencing the model equation at all timesteps but are constant over the entire horizon. Parameters could also be introduced as states without dynamic but this would increase the total number of optimization variables.

Configuration and setup:

Configuring and setting up the MHE involves the following steps:

  1. Use set_param() to configure the MHE. See docstring for details.
  2. Set the objective of the control problem with set_default_objective() or use the low-level interface set_objective().
  1. Set upper and lower bounds.
  2. Optionally, set further (non-linear) constraints with set_nl_cons().
  3. Use get_p_template() and set_p_fun() to set the function for the (not estimated) parameters.
  4. Use get_tvp_template() and set_tvp_fun() to create a method to obtain new time-varying parameters at each iteration.
  5. To finalize the class configuration there are two routes. The default approach is to call setup(). For deep customization use the combination of prepare_nlp() and create_nlp(). See graph below for an illustration of the process.

digraph G { graph [fontname = "helvetica"]; rankdir=LR; subgraph cluster_main { node [fontname = "helvetica", shape=box, fontcolor="#404040", color="#707070"]; edge [fontname = "helvetica", color="#707070"]; start [label="Two ways to setup"]; setup [label="setup", href="../api/do_mpc.estimator.MHE.setup.html", target="_top", fontname = "Consolas"]; create_nlp [label="create_nlp", href="../api/do_mpc.estimator.MHE.create_nlp.html", target="_top", fontname = "Consolas"]; process [label="Modify NLP"]; prepare_nlp [label="prepare_nlp", href="../api/do_mpc.estimator.MHE.prepare_nlp.html", target="_top", fontname = "Consolas"]; finish [label="Configured MHE class"] start -> setup, prepare_nlp; prepare_nlp -> process; process -> create_nlp; setup, create_nlp -> finish; color=none; } subgraph cluster_modification { rankdir=TB; node [fontname = "helvetica", shape=box, fontcolor="#404040", color="#707070"]; edge [fontname = "helvetica", color="#707070"]; opt_x [label="opt_x", href="../api/do_mpc.estimator.MHE.opt_x.html", target="_top", fontname = "Consolas"]; opt_p [label="opt_p", href="../api/do_mpc.estimator.MHE.opt_p.html", target="_top", fontname = "Consolas"]; nlp_cons [label="nlp_cons", href="../api/do_mpc.estimator.MHE.nlp_cons.html", target="_top", fontname = "Consolas"]; nlp_obj [label="nlp_obj", href="../api/do_mpc.estimator.MHE.nlp_obj.html", target="_top", fontname = "Consolas"]; opt_x -> nlp_cons, nlp_obj; opt_p -> nlp_cons, nlp_obj; label = "Attributes to modify the NLP."; color=black; } nlp_cons -> process; nlp_obj -> process; }

Route to setting up the MHE class.


Before running the estimator, make sure to supply a valid initial guess for all estimated variables (states, algebraic states, inputs and parameters). Simply set the intial values of x0, z0, u0 and p_est0 and then call set_initial_guess().

To take full control over the initial guess, modify the values of opt_x_num.

During runtime use make_step() with the most recent measurement to obtain the estimated states.



MHE.bounds Query and set bounds of the optimization variables.
MHE.lb_opt_x Query and modify the lower bounds of all optimization variables opt_x.
MHE.nlp_cons Query and modify (symbolically) the NLP constraints.
MHE.nlp_cons_lb Query and modify the lower bounds of the nlp_cons.
MHE.nlp_cons_ub Query and modify the upper bounds of the nlp_cons.
MHE.nlp_obj Query and modify (symbolically) the NLP objective function.
MHE.opt_p Full structure of (symbolic) MHE parameters.
MHE.opt_p_num Full MHE parameter vector.
MHE.opt_x Full structure of the (symbolic) MHE optimization variables.
MHE.opt_x_num Full MHE solution and initial guess.
MHE.p_est0 Initial value of estimated parameters and current iterate.
MHE.scaling Query and set scaling of the optimization variables.
MHE.t0 Current time marker of the class.
MHE.u0 Initial input and current iterate.
MHE.ub_opt_x Query and modify the lower bounds of all optimization variables opt_x.
MHE.x0 Initial state and current iterate.
MHE.z0 Initial algebraic state and current iterate.


MHE.create_nlp Create the optimization problem.
MHE.get_p_template Obtain output template for set_p_fun().
MHE.get_tvp_template Obtain output template for set_tvp_fun().
MHE.get_y_template Obtain output template for set_y_fun().
MHE.make_step Main method of the class during runtime.
MHE.prepare_nlp Prepare the optimization problem.
MHE.reset_history Reset the history of the optimizer.
MHE.set_default_objective Configure the suggested default MHE formulation.
MHE.set_initial_guess Initial guess for optimization variables.
MHE.set_nl_cons Introduce new constraint to the class.
MHE.set_objective Set the stage cost \(l(\cdot)\) and arrival cost \(m(\cdot)\) function for the MHE problem:
MHE.set_p_fun Set function which returns parameters..
MHE.set_param Method to set the parameters of the MHE class.
MHE.set_tvp_fun Set function which returns time-varying parameters.
MHE.set_y_fun Set the measurement function.
MHE.setup The setup method finalizes the MHE creation.
MHE.solve Solves the optmization problem.

This page is auto-generated. Page source is not available on Github.