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

Addressing #84 and #85#91

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 3 commits intopython-control:masterfrommp4096:master
May 30, 2016
Merged

Addressing #84 and #85#91

murrayrm merged 3 commits intopython-control:masterfrommp4096:master
May 30, 2016

Conversation

mp4096
Copy link
Contributor

  • Compute poles of a state-space system usingnumpy.linalg.eigvals as suggested inCalculate poles more smarter for state-space systems #84
  • Replaced matrix inversion in the feedback computation bynumpy.linalg.solve as suggested inAvoid using inv when not necessary #85
  • Also replaced the singularity check with a more stable one.numpy.linalg.matrix_rank uses a reasonable numerical threshold, so that we don't need to checkabs(det(F)) by hand. Determinant is actually very sensitive to matrix scaling, so better not use it. Both the determinant and the SVD required formatrix_rank are cubic, so there should be no slowdown.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 74.042% when pulling6aee194 on mp4096:master into0b26e06 on python-control:master.

@mp4096
Copy link
ContributorAuthor

Travis fails exactly at thesame test asmaster, also see#70

@pmli
Copy link

Kudos for findingabs(det(F)). Determinant gives no information about the distance to singularity, therefore it cannot be used to numerically check for singularity. SVD is definitely much better. But, wouldn't it be even better to drop the singularity check and trustnumpy.linalg.solve to raiseLinAlgError if singularity is detected? Do you have a use case whennumpy.linalg.matrix_rank detects singularity, butnumpy.linalg.solve doesn't?

@mp4096
Copy link
ContributorAuthor

Thanks for the hint. Indeed, an additional SVD seems to be superfluous. However, it can be really helpful.

Consider this code:

importnumpyasnpimportmatplotlib.pyplotaspltmatrix_size=3forspreadin [5,10,20]:A1=np.random.rand(matrix_size,matrix_size)A2=np.diag(np.logspace(-spread,+spread,matrix_size))A3=np.random.rand(matrix_size,matrix_size)A=A1@A2@A3invA_A=np.linalg.solve(A,A)message="Matrix size: {:d}, matrix rank: {:d}"print(message.format(matrix_size,np.linalg.matrix_rank(A)))# Should be an identity matrixplt.figure()plt.imshow(np.log10(np.absolute(invA_A)),interpolation="none")plt.colorbar()

So instead of raising an exception,numpy.linalg.solve just returns some numerical garbage. The problem is,numpy.linalg.solve relies on LAPACK'sDGESV, which in turn callsDGETRF to perform an LUP decomposition.DGETRF raises an exception only if a diagonal element isexactly zero:

INFO is INTEGER= 0:  successful exit< 0:  if INFO = -i, the i-th argument had an illegal value> 0:  if INFO = i, U(i,i) is exactly zero. The factorization    has been completed, but the factor U is exactly    singular, and division by zero will occur if it is used    to solve a system of equations.

Hence, numerical rank loss cannot be detected innumpy.linalg.solve

@pmli
Copy link

Thanks for the detailed explanation. I assumed NumPy/SciPy would emulate Matlab with its warnings about large condition numbers, usingDGESVX. At least, there is an openNumPy issue concerning exactly this, although it is quite old. Until it is closed, I don't see a way to cheaply estimate the condition number in NumPy which could replace SVD.

@mp4096
Copy link
ContributorAuthor

Oh, I didn't knew about this issue, thanks! But it doesn't seem they're going to do anything about this behaviour.

Anyway, most technical systems have very few (in terms of linear algebra 😉) inputs/outputs. I think this additional SVD-based rank check will makes things slower only if there are at least 1000 inputs/outputs (we're invertingD here).

@murrayrmmurrayrm merged commit6dfd5a5 intopython-control:masterMay 30, 2016
@mp4096
Copy link
ContributorAuthor

Thank you! I think one can close#84 and#85 now.

slivingston added a commit that referenced this pull requestDec 31, 2016
#101Changes are from branch `master` ofhttps://github.com/mp4096/python-control.gitThere was merge conflict in how a for-loop was refactored into`map` (here) vs. list comprehension (from PR#110).I compared the two alternatives using %timeit of Jupyter for matricesthat would correspond to LTI systems with 10 state dimensions, 2inputs, 2 outputs (so, the A matrix has shape (10, 10), B matrix hasshape (10,2), etc.), and with 100 state dimensions, 20 inputs,20 outputs, all using matrices from numpy.random.random((r,c)).The difference in timing performance does not appearsignificant. However, the case of `map` was slightly faster(approximately 500 to 900 ns less in duration), so I decided to usethat one to resolve the merge conflict.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@mp4096@coveralls@pmli@murrayrm

[8]ページ先頭

©2009-2025 Movatter.jp