Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow np.array or np.matrix for state space matrices, operations#314

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
murrayrm merged 4 commits intopython-control:masterfrommurrayrm:ss_matrix
Jun 30, 2019

Conversation

murrayrm
Copy link
Member

This PR addresses issue#233 regarding (eventual) deprecation of thenumpy.matrix class. In this PR, state space objects are stored as eithernumpy.matrix (default) ornumpy.array objects, with the selection determined based on theuse_numpy_array() function.

For backward compatibility, thenumpy.matrix class is the current default, but all operations are compatible with usingnumpy.array as the default storage and output class and this will be the default whennumpy.matrix is deprecated.

A set of unit tests is also included for testing basic operations when thenumpy.array class is used as the state space storage and output class. This PR does not convert all of the existing unit tests to usenumpy.array instead ofnumpy.matrix, so there are still lots of warning messages. At some point we will need to update all unit tests to work withnumpy.array objects (as we as done in abandoned PR#292).

@coveralls
Copy link

coveralls commentedJun 15, 2019
edited
Loading

Coverage Status

Coverage increased (+0.06%) to 82.173% when pulling7c9d9a6 on murrayrm:ss_matrix intoe2346cd on python-control:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 82.179% when pulling0c1e983 on murrayrm:ss_matrix intoe2346cd on python-control:master.

>>> sys = append(sys1, sys2)
>>> Q =sp.mat([ [1, 2], [2, -1]])# basically feedback, output 2 in 1
>>> Q =[[1, 2], [2, -1]]) # negative feedback interconnection
Copy link
Contributor

Choose a reason for hiding this comment

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

trailing parenthesis here looks wrong. Do we run these with doctest?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed.

We are not currently using doctest, but I ran the revised version manually to make sure it was OK.

eye(self.inputs))
eye(self.inputs)
+ np.dot(other.fresp[:, :, k], self.fresp[:, :, k]),
eye(self.inputs))
Copy link
Contributor

@roryyorkeroryyorkeJun 16, 2019
edited
Loading

Choose a reason for hiding this comment

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

I know this is not the point of this change, but islinalg(X, eye(shape)) any better thannp.linalg.inv? I'd have thought a "right divide" (linalg.solve with appropriate transposes) would have been a more standard approach.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I agree that this could usesp.linalg.solve instead, but since I wasn't the original author I just did the conversion to remove thenp.matrix dependence. I've added a TODO for someone to fix this, so at least we don't forget about it (in principle).

@@ -41,16 +41,17 @@
Author: Bjorn Olofsson
"""

from scipy import shape, size,asarray, asmatrix, copy, zeros, eye, dot
from scipy import shape, size,array, asarray, copy, zeros, eye, dot
Copy link
Contributor

Choose a reason for hiding this comment

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

again not the point, but since you removeimport scipy as sp, I think this should befrom numpy import ...

@@ -69,7 +70,9 @@ def lyap(A,Q,C=None,E=None):
:math:`A X E^T + E X A^T + Q = 0`

where Q is a symmetric matrix and A, Q and E are square matrices
of the same dimension. """
of the same dimension.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not super-familiar with PEP8 and so on, but this extra blank line seems odd.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@@ -252,13 +253,13 @@ def acker(A, B, poles):

# Place the poles using Ackermann's method
n = np.size(p)
pmat = p[n-1]*a**0
pmat = p[n-1] * np.linalg.matrix_power(a, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

np.eye(a.shape) ? I suppose thematrix_power call sets the stage for the upcoming for-loop.

for i in np.arange(1,n):
pmat = pmat + p[n-i-1]*a**i
pmat = pmat +np.dot(p[n-i-1], np.linalg.matrix_power(a, i))
Copy link
Contributor

Choose a reason for hiding this comment

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

Again somewhat beside the point of this commit, but would it be possible to use Horner's method here?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Added a TODO for someone to do this in a separate PR.

@murrayrm
Copy link
MemberAuthor

CI tests are failing due to issue#321. Need to fix before merging.

@murrayrmmurrayrm merged commitde9e3e7 intopython-control:masterJun 30, 2019
@murrayrmmurrayrm deleted the ss_matrix branchJuly 1, 2019 05:20
@murrayrmmurrayrm added this to the0.8.3 milestoneJan 4, 2020
murrayrm pushed a commit that referenced this pull requestJan 5, 2020
PR#314 duplicates a lot of code in the test cases by introducing *_array_test.py files. Thus issue#190 addressed in PR#320 resurfaces and needs to be introduced to robust_array_test.pyas well.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@roryyorkeroryyorkeroryyorke left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
0.8.3
Development

Successfully merging this pull request may close these issues.

3 participants
@murrayrm@coveralls@roryyorke

[8]ページ先頭

©2009-2025 Movatter.jp