Skip to content

Restructure POD interface #25

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

Merged
merged 10 commits into from
Aug 9, 2022
Merged

Conversation

FHoltorf
Copy link
Contributor

@FHoltorf FHoltorf commented Aug 1, 2022

Hey,

I revisited some of the POD interface and realized there were a few problems:

First of all, the type specs in the POD type are problematic: For example, specifiying integer-valued data will error as the rel. energy and the reduced basis is then constrained to be integer-valued as well (obviously not generally true):

mutable struct POD{FT} <: AbstractDRProblem
    snapshots::Union{Vector{Vector{FT}}, Matrix{FT}}
    nmodes::Int
    rbasis::Matrix{FT}
    renergy::FT

Further, the interface did not accommodate a typical workflow for POD. Specifically, one often would like to reduce the dimensionality to capture a specified minimum relative energy (say 95%). Right now we require the dimension to be specified directly. So a user would effectively need to take the SVD of their data, look at the spectrum and decide on the cutoff, just to then take the svd all over again within ModelOrderReduction. I adjusted the POD type to also carry fields min_renergy, min_nmodes, max_nmodes, referring to the min relative energy captured as well as the minimum and maximum number of modes retained, respectively. I updated the reduction step accordingly to choose the reduction to be inline with these specifications. Moreover, I added a field spectrum that carries the singular spectrum (which is often of interest for a posterior analysis).

Lastly, I changed the reduce statement to dispatch directly on the type of the data to be reduced. Consequently, POD can be applied via this interface to any data set which admits computation of a singular value decomposition via the specified routine. That way, everything composes better with the greater ecosystem.

Let me know!
Flemming

Comment on lines 10 to 14
function svd(data::Vector{Vector{T}}) where {T}
mat_data = matricize(data)
return svd(mat_data)
end

Copy link
Member

Choose a reason for hiding this comment

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

Redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

absolutely

Comment on lines 10 to 12
import TSVD.tsvd
import RandomizedLinAlg.rsvd
import LinearAlgebra.svd
Copy link
Member

Choose a reason for hiding this comment

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

This makes it piracy because it's then adding a function on Base types. It would be safer to just shadow or define a _tsvd etc. inside of the package for the Vector{Vector} form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. Didn't think about that whatsoever. Should be fixed now.

@codecov
Copy link

codecov bot commented Aug 8, 2022

Codecov Report

Merging #25 (16198a8) into main (4910f4a) will increase coverage by 9.60%.
The diff coverage is 87.30%.

@@            Coverage Diff             @@
##             main      #25      +/-   ##
==========================================
+ Coverage   72.34%   81.94%   +9.60%     
==========================================
  Files           3        3              
  Lines          47       72      +25     
==========================================
+ Hits           34       59      +25     
  Misses         13       13              
Impacted Files Coverage Δ
src/DataReduction/POD.jl 75.92% <82.60%> (+8.42%) ⬆️
src/ErrorHandle.jl 100.00% <100.00%> (ø)
src/Types.jl 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@ChrisRackauckas
Copy link
Member

Other than the shadowing issue, I think this is good.

@ChrisRackauckas ChrisRackauckas merged commit a0b1ebe into SciML:main Aug 9, 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.

2 participants