Английская Википедия:Hadamard transform

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Redirect-distinguish Шаблон:Use American English

Файл:1010 0110 Walsh spectrum (single row).svg
The product of a Boolean function and a Hadamard matrix is its Walsh spectrum:[1]
(1, 0, 1, 0, 0, 1, 1, 0) × H(8) = (4, 2, 0, −2, 0, 2, 0, 2)
Файл:1010 0110 Walsh spectrum (fast WHT).svg
Fast Walsh–Hadamard transform, a faster way to calculate the Walsh spectrum of (1, 0, 1, 0, 0, 1, 1, 0).
Файл:1010 0110 Walsh spectrum (polynomial).svg
The original function can be expressed by means of its Walsh spectrum as an arithmetical polynomial.

The Hadamard transform (also known as the Walsh–Hadamard transform, Hadamard–Rademacher–Walsh transform, Walsh transform, or Walsh–Fourier transform) is an example of a generalized class of Fourier transforms. It performs an orthogonal, symmetric, involutive, linear operation on Шаблон:Math real numbers (or complex, or hypercomplex numbers, although the Hadamard matrices themselves are purely real).

The Hadamard transform can be regarded as being built out of size-2 discrete Fourier transforms (DFTs), and is in fact equivalent to a multidimensional DFT of size Шаблон:Math.[2] It decomposes an arbitrary input vector into a superposition of Walsh functions.

The transform is named for the French mathematician Jacques Hadamard (Шаблон:IPA-fr), the German-American mathematician Hans Rademacher, and the American mathematician Joseph L. Walsh.

Definition

The Hadamard transform Hm is a 2m × 2m matrix, the Hadamard matrix (scaled by a normalization factor), that transforms 2m real numbers xn into 2m real numbers Xk. The Hadamard transform can be defined in two ways: recursively, or by using the binary (base-2) representation of the indices n and k.

Recursively, we define the 1 × 1 Hadamard transform H0 by the identity H0 = 1, and then define Hm for m > 0 by: <math display="block">H_m = \frac{1}{\sqrt2} \begin{pmatrix} H_{m-1} & H_{m-1} \\ H_{m-1} & -H_{m-1} \end{pmatrix}</math> where the 1/Шаблон:Radic is a normalization that is sometimes omitted.

For m > 1, we can also define Hm by: <math display="block">H_m = H_{1} \otimes H_{m-1}</math> where <math> \otimes </math> represents the Kronecker product. Thus, other than this normalization factor, the Hadamard matrices are made up entirely of 1 and −1.

Equivalently, we can define the Hadamard matrix by its (kn)-th entry by writing <math display="block">\begin{align}

 k &= \sum^{m-1}_{i=0} {k_i 2^i} = k_{m-1} 2^{m-1} + k_{m-2} 2^{m-2} + \dots + k_1 2 + k_0 \\
 n &= \sum^{m-1}_{i=0} {n_i 2^i} = n_{m-1} 2^{m-1} + n_{m-2} 2^{m-2} + \dots + n_1 2 + n_0

\end{align}</math>

where the kj and nj are the bit elements (0 or 1) of k and n, respectively. Note that for the element in the top left corner, we define: <math>k = n = 0</math>. In this case, we have: <math display="block"> (H_m)_{k,n} = \frac{1}{2^{m/2}} (-1)^{\sum_j k_j n_j}</math>

This is exactly the multidimensional <math display=inline> 2 \times 2 \times \cdots \times 2 \times 2</math> DFT, normalized to be unitary, if the inputs and outputs are regarded as multidimensional arrays indexed by the nj and kj, respectively.

Some examples of the Hadamard matrices follow. <math display="block"> \begin{align}

 H_0 & = +\begin{pmatrix}1\end{pmatrix}\\[5pt]
 H_1 & = \frac{1}{\sqrt2}
           \left(\begin{array}{rr}
             1 &  1\\
             1 & -1
           \end{array}\right)\\[5pt]
 H_2 & = \frac{1}{2}
  \left(\begin{array}{rrrr}
     1 &  1 &  1 &  1\\
     1 & -1 &  1 & -1\\
     1 &  1 & -1 & -1\\
     1 & -1 & -1 &  1
  \end{array}\right)\\[5pt]
 H_3 & = \frac{1}{2^{3/2}}
  \left(\begin{array}{rrrrrrrr}
     1 &  1 &  1 &  1 &  1 &  1 &  1 &  1\\
     1 & -1 &  1 & -1 &  1 & -1 &  1 & -1\\
     1 &  1 & -1 & -1 &  1 &  1 & -1 & -1\\
     1 & -1 & -1 &  1 &  1 & -1 & -1 &  1\\ 
     1 &  1 &  1 &  1 & -1 & -1 & -1 & -1\\
     1 & -1 &  1 & -1 & -1 &  1 & -1 &  1\\
     1 &  1 & -1 & -1 & -1 & -1 &  1 &  1\\
     1 & -1 & -1 &  1 & -1 &  1 &  1 & -1
  \end{array}\right)\\[5pt]
 (H_n)_{i,j} & = \frac{1}{2^{n/2}} (-1)^{i \cdot j}

\end{align} </math> where <math> i \cdot j </math> is the bitwise dot product of the binary representations of the numbers i and j. For example, if <math display="inline"> n \;\geq\; 2</math>, then <math display="block"> (H_n)_{3,2} \;=\; (-1)^{3 \cdot 2} \;=\; (-1)^{(1,1) \cdot (1,0)} \;=\; (-1)^{1+0} \;=\; (-1)^1 \;=\; -1</math>agreeing with the above (ignoring the overall constant). Note that the first row, first column element of the matrix is denoted by <math display="inline"> (H_n)_{0,0} </math>.

H1 is precisely the size-2 DFT. It can also be regarded as the Fourier transform on the two-element additive group of Z/(2).

The rows of the Hadamard matrices are the Walsh functions.

Advantages of the Walsh–Hadamard transform

Real

According to the above definition of matrix H, here we let H = H[m,n] <math display="block">H[m,n]=\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}</math>

In the Walsh transform, only 1 and −1 will appear in the matrix. The numbers 1 and −1 are real numbers so there is no need to perform a complex number calculation.

No multiplication is required

The DFT needs irrational multiplication, while the Hadamard transform does not. Even rational multiplication is not needed, since sign flips is all it takes.

Some properties are similar to those of the DFT

In the Walsh transform matrix, all entries in the first row (and column) are equal to 1. <math display="block">H[m,n] = \left(\begin{array}{rrrrrrrr}

 1 &  1 &  1 &  1 &  1 &  1 &  1 &  1\\
 1 &  1 &  1 &  1 & -1 & -1 & -1 & -1\\
 1 &  1 & -1 & -1 & -1 & -1 &  1 &  1\\
 1 &  1 & -1 & -1 &  1 &  1 & -1 & -1\\ 
 1 & -1 & -1 &  1 &  1 & -1 & -1 &  1\\
 1 & -1 & -1 &  1 & -1 &  1 &  1 & -1\\
 1 & -1 &  1 & -1 & -1 &  1 & -1 &  1\\
 1 & -1 &  1 & -1 &  1 & -1 &  1 & -1

\end{array}\right)</math>

Discrete Fourier transform: <math display="block">e^{-j 2\pi mn/N}</math>

In discrete Fourier transform, when m equal to zeros (mean first row), the result of DFT also is 1. At the second row, although it is different from the first row we can observe a characteristic of the matrix that the signal in the first raw matrix is low frequency and it will increase the frequency at second row, increase more frequency until the last row.

If we calculate zero crossing:

First row  = 0 zero crossing
Second row = 1 zero crossing
Third row  = 2 zero crossings
           ⋮
Eight row  = 7 zero crossings

Relation to Fourier transform

The Hadamard transform is in fact equivalent to a multidimensional DFT of size Шаблон:Math.[2]

Another approach is to view the Hadamard transform as a Fourier transform on the Boolean group <math>(\Z / 2\Z)^n</math>.[3] [4] Using the Fourier transform on finite (abelian) groups, the Fourier transform of a function <math>f \colon (\Z/2\Z)^n \to \Complex</math> is the function <math>\widehat f</math> defined by <math display="block">\widehat{f}(\chi) = \sum_{a \in (\Z/2\Z)^n} f(a) \bar{\chi}(a)</math> where <math>\chi</math> is a character of <math>(\Z/2\Z)^n</math>. Each character has the form <math>\chi_r(a) = (-1)^{a \cdot r}</math> for some <math>r \in (\Z/2\Z)^n</math>, where the multiplication is the boolean dot product on bit strings, so we can identify the input to <math>\widehat{f}</math> with <math>r \in (\Z/2\Z)^n</math> (Pontryagin duality) and define <math>\widehat f \colon (\Z/2\Z)^n \to \Complex</math> by <math display="block">\widehat{f}(r) = \sum_{a \in (\Z/2\Z)^n} f(a) (-1)^{r \cdot a}</math>

This is the Hadamard transform of <math>f</math>, considering the input to <math>f</math> and <math>\widehat{f}</math> as boolean strings.

In terms of the above formulation where the Hadamard transform multiplies a vector of <math>2^n</math> complex numbers <math>v</math> on the left by the Hadamard matrix <math>H_n</math> the equivalence is seen by taking <math>f</math> to take as input the bit string corresponding to the index of an element of <math>v</math>, and having <math>f</math> output the corresponding element of <math>v</math>.

Compare this to the usual discrete Fourier transform which when applied to a vector <math>v</math> of <math>2^n</math> complex numbers instead uses characters of the cyclic group <math>\Z / 2^n \Z</math>.

Computational complexity

In the classical domain, the Hadamard transform can be computed in <math>n \log n</math> operations (<math>n = 2^m</math>), using the fast Hadamard transform algorithm.

In the quantum domain, the Hadamard transform can be computed in <math>O(1)</math> time, as it is a quantum logic gate that can be parallelized.

Quantum computing applications

The Hadamard transform is used extensively in quantum computing. The 2 × 2 Hadamard transform <math>H_1</math> is the quantum logic gate known as the Hadamard gate, and the application of a Hadamard gate to each qubit of an Шаблон:Nowrap register in parallel is equivalent to the Hadamard transform Шаблон:Nowrap

Hadamard gate

Шаблон:Further In quantum computing, the Hadamard gate is a one-qubit rotation, mapping the qubit-basis states <math>|0 \rangle </math> and <math>|1 \rangle </math> to two superposition states with equal weight of the computational basis states <math>|0 \rangle </math> and <math>|1 \rangle </math>. Usually the phases are chosen so that <math display="block">H=\frac{|0\rangle+|1\rangle}{\sqrt{2}}\langle0|+\frac{|0\rangle-|1\rangle}{\sqrt{2}}\langle1|</math>

in Dirac notation. This corresponds to the transformation matrix <math display="block">H_1=\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}</math> in the <math>|0 \rangle , |1 \rangle </math> basis, also known as the computational basis. The states <math display="inline"> \frac{\left|0\right\rangle + \left|1\right\rangle}{\sqrt{2}}</math> and <math display="inline">\frac{\left|0\right\rangle - \left|1\right\rangle}{\sqrt{2}}</math> are known as <math>\left|\boldsymbol{+}\right\rangle</math> and <math>\left|\boldsymbol{-}\right\rangle</math> respectively, and together constitute the polar basis in quantum computing.

Hadamard gate operations

<math display="block">\begin{align}

 H(|0\rangle) &= \frac{1}{\sqrt 2}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle =: |+\rangle\\
 H(|1\rangle) &= \frac{1}{\sqrt 2}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle =: |-\rangle\\
 H(|+\rangle) &= H\left( \frac{1}{\sqrt 2}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle \right) = \frac{1}{2}\Big( |0\rangle + |1\rangle\Big) + \frac{1}{2}\Big(|0\rangle - |1\rangle\Big) = |0\rangle\\
 H(|-\rangle) &= H\left( \frac{1}{\sqrt 2}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle \right) = \frac{1}{2}\Big( |0\rangle + |1\rangle\Big) - \frac{1}{2}\Big(|0\rangle - |1\rangle\Big) = |1\rangle

\end{align}</math>

One application of the Hadamard gate to either a 0 or 1 qubit will produce a quantum state that, if observed, will be a 0 or 1 with equal probability (as seen in the first two operations). This is exactly like flipping a fair coin in the standard probabilistic model of computation. However, if the Hadamard gate is applied twice in succession (as is effectively being done in the last two operations), then the final state is always the same as the initial state.

Hadamard transform in quantum algorithms

Computing the quantum Hadamard transform is simply the application of a Hadamard gate to each qubit individually because of the tensor product structure of the Hadamard transform. This simple result means the quantum Hadamard transform requires <math>\log_2 N </math> operations, compared to the classical case of <math>N \log_2 N</math> operations.


For an <math>n</math>-qubit system, Hadamard gates acting on each of the <math>n</math> qubits (each initialized to the <math>|0\rangle</math>) can be used to prepare uniform quantum superposition states when <math>N</math> is of the form <math>N = 2^n</math>. In this case case with <math>n</math> qubits, the combined Hadamard gate <math>H_n</math> is expressed as the tensor product of <math>n</math> Hadamard gates: <math>H_n = \underbrace{H \otimes H \otimes \ldots \otimes H}_{n \text{ times}}</math>

The resulting uniform quantum superposition state is then: <math> H_{n} |0\rangle^{\otimes n} = \frac{1}{\sqrt{2^n}} \sum_{j=0}^{2^n-1} |j\rangle</math> This generalizes the preparation of uniform quantum states using Hadamard gates for any <math>N = 2^n</math> [5].

Measurement of this uniform quantum state results in a random random state between <math>|0\rangle</math> and Шаблон:Nowrap

Many quantum algorithms use the Hadamard transform as an initial step, since as explained earlier, it maps n qubits initialized with <math>|0 \rangle</math> to a superposition of all 2n orthogonal states in the <math> |0 \rangle , |1 \rangle </math> basis with equal weight. For example, this is used in the Deutsch–Jozsa algorithm, Simon's algorithm, the Bernstein–Vazirani algorithm, and in Grover's algorithm. Note that Shor's algorithm uses both an initial Hadamard transform, as well as the quantum Fourier transform, which are both types of Fourier transforms on finite groups; the first on <math>(\Z / 2 \Z)^n</math> and the second on <math>\Z /2^n \Z</math>.

Preparation of uniform quantum superposition states in the general case, when <math>N </math> ≠ <math>2^n</math> is non-trivial and requires more work. An efficient and deterministic approach for preparing the superposition state <math display="block"> |\Psi\rangle = \frac{1}{\sqrt{N}} \sum_{j=0}^{N-1} |j\rangle </math> with a gate complexity and circuit depth of only <math> O(\log_2 N)</math> for all <math>N</math> was recently presented [6]. This approach requires only <math> n = \lceil \log_2 N \rceil</math> qubits. Importantly, neither ancilla qubits nor any quantum gates with multiple controls are needed in this approach for creating the uniform superposition state <math> |\Psi\rangle </math>.

Molecular phylogenetics (evolutionary biology) applications

The Hadamard transform can be used to estimate phylogenetic trees from molecular data.[7][8][9] Phylogenetics is the subfield of evolutionary biology focused on understanding the relationships among organisms. A Hadamard transform applied to a vector (or matrix) of site pattern frequencies obtained from a DNA multiple sequence alignment can be used to generate another vector that carries information about the tree topology. The invertible nature of the phylogenetic Hadamard transform also allows the calculation of site likelihoods from a tree topology vector, allowing one to use the Hadamard transform for maximum likelihood estimation of phylogenetic trees. However, the latter application is less useful than the transformation from the site pattern vector to the tree vector because there are other ways to calculate site likelihoods[10][11] that are much more efficient. However, the invertible nature of the phylogenetic Hadamard transform does provide an elegant tool for mathematic phylogenetics.[12][13]

The mechanics of the phylogenetic Hadamard transform involve the calculation of a vector <math>\gamma(T)</math> that provides information about the topology and branch lengths for tree <math>T</math> using the site pattern vector or matrix <math>s(T)</math>.

<math display="block">\gamma(T) = H^{-1}(\ln(Hs(T)))</math> where <math>H</math> is the Hadamard matrix of the appropriate size. This equation can be rewritten as a series of three equations to simplify its interpretation:

<math display="block">\begin{align}

         r &= H s(T) \\
      \rho &= \ln r \\
 \gamma(T) &= H^{-1}\rho

\end{align}</math>

The invertible nature of this equation allows one to calculate an expected site pattern vector (or matrix) as follows:

<math display="block">s(T)=H^{-1}(\exp(H\gamma(T)))</math>

We can use the Cavender–Farris–Neyman (CFN) two-state substitution model for DNA by encoding the nucleotides as binary characters (the purines A and G are encoded as R and the pyrimidines C and T are encoded as Y). This makes it possible to encode the multiple sequence alignment as the site pattern vector <math>s(T)</math> that can be converted to a tree vector <math>\gamma(T)</math>, as shown in the following example:

Example showing the Hadamard transform for a specific tree (values for worked example adapted from Waddell et al. 1997[14])
Index Binary pattern Alignment patterns <math>\gamma(T)</math> <math>\rho = H^{-1}\gamma(T)</math> <math>r = \exp(\rho)</math> <math>s(T) = H^{-1}\rho</math>
0 0000 RRRR and YYYY −0.475 0 1 0.6479
1 0001 RRRY and YYYR 0.2 −0.5 0.6065 0.1283
2 0010 RRYR and YYRY 0.025 −0.15 0.8607 0.02
3* 0011 RRYY and YYRR 0.025 −0.45 0.6376 0.0226
4 0100 RYRR and YRYY 0.2 −0.45 0.6376 0.1283
5* 0101 RYRY and YRYR 0 −0.85 0.4274 0.0258
6* 0110 RYYR and YRRY 0 −0.5 0.6065 0.0070
7 0111 RYYY and YRRR 0.025 −0.9 0.4066 0.02

The example shown in this table uses the simplified three equation scheme and it is for a four taxon tree that can be written as ((A,B),(C,D)); in newick format. The site patterns are written in the order ABCD. This particular tree has two long terminal branches (0.2 transversion substitutions per site), two short terminal branches (0.025 transversion substitutions per site), and a short internal branch (0.025 transversion substitutions per site); thus, it would be written as ((A:0.025,B:0.2):0.025,(C:0.025,D:0.2)); in newick format. This tree will exhibit long branch attraction if the data are analyzed using the maximum parsimony criterion (assuming the sequence analyzed is long enough for the observed site pattern frequencies to be close to the expected frequencies shown in the <math>s(T)=H^{-1}\rho</math> column). The long branch attraction reflects the fact that the expected number of site patterns with index 6 -- which support the tree ((A,C),(B,D)); -- exceed the expected number of site patterns that support the true tree (index 4). Obviously, the invertible nature of the phylogenetic Hadamard transform means that the tree vector means that the tree vector <math>\gamma(T)</math> corresponds to the correct tree. Parsimony analysis after the transformation is therefore statistically consistent,[15] as would be a standard maximum likelihood analysis using the correct model (in this case the CFN model).

Note that the site pattern with 0 corresponds to the sites that have not changed (after encoding the nucleotides as purines or pyrimidines). The indices with asterisks (3, 5, and 6) are "parsimony-informative", and. the remaining indices represent site patterns where a single taxon differs from the other three taxa (so they are the equivalent of terminal branch lengths in a standard maximum likelihood phylogenetic tree).

If one wishes to use nucleotide data without recoding as R and Y (and ultimately as 0 and 1) it is possible to encode the site patterns as a matrix. If we consider a four-taxon tree there are a total of 256 site patterns (four nucleotides to the 4th power). However, symmetries of the Kimura three-parameter (or K81) model allow us to reduce the 256 possible site patterns for DNA to 64 patterns, making it possible to encode the nucleotide data for a four-taxon tree as an 8 × 8 matrix[16] in a manner similar to the vector of 8 elements used above for transversion (RY) site patterns. This is accomplished by recoding the data using the Klein four-group:

Klein four-group coding for phylogenetic Hadamard transform
Nucleotide 1 Nucleotide 2 Nucleotide 3 Nucleotide 4
A (0,0) G (1,0) C (0,1) T (1,1)
C (0,0) T (1,0) A (0,1) G (1,1)
G (0,0) A (1,0) T (0,1) C (1,1)
T (0,0) C (1,0) G (0,1) A (1,1)

As with RY data, site patterns are indexed relative to the base in the arbitrarily chosen first taxon with the bases in the subsequent taxa encoded relative to that first base. Thus, the first taxon receives the bit pair (0,0). Using those bit pairs one can produce two vectors similar to the RY vectors and then populate the matrix using those vectors. This can be illustrated using the example from Hendy et al. (1994),[16] which is based on a multiple sequence alignment of four primate hemoglobin pseudogenes:

Example of encoded sequence alignment (from Hendy et al. 1994[16]) (values are counts out of 9879 sites)
0 8 16 24 32 40 48 56
0 8988 9 10 12 24 90
1 41 9 **
2 45 13
3 54* 14 3
4 94 20
5 1
6 2 2
7 356 1 1 75

The much larger number of site patterns in column 0 reflects the fact that column 0 corresponds to transition differences, which accumulate more rapidly than transversion differences in virtually all comparisons of genomic regions (and definitely accumulate more rapidly in the hemoglobin pseudogenes used for this worked example[17]). If we consider the site pattern AAGG it would to binary pattern 0000 for the second element of the Klein group bit pair and 0011 for the first element. in this case binary pattern based on the first element first element corresponds to index 3 (so row 3 in column 0; indicated with a single asterisk in the table). The site patterns GGAA, CCTT, and TTCC would be encoded in the exact same way. The site pattern AACT would be encoded with binary pattern 0011 based on the second element and 0001 based on the first element; this yields index 1 for the first element and index 3 for the second. The index based on the second Klein group bit pair is multiplied by 8 to yield the column index (in this case it would be column 24) The cell that would include the count of AACT site patterns is indicated with two asterisks; however, the absence of a number in the example indicates that the sequence alignment include no AACT site patterns (likewise, CCAG, GGTC, and TTGA site patterns, which would be encoded in the same way, are absent).

Other applications

The Hadamard transform is also used in data encryption, as well as many signal processing and data compression algorithms, such as JPEG XR and MPEG-4 AVC. In video compression applications, it is usually used in the form of the sum of absolute transformed differences. It is also a crucial part of significant number of algorithms in quantum computing. The Hadamard transform is also applied in experimental techniques such as NMR, mass spectrometry and crystallography. It is additionally used in some versions of locality-sensitive hashing, to obtain pseudo-random matrix rotations.

See also

External links

References

Шаблон:Reflist