- Notifications
You must be signed in to change notification settings - Fork441
Optimization-based and moving horizon estimation#877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
14 commits Select commitHold shift + click to select a range
b0b6121
add pytest --skipslow
murrayrm823dfbc
mark selected optimal, rlocus tests as slow
murrayrmcf45109
initial implementation of optimal estimation problem
murrayrmbd7ba6d
updated documentation + Jupyter notebook
murrayrm8375127
add standard _process_indices function
murrayrme165dd5
add {control, disturbance}_indices to create_estimator_iosystem
murrayrm1c1ce0c
implement {control, disturbance}_indices in oep
murrayrmebedf19
regularize *_labels processing across create_*_iosystem
murrayrmdf4508c
updated docstrings and docs, trim slow unit tests
murrayrm039b22d
remove pytest --skipslow; use pytest -m "not slow" instead
murrayrm9373f8e
fix dtime integral cost calculation; trim unit tests for speed
murrayrm2a42fe8
add benchmarks for optimal estimation
murrayrm1599f44
Update doc/optimal.rst
murrayrma329323
add executed mhe-pvtol.ipynb to fix doctest failure
murrayrmFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.pyc | ||
__pycache__/ | ||
build/ | ||
dist/ | ||
htmlcov/ | ||
87 changes: 87 additions & 0 deletionsbenchmarks/optestim_bench.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# optestim_bench.py - benchmarks for optimal/moving horizon estimation | ||
# RMM, 14 Mar 2023 | ||
# | ||
# This benchmark tests the timing for the optimal estimation routines and | ||
# is intended to be used for helping tune the performance of the functions | ||
# used for optimization-based estimation. | ||
import numpy as np | ||
import math | ||
import control as ct | ||
import control.optimal as opt | ||
minimizer_table = { | ||
'default': (None, {}), | ||
'trust': ('trust-constr', {}), | ||
'trust_bigstep': ('trust-constr', {'finite_diff_rel_step': 0.01}), | ||
'SLSQP': ('SLSQP', {}), | ||
'SLSQP_bigstep': ('SLSQP', {'eps': 0.01}), | ||
'COBYLA': ('COBYLA', {}), | ||
} | ||
# Table to turn on and off process disturbances and measurement noise | ||
noise_table = { | ||
'noisy': (1e-1, 1e-3), | ||
'nodist': (0, 1e-3), | ||
'nomeas': (1e-1, 0), | ||
'clean': (0, 0) | ||
} | ||
# Assess performance as a function of optimization and integration methods | ||
def time_oep_minimizer_methods(minimizer_name, noise_name, initial_guess): | ||
# Use fixed system to avoid randome errors (was csys = ct.rss(4, 2, 5)) | ||
csys = ct.ss( | ||
[[-0.5, 1, 0, 0], [0, -1, 1, 0], [0, 0, -2, 1], [0, 0, 0, -3]], # A | ||
[[0, 0.1], [0, 0.1], [0, 0.1], [1, 0.1]], # B | ||
[[1, 0, 0, 0], [0, 0, 1, 0]], # C | ||
0, dt=0) | ||
# dsys = ct.c2d(csys, dt) | ||
# sys = csys if dt == 0 else dsys | ||
sys = csys | ||
# Decide on process disturbances and measurement noise | ||
dist_mag, meas_mag = noise_table[noise_name] | ||
# Create disturbances and noise (fixed, to avoid random errors) | ||
Rv = 0.1 * np.eye(1) # scalar disturbance | ||
Rw = 0.01 * np.eye(sys.noutputs) | ||
timepts = np.arange(0, 10.1, 1) | ||
V = np.array( | ||
[0 if t % 2 == 1 else 1 if t % 4 == 0 else -1 for t in timepts] | ||
).reshape(1, -1) * dist_mag | ||
W = np.vstack([np.sin(2*timepts), np.cos(3*timepts)]) * meas_mag | ||
# Generate system data | ||
U = np.sin(timepts).reshape(1, -1) | ||
res = ct.input_output_response(sys, timepts, [U, V]) | ||
Y = res.outputs + W | ||
# Decide on the initial guess to use | ||
if initial_guess == 'xhat': | ||
initial_guess = (res.states, V*0) | ||
elif initial_guess == 'both': | ||
initial_guess = (res.states, V) | ||
else: | ||
initial_guess = None | ||
# Set up optimal estimation function using Gaussian likelihoods for cost | ||
traj_cost = opt.gaussian_likelihood_cost(sys, Rv, Rw) | ||
init_cost = lambda xhat, x: (xhat - x) @ (xhat - x) | ||
oep = opt.OptimalEstimationProblem( | ||
sys, timepts, traj_cost, terminal_cost=init_cost) | ||
# Noise and disturbances (the standard case) | ||
est = oep.compute_estimate(Y, U, initial_guess=initial_guess) | ||
assert est.success | ||
np.testing.assert_allclose( | ||
est.states[:, -1], res.states[:, -1], atol=1e-1, rtol=1e-2) | ||
# Parameterize the test against different choices of integrator and minimizer | ||
time_oep_minimizer_methods.param_names = ['minimizer', 'noise', 'initial'] | ||
time_oep_minimizer_methods.params = ( | ||
['default', 'trust', 'SLSQP', 'COBYLA'], | ||
['noisy', 'nodist', 'nomeas', 'clean'], | ||
['none', 'xhat', 'both']) |
23 changes: 23 additions & 0 deletionscontrol/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncontrol/iosys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
104 changes: 102 additions & 2 deletionscontrol/namedio.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.