WaveletsExt.WaveMult.dyadlength
WaveletsExt.WaveMult.isft
WaveletsExt.WaveMult.mat2sparseform_nonstd
WaveletsExt.WaveMult.mat2sparseform_std
WaveletsExt.WaveMult.ndyad
WaveletsExt.WaveMult.nonstd_wavemult
WaveletsExt.WaveMult.ns_dwt
WaveletsExt.WaveMult.ns_idwt
WaveletsExt.WaveMult.sft
WaveletsExt.WaveMult.std_wavemult
WaveletsExt.WaveMult.stretchmatrix
Wavelet Multiplication
WaveletsExt.WaveMult.nonstd_wavemult
— Functionnonstd_wavemult(M, x, wt, [L], [ϵ])
nonstd_wavemult(NM, x, wt, [L])
If M
is an $n$ by $n$ matrix, there are two ways to compute $y = Mx$. The first is to use the standard matrix multiplication to compute the product. This algorithm works in order of $O(n^2)$, where $n$ is the length of x
.
The second is to transform both the matrix and vector to their nonstandard forms and multiply the nonstandard forms. If the matrix is sparse in nonstandard form, this can be an order $O(n)$ algorithm.
One may choose to use the original matrix M
as input by doing nonstd_wavemult(M, x, wt, [L], [ϵ])
. However, if the nonstandard form sparse matrix NM
is already computed prior, one can skip the redundant step by doing nonstd_wavemult(NM, x, wt, [L])
.
Arguments
M::AbstractVector{T} where T<:AbstractFloat
: $n$ by $n$ matrix.NM::SparseMatrixCSC{T,S} where {T<:AbstractFloat, S<:Integer}
: Nonstandard transformed sparse matrix ofM
.x::AbstractVector{T} where T<:AbstractFloat
: Vector of length $n$ in natural basis.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: (Default:maxtransformlevels(x)
) Number of decomposition levels.ϵ::T where T<:AbstractFloat
: (Default:1e-4
) Truncation criterion for nonstandard transform ofM
.
Returns
y::Vector{T}
: Standard approximation of $Mx$.
Examples
julia> using Wavelets, WaveletsExt
julia> M = randn(4,4); x = randn(4); wt = wavelet(WT.haar);
julia> NM = mat2sparseform_nonstd(M, wt); y₀ = nonstd_wavemult(NM, x, wt)
4-element Vector{Float64}:
-1.2590015844047044
-1.3234024176418535
2.1158027198405627
1.5364835417087566
julia> y₁ = nonstd_wavemult(M, x, wt)
4-element Vector{Float64}:
-1.2590015844047044
-1.3234024176418535
2.1158027198405627
1.5364835417087566
julia> y₀ == y₁ # Both methods are equivalent
true
**See also:* std_wavemult
, mat2sparseform_nonstd
, ns_dwt
, ns_idwt
WaveletsExt.WaveMult.std_wavemult
— Functionstd_wavemult(M, x, wt, [L], [ϵ])
std_wavemult(SM, x, wt, [L])
If M
is an $n$ by $n$ matrix, there are two ways to compute $y = Mx$. The first is to use the standard matrix multiplication to compute the product. This algorithm works in order of $O(n^2)$, where $n$ is the length of x
.
The second is to transform both the matrix and vector to their standard forms and multiply the standard forms. If the matrix is sparse in standard form, this can be an order $O(n)$ algorithm.
One may choose to use the original matrix M
as input by doing std_wavemult(M, x, wt, [L], [ϵ])
. However, if the standard form sparse matrix SM
is already computed prior, one can skip the redundant step by doing std_wavemult(SM, x, wt, [L])
.
Arguments
M::AbstractVector{T} where T<:AbstractFloat
: $n$ by $n$ matrix.NM::SparseMatrixCSC{T,S} where {T<:AbstractFloat, S<:Integer}
: Standard transformed sparse matrix ofM
.x::AbstractVector{T} where T<:AbstractFloat
: Vector of length $n$ in natural basis.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: (Default:maxtransformlevels(x)
) Number of decomposition levels.ϵ::T where T<:AbstractFloat
: (Default:1e-4
) Truncation criterion for standard transform ofM
.
Returns
y::Vector{T}
: Standard form approximation of $Mx$.
Examples
julia> using Wavelets, WaveletsExt
julia> M = randn(4,4); x = randn(4); wt = wavelet(WT.haar);
julia> SM = mat2sparseform_std(M, wt); y₀ = std_wavemult(SM, x, wt)
4-element Vector{Float64}:
2.2303830532617344
-0.12704611958926648
2.656411941014368
-4.811388406857621
julia> y₁ = std_wavemult(M, x, wt)
4-element Vector{Float64}:
2.2303830532617344
-0.12704611958926648
2.656411941014368
-4.811388406857621
julia> y₀ == y₁
true
See also: nonstd_wavemult
, mat2sparseform_std
Matrix to Sparse Format
WaveletsExt.WaveMult.mat2sparseform_nonstd
— Functionmat2sparseform_nonstd(M, wt, [L], [ϵ])
Transform the matrix M
into the wavelet basis. Then, it is stretched into its nonstandard form. Elements exceeding ϵ * maximum column norm
are set to zero. The resulting output sparse matrix, and can be used as input to nonstd_wavemult
.
Arguments
M::AbstractMatrix{T} where T<:AbstractFloat
:n
byn
matrix (n
dyadic) to be put in Sparse Nonstandard form.wt::OrthoFilter
: Wavelet filter.L::Integer
: (Default:maxtransformlevels(M)
) Number of decomposition levels.ϵ::T where T<:AbstractFloat
: (Default:1e-4
) Truncation Criterion.
Returns
NM::SparseMatrixCSC{T, Integer}
: Sparse nonstandard form of matrix of size 2n x 2n.
Examples
julia> using Wavelets, WaveletsExt; import Random: seed!
julia> seed!(1234); M = randn(4,4); wt = wavelet(WT.haar);
julia> mat2sparseform_nonstd(M, wt)
8×8 SparseArrays.SparseMatrixCSC{Float64, Int64} with 16 stored entries:
1.88685 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ 0.363656 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ 2.49634 -1.08139 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ -1.0187 0.539411
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.68141 0.0351839
⋅ ⋅ ⋅ ⋅ -1.39713 -1.21352 0.552745 0.427717
⋅ ⋅ ⋅ ⋅ -1.05882 0.16666 -0.124156 -0.218902
See also: mat2sparseform_std
, stretchmatrix
WaveletsExt.WaveMult.mat2sparseform_std
— Functionmat2sparseform_std(M, wt, [L], [ϵ])
Transform the matrix M
into the standard form. Then, elements exceeding ϵ * maximum column norm
are set to zero. The resulting output sparse matrix, and can be used as input to std_wavemult
.
Arguments
M::AbstractMatrix{T} where T<:AbstractFloat
: Matrix to be put in Sparse Standard form.wt::OrthoFilter
: Wavelet filter.L::Integer
: (Default:maxtransformlevels(M)
) Number of decomposition levels.ϵ::T where T<:AbstractFloat
: (Default:1e-4
) Truncation Criterion.
Returns
SM::SparseMatrixCSC{T, Integer}
: Sparse standard form of matrix of size $n imes n$.
Examples
julia> using Wavelets, WaveletsExt; import Random: seed!
julia> seed!(1234); M = randn(4,4); wt = wavelet(WT.haar);
julia> mat2sparseform_std(M, wt)
4×4 SparseArrays.SparseMatrixCSC{Float64, Int64} with 16 stored entries:
1.88685 0.363656 0.468602 0.4063
2.49634 -1.08139 1.90927 -0.356542
-1.84601 0.129829 0.552745 0.427717
-0.630852 0.866545 -0.124156 -0.218902
See also: mat2sparseform_nonstd
, sft
Fast Transform Algorithms
WaveletsExt.WaveMult.ns_dwt
— Functionns_dwt(x, wt, [L])
Nonstandard wavelet transform on 1D signals.
Arguments
x::AbstractVector{T} where T<:AbstractFloat
: 1D signal of length $2^J$.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: (Default:maxtransformlevels(x)
) Number of decomposition levels.
Returns
nxw::Vector{T}
: Nonstandard wavelet transform ofx
of length $2^{J+1}$.
Examples
julia> using Wavelets, WaveletsExt; import Random: seed!
julia> seed!(1234); x = randn(4)
4-element Vector{Float64}:
-0.3597289068234817
1.0872084924285859
-0.4195896169388487
0.7189099374659392
julia> wt = wavelet(WT.haar);
julia> nxw = ns_dwt(x, wt) # Nonstandard transform
8-element Vector{Float64}:
0.0
0.0
0.5133999530660974
-0.2140796325390069
0.5144057481561487
0.21165142839163664
1.0231392469635638
0.8050407552974883
julia> x̂ = ns_idwt(nxw, wt) # Nonstandard inverse transform
4-element Vector{Float64}:
0.004010885979070622
1.4509482852311382
-0.2699294566753035
0.8685700977294846
julia> x ≈ x̂ # Unlike standard dwt, x ≠ x̂
false
See also: nonstd_wavemult
, mat2sparseform_nonstd
, ns_idwt
, ndyad
WaveletsExt.WaveMult.ns_idwt
— Functionns_idwt(nxw, wt, [L])
Inverse nonstandard wavelet transform on 1D signals.
Arguments
nxw::AbstractVector{T} where T<:AbstractFloat
: Nonstandard wavelet transformed 1D signal of length $2^{J+1}$.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: (Default:maxtransformlevels(nxw) - 1
) Number of decomposition levels.
Returns
x::Vector{T}
: 1D signal of length $2^J$.
Examples
julia> using Wavelets, WaveletsExt; import Random: seed!
julia> seed!(1234); x = randn(4)
4-element Vector{Float64}:
-0.3597289068234817
1.0872084924285859
-0.4195896169388487
0.7189099374659392
julia> wt = wavelet(WT.haar);
julia> nxw = ns_dwt(x, wt) # Nonstandard transform
8-element Vector{Float64}:
0.0
0.0
0.5133999530660974
-0.2140796325390069
0.5144057481561487
0.21165142839163664
1.0231392469635638
0.8050407552974883
julia> x̂ = ns_idwt(nxw, wt) # Nonstandard inverse transform
4-element Vector{Float64}:
0.004010885979070622
1.4509482852311382
-0.2699294566753035
0.8685700977294846
julia> x ≈ x̂ # Unlike standard dwt, x ≠ x̂
false
See also: nonstd_wavemult
, mat2sparseform_nonstd
, ns_dwt
, ndyad
WaveletsExt.WaveMult.sft
— Functionsft(M, wt, [L])
Transforms a matrix M
to be then represented in the sparse standard form. This is achieved by first computing $L$ levels of wavelet transform on each column of M
, and then computing $L$ levels of wavelet transform on each row of M
.
Arguments
M::AbstractMatrix{T} where T<:AbstractFloat
: Matrix to be put in standard form.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: Number of decomposition levels.
Returns
Mw::Matrix{T}
: Matrix in the standard form.
Examples
import WaveletsExt.WaveMult: sft
using Wavelets
M = randn(4,4); wt = wavelet(WT.haar)
Mw = sft(M, wt)
M̂ = isft(Mw, wt)
See also: mat2sparseform_std
, isft
WaveletsExt.WaveMult.isft
— Functionisft(Mw, wt, [L])
Reconstructs the matrix M
from the sparse standard form Mw
. This is achieved by first computing $L$ levels of inverse wavelet transform on each row of Mw
, and then computing $L$ levels of inverse wavelet transform on each column of Mw
.
Arguments
Mw::AbstractMatrix{T} where T<:AbstractFloat
: Matrix in standard form.wt::OrthoFilter
: Type of wavelet filter.L::Integer
: Number of decomposition levels.
Returns
M::Matrix{T}
: Reconstructed matrix.
Examples
import WaveletsExt.WaveMult: sft
using Wavelets
M = randn(4,4); wt = wavelet(WT.haar)
Mw = sft(M, wt)
M̂ = isft(Mw, wt)
See also: sft
Miscellaneous
WaveletsExt.WaveMult.dyadlength
— Functiondyadlength(x)
dyadlength(n)
Find dyadic length of array.
Arguments
x::AbstractArray
: Array of lengthn
. Preferred array length is $2^J$ where $J$ is an integer.n::Integer
: Length of array.
Returns
J::Integer
: Least power of two greater thann
.
The function dyadlength
is very similar to the function maxtransformlevels
from Wavelets.jl. The only difference here is the way it handles n
when n
is not a power of 2. The example below provides a demonstration of the differences in the 2 functions.
Examples
julia> import WaveletsExt.WaveMult: dyadlength
julia> import Wavelets: maxtransformlevels
julia> x = randn(16); dyadlength(x)
4
julia> dyadlength(16) # Same as previous
4
julia> maxtransformlevels(16) # Equivalent to dyadlength when n is power of 2
4
julia> dyadlength(15) # Produces warning when n is not power of 2
┌ Warning: Dyadlength n != 2^J
└ @ WaveletsExt.WaveMult
4
julia> maxtransformlevels(15) # Not equivalent to dyadlength when n is not power of 2
0
WaveletsExt.WaveMult.ndyad
— Functionndyad(L, Lmax, gender)
Index dyad of nonstandard wavelet transform.
Arguments
L::T where T<:Integer
: Current level of node.Lmax::T where T<:Integer
: Max level of a signal being analyzed.gender::Bool
: "Gender" of node.true
= Female: Node is detail coefficients of the decomposition of its parent.false
= Male: Node is approximate coefficients of the decomposition of its parent.
Current level of node L
cannot be 0 or larger than its max possible level Lmax
.
Returns
::UnitRange{T}
: Range of all coefficients at theL
-th level attached to wavelets of indicated gender.
Examples
julia> import WaveletsExt.WaveMult: ndyad
julia> ndyad(1, 4, false)
17:24
julia> ndyad(1, 4, true)
25:32
WaveletsExt.WaveMult.stretchmatrix
— Functionstretchmatrix(i, j, n, L)
Stretch matrix into BCR nonstandard form.
Arguments
i::AbstractVector{T} where T<:Integer
: Row indices of nonzero elements of matrix.j::AbstractVector{T} where T<:Integer
: Column indices of nonzero elements of matrix.n::T where T<:Integer
: Size of square matrix.L::T where T<:Integer
: Number of resolution levels.
Returns
ie::Vector{T}
: Row indices of elements in nonstandard form of matrix.je::Vector{T}
: Column indices of elements in nonstandard form of matrix.
Examples
julia> M = [1 0 0 0;
0 2 0 0;
0 0 3 0;
0 0 0 4];
julia> idx = findall(!iszero, M)
2-element Vector{CartesianIndex{2}}:
CartesianIndex(1, 1)
CartesianIndex(2, 2)
julia> i = getindex.(idx, 1)
4-element Vector{Int64}:
1
2
3
4
julia> j = getindex.(idx, 2)
4-element Vector{Int64}:
1
2
3
4
julia> stretchmatrix(i, j, 4, 2)
([1, 4, 7, 8], [1, 4, 7, 8])