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.RealSquareMatrixusing adouble[]array to store entries. Values are addressed usingi*dim + jwheredimis 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[]dataEntries of the matrix.private intdimDimension.private intexpMatrix scale.private static doubleSCALE_THRESHOLDThe 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 voidcheckExponent(int p)Check the exponent is not negative.intdimension()Gets the dimension for the rows and columns.doubleget(int i, int j)Gets the value.private SquareMatrixSupport.RealSquareMatrixidentity()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.SquareMatrixSupport.RealSquareMatrixpower(int n)Returns the result of multiplyingthiswith itselfntimes.intscale()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.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:
SquareMatrixSupport.RealSquareMatrix.scale()
-
power
public SquareMatrixSupport.RealSquareMatrix power(int n)
Description copied from interface:SquareMatrixSupport.RealSquareMatrixReturns the result of multiplyingthiswith itselfntimes.- Specified by:
powerin interfaceSquareMatrixSupport.RealSquareMatrix- Parameters:
n- raisethisto 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 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:
java.lang.IllegalArgumentException- if the exponent is negative
-
-