Skip to content

Commit

Permalink
patch Grouped Transforms for Wavelets
Browse files Browse the repository at this point in the history
  • Loading branch information
mischmi96 committed Apr 20, 2022
1 parent f02b54e commit 079fb86
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 38 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.6]
julia-version: [1.7]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
Expand All @@ -24,6 +24,5 @@ jobs:
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
file: ./lcov.info
name: codecov-umbrella
if: ${{ matrix.julia-version == '1.6' && matrix.os =='ubuntu-latest' }}
if: ${{ matrix.julia-version == '1.7' && matrix.os =='ubuntu-latest' }}
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ANOVAapprox"
uuid = "5e027bd6-ab01-4733-8320-e0223e929ebb"
authors = ["Michael Schmischke <[email protected]> and Felix Bartel <[email protected]>"]
version = "1.1.5"
version = "1.1.6"

[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand All @@ -16,7 +16,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.5"
GroupedTransforms = "1.1.2"
GroupedTransforms = "1.1.4"
IterativeSolvers = "0.8, 0.9"
LinearMaps = "3"
SpecialFunctions = "1"
Expand Down
24 changes: 21 additions & 3 deletions src/ANOVAapprox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ module ANOVAapprox
using GroupedTransforms,
LinearAlgebra, IterativeSolvers, LinearMaps, Distributed, SpecialFunctions

bases = ["per", "cos", "cheb", "std" ,"wav1", "wav2", "wav3", "wav4"]
types = Dict("per" => ComplexF64, "cos" => Float64, "cheb" => Float64, "std" => Float64, "wav1" => Float64, "wav2" => Float64,"wav3" => Float64,"wav4" => Float64)
bases = ["per", "cos", "cheb", "std", "wav1", "wav2", "wav3", "wav4"]
types = Dict(
"per" => ComplexF64,
"cos" => Float64,
"cheb" => Float64,
"std" => Float64,
"wav1" => Float64,
"wav2" => Float64,
"wav3" => Float64,
"wav4" => Float64,
)
vtypes = Dict(
"per" => Vector{ComplexF64},
"cos" => Vector{Float64},
Expand All @@ -15,7 +24,16 @@ vtypes = Dict(
"wav3" => Vector{Float64},
"wav4" => Vector{Float64},
)
gt_systems = Dict("per" => "exp", "cos" => "cos", "cheb" => "cos", "std" => "cos", "wav1" => "wav1", "wav2" => "wav2", "wav3" => "wav3", "wav4" => "wav4")
gt_systems = Dict(
"per" => "exp",
"cos" => "cos",
"cheb" => "cos",
"std" => "cos",
"wav1" => "wav1",
"wav2" => "wav2",
"wav3" => "wav3",
"wav4" => "wav4",
)

function get_orderDependentBW(U::Vector{Vector{Int}}, N::Vector{Int})::Vector{Int}
N_bw = zeros(Int64, length(U))
Expand Down
36 changes: 18 additions & 18 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ function get_GSI(
dict::Bool = false,
)::Union{Vector{Float64},Dict{Vector{Int},Float64}}
if a.basis == "wav1"
variances = norms(a.fc[λ],1,dict=false) .^ 2
variances = norms(a.fc[λ], 1, dict = false) .^ 2
elseif a.basis == "wav2"
variances = norms(a.fc[λ],2,dict=false) .^ 2
variances = norms(a.fc[λ], 2, dict = false) .^ 2
elseif a.basis == "wav3"
variances = norms(a.fc[λ],3,dict=false) .^ 2
variances = norms(a.fc[λ], 3, dict = false) .^ 2
elseif a.basis == "wav4"
variances = norms(a.fc[λ],4,dict=false) .^ 2
variances = norms(a.fc[λ], 4, dict = false) .^ 2
else
variances = norms(a.fc[λ]) .^ 2
end
Expand All @@ -25,18 +25,18 @@ function get_GSI(
if dict
gsis = Dict{Vector{Int},Float64}()
if a.basis == "wav1"
variances = norms(a.fc[λ],1,dict=true)
variances = norms(a.fc[λ], 1, dict = true)
elseif a.basis == "wav2"
variances = norms(a.fc[λ],2,dict=true)
variances = norms(a.fc[λ], 2, dict = true)
elseif a.basis == "wav3"
variances = norms(a.fc[λ],3,dict=true)
variances = norms(a.fc[λ], 3, dict = true)
elseif a.basis == "wav4"
variances = norms(a.fc[λ],4,dict=true)
variances = norms(a.fc[λ], 4, dict = true)
else
variances = norms(a.fc[λ],dict = true)
variances = norms(a.fc[λ], dict = true)
end

return Dict((u,variances[u]^2/variance_f) for u in keys(variances))
return Dict((u, variances[u]^2 / variance_f) for u in keys(variances))

else
return variances ./ variance_f
Expand Down Expand Up @@ -64,7 +64,7 @@ function get_AttributeRanking(a::approx, λ::Float64)::Vector{Float64}
d = size(a.X, 1)
gsis = get_GSI(a, λ, dict = true)
U = collect(keys(gsis))
lengths = [ length(u) for u in U ]
lengths = [length(u) for u in U]
ds = maximum(lengths)

factors = zeros(Int64, d, ds)
Expand All @@ -73,7 +73,7 @@ function get_AttributeRanking(a::approx, λ::Float64)::Vector{Float64}
for j = 1:ds
for v in U
if (i in v) && (length(v) == j)
factors[i,j] += 1
factors[i, j] += 1
end
end
end
Expand All @@ -85,8 +85,8 @@ function get_AttributeRanking(a::approx, λ::Float64)::Vector{Float64}
for u in U
weights = 0.0
for s in u
r[s] += gsis[u] * 1/factors[s, length(u)]
weights += 1/factors[s, length(u)]
r[s] += gsis[u] * 1 / factors[s, length(u)]
weights += 1 / factors[s, length(u)]
end
nf += weights * gsis[u]
end
Expand All @@ -103,13 +103,13 @@ function get_AttributeRanking(a::approx)::Dict{Float64,Vector{Float64}}
return Dict=> get_AttributeRanking(a, λ) for λ in collect(keys(a.fc)))
end

function get_ActiveSet( a::approx, eps::Vector{Float64}, λ::Float64 )::Vector{Vector{Int}}
function get_ActiveSet(a::approx, eps::Vector{Float64}, λ::Float64)::Vector{Vector{Int}}
U = a.U[2:end]
lengths = [ length(u) for u in U ]
lengths = [length(u) for u in U]
ds = maximum(lengths)

if length(eps) != ds
error( "Entries in vector eps have to be ds.")
error("Entries in vector eps have to be ds.")
end

gsi = get_GSI(a, λ)
Expand All @@ -122,7 +122,7 @@ function get_ActiveSet( a::approx, eps::Vector{Float64}, λ::Float64 )::Vector{V
end
end

U_active = Vector{Vector{Int}}(undef, n+1)
U_active = Vector{Vector{Int}}(undef, n + 1)
U_active[1] = []
idx = 2

Expand Down
8 changes: 7 additions & 1 deletion src/approx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ mutable struct approx
bw = N
end

if (basis == "per" || basis == "wav1" || basis == "wav2" || basis == "wav3" || basis == "wav4" ) && ((minimum(X) < -0.5) || (maximum(X) >= 0.5))
if (
basis == "per" ||
basis == "wav1" ||
basis == "wav2" ||
basis == "wav3" ||
basis == "wav4"
) && ((minimum(X) < -0.5) || (maximum(X) >= 0.5))
error("Nodes need to be between -0.5 and 0.5.")
elseif (basis == "cos") && ((minimum(X) < 0) || (maximum(X) > 1))
error("Nodes need to be between 0 and 1.")
Expand Down
2 changes: 1 addition & 1 deletion src/errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ end
This function computes the relative ``L_2`` error of the function given the norm `norm` and a function that returns the basis coefficients `bc_fun` for regularization parameter `λ`.
"""
function get_L2error(a::approx, norm::Float64, bc_fun::Function, λ::Float64)::Float64
if a.basis=="per" || a.basis == "cos" || a.basis =="cheb"|| a.basis == "std"
if a.basis == "per" || a.basis == "cos" || a.basis == "cheb" || a.basis == "std"
error = norm^2
index_set = get_IndexSet(a.trafo.setting, size(a.X, 1))

Expand Down
2 changes: 1 addition & 1 deletion test/TestFunctionPeriodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function f(x::Vector{Float64})::Float64
error("Argument has to be 6-dimensional")
end

if !isempty(x[(x.>0.5).|(x.<-.5)])
if !isempty(x[(x.>0.5).|(x.<-0.5)])
error("The nodes have to be between -0.5 and 0.5.")
end

Expand Down
2 changes: 1 addition & 1 deletion test/per_fista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ y_test = [TestFunctionPeriodic.f(X_test[:, i]) for i = 1:M]

ads = ANOVAapprox.approx(X, complex(y), ds, bw, "per")
ANOVAapprox.approximate(ads, lambda = λs, solver = "fista")
ANOVAapprox.get_ActiveSet(ads, [0.05,0.05])
ANOVAapprox.get_ActiveSet(ads, [0.05, 0.05])
bw = ANOVAapprox.get_orderDependentBW(TestFunctionPeriodic.AS, [128, 32])

aU = ANOVAapprox.approx(X, complex(y), TestFunctionPeriodic.AS, bw, "per")
Expand Down
4 changes: 2 additions & 2 deletions test/per_lsqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ y_test = [TestFunctionPeriodic.f(X_test[:, i]) for i = 1:M]
ads = ANOVAapprox.approx(X, complex(y), ds, bw, "per")
ANOVAapprox.approximate(ads, lambda = λs)

println( "AR: ", sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) )
@test abs( sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) - 1 ) < 0.0001
println("AR: ", sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)))
@test abs(sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) - 1) < 0.0001

bw = ANOVAapprox.get_orderDependentBW(TestFunctionPeriodic.AS, [128, 32])

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using .TestFunctionCheb

rng = MersenneTwister(1234)

tests = ["misc", "cheb_fista", "cheb_lsqr", "per_lsqr", "per_fista","wav_lsqr"]
tests = ["misc", "cheb_fista", "cheb_lsqr", "per_lsqr", "per_fista", "wav_lsqr"]
#tests = ["misc", "cheb_lsqr", "per_lsqr", "per_fista"]

for t in tests
Expand Down
10 changes: 5 additions & 5 deletions test/wav_lsqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ d = 6
ds = 2
M = 10_000
max_iter = 50
bw = [4,4]
bw = [4, 4]
λs = [0.0, 1.0]


X = rand( d, M) .- 0.5
X = rand(d, M) .- 0.5
y = [TestFunctionPeriodic.f(X[:, i]) for i = 1:M]
X_test = rand(d, M) .- 0.5
y_test = [TestFunctionPeriodic.f(X_test[:, i]) for i = 1:M]
Expand All @@ -23,10 +23,10 @@ y_test = [TestFunctionPeriodic.f(X_test[:, i]) for i = 1:M]
ads = ANOVAapprox.approx(X, y, ds, bw, "wav2")
ANOVAapprox.approximate(ads, lambda = λs)

println( "AR: ", sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) )
@test abs( sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) - 1 ) < 0.0001
println("AR: ", sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)))
@test abs(sum(ANOVAapprox.get_AttributeRanking(ads, 0.0)) - 1) < 0.0001

bw = ANOVAapprox.get_orderDependentBW(TestFunctionPeriodic.AS, [4,4])
bw = ANOVAapprox.get_orderDependentBW(TestFunctionPeriodic.AS, [4, 4])

aU = ANOVAapprox.approx(X, y, TestFunctionPeriodic.AS, bw, "wav2")
ANOVAapprox.approximate(aU, lambda = λs)
Expand Down

2 comments on commit 079fb86

@mischmi96
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register branch=main

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/58802

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.6 -m "<description of version>" 079fb86e988b21d83cbaa20f9ff822d1d913c2e6
git push origin v1.1.6

Please sign in to comment.