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

Fix and activate doctests; fix add_dimension #777

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MathematicalSystems = "d14a8603-c872-5ed3-9ece-53e0e82e39da"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

Expand All @@ -21,5 +22,6 @@ JLD2 = "0.4"
LaTeXStrings = "1"
LazySets = "2"
Literate = "2"
MathematicalSystems = "0.11 - 0.13"
Plots = "1"
Symbolics = "5"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ makedocs(;
assets=["assets/aligned.css"]),
sitename="ReachabilityAnalysis.jl",
modules=[ReachabilityAnalysis],
doctest=false,
#doctest=false,
pagesonly=true,
pages=["Overview" => "index.md",
"Tutorials" => vcat(SET_REPRESENTATIONS,
Expand Down
52 changes: 27 additions & 25 deletions src/Continuous/normalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ Append one or more zero rows and columns to a matrix.

```jldoctest add_dimension_test
julia> A = [0.4 0.25; 0.46 -0.67]
2×2 Array{Float64,2}:
2×2 Matrix{Float64}:
0.4 0.25
0.46 -0.67

julia> add_dimension(A)
3×3 Array{Float64,2}:
julia> ReachabilityAnalysis.add_dimension(A)
Copy link
Member

Choose a reason for hiding this comment

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

tip: one can use ````jldoctest; setup=:(using ReachabilityAnalysis: add_dimension)` just once and remove the module prefixes below too

3×3 Matrix{Float64}:
0.4 0.25 0.0
0.46 -0.67 0.0
0.0 0.0 0.0
```
To append more than one zero row-column, use the second argument `m`:

```jldoctest add_dimension_test
julia> add_dimension(A, 2)
4×4 Array{Float64,2}:
julia> ReachabilityAnalysis.add_dimension(A, 2)
4×4 Matrix{Float64}:
0.4 0.25 0.0 0.0
0.46 -0.67 0.0 0.0
0.0 0.0 0.0 0.0
Expand Down Expand Up @@ -101,14 +101,14 @@ julia> X = BallInf(ones(9), 0.5);
julia> dim(X)
9

julia> Xext = add_dimension(X);
julia> Xext = ReachabilityAnalysis.add_dimension(X);

julia> dim(Xext)
10

julia> X = ZeroSet(4);

julia> dim(add_dimension(X))
julia> dim(ReachabilityAnalysis.add_dimension(X))
5

julia> typeof(X)
Expand All @@ -118,7 +118,7 @@ ZeroSet{Float64}
More than one dimension can be added passing the second argument:

```jldoctest add_dimension_set
julia> Xext = add_dimension(BallInf(zeros(10), 0.1), 4);
julia> Xext = ReachabilityAnalysis.add_dimension(BallInf(zeros(10), 0.1), 4);

julia> dim(Xext)
14
Expand All @@ -138,14 +138,14 @@ function add_dimension(X::ZeroSet, m=1)
end

"""
add_dimension(cs, m=1)
add_dimension(ivp::IVP, m=1)

Adds an extra dimension to a continuous system.
Adds an extra dimension to a initial-value system.

### Input

- `cs` -- continuous system
- `m` -- (optional, default: `1`) the number of extra dimensions
- `ivp` -- initial-value system
- `m` -- (optional, default: `1`) the number of extra dimensions

### Examples

Expand All @@ -158,7 +158,7 @@ julia> X0 = BallInf(zeros(3), 1.0);

julia> s = InitialValueProblem(LinearContinuousSystem(A), X0);

julia> sext = add_dimension(s);
julia> sext = ReachabilityAnalysis.add_dimension(s);

julia> statedim(sext)
4
Expand All @@ -167,16 +167,18 @@ julia> statedim(sext)
If there is an input set, it is also extended:

```jldoctest add_dimension_cont_sys
julia> using LinearAlgebra

julia> U = ConstantInput(Ball2(ones(3), 0.1));

julia> s = InitialValueProblem(ConstrainedLinearControlContinuousSystem(A, Matrix(1.0I, size(A)), nothing, U), X0);

julia> sext = add_dimension(s);
julia> sext = ReachabilityAnalysis.add_dimension(s);

julia> statedim(sext)
4

julia> dim(next_set(inputset(sext)))
julia> dim(ReachabilityAnalysis.next_set(inputset(sext)))
4
```

Expand All @@ -189,32 +191,32 @@ julia> U = VaryingInput([Ball2(ones(3), 0.1 * i) for i in 1:3]);

julia> s = InitialValueProblem(ConstrainedLinearControlContinuousSystem(A, Matrix(1.0I, size(A)), nothing, U), X0);

julia> sext = add_dimension(s);
julia> sext = ReachabilityAnalysis.add_dimension(s);

julia> statedim(sext)
4

julia> dim(next_set(inputset(sext), 1))
julia> dim(ReachabilityAnalysis.next_set(inputset(sext), 1))
4
```

Extending a varying input set with more than one extra dimension:
1] normalize(::AffineContinuousSystem{Float64,Array{Float64,2},Array{Float64,1}}) at /home/mforets/.julia/dev/ReachabilityAnalysis/src/Continuous/normalization.jl:387

```jldoctest add_dimension_cont_sys
julia> sext = add_dimension(s, 7);
julia> sext = ReachabilityAnalysis.add_dimension(s, 7);

julia> statedim(sext)
10

julia> dim(next_set(inputset(sext), 1))
julia> dim(ReachabilityAnalysis.next_set(inputset(sext), 1))
10
```
"""
function add_dimension(cs, m=1)
Aext = add_dimension(cs.s.A, m)
X0ext = add_dimension(cs.x0, m)
if hasmethod(inputset, Tuple{typeof(cs.s)})
Uext = map(x -> add_dimension(x, m), inputset(cs))
function add_dimension(ivp::IVP, m=1) # only correct for linear systems
Aext = add_dimension(ivp.s.A, m)
X0ext = add_dimension(ivp.x0, m)
if !isnothing(inputset(ivp))
Uext = map(x -> add_dimension(x, m), inputset(ivp))
s = CLCCS(Aext, Matrix(1.0I, size(Aext)), nothing, Uext)
else
s = LCS(Aext)
Expand Down
6 changes: 5 additions & 1 deletion src/Discretization/DiscretizationModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ in the docstring of each method. Here is a list of all the available approximati

```jldoctest
julia> subtypes(ReachabilityAnalysis.AbstractApproximationModel)
5-element Vector{Any}:
9-element Vector{Any}:
Backward
CorrectionHull
FirstOrder
FirstOrderZonotope
Forward
ForwardBackward
NoBloating
SecondOrderddt
StepIntersect
```

Expand Down
Loading