Liking cljdoc? Tell your friends :D

fastmath.signal.denoise

Wavelet shrinkage (denoising).

threshold estimates a threshold from wavelet coefficients, denoise applies a shrinkage rule to the detail coefficients: either to the bands returned by fastmath.transform/dwt, to flat coefficients, or to a signal transformed with a given wavelet.

Shrinkage rules for a threshold t (the first three as pywt.threshold):

  • :hard - x when |x| >= t, otherwise 0
  • :soft - sign(x) * max(|x| - t, 0)
  • :garrote - x - t^2/x when |x| > t, otherwise 0
  • :hyperbole - sign(x) * sqrt(x^2 - t^2) when |x| > t, otherwise 0
Wavelet shrinkage (denoising).

[[threshold]] estimates a threshold from wavelet coefficients, [[denoise]] applies a shrinkage rule to the detail coefficients: either to the bands returned by `fastmath.transform/dwt`, to flat coefficients, or to a signal transformed with a given wavelet.

Shrinkage rules for a threshold `t` (the first three as `pywt.threshold`):

* `:hard` - `x` when `|x| >= t`, otherwise 0
* `:soft` - `sign(x) * max(|x| - t, 0)`
* `:garrote` - `x - t^2/x` when `|x| > t`, otherwise 0
* `:hyperbole` - `sign(x) * sqrt(x^2 - t^2)` when `|x| > t`, otherwise 0
raw docstring

denoiseclj

(denoise coeffs)
(denoise coeffs
         {:keys [method thr skip high? top-n-ratio]
          :or {method :hard thr :sure skip 0 top-n-ratio 0.25}})
(denoise wavelet-or-transformer xs options)

Applies wavelet shrinkage to the detail coefficients.

Arities:

  • [coeffs], [coeffs options] - coeffs are bands from fastmath.transform/dwt ([cA cD_n ... cD_1]) or flat coefficients
  • [wavelet xs options] - denoises signal xs: fastmath.transform/dwt with wavelet (a name or wavelet object) and :level / :mode from options, shrinkage of the bands, fastmath.transform/idwt; returns the signal of the original length
  • [transformer xs options] - as above with a transform object from fastmath.transform/transformer and flat coefficients without band lengths (the flat rule below, :skip protects the approximation); options are passed to the transform, the reverse transform also gets :n

Options:

  • :method - shrinkage rule :hard (default), :soft, :garrote or :hyperbole, see the namespace docstring
  • :thr - a number or a method of threshold (default :sure)
  • :top-n-ratio - for threshold (default 0.25)
  • :high? - estimate the threshold from the finest details only (default true for :visu and :universal, false otherwise); for bands the finest detail band cD_1, for flat coefficients the second half
  • :skip - flat coefficients only: number of leading coefficients left unchanged (default 0)

Bands: the approximation band is never changed; one threshold, estimated from the finest band or from all detail bands, is applied to every detail band. Flat coefficients from fastmath.transform/dwt with :flat? true (metadata with band :lengths) are treated as bands. Other flat coefficients: the threshold is estimated from the second half (:high?) or from all coefficients and applied to all coefficients after :skip.

Returns bands, or a vector of flat coefficients, with the metadata of coeffs (so fastmath.transform/idwt still works); the signal arities return a vector of doubles. Throws ex-info for empty coefficients or an unknown method or threshold.

Applies wavelet shrinkage to the detail coefficients.

Arities:

* `[coeffs]`, `[coeffs options]` - `coeffs` are bands from `fastmath.transform/dwt` (`[cA cD_n ... cD_1]`) or flat coefficients
* `[wavelet xs options]` - denoises signal `xs`: `fastmath.transform/dwt` with `wavelet` (a name or wavelet object) and `:level` / `:mode` from options, shrinkage of the bands, `fastmath.transform/idwt`; returns the signal of the original length
* `[transformer xs options]` - as above with a transform object from `fastmath.transform/transformer` and flat coefficients without band lengths (the flat rule below, `:skip` protects the approximation); options are passed to the transform, the reverse transform also gets `:n`

Options:

* `:method` - shrinkage rule `:hard` (default), `:soft`, `:garrote` or `:hyperbole`, see the namespace docstring
* `:thr` - a number or a method of [[threshold]] (default `:sure`)
* `:top-n-ratio` - for [[threshold]] (default 0.25)
* `:high?` - estimate the threshold from the finest details only (default `true` for `:visu` and `:universal`, `false` otherwise); for bands the finest detail band `cD_1`, for flat coefficients the second half
* `:skip` - flat coefficients only: number of leading coefficients left unchanged (default 0)

Bands: the approximation band is never changed; one threshold, estimated from the finest band or from all detail bands, is applied to every detail band. Flat coefficients from `fastmath.transform/dwt` with `:flat? true` (metadata with band `:lengths`) are treated as bands. Other flat coefficients: the threshold is estimated from the second half (`:high?`) or from all coefficients and applied to all coefficients after `:skip`.

Returns bands, or a vector of flat coefficients, with the metadata of `coeffs` (so `fastmath.transform/idwt` still works); the signal arities return a vector of doubles. Throws `ex-info` for empty coefficients or an unknown method or threshold.
raw docstring

minfdr-thresholdclj

(minfdr-threshold xs top-n robust?)

Threshold from the top-n quantile of two-sided normal p-values of the coefficients: the value whose p-value equals that quantile.

The noise level is [[robust-stddev]] when robust? is true, the standard deviation otherwise; a zero noise level gives threshold 0.

Throws ex-info for empty input.

Threshold from the `top-n` quantile of two-sided normal p-values of the coefficients: the value whose p-value equals that quantile.

The noise level is [[robust-stddev]] when `robust?` is `true`, the standard deviation otherwise; a zero noise level gives threshold 0.

Throws `ex-info` for empty input.
raw docstring

sureclj

(sure xs)

Stein's Unbiased Risk Estimate threshold for coefficients with unit noise level, as MATLAB thselect(x, 'rigrsure').

With s the sorted squared absolute values, the risk of the k-th candidate is (n - 2k + sum(s_1..s_k) + (n - k) s_k) / n and the threshold is sqrt(s_k) of the smallest risk.

Throws ex-info for empty input.

Stein's Unbiased Risk Estimate threshold for coefficients with unit noise level, as MATLAB `thselect(x, 'rigrsure')`.

With `s` the sorted squared absolute values, the risk of the `k`-th candidate is `(n - 2k + sum(s_1..s_k) + (n - k) s_k) / n` and the threshold is `sqrt(s_k)` of the smallest risk.

Throws `ex-info` for empty input.
raw docstring

thresholdclj

(threshold coeffs)
(threshold coeffs thr)
(threshold coeffs thr top-n-ratio)

Estimates a denoising threshold from wavelet coefficients coeffs.

thr is a number (returned as is) or one of:

  • :visu (default) - sigma * sqrt(2 ln n), sigma estimated by [[robust-stddev]], n the number of coefficients
  • :universal - as :visu, with the standard deviation
  • :sure or :rigrsure - sure of the coefficients divided by sigma ([[robust-stddev]]), multiplied by sigma
  • :hybrid or :heursure - MATLAB heursure on the coefficients divided by sigma, multiplied by sigma: sqrt(2 ln n) when the signal energy is small, otherwise the smaller of SURE and sqrt(2 ln n)
  • :avg - mean of absolute values
  • :peaksavg or :peaks-avg - mid point between the minimum and maximum absolute value
  • :topn or :top-n - keep the top-n-ratio fraction of largest coefficients (top-N-threshold)
  • :minfdr, :minfdr-robust - minfdr-threshold with the standard deviation or [[robust-stddev]]

top-n-ratio (default 0.25) is used by :topn, :minfdr and :minfdr-robust. All given coefficients are used; pass only detail coefficients to estimate from them.

Throws ex-info for empty coefficients or an unknown thr.

Estimates a denoising threshold from wavelet coefficients `coeffs`.

`thr` is a number (returned as is) or one of:

* `:visu` (default) - `sigma * sqrt(2 ln n)`, `sigma` estimated by [[robust-stddev]], `n` the number of coefficients
* `:universal` - as `:visu`, with the standard deviation
* `:sure` or `:rigrsure` - [[sure]] of the coefficients divided by `sigma` ([[robust-stddev]]), multiplied by `sigma`
* `:hybrid` or `:heursure` - MATLAB `heursure` on the coefficients divided by `sigma`, multiplied by `sigma`: `sqrt(2 ln n)` when the signal energy is small, otherwise the smaller of SURE and `sqrt(2 ln n)`
* `:avg` - mean of absolute values
* `:peaksavg` or `:peaks-avg` - mid point between the minimum and maximum absolute value
* `:topn` or `:top-n` - keep the `top-n-ratio` fraction of largest coefficients ([[top-N-threshold]])
* `:minfdr`, `:minfdr-robust` - [[minfdr-threshold]] with the standard deviation or [[robust-stddev]]

`top-n-ratio` (default 0.25) is used by `:topn`, `:minfdr` and `:minfdr-robust`. All given coefficients are used; pass only detail coefficients to estimate from them.

Throws `ex-info` for empty coefficients or an unknown `thr`.
raw docstring

top-N-thresholdclj

(top-N-threshold xs top-n)

Threshold keeping the top-n fraction of the largest absolute coefficients: the 1 - top-n quantile of absolute values.

Threshold keeping the `top-n` fraction of the largest absolute coefficients: the `1 - top-n` quantile of absolute values.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close