question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StateSpace constructor should not call _remove_useless_states

See original GitHub issue

State space representations should, in my opinion, not be reduced automatically with StateSpace._remove_useless_states(), similar to the fact that we don’t call minreal() automatically.

Unlike transfer functions, state space models can model non-observable or non-controllable behaviour, and cannot always be considered equivalent to their minimized form. Additionally, it is rather confusing to have ss(A,B,C,D).A !== A and e.g. ss(A,B,C,D).sample(T).A !== expm(A*T). For a more object-oriented interface, it would also be great to have member functions like stateSpace.isControllable(), which do not make sense if the system has already been minimized.

To give an example: The autonomous system x’=0, y=x is a signal model for the constant output y=x(0). It is not equivalent to the system y=0 if you consider the initial response for x(0) !== 0.

​import control
print(control.__version__)
print(control.ss(0,0,1,0)) # expected: A,B,C,D unchanged from input
print(control.ss(0,0,1,0).sample(1)) # expected: ss(1,0,1,0, dt=1)

output:

0.8.0

A = []
B = []
C = []
D = [[0]]

A = []
B = []
C = []
D = [[0]]
dt = 1

Is there a reason for the current behavior, or would it be okay to change it?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
murrayrmcommented, Jan 15, 2021

Found something unexpected in the way that the feedback function was implemented: if you pass a constant as one of the arguments for feedback (eg, feedback(P*C, 1)) then the constant was being converted to a state space system with a single state and B=0, C=0. This gives the right input/output response, but created an unobservable/uncontrollable (= “useless”) state. This generated a half dozen or so errors when I switched remove_useless_states to False since systems had an “extra” state.

By changing the statesp._convert_to_state_space function to create a state space with no state (A = []) the problem went away and all but one unit test passed. That unit test was explicitly testing that useless states were removed, so had to pass remove_useless_states=True to make that happen.

With that fix, everything appears to work. PR coming as soon as I confirm via CI.

0reactions
murrayrmcommented, Jan 18, 2021

Fixed in #509.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CA2214: Do not call overridable methods in constructors
When a constructor calls a virtual method, it's possible that the constructor for the instance that invokes the method has not executed. This ......
Read more >
Constructor should generally not call methods
In C++ a constructor must beware when calling a virtual function, in that the actual function it is calling is the class implementation....
Read more >
Why it is not a good idea to call Set method from constructor?
It is very true. Because setters are always public methods. And if you class is not final then there is issue of alien...
Read more >
MATLAB createPlanningTemplate - MathWorks
Set a default value for the state space if one is not provided. Call the constructor of the base class. Initialize any other...
Read more >
Constructors should only call non-overridable methods
Calling an overridable method from a constructor could result in failures or ... in Parent constructor which triggers a NullPointerException as foo has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found