Observers

class hilo_mpc.MovingHorizonEstimator(model, id=None, name=None, plot_backend=None, time=0)[source]

Moving Horizon Estimator (MHE) class for state and parameter estimation.

Parameters:
  • model (HILO-MPC Model) – HILO-MPC model object that will be used in the estimator.

  • id (str, optional) – id name

  • name (str, optional) – The name of the MHE. By default the MHE has no name.

  • plot_backend (str, optional) – Plot package. Can be ‘bokeh’ (recommended) or ‘matplotlib’ (default: matplotlib).

  • time (float or int, optional) – Initial time. Useful for time-varying systems (default: 0 ).

mhe_opts: options list

Opts

Description

arrival_cost_update

Can be smoothing or filtering

add_measurements(y_meas, u_meas=None)[source]

Add new measurements to the estimation window.

Measurements are stored in a sliding window of length equal to the horizon. When the horizon is reached, the MHE is ready to estimate.

Parameters:
  • y_meas – Output measurements at current time

  • u_meas – Input measurements at current time (optional)

Raises:

RuntimeError – If MHE has not been set up via setup()

estimate(x_arrival=None, p_arrival=None, v0=None, runs=0, **kwargs)[source]

Solve the MHE optimization problem to estimate states and parameters.

Parameters:
  • x_arrival – Prior state estimate at beginning of horizon (optional, auto-updated if None)

  • p_arrival – Prior parameter estimate (optional, auto-updated if None)

  • v0 – Initial guess for optimization variables (optional)

  • runs – Number of optimization runs with random perturbations (default: 0 = single run, if >0 performs multistart)

  • kwargs – Additional options (e.g., pert_factor for perturbation magnitude)

Returns:

Tuple (x_opt, p_opt) with estimated current state and parameters (None before horizon reached)

Raises:

ValueError – If MHE has not been set up via setup()

plot_mhe_estimation(save_plot=False, plot_dir=None, name_file='mhe_estimation.html', show_plot=True, extras=None, extras_names=None, title=None, format_figure=None)[source]
Parameters:
  • save_plot – if True plot will be saved under ‘plot_dir/name_file.html’ if they are declared, otherwise in current directory

  • plot_dir – path to the folder where plots are saved (default = None)

  • name_file – name of the file where plot will be saved (default = mpc_prediction.html)

  • show_plot – if True, shows plots (default = False)

  • extras – dictionary with values that will be plotted over the predictions if keys are equal to predicted states/inputs

  • extras_names – tags that will be attached to the extras in the legend

  • title – title of the plots

  • format_figure – python function that modifies the format of the figure

Returns:

return_mhe_estimation()[source]

Extract state trajectory and noise estimates from MHE solution.

Returns:

Tuple (x_pred, w_pred) with state trajectory (n_x × horizon+1) and noise trajectory (n_x × horizon), or (None, None) if no solution is available

set_aux_nonlinear_constraints(aux_nl_const=None, ub=None, lb=None)[source]

Set auxiliary nonlinear constraints (deprecated, use stage_constraint instead).

Parameters:
  • aux_nl_const – CasADi expression for constraint function

  • ub – Upper bounds for constraints

  • lb – Lower bounds for constraints

Raises:

ValueError – If constraint function provided without bounds or vice versa

set_box_constraints(x_ub=None, x_lb=None, w_ub=None, w_lb=None, p_lb=None, p_ub=None, z_ub=None, z_lb=None)[source]

Set box constraints on states, noise, parameters, and algebraic variables.

Parameters:
  • x_ub – Upper bounds for states (default: inf)

  • x_lb – Lower bounds for states (default: -inf)

  • w_ub – Upper bounds for state noise (default: inf)

  • w_lb – Lower bounds for state noise (default: -inf)

  • p_lb – Lower bounds for parameters (default: -inf)

  • p_ub – Upper bounds for parameters (default: inf)

  • z_ub – Upper bounds for algebraic states (default: inf)

  • z_lb – Lower bounds for algebraic states (default: -inf)

Raises:

TypeError – If algebraic state bounds dimension mismatch

set_initial_guess(x_guess=None, w_guess=None, p_guess=None, z_guess=None)[source]

Set initial guess for optimization variables.

If not provided, guesses are computed from constraint bounds (midpoint) or set to zero.

Parameters:
  • x_guess – Initial guess for states

  • w_guess – Initial guess for state noise (default: zeros)

  • p_guess – Initial guess for parameters

  • z_guess – Initial guess for algebraic states

Raises:

ValueError – If guess dimensions don’t match model

set_nlp_options(*args, **kwargs)[source]

Sets the options that modify how the mhe problem is set

Parameters:
  • args

  • kwargs

Returns:

set_scaling(x_scaling=None, w_scaling=None, p_scaling=None, u_scaling=None)[source]

Scales the states and input. This is important for systems with large difference of order of magnitude in states and inputs.

Parameters:
  • x_scaling – list of scaling factors

  • w_scaling – list of scaling factors

  • p_scaling – list of scaling factors

  • u_scaling – list of scaling factors

Returns:

set_time_varying_parameters(time_varying_parameters=None)[source]

Sets the time-varying parameters for the estimator. The estimator will expect these as an input at every iteration

Parameters:

time_varying_parameters – list of strings with time varying parameter names

Returns:

setup(options=None, nlp_opts=None, solver='ipopt')[source]

Configure and build the MHE optimization problem.

This method constructs the NLP formulation, sets up the solver, and prepares the MHE for estimation. Must be called before estimate().

Parameters:
  • options – Dictionary with NLP formulation options (integration method, collocation settings, etc.)

  • nlp_opts – Solver-specific options (deprecated, use solver options via set_solver_opts)

  • solver – Solver name (‘ipopt’ or ‘qpsol’, default: ‘ipopt’)

property has_state_noise

Check if state noise is included in the MHE formulation.

Returns:

True if state noise variables are used, False otherwise

class hilo_mpc.KalmanFilter(model, id=None, name=None, plot_backend=None, square_root_form=True)[source]

Kalman filter (KF) class for state estimation (parameter estimation will follow soon)

Parameters:
  • model

  • id – The identifier of the KF object. If no identifier is given, a random one will be generated.

  • name – The name of the KF object. By default the KF object has no name.

  • plot_backend – Plotting library that is used to visualize estimated data. At the moment only Matplotlib and Bokeh are supported. By default no plotting library is selected, i.e. no plots can be generated.

  • square_root_form – Not used at the moment (will be implemented in the future)

hilo_mpc.KF

alias of KalmanFilter

class hilo_mpc.ExtendedKalmanFilter(model, id=None, name=None, plot_backend=None, square_root_form=True)[source]

Extended Kalman filter (EKF) class for state estimation (parameter estimation will follow soon)

Parameters:
  • model

  • id – The identifier of the EKF object. If no identifier is given, a random one will be generated.

  • name – The name of the EKF object. By default the EKF object has no name.

  • plot_backend

    Plotting library that is used to visualize estimated data. At the moment only Matplotlib and Bokeh are supported. By default no plotting library is selected, i.e. no plots can be generated.

  • square_root_form – Not used at the moment (will be implemented in the future)

Note:

The same methods and properties as for the Kalman filter apply

hilo_mpc.EKF

alias of ExtendedKalmanFilter

class hilo_mpc.UnscentedKalmanFilter(model, id=None, name=None, alpha=None, beta=None, kappa=None, plot_backend=None, square_root_form=True)[source]

Unscented Kalman filter (UKF) class for state estimation (parameter estimation will follow soon)

Parameters:
  • model

  • id – The identifier of the UKF object. If no identifier is given, a random one will be generated.

  • name – The name of the UKF object. By default the UKF object has no name.

  • alpha

  • beta

  • kappa

  • plot_backend

    Plotting library that is used to visualize estimated data. At the moment only Matplotlib and Bokeh are supported. By default no plotting library is selected, i.e. no plots can be generated.

  • square_root_form – Not used at the moment (will be implemented in the future)

property alpha

return:

property beta

return:

property kappa

return:

hilo_mpc.UKF

alias of UnscentedKalmanFilter

class hilo_mpc.ParticleFilter(model, id=None, name=None, plot_backend=None, variant=None, roughening=False, prior_editing=False, **kwargs)[source]

Particle filter (PF) class for state estimation

Parameters:
  • model

  • id – The identifier of the PF object. If no identifier is given, a random one will be generated.

  • name – The name of the PF object. By default the PF object has no name.

  • plot_backend

    Plotting library that is used to visualize estimated data. At the moment only Matplotlib and Bokeh are supported. By default no plotting library is selected, i.e. no plots can be generated.

  • variant

  • roughening

  • prior_editing

  • kwargs

estimate(*args, **kwargs)[source]
Parameters:
  • args

  • kwargs

Returns:

setup(**kwargs)[source]
Parameters:

kwargs

Returns:

property n_samples

return:

property pdf

return:

property probability_density_function

return:

property sample_size

return:

property variant

return:

hilo_mpc.PF

alias of ParticleFilter