-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix crashes in Schur transformation #689
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
export transform | ||
using LinearAlgebra | ||
|
||
export transform, | ||
backtransform | ||
|
||
""" | ||
backtransform(Rsets::ReachSolution, options::Options) | ||
|
||
Undo a coordinate transformation. | ||
|
||
### Input | ||
|
||
- `Rsets` -- flowpipe | ||
- `option` -- problem options containing an `:transformation_matrix` entry | ||
|
||
### Output | ||
|
||
A new flowpipe where each reach set has been transformed. | ||
|
||
### Notes | ||
|
||
The transformation is implemented with a lazy `LinearMap`. | ||
""" | ||
function backtransform(Rsets, options::Options) | ||
transformation_matrix = options[:transformation_matrix] | ||
if transformation_matrix == nothing | ||
return Rsets | ||
end | ||
return project(Rsets, transformation_matrix) | ||
end | ||
|
||
""" | ||
transform(problem::InitialValueProblem, options::Options) | ||
|
@@ -25,8 +54,8 @@ function transform(problem::InitialValueProblem, options::Options) | |
if method == "" | ||
nothing # no-op | ||
elseif method == "schur" | ||
options[:transformation_matrix] = Tm | ||
problem = schur_transform(problem) | ||
problem, T_inverse = schur_transform(problem) | ||
options[:transformation_matrix] = T_inverse | ||
else | ||
error("the transformation method $method is undefined") | ||
end | ||
|
@@ -40,7 +69,7 @@ Applies a Schur transformation to a discrete or continuous initial-value problem | |
|
||
### Input | ||
|
||
- `S` -- discrete or continuous initial-value problem | ||
- `problem` -- discrete or continuous initial-value problem | ||
|
||
### Output | ||
|
||
|
@@ -58,19 +87,26 @@ function schur_transform(problem::InitialValueProblem{PT, ST} | |
n = size(problem.s.A, 1) | ||
|
||
# full (dense) matrix is required by schur | ||
A_new, T_new = schur(Matrix(problem.s.A)) | ||
# result S is a struct such that | ||
# - S.Schur is in Schur form and | ||
# - A == S.vectors * S.Schur * S.vectors' | ||
S = schur(Matrix(problem.s.A)) | ||
|
||
# recall that for Schur matrices, inv(T) == T' | ||
Z_inverse = copy(transpose(T_new)) | ||
Z_inverse = copy(transpose(S.vectors)) | ||
|
||
# obtain transformed system matrix | ||
A_new = S.Schur | ||
|
||
# apply transformation to the initial states | ||
X0_new = Z_inverse * problem.x0 | ||
|
||
# apply transformation to the inputs | ||
U_new = Z_inverse * problem.s.U | ||
B_new = Z_inverse * problem.s.B | ||
U_new = problem.s.U | ||
|
||
# obtain the transformation matrix for reverting the transformation again | ||
T_inverse = F[:vectors] | ||
# matrix for reverting the transformation again | ||
T_inverse = S.vectors | ||
|
||
# apply transformation to the invariant | ||
if hasmethod(stateset, Tuple{typeof(problem.s)}) | ||
|
@@ -79,6 +115,17 @@ function schur_transform(problem::InitialValueProblem{PT, ST} | |
invariant_new = Universe(n) | ||
end | ||
|
||
system_new = (A_new, I(n), invariant_new, U_new) | ||
return InitialValueProblem(PT(system_new), X0_new) | ||
system_new = _wrap_system(PT, A_new, B_new, invariant_new, U_new) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The helper function |
||
problem_new = InitialValueProblem(system_new, X0_new) | ||
return problem_new, T_inverse | ||
end | ||
|
||
function _wrap_system(PT::Type{<:ConstrainedLinearControlDiscreteSystem}, | ||
A, B, invariant, U) | ||
return ConstrainedLinearControlDiscreteSystem(A, B, invariant, U) | ||
end | ||
|
||
function _wrap_system(PT::Type{<:ConstrainedLinearControlContinuousSystem}, | ||
A, B, invariant, U) | ||
return ConstrainedLinearControlContinuousSystem(A, B, invariant, U) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of
Rsets
should beReachSolution
, but that type is not available in this module because it is only defined later in theReachSets
module.