Package org.hipparchus.transform
Class FastHadamardTransformer
- java.lang.Object
-
- org.hipparchus.transform.FastHadamardTransformer
-
- All Implemented Interfaces:
Serializable
,RealTransformer
public class FastHadamardTransformer extends Object implements RealTransformer, Serializable
Implements the Fast Hadamard Transform (FHT). Transformation of an input vector x to the output vector y.In addition to transformation of real vectors, the Hadamard transform can transform integer vectors into integer vectors. However, this integer transform cannot be inverted directly. Due to a scaling factor it may lead to rational results. As an example, the inverse transform of integer vector (0, 1, 0, 1) is rational vector (1/2, -1/2, 0, 0).
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FastHadamardTransformer()
Empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double[]
fht(double[] x)
The FHT (Fast Hadamard Transformation) which uses only subtraction and addition.protected int[]
fht(int[] x)
Returns the forward transform of the specified integer data set.double[]
transform(double[] f, TransformType type)
Returns the (forward, inverse) transform of the specified real data set.int[]
transform(int[] f)
Returns the forward transform of the specified integer data set.The integer transform cannot be inverted directly, due to a scaling factor which may lead to double results.double[]
transform(UnivariateFunction f, double min, double max, int n, TransformType type)
Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.
-
-
-
Method Detail
-
transform
public double[] transform(double[] f, TransformType type)
Returns the (forward, inverse) transform of the specified real data set.- Specified by:
transform
in interfaceRealTransformer
- Parameters:
f
- the real data array to be transformed (signal)type
- the type of transform (forward, inverse) to be performed- Returns:
- the real transformed array (spectrum)
- Throws:
MathIllegalArgumentException
- if the length of the data array is not a power of two
-
transform
public double[] transform(UnivariateFunction f, double min, double max, int n, TransformType type)
Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.- Specified by:
transform
in interfaceRealTransformer
- Parameters:
f
- the function to be sampled and transformedmin
- the (inclusive) lower bound for the intervalmax
- the (exclusive) upper bound for the intervaln
- the number of sample pointstype
- the type of transform (forward, inverse) to be performed- Returns:
- the real transformed array
- Throws:
MathIllegalArgumentException
- if the lower bound is greater than, or equal to the upper boundMathIllegalArgumentException
- if the number of sample points is negativeMathIllegalArgumentException
- if the number of sample points is not a power of two
-
transform
public int[] transform(int[] f)
Returns the forward transform of the specified integer data set.The integer transform cannot be inverted directly, due to a scaling factor which may lead to double results.- Parameters:
f
- the integer data array to be transformed (signal)- Returns:
- the integer transformed array (spectrum)
- Throws:
MathIllegalArgumentException
- if the length of the data array is not a power of two
-
fht
protected double[] fht(double[] x) throws MathIllegalArgumentException
The FHT (Fast Hadamard Transformation) which uses only subtraction and addition. RequiresN * log2(N) = n * 2^n
additions.- x is the input vector to be transformed,
- y is the output vector (Fast Hadamard transform of x),
- a and b are helper rows.
Short Table of manual calculation for N=8 x a b y x0 a0 = x0 + x1 b0 = a0 + a1 y0 = b0+ b1 x1 a1 = x2 + x3 b0 = a2 + a3 y0 = b2 + b3 x2 a2 = x4 + x5 b0 = a4 + a5 y0 = b4 + b5 x3 a3 = x6 + x7 b0 = a6 + a7 y0 = b6 + b7 x4 a0 = x0 - x1 b0 = a0 - a1 y0 = b0 - b1 x5 a1 = x2 - x3 b0 = a2 - a3 y0 = b2 - b3 x6 a2 = x4 - x5 b0 = a4 - a5 y0 = b4 - b5 x7 a3 = x6 - x7 b0 = a6 - a7 y0 = b6 - b7 How it works
- Construct a matrix with
N
rows andn + 1
columns,hadm[n+1][N]
.
(If I use [x][y] it always means [row-offset][column-offset] of a Matrix with n rows and m columns. Its entries go from M[0][0] to M[n][N]) - Place the input vector
x[N]
in the first column of the matrixhadm
. - The entries of the submatrix
D_top
are calculated as followsD_top
goes from entry[0][1]
to[N / 2 - 1][n + 1]
,- the columns of
D_top
are the pairwise mutually exclusive sums of the previous column.
- The entries of the submatrix
D_bottom
are calculated as followsD_bottom
goes from entry[N / 2][1]
to[N][n + 1]
,- the columns of
D_bottom
are the pairwise differences of the previous column.
- The consputation of
D_top
andD_bottom
are best understood with the above example (forN = 8
). - The output vector
y
is now in the last column ofhadm
. - Algorithm from chipcenter.
visually 0 1 2 3 … n + 1 0 x0 ↑
← Dtop →
↓1 x1 2 x2 … … N / 2 - 1 xN/2-1 N / 2 xN/2 ↑
← Dbottom →
↓N / 2 + 1 xN/2+1 N / 2 + 2 xN/2+2 … … N xN - Parameters:
x
- the real data array to be transformed- Returns:
- the real transformed array,
y
- Throws:
MathIllegalArgumentException
- if the length of the data array is not a power of two
-
fht
protected int[] fht(int[] x) throws MathIllegalArgumentException
Returns the forward transform of the specified integer data set. The FHT (Fast Hadamard Transform) uses only subtraction and addition.- Parameters:
x
- the integer data array to be transformed- Returns:
- the integer transformed array,
y
- Throws:
MathIllegalArgumentException
- if the length of the data array is not a power of two
-
-