-
Notifications
You must be signed in to change notification settings - Fork 9
/
as.jl
27 lines (24 loc) · 1.27 KB
/
as.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
ActiveSubspace{T<:Real} <: DimensionReducer
Q :: Function
∇Q :: Function (gradient of Q)
tol :: T
Use the theory of active subspaces, with a given quantity of interest (expressed as the function Q) which takes a Configuration as an input and outputs a real scalar. ∇Q should input a Configuration and output an appropriate gradient.
If tol is a float then the number of components to keep is determined by the smallest n such that relative percentage of variance explained by keeping the leading n principle components is greater than 1 - tol. If tol is an int, then we return the components corresponding to the tol largest eigenvalues.
"""
struct ActiveSubspace{T<:Real} <: DimensionReducer
Q::Function
∇Q::Function
tol::T
end
function ActiveSubspace(Q::Function, ∇Q::Function; tol = 0.01)
ActiveSubspace(Q, ∇Q, tol)
end
"""
fit(ds::DataSet, as::ActiveSubspace)
Fits a linear dimension reduction routine using the eigendirections of the uncentered covariance of the function ∇Q(c::Configuration) over the configurations in ds. Primarily used to reduce the dimension of the descriptors.
"""
function fit(ds::DataSet, as::ActiveSubspace)
d = [as.∇Q(c) for c in ds]
λ, W = select_eigendirections(d, as.tol)
end