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 java.lang.Object implements SquareMatrixSupport.RealSquareMatrix
Implementation ofSquareMatrixSupport.RealSquareMatrix
using adouble[]
array to store entries. Values are addressed usingi*dim + j
wheredim
is the square dimension.Scaling is supported using the central element
[m][m]
wherem = 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
Fields Modifier and Type Field Description private double[]
data
Entries of the matrix.private int
dim
Dimension.private int
exp
Matrix scale.private static double
SCALE_THRESHOLD
The scaling threshold.
-
Constructor Summary
Constructors Constructor Description ArrayRealSquareMatrix(int dimension, double[] data, int scale)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkExponent(int p)
Check the exponent is not negative.int
dimension()
Gets the dimension for the rows and columns.double
get(int i, int j)
Gets the value.private SquareMatrixSupport.RealSquareMatrix
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
.SquareMatrixSupport.RealSquareMatrix
power(int n)
Returns the result of multiplyingthis
with itselfn
times.int
scale()
Gets the scale of the matrix values.
-
-
-
Field Detail
-
SCALE_THRESHOLD
private static final double SCALE_THRESHOLD
The scaling threshold. Marsaglia used 1e140. This uses 2^400 ~ 2.58e120- See Also:
- Constant Field Values
-
dim
private final int dim
Dimension.
-
data
private final double[] data
Entries of the matrix.
-
exp
private final int exp
Matrix scale.
-
-
Method Detail
-
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:
SquareMatrixSupport.RealSquareMatrix.scale()
-
power
public SquareMatrixSupport.RealSquareMatrix power(int n)
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
private SquareMatrixSupport.RealSquareMatrix 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:
java.lang.IllegalArgumentException
- if the exponent is negative
-
-