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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]
Entries of the matrix.private final int
Dimension.private final int
Matrix scale.private static final double
The scaling threshold. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
checkExponent
(int p) Check the exponent is not negative.int
Gets the dimension for the rows and columns.double
get
(int i, int j) Gets the value.identity()
Creates the identity matrix I with the same dimension asthis
.private static int
multiply
(double[] a, int sa, double[] b, int sb, double[] col, double[] out) Returns the result of postmultiplyinga
byb
.power
(int n) Returns the result of multiplyingthis
with itselfn
times.int
scale()
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.RealSquareMatrix
Gets the dimension for the rows and columns.- Specified by:
dimension
in interfaceSquareMatrixSupport.RealSquareMatrix
- Returns:
- the dimension
-
scale
public int scale()Description copied from interface:SquareMatrixSupport.RealSquareMatrix
Gets the scale of the matrix values. The true value is the value returned fromSquareMatrixSupport.RealSquareMatrix.get(int, int)
multiplied by2^scale
.- Specified by:
scale
in interfaceSquareMatrixSupport.RealSquareMatrix
- Returns:
- the scale
-
get
public double get(int i, int j) Description copied from interface:SquareMatrixSupport.RealSquareMatrix
Gets the value. This is a scaled value. The true value is the value returned multiplied by2^scale
.- Specified by:
get
in interfaceSquareMatrixSupport.RealSquareMatrix
- Parameters:
i
- Rowj
- Column- Returns:
- the value
- See Also:
-
power
Description copied from interface:SquareMatrixSupport.RealSquareMatrix
Returns the result of multiplyingthis
with itselfn
times.- Specified by:
power
in interfaceSquareMatrixSupport.RealSquareMatrix
- Parameters:
n
- raisethis
to 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 postmultiplyinga
byb
. 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
-