Skip to content
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

feat: add prescale(sys::StateSpace) and corresponding test. #464

Merged
merged 3 commits into from
Apr 2, 2021

Conversation

tfoliva
Copy link
Contributor

@tfoliva tfoliva commented Apr 1, 2021

Adds a prescale function as mentioned in #462

test/test_matrix_comps.jl Outdated Show resolved Hide resolved
Copy link
Contributor Author

@tfoliva tfoliva left a comment

Choose a reason for hiding this comment

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

Fixes the isdiag test

@tfoliva
Copy link
Contributor Author

tfoliva commented Apr 1, 2021

I noticed that somehow the test_matrix_comps file does not recognize the change I made to matrix_comps when defining the new function prescale. I got the same behavior locally at my machine, It seems that the tests import the official ControlSystems package version from the Julia registry. How can I perform the tests considering the changes I made?

@baggepinnen
Copy link
Member

You have forgotten to export the name of the new function, that's why it's not found in the tests. Where does the name come from? Is it a standard name?

Copy link
Contributor Author

@tfoliva tfoliva left a comment

Choose a reason for hiding this comment

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

exported previously written functions

@tfoliva
Copy link
Contributor Author

tfoliva commented Apr 2, 2021

You have forgotten to export the name of the new function, that's why it's not found in the tests. Where does the name come from? Is it a standard name?

Now I have exported the function. As for the name: I saw it was already used in MATLAB and GNU Octave's Control toolbox. Also Python-control lists a function with the same name in a sort of "to-do list" of MATLAB vs. Python-control compatibility.

On the other hand, I am also working on canon function to decompose a state space model in its canonical forms (diagonal, controlable and observable) and the diagonal form would eventually overcome the need for the prescale function.

However, the prescale function seems to be called on lots of other functions in the aforementioned control libraries due to the fact that it returns a numerically robust representation of the system. I think here, it could have a similar role perhaps.

@codecov
Copy link

codecov bot commented Apr 2, 2021

Codecov Report

Merging #464 (4139f2d) into master (6dcb3d8) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #464      +/-   ##
==========================================
+ Coverage   85.17%   85.20%   +0.02%     
==========================================
  Files          31       31              
  Lines        3096     3102       +6     
==========================================
+ Hits         2637     2643       +6     
  Misses        459      459              
Impacted Files Coverage Δ
src/ControlSystems.jl 100.00% <ø> (ø)
src/matrix_comps.jl 87.93% <100.00%> (+0.33%) ⬆️
src/types/Lti.jl 54.54% <0.00%> (-1.02%) ⬇️
src/types/DelayLtiSystem.jl 73.68% <0.00%> (-0.28%) ⬇️
src/utilities.jl 83.67% <0.00%> (-0.17%) ⬇️
src/connections.jl 94.28% <0.00%> (-0.04%) ⬇️
src/types/conversion.jl 96.92% <0.00%> (-0.03%) ⬇️
src/synthesis.jl 65.11% <0.00%> (ø)
src/types/StateSpace.jl 92.34% <0.00%> (+0.03%) ⬆️
src/types/tf.jl 96.15% <0.00%> (+0.07%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dcb3d8...4139f2d. Read the comment docs.

@baggepinnen
Copy link
Member

Alright great! I'm not sure why the doc tests are failing, the output looks correct to me. In either case, the failures are unrelated to this PR

@baggepinnen baggepinnen merged commit 25df9fe into JuliaControl:master Apr 2, 2021
A = Diagonal(d)
B = S\sys.B
C = sys.C*S
normalized_sys = iscontinuous(sys) ? ss(A, B, C, sys.D) : ss(A, B, C, sys.D, sys.Ts)
Copy link
Member

@mfalt mfalt Apr 2, 2021

Choose a reason for hiding this comment

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

StateSpace(A,B,C,sys.C,sys.timeevol) would have been an approach that avoid the conditional here. We should probably also extend it to AbstractStateSpace, but there is a separate issue for that.

@olof3
Copy link
Contributor

olof3 commented Apr 3, 2021

Now I have exported the function. As for the name: I saw it was already used in MATLAB and GNU Octave's Control toolbox. Also Python-control lists a function with the same name in a sort of "to-do list" of MATLAB vs. Python-control compatibility.

The function prescale implemented in this PR does not seem to do the same thing as the Matlab function with the same name? E.g., prescale on a random system in Matlab does not give me a system with a diagonal A matrix.

I think the issue in #462 was that similarity_transform was broken, that would have been good to fix.

On the other hand, I am also working on canon function to decompose a state space model in its canonical forms (diagonal, controlable and observable) and the diagonal form would eventually overcome the need for the prescale function.

Something like this could occasionally be useful though.

@tfoliva
Copy link
Contributor Author

tfoliva commented Apr 3, 2021

The function prescale implemented in this PR does not seem to do the same thing as the Matlab function with the same name? E.g., prescale on a random system in Matlab does not give me a system with a diagonal A matrix.

It has been a long time since I don't use MATLAB, so I did not check if it returned a diagonal matrix. The name was taken as inspiration but it could be changed.

The idea behind the prescale function here was to take a badly conditioned system and transform it to diagonal canonical form which is more numerically robust. Which it does in fact do.

For the naming part, when the canon function is ready it could be called with a 'diagonal' option which would do the same thing as the prescale function and thus the latter function could be deleted.

@tfoliva
Copy link
Contributor Author

tfoliva commented Apr 3, 2021

I will look deeper into what prescale actually does in this other packages. Apparently as @olof3 said MATLAB uses a different scaling procedure, so I will try to find which one.

@baggepinnen
Copy link
Member

Bump, is the current version of prescale something we'd like to keep for v1.0? It produces complex-coefficient systems in general, which is probably not what most people want?

@baggepinnen baggepinnen mentioned this pull request Jan 26, 2022
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