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

#934 - Add exact projection method #935

Merged
merged 5 commits into from Dec 11, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/Approximations/decompositions.jl
Expand Up @@ -217,7 +217,7 @@ julia> [typeof(ai) for ai in array(decompose(S, block_types=bt, ε=0.01))]
```
"""
function decompose(S::LazySet{N};
set_type::Type{<:Union{HPolygon, Hyperrectangle, Interval}}=Hyperrectangle,
set_type::Type{<:Union{HPolygon, Hyperrectangle, Interval, LinearMap}}=Hyperrectangle,
ε::Real=Inf,
blocks::AbstractVector{Int}=default_block_structure(S, set_type),
block_types=Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(),
Expand All @@ -226,9 +226,15 @@ function decompose(S::LazySet{N};
n = dim(S)
result = Vector{LazySet{N}}()

if directions != nothing
if set_type == LinearMap
block_start = 1
@inbounds for bi in blocks
push!(result, project(S, block_start:(block_start + bi - 1), n))
block_start += bi
end
elseif directions != nothing
schillic marked this conversation as resolved.
Show resolved Hide resolved
# template directions
# potentially defined option set_type is *ignored*
# potentially defined option set_type is *ignored*
block_start = 1
@inbounds for bi in blocks
push!(result, project(S, block_start:(block_start + bi - 1), directions(bi), n))
Expand Down Expand Up @@ -268,6 +274,7 @@ function decompose(S::LazySet{N};
return CartesianProductArray(result)
end


"""
project(S::LazySet{N},
block::AbstractVector{Int},
Expand Down Expand Up @@ -442,3 +449,29 @@ The template direction approximation of the projection of `S`.
M = sparse(1:length(block), block, ones(N, length(block)), length(block), n)
return overapproximate(M * S, directions)
end

"""
project(S::LazySet{N},
block::AbstractVector{Int},
n::Int
)::LinearMap where {N<:Real}

Project a high-dimensional set to a low-dimensional set.
schillic marked this conversation as resolved.
Show resolved Hide resolved

### Input

- `S` -- set
- `block` -- block structure - a vector with the dimensions of interest
- `n` -- (optional, default: `dim(S)`) ambient dimension of the set `S`

### Output

The lazy linear map of the projection of `S`.
"""
schillic marked this conversation as resolved.
Show resolved Hide resolved
@inline function project(S::LazySet{N},
schillic marked this conversation as resolved.
Show resolved Hide resolved
block::AbstractVector{Int},
n::Int=dim(S)
)::LinearMap where {N<:Real}
M = sparse(1:length(block), block, ones(N, length(block)), length(block), n)
return M * S
end