Repository navigation
Improve markov function, add mimo support, change api to TimeResponseData #1022
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
Merged
murrayrm
merged 13 commits into
python-control:main
from
KybernetikJo:improve_markove_mimo
Aug 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2f0e3e
Improve markov function, add mimo support, change api to TimeResponse…
KybernetikJo 6c95fbc
Fix inputs dimension
KybernetikJo 14ce769
Add plot_inputs=False to TimeResponseData output
KybernetikJo efa3f39
Add markov example
KybernetikJo a597bbc
Add markov example, add example to doc
KybernetikJo 6023480
Change output to ndarray
KybernetikJo 92307f0
Update example, values taken from a book
KybernetikJo a646100
Change API to work with ndarray and TimeResponseData as input
KybernetikJo 42962f2
Update pytest
KybernetikJo a3276b7
Refactor api, keep old api working
KybernetikJo 7ac6ee0
Remove parenthesis form if, update docstrings and comments
KybernetikJo 8d62775
Change default value of dt to None, add equally spaced check for resp…
KybernetikJo e61ac53
Add unit tests to increase code coverage
KybernetikJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor api, keep old api working
- Loading branch information
commit a3276b72f32a0b2174f4724252e8877be1465b17
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -402,7 +402,7 @@ def era(YY, m, n, nin, nout, r): | |
| raise NotImplementedError('This function is not implemented yet.') | ||
|
|
||
|
|
||
| def markov(*args, **kwargs): | ||
| def markov(*args, m=None, transpose=False, dt=True, truncate=False): | ||
| """markov(Y, U, [, m]) | ||
|
|
||
| Calculate the first `m` Markov parameters [D CB CAB ...] | ||
|
|
@@ -420,12 +420,12 @@ def markov(*args, **kwargs): | |
| the input data is less than the desired number of Markov parameters (a | ||
| warning message is generated in this case). | ||
|
|
||
| The function can be called with either 1, 2, or 3 arguments: | ||
| The function can be called with either 1, 2 or 3 arguments: | ||
|
|
||
| * ``K, S, E = lqr(response)`` | ||
| * ``K, S, E = lqr(respnose, m)`` | ||
| * ``K, S, E = lqr(Y, U)`` | ||
| * ``K, S, E = lqr(Y, U, m)`` | ||
| * ``H = markov(response)`` | ||
| * ``H = markov(respnose, m)`` | ||
| * ``H = markov(Y, U)`` | ||
| * ``H = markov(Y, U, m)`` | ||
|
|
||
| where `response` is an `TimeResponseData` object, and `Y`, `U`, are 1D or 2D | ||
| array and m is an integer. | ||
|
|
@@ -446,26 +446,20 @@ def markov(*args, **kwargs): | |
| Number of Markov parameters to output. Defaults to len(U). | ||
| dt : True of float, optional | ||
| True indicates discrete time with unspecified sampling time, | ||
| positive number is discrete time with specified sampling time. | ||
| It can be used to scale the markov parameters in order to match | ||
| the impulse response of this library. | ||
| Default values is True. | ||
| positive number is discrete time with specified sampling time.It | ||
| can be used to scale the markov parameters in order to match the | ||
| impulse response of this library. Default is True. | ||
| truncate : bool, optional | ||
| Do not use first m equation for least least squares. | ||
| Default value is False. | ||
| Do not use first m equation for least least squares. Default is False. | ||
| transpose : bool, optional | ||
| Assume that input data is transposed relative to the standard | ||
| :ref:`time-series-convention`. For TimeResponseData this parameter | ||
| is ignored. Default is False. | ||
|
|
||
| Returns | ||
| ------- | ||
| H : ndarray | ||
| First m Markov parameters, [D CB CAB ...] | ||
|
|
||
|
|
||
| Notes | ||
| ----- | ||
| It works for SISO and MIMO systems. | ||
|
|
||
| This function does comply with the Python Control Library | ||
| :ref:`time-series-convention` for representation of time series data. | ||
|
|
||
| References | ||
| ---------- | ||
|
|
@@ -494,25 +488,21 @@ def markov(*args, **kwargs): | |
| transpose = args[0].transpose | ||
| if args[0].transpose and not args[0].issiso: | ||
| Umat, Ymat = np.transpose(Umat), np.transpose(Ymat) | ||
| index = 1 | ||
| if (len(args) == 2): | ||
| m = args[1] | ||
| elif (len(args) > 2): | ||
| raise ControlArgument("too many positional arguments") | ||
| else: | ||
| if (len(args) < 2): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK to remove parens (here and below).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| raise ControlArgument("not enough input arguments") | ||
| Umat = np.array(args[0], ndmin=2) | ||
| Ymat = np.array(args[1], ndmin=2) | ||
| transpose = kwargs.pop('transpose', False) | ||
| Umat = np.array(args[1], ndmin=2) | ||
| Ymat = np.array(args[0], ndmin=2) | ||
| if transpose: | ||
| Umat, Ymat = np.transpose(Umat), np.transpose(Ymat) | ||
| index = 2 | ||
|
|
||
|
|
||
| if (len(args) > index): | ||
| m = args[index] | ||
| else: | ||
| m = None | ||
|
|
||
| dt = kwargs.pop('dt', True) | ||
| truncate = kwargs.pop('truncate', False) | ||
| if (len(args) == 3): | ||
| m = args[2] | ||
| elif (len(args) > 3): | ||
| raise ControlArgument("too many positional arguments") | ||
|
|
||
| # Make sure the number of time points match | ||
| if Umat.shape[1] != Ymat.shape[1]: | ||
|
|
||
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
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.
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.
Markov should be capitalized.
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.
Done.