Skip to content

Updates to balred() and gram() #118

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
merged 2 commits into from
Jan 20, 2017
Merged

Updates to balred() and gram() #118

merged 2 commits into from
Jan 20, 2017

Conversation

mdclemen
Copy link
Contributor

balred() now supports "matchdc" and will handle unstable systems and will accept a list of ORDERS, which will return a list of reduced order systems. gram() now does Cholesky factored gramians if desired. Requires my updates to slycot.

@coveralls
Copy link

coveralls commented Dec 25, 2016

Coverage Status

Coverage decreased (-0.2%) to 75.797% when pulling f2bdde4 on mdclemen:master into cdd3e73 on python-control:master.

@slivingston slivingston self-assigned this Dec 26, 2016
@@ -347,6 +347,9 @@ def gram(sys,type):
#Check for ss system object
if not isinstance(sys,statesp.StateSpace):
raise ValueError("System must be StateSpace!")
gramtypes = ['c', 'o', 'cf', 'of']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you declare gramtypes as a variable? It only appears to be used in the conditional expression on the next line, so the motivation for allocating a variable with function-level scope is not apparent to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really remember, I wrote that function a few months ago. If you think there is a better way to do things, then by all means change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reason that I gave above, moving the list into the conditional expression improves code quality, and thus, I recommend the change. However, it is not critical for accepting this pull request.

Just to be clear, I am belatedly providing review of your proposed changes now.

@@ -50,7 +50,7 @@
from .statesp import StateSpace
from .statefbk import gram

__all__ = ['hsvd', 'balred', 'modred', 'era', 'markov', 'minreal']
__all__ = ['hsvd', 'balred', 'modred', 'era', 'markov', 'minreal',]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add a trailing , in this list expression? It is not a syntax error, but it is not consistent with the current style of the control package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to delete the trailing ','.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you delete it, then? I am writing additional comments now, so you might want to wait before rebasing until I send them all.

@slivingston
Copy link
Member

In the first commit (cc4b5c7) of this pull request, the message and author are incorrectly copied from cdd3e73. When I skim the diff, it appears that you applied changes as part of your own work, but then, those were combined with the patch corresponding to commit cdd3e73. Can you clean it up, in particular remove the re-applied pieces of commit cdd3e73?

@slivingston
Copy link
Member

It appears that substantial amounts of code are added in the first commit and then deleted or modified in the second. Can you add details in the commit messages to explain this transition? Alternatively, can you squash changes into a single commit?

Those are all of my questions and requests for now. I will wait until you respond or rebase before continuing to review.

@mdclemen
Copy link
Contributor Author

mdclemen commented Jan 3, 2017

I made changes to the code that you recommended, but my git skills might not be good enough for the other things you want me to do.

@slivingston
Copy link
Member

@mdclemen Can I have your permission to create a commit that has your changes from this PR and lists you as author (and me as committer)? This way I can make the rebasing adjustments that I requested above. If I do this, how do you prefer your name to be written? E.g., I can use "clementm" as in your commit f74e665, or your name as it appears in your publications.

Alternatively, we can arrange to meet in IRC to work through the rebase process together.

… will accept a list of 'orders'. gram() now does Cholesky factored gramians if desired. Requires slycot routines AB09MD, AB09ND, SB03OD.
@@ -211,26 +218,46 @@ def balred(sys, orders, method='truncate'):
of systems)
method: string
Method of removing states, either ``'truncate'`` or ``'matchdc'``.
alpha: float
Specifies the alpha-stability boundary for the eigenvalues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text description of alpha appears to be copied from AB09MD.f of the SLICOT source code. Is that true? SLICOT is under the GNU GPL, whereas we want to keep this control package under the BSD license.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the text was indeed copied, can you create a new description of the alpha parameter? An easy solution for now is to write a brief summary and indicate where more information can be found (the documentation of SLICOT).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original text from SLICOT to which I am referring is in lines 89-96 of AB09MD.f

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did in fact copy the description of alpha from AB09MD.f.

"""
Balanced reduced order model of sys of a given order.
States are eliminated based on Hankel singular value.
If sys has unstable modes, they are removed, the
balanced realization is done on the stable part, then
reinserted IAW reference below.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "IAW"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you write "in accordance with" explicitly? The abbreviation might not be widely recognized.

I can also make the change after merging.

@mdclemen
Copy link
Contributor Author

mdclemen commented Jan 18, 2017 via email

@slivingston
Copy link
Member

I resolved the merge conflicts, but before I apply them here, can you first address my question about the description of the alpha parameter?

@slivingston
Copy link
Member

Should we keep the original call to AB09AD when the system is stable? Otherwise (if method='truncate' and the system is not stable), your newly introduced call to AB09MD is used.

The Fortran implementations of these two subroutines are different, so I am motivated to understand them more before removing the one dedicated to the case of stable systems.

@slivingston
Copy link
Member

slivingston commented Jan 18, 2017

After we decide actions regarding AB09AD and the description of the alpha parameter, then this PR will be ready for merging. Thanks for your good work on the gram and balred functions!

@mdclemen
Copy link
Contributor Author

I don't know why the SLICOT authors decided to include a user defined boundary for what constitutes unstable eigenvalues but essentially alpha allows the user to redefine the boundary for a stable eigenvalue.

…ibe `alpha`. In balred(), if method='truncate' and the system is stable, slycot ab09ab is used, otherwise ab09md is used.
@mdclemen
Copy link
Contributor Author

@slivingston let me know what you think of my updates.

By default for continuous-time systems, alpha <= 0 defines the stability
boundary for the real part of A's eigenvalues and for discrete-time
systems, 0 <= alpha <= 1 defines the stability boundary for the modulus
of A's eigenvalues.See SLICOT routines AB09MD and AB09ND for more
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While resolving the merge conflict, I added a space here after the .. So, now it reads "...eigenvalues. See SLICOT...".

@slivingston
Copy link
Member

Your updates are good. Thanks for addressing my comments.

@slivingston slivingston merged commit 4815cf0 into python-control:master Jan 20, 2017
slivingston added a commit that referenced this pull request Jan 20, 2017
slivingston added a commit that referenced this pull request Feb 14, 2017
testBalredMatchDC, testGramRc, testGramRo
which were introduced in PR #118
use functions that depend on Slycot,
so the tests should be skipped if it is not found.
slivingston added a commit that referenced this pull request Feb 17, 2017
testBalredMatchDC, testGramRc, testGramRo
which were introduced in PR #118
use functions that depend on Slycot,
so the tests should be skipped if it is not found.
@murrayrm murrayrm added this to the 0.8.0 milestone Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants