-
Notifications
You must be signed in to change notification settings - Fork 440
update model_reduction to allow input/output selection + unstable warning (vs exception) #1074
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update model_reduction to allow input/output selection + unstable warning (vs exception) #1074
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvement! I made several stylistic and misprint-related comments. Else, ready to merge.
control/modelsimp.py
Outdated
eliminated or those to be kept. | ||
|
||
Two methods of state reduction are possible: 'truncate' removes the | ||
states marked for elimination, while 'matchdc' replaces the the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
states marked for elimination, while 'matchdc' replaces the the | |
states marked for elimination, while 'matchdc' replaces the |
control/modelsimp.py
Outdated
unstable eigenvalues, since in those situations the stability reduced | ||
order model may be different that the stability of the full model. No | ||
other checking is done, so users to be careful not to render a system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unstable eigenvalues, since in those situations the stability reduced | |
order model may be different that the stability of the full model. No | |
other checking is done, so users to be careful not to render a system | |
unstable eigenvalues, since in those situations the stability of the reduced | |
order model may be different than the stability of the full model. No | |
other checking is done, so users must be careful not to render a system |
control/modelsimp.py
Outdated
dico = 'C' | ||
else: | ||
raise NotImplementedError("Function not implemented in discrete time") | ||
States, inputs, and outputs can be specified using integer offers or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
States, inputs, and outputs can be specified using integer offers or | |
States, inputs, and outputs can be specified using integer offsets or |
control/tests/modelsimp_test.py
Outdated
({'elim_inputs': [0, 1, 2]}, 5, 3, 0), # no inputs | ||
({'elim_outputs': [0, 1, 2]}, 5, 0, 3), # no outputs | ||
({'elim_states': [0, 1, 2, 3, 4]}, 0, 3, 3), # no states | ||
({'elim_states': [0, 1], 'keep_states': [1, 2]}, None, None, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
control/modelsimp.py
Outdated
See Also | ||
-------- | ||
balanced_reduction : Eliminate states using Hankel singular values. | ||
minimal_realization : Eliminate unreachable or unobseravble states. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minimal_realization : Eliminate unreachable or unobseravble states. | |
minimal_realization : Eliminate unreachable or unobservable states. |
control/modelsimp.py
Outdated
warnings.warn("System is unstable; reduction may be meaningless") | ||
|
||
# Utility function to process keep/elim keywords | ||
def _process_elim_or_keep(elim, keep, labels, allow_both=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to keep allow_both
? _process_elim_or_keep() is a function defined only in the scope of model_reduction(), and all calls to it have the default allow_both
value (allow_both=False
).
control/modelsimp.py
Outdated
method : string | ||
Method of removing states in `ELIM`: either 'truncate' or | ||
'matchdc'. | ||
Method of removing states in `elim`: either 'truncate' or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method of removing states in `elim`: either 'truncate' or | |
Method of removing inputs, outputs, and/or states: either 'truncate' or |
This is confusing because there is no elim
parameter and because inputs and outputs can be removed as well, in addition to states.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update, but this only applies to the way states are removed.
control/modelsimp.py
Outdated
|
||
""" | ||
if not isinstance(sys, StateSpace): | ||
raise TypeError("system must be a a StateSpace system") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise TypeError("system must be a a StateSpace system") | |
raise TypeError("system must be a StateSpace system") |
This PR updates the
model_reduction
function to add some additional functionality. From the docstring:Specific updates:
ELIM
positional parameter toelim_states
(positional or keyword).keep_states
to allow specifying the list of states to keep instead of those to eliminate.elim_inputs
,elim_outputs
,keep_inputs
,keep_outputs
to allow selection of inputs and outputs.warn_unstable=False
.modelsimp.py
since we know just use theLICENSE
file.This PR was motivated by an example from FBS2e (see steering.py), where I wanted to extract the dynamics of a subsystem (and the original system had an eigenvalue at the origin). It is possible to accomplish the same result by using the old implementation (assuming the exception is changed to a warning) and then indexing the system directly to handle the inputs and outputs, but it seemed natural to include in a single function call.