WaveletBestBasis[dwd]
computes a best basis representation in the DiscreteWaveletData object dwd.
WaveletBestBasis[dwd,cspec]
computes a best basis representation using the cost specification cspec.
WaveletBestBasis
WaveletBestBasis[dwd]
computes a best basis representation in the DiscreteWaveletData object dwd.
WaveletBestBasis[dwd,cspec]
computes a best basis representation using the cost specification cspec.
Details and Options
- WaveletBestBasis[dwd] returns a DiscreteWaveletData odwd object where the optimal basis has been computed and will be used by functions such as InverseWaveletTransform, WaveletListPlot, etc.
- Properties of the DiscreteWaveletData odwd can be found using odwd["prop"].
- Properties related to best basis include:
-
"BasisIndex" wavelet indices used for inverse transform "BestBasisBlockView" block grid view of best basis "BestBasisCostValues" cost value for each wavelet coefficient "TreeView" tree view of decomposition with best basis highlighted - WaveletBestBasis[dwd] is equivalent to WaveletBestBasis[dwd,"ShannonEntropy"].
- Possible cspec values include:
-
"ShannonEntropy" Shannon entropy 
"LogEnergy" log energy 
{"Norm",p} norm like
for
and
for 
{"Threshold",δ} number of elements above
fn apply fn to each coefficient array to get a cost value - A cost function fn must satisfy fn[{a1,…,am,b1,…,bn}]fn[{a1,…,am}]+fn[{b1,…,bn}] and fn[{0,…}]0.
- The best basis is a complete basis for the wavelet decomposition giving the least total cost.
Examples
open all close allBasic Examples (1)
Compute an optimal wavelet basis:
dwd = DiscreteWaveletPacketTransform[{0, 0, 1, 1}];best = WaveletBestBasis[dwd]Compare default basis with best basis in a tree plot of all coefficients:
{Labeled[dwd[{"TreeView", Left}], Text["default basis"]], Labeled[best[{"TreeView", Left}], Text["best basis"]]}Scope (11)
Basic Uses (6)
Compute an optimal wavelet basis for vector data:
dwd = WaveletBestBasis[DiscreteWaveletPacketTransform[{1, 1, 2, 3, 2, 2}]]The best basis is stored in the resulting DiscreteWaveletData object:
dwd["BasisIndex"]Show the coefficient array corresponding to each index in the basis:
dwd[Automatic]Wavelet packet transforms give a DiscreteWaveletData object that includes a default basis:
dwd = DiscreteWaveletPacketTransform[{0, 0, 1, 1, 1, 2, 3, 4}];dwd["BasisIndex"]The basis includes all coefficients at the highest level of refinement:
dwd[{"TreeView", Left}]WaveletBestBasis gives a new DiscreteWaveletData object with a different, optimal basis:
WaveletBestBasis[dwd]["BasisIndex"]WaveletBestBasis[dwd][{"TreeView", Left}]Compute best basis for packet transforms with any number of levels of refinement:
Table[WaveletBestBasis[DiscreteWaveletPacketTransform[{1, 2, 8, 6, 0, 7, 6, 3, 8, 3, 5, 9}, Automatic, r]]["BestBasisBlockView"], {r, 4}]Compute wavelet basis, minimizing log-energy for an image:
dwd = DiscreteWaveletPacketTransform[[image], CDFWavelet[], 3];best = WaveletBestBasis[dwd, "LogEnergy"]Compare default basis with best basis in a hierarchical grid layout of coefficient images:
{Labeled[WaveletImagePlot[dwd], Text@"default basis"], Labeled[WaveletImagePlot[best], Text@"best basis"]}Compute best basis with custom cost function:
dwd = DiscreteWaveletPacketTransform[{3.3, 4.3, 0.7, 0.5, 0.6, 2.8, 2.7, 4.9}]Choose basis with fewest coefficients lying between -1 and 1:
cost[coeff_] := -Count[coeff, u_ /; ¬-1 < u < 1]best = WaveletBestBasis[dwd, cost]Count values lying between -1 and 1 in default basis:
Count[Last /@ dwd[Automatic], u_ /; -1 < u < 1, ∞]Count[Last /@ best[Automatic], u_ /; -1 < u < 1, ∞]WaveletBestBasis gives the optimal basis among all possible wavelet bases:
dwd = DiscreteWaveletPacketTransform[RandomReal[1, 32], Automatic, 5];best = WaveletBestBasis[dwd]Recursively enumerate all possible wavelet bases for
levels of refinement:
b[n_, i___] := Prepend[Flatten[Outer[Join, b[n, i, 0], b[n, i, 1], 1], 1], {{i}}]
b[n_, i___] := {{{i}}} /; Length[{i}] == nShow the 5 possible wavelet bases for 2 levels of refinement:
Framed /@ b[2]The number of possible bases grows extremely quickly as a function of refinement level:
ListLogPlot[Table[Length[b[n]], {n, 5}], Joined -> True, PlotMarkers -> Automatic]Total[best["BasisIndex"] /. best["BestBasisCostValues"]]Distribution of cost values of a random sample of 1000 bases:
Histogram[Map[Total, RandomSample[b[5], 1000] /. best["BestBasisCostValues"]]]Cost Functions (5)
Apply cost functions to coefficients with fixed total energy:
w = {Sqrt[e], Sqrt[1 - e]};Plot cost as a function of first component energy
for "ShannonEntropy":
Plot[Total[-w^2Log[w^2]], {e, 0, 1}]Plot[Total[Log[w^2]], {e, 0, 1}]Table[Plot[Total[If[0 < p < 2, Abs[w]^p, -Abs[w]^p]], {e, 0, 1}, PlotLabel -> p], {p, {0.5, 1.5, 3}}]Table[Plot[Total[Boole[Thread[Abs[w] > δ]]], {e, 0, 1}, PlotLabel -> δ, Exclusions -> None, PlotRange -> {0, 2}], {δ, {0.3, 0.6, 0.9}}]In general, each cost function can lead to a different best basis:
dwd = DiscreteWaveletPacketTransform[{3.8, 6.5, 0.8, 8.3, 9.5, 5.7, 6., 1.3, 5.2, 7.5, 1., 9.4, 7.8, 6.3, 8.8, 9.8}];Table[Labeled[WaveletBestBasis[dwd, cf]["BestBasisBlockView"], Text@cf], {cf, {"ShannonEntropy", {"Norm", 1}, {"Norm", 3}, "LogEnergy", {"Threshold", 0.5}, {"Threshold", 2}}}]Plot distribution of energy among best basis coefficient values for each cost function:
Table[ListLogPlot[Sort[Flatten[Last /@ WaveletBestBasis[dwd, cf][Automatic]]^2], PlotLabel -> cf, Filling -> Axis, PlotRange -> {0.0001, 1000}], {cf, {"ShannonEntropy", {"Norm", 1}, {"Norm", 3}, "LogEnergy", {"Threshold", 0.5}, {"Threshold", 2}}}]Different cost functions often lead to similar best bases:
dwd = DiscreteWaveletPacketTransform[RandomReal[10, 16]];Table[Labeled[WaveletBestBasis[dwd, c]["BestBasisBlockView"], Text@c], {c, {"ShannonEntropy", {"Norm", 1}, {"Norm", 3}, "LogEnergy", {"Threshold", 0.5}, {"Threshold", 2}}}]Define a custom cost function that favors coefficients that are nearer to integers:
int[w_] := Norm[w - Round[w], 2] ^ 2Best basis for list data using custom cost function:
d = RandomReal[3, 16];dwd = WaveletBestBasis[DiscreteWaveletPacketTransform[d, Automatic, 4], int]The computed cost value for the {} coefficient is the custom cost value of the original data:
{int[d], {} /. dwd["BestBasisCostValues"]}Cost value of the best basis coefficients:
Total[dwd["BasisIndex"] /. dwd["BestBasisCostValues"]]The best basis coefficients are clustered around integers:
ListPlot[Sort@Flatten[dwd["BasisIndex"] /. Normal[dwd]], PlotRange -> All]Reproduce the built-in cost functions as custom ones:
dwd = DiscreteWaveletPacketTransform[RandomReal[10, 16]]shannon[w_] := Piecewise[{{-w^2Log[w^2], w ≠ 0}}]{WaveletBestBasis[dwd, v Total@Map[shannon, v]]["BestBasisBlockView"], WaveletBestBasis[dwd, "ShannonEntropy"]["BestBasisBlockView"]}loge[w_] := Piecewise[{{Log[w^2], w ≠ 0}}]{WaveletBestBasis[dwd, v Total@Map[loge, v]]["BestBasisBlockView"], WaveletBestBasis[dwd, "LogEnergy"]["BestBasisBlockView"]}pwnorm[w_, p_] := Piecewise[{{Norm[w, p] ^ p, 0 < p < 2}, {-Norm[w, p] ^ p, p ≥ 2}}]{WaveletBestBasis[dwd, pwnorm[#, 3]&]["BestBasisBlockView"], WaveletBestBasis[dwd, {"Norm", 3}]["BestBasisBlockView"]}thr[w_, δ_] := Count[w, u_ /; Abs[u] > δ]{WaveletBestBasis[dwd, thr[#, 1]&]["BestBasisBlockView"], WaveletBestBasis[dwd, {"Threshold", 1}]["BestBasisBlockView"]}Generalizations & Extensions (2)
Explicitly specify the full wavelet basis:
dwd = WaveletBestBasis[DiscreteWaveletPacketTransform[{1, 2, 3, 5}], {{1}, {0, 1}, {0, 0}}]The specified basis is taken to be the best basis:
dwd["BestBasisBlockView"]Select a basis containing the specified wavelet indexes:
dwd = WaveletBestBasis[DiscreteWaveletPacketTransform[Range[8]], {{1}, {0, 0, 0}}]The smallest full basis containing the specified indexes is chosen:
dwd[{"TreeView", Left}]Applications (3)
Compression (3)
Use WaveletBestBasis to choose a wavelet basis for threshold-based data compression:
data = Table[Sin[x + x ^ 2], {x, 0, 10, 0.01}];WaveletBestBasis[DiscreteWaveletPacketTransform[data, DaubechiesWavelet[4], 4]]dwd = WaveletThreshold[%, {"Hard", 0.1}]Count nonzero values in thresholded coefficients as a measure of compression:
Count[Last /@ dwd[Automatic], Except[0.], ∞]Compare with compression by thresholding original data:
Count[Chop[data, 0.2], Except[0], ∞]Plot original and reconstructed data:
{ListLinePlot[data], ListLinePlot[InverseWaveletTransform[dwd]]}Compare threshold-based compression for various threshold values
:
data = Table[Sin[x + x ^ 2], {x, 0, 10, 0.01}];dwd = DiscreteWaveletPacketTransform[data, DaubechiesWavelet[], 4];Use the same threshold value
for best basis selection and thresholding:
dwds = Table[WaveletThreshold[WaveletBestBasis[dwd, {"Threshold", δ}], {"Hard", δ}], {δ, {0.05, 0.1, 0.2, 0.5}}]Show reconstructed data along with the number of nonzero values as a measure of compression:
Table[ListLinePlot[InverseWaveletTransform[d], PlotLabel -> Row[{"non-zero values: ", Count[Last /@ d[Automatic], Except[0.], ∞]}]], {d, dwds}]Length of uncompressed original data:
Length[data]Simple lossy image compression for various threshold values
:
dwd = DiscreteWaveletPacketTransform[[image], CDFWavelet[], 3];dwds = Table[WaveletThreshold[WaveletBestBasis[dwd, {"Threshold", δ}], {"Hard", δ}], {δ, {0.02, 0.05, 0.2, 0.5}}]Show reconstructed data along with the number of nonzero values as a measure of compression:
Table[Labeled[InverseWaveletTransform[d], Text["non-zero values: " <> ToString[Count[Last /@ d[Automatic], Except[0.], ∞]]]], {d, dwds}]Total number of pixel values in all channels of original image:
ImageChannels[[image]] * Apply[Times, ImageDimensions[[image]]]Properties & Relations (4)
The best basis coefficients typically contain fewer, larger nonzero values than the original data:
dwd = DiscreteWaveletPacketTransform[{0, 0, 1, 1}];best = WaveletBestBasis[dwd];Compare default basis for wavelet packet transforms with best basis:
dwd[Automatic]best[Automatic]Compare with the basis for non-packet wavelet transforms:
DiscreteWaveletTransform[{0, 0, 1, 1}][Automatic]Non-packet transforms give a DiscreteWaveletData object with a permanently fixed basis:
dwd = DiscreteWaveletTransform[{0, 0, 1, 1, 1, 2, 3, 4}];dwd["BasisIndex"]The basis includes the detail coefficients {…,1} and the last coarse coefficient {…,0}:
dwd["TreeView"]The result of WaveletBestBasis[dwd] has exactly the same wavelet coefficients as dwd:
dwd = DiscreteWaveletPacketTransform[{0, 0, 1, 1, 1, 2, 3, 4}];Normal[WaveletBestBasis[dwd]] === Normal[dwd]Only the wavelet basis is different:
WaveletBestBasis[dwd]["BasisIndex"] === dwd["BasisIndex"]The {} coefficient of "BestBasisCostValues" is the cost value of the original data:
dwd = WaveletBestBasis[DiscreteWaveletPacketTransform[{1, 2, 1, 1.1}], "LogEnergy"];{} /. dwd["BestBasisCostValues"]Directly compute log-energy from the data:
Total[Log[{1, 2, 1, 1.1} ^ 2]]The log-energy of the best basis is lower than that of the data:
Total[dwd["BasisIndex"] /. dwd["BestBasisCostValues"]]Possible Issues (5)
DiscreteWaveletTransform does not compute the full tree of wavelet coefficients:
WaveletBestBasis[DiscreteWaveletTransform[{0, 0, 1, 1}]]DiscreteWaveletTransform[{0, 0, 1, 1}]["TreeView"]Use DiscreteWaveletPacketTransform to get the full tree:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, 1}]]DiscreteWaveletPacketTransform[{0, 0, 1, 1}]["TreeView"]The cost function must be additive with respect to Join:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, 1}], -Norm[#, 3]&]The specified function is not additive:
Norm[{1}, 3] + Norm[{2}, 3] == Norm[{1, 2}, 3]Modify the cost function to be additive:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, 1}], -Norm[#, 3] ^ 3&]The cost function must be zero for zero-valued coefficients:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, 1}], Total[Exp[Abs[#]]]&]Modify the cost function to be compatible:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, 1}], Total[Exp[Abs[#]] - 1]&]The best basis algorithm requires numeric coefficients:
WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, n}]]Use specific numerical values:
Table[WaveletBestBasis[DiscreteWaveletPacketTransform[{0, 0, 1, n}]], {n, {0.5, 1, 1.5, 2}}]An explicit basis specification wind needs to be consistent:
dwd = DiscreteWaveletPacketTransform[RandomReal[1, 4]];WaveletBestBasis[dwd, {{1}, {1, 0}}]A basis cannot include both {1} and {1,0} since {1,0} can be computed from {1}:
dwd["TreeView"]Select a basis using a consistent wind specification:
{WaveletBestBasis[dwd, {{1}}]["TreeView"], WaveletBestBasis[dwd, {{1, 0}}]["TreeView"]}Related Guides
History
Text
Wolfram Research (2010), WaveletBestBasis, Wolfram Language function, https://reference.wolfram.com/language/ref/WaveletBestBasis.html.
CMS
Wolfram Language. 2010. "WaveletBestBasis." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/WaveletBestBasis.html.
APA
Wolfram Language. (2010). WaveletBestBasis. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WaveletBestBasis.html
BibTeX
@misc{reference.wolfram_2026_waveletbestbasis, author="Wolfram Research", title="{WaveletBestBasis}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/WaveletBestBasis.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_waveletbestbasis, organization={Wolfram Research}, title={WaveletBestBasis}, year={2010}, url={https://reference.wolfram.com/language/ref/WaveletBestBasis.html}, note=[Accessed: 13-June-2026]}