Class SquareMatrixSupport.ArrayRealSquareMatrix
java.lang.Object
org.apache.commons.statistics.inference.SquareMatrixSupport.ArrayRealSquareMatrix
- All Implemented Interfaces:
SquareMatrixSupport.RealSquareMatrix
- Enclosing class:
SquareMatrixSupport
private static class SquareMatrixSupport.ArrayRealSquareMatrix
extends Object
implements SquareMatrixSupport.RealSquareMatrix
Implementation of
SquareMatrixSupport.RealSquareMatrix using a double[] array to
store entries. Values are addressed using i*dim + j where dim is
the square dimension.
Scaling is supported using the central element [m][m] where
m = dimension/2. Scaling is only implemented post-multiplication
to protect against overflow during repeat multiplication operations.
Note: The scaling is implemented to support computation of Kolmogorov's distribution as described in:
- Marsaglia, G., Tsang, W. W., & Wang, J. (2003). Evaluating Kolmogorov's Distribution. Journal of Statistical Software, 8(18), 1–4.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]Entries of the matrix.private final intDimension.private final intMatrix scale.private static final doubleThe scaling threshold. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckExponent(int p) Check the exponent is not negative.intGets the dimension for the rows and columns.doubleget(int i, int j) Gets the value.identity()Creates the identity matrix I with the same dimension asthis.private static intmultiply(double[] a, int sa, double[] b, int sb, double[] col, double[] out) Returns the result of postmultiplyingabyb.power(int n) Returns the result of multiplyingthiswith itselfntimes.intscale()Gets the scale of the matrix values.
-
Field Details
-
SCALE_THRESHOLD
private static final double SCALE_THRESHOLDThe scaling threshold. Marsaglia used 1e140. This uses 2^400 ~ 2.58e120- See Also:
-
dim
private final int dimDimension. -
data
private final double[] dataEntries of the matrix. -
exp
private final int expMatrix scale.
-
-
Constructor Details
-
ArrayRealSquareMatrix
ArrayRealSquareMatrix(int dimension, double[] data, int scale) - Parameters:
dimension- Matrix dimension.data- Matrix data.scale- Matrix scale.
-
-
Method Details
-
dimension
public int dimension()Description copied from interface:SquareMatrixSupport.RealSquareMatrixGets the dimension for the rows and columns.- Specified by:
dimensionin interfaceSquareMatrixSupport.RealSquareMatrix- Returns:
- the dimension
-
scale
public int scale()Description copied from interface:SquareMatrixSupport.RealSquareMatrixGets the scale of the matrix values. The true value is the value returned fromSquareMatrixSupport.RealSquareMatrix.get(int, int)multiplied by2^scale.- Specified by:
scalein interfaceSquareMatrixSupport.RealSquareMatrix- Returns:
- the scale
-
get
public double get(int i, int j) Description copied from interface:SquareMatrixSupport.RealSquareMatrixGets the value. This is a scaled value. The true value is the value returned multiplied by2^scale.- Specified by:
getin interfaceSquareMatrixSupport.RealSquareMatrix- Parameters:
i- Rowj- Column- Returns:
- the value
- See Also:
-
power
Description copied from interface:SquareMatrixSupport.RealSquareMatrixReturns the result of multiplyingthiswith itselfntimes.- Specified by:
powerin interfaceSquareMatrixSupport.RealSquareMatrix- Parameters:
n- raisethisto powern- Returns:
this^n
-
identity
Creates the identity matrix I with the same dimension asthis.- Returns:
- I
-
multiply
private static int multiply(double[] a, int sa, double[] b, int sb, double[] col, double[] out) Returns the result of postmultiplyingabyb. It is expected the scale of the result will be the sum of the scale of the arguments; this may be adjusted by the scale power if the result is scaled by a power of two for overflow protection.- Parameters:
a- Matrix.sa- Scale of matrix a.b- Matrix to postmultiply by.sb- Scale of matrix b.col- Working array for a column of the matrix.out- Outputa * b- Returns:
- Scale of
a * b
-
checkExponent
private static void checkExponent(int p) Check the exponent is not negative.- Parameters:
p- Exponent.- Throws:
IllegalArgumentException- if the exponent is negative
-