Class SvdImplicitQrAlgorithm_FDRM
- java.lang.Object
-
- org.ejml.dense.row.decomposition.svd.implicitqr.SvdImplicitQrAlgorithm_FDRM
-
public class SvdImplicitQrAlgorithm_FDRM extends java.lang.ObjectComputes the QR decomposition of a bidiagonal matrix. Internally this matrix is stored as two arrays. Shifts can either be provided to it or it can generate the shifts on its own. It optionally computes the U and V matrices. This comparability allows it to be used to compute singular values and associated matrices efficiently.
A = U*S*VT
where A is the original m by n matrix.Based off of the outline provided in:
David S. Watkins, "Fundamentals of Matrix Computations," Second Edition. Page 404-411Note: To watch it process the matrix step by step uncomment commented out code.
-
-
Field Summary
Fields Modifier and Type Field Description protected float[]diagprotected EigenvalueSmall_F32eigenSmallprotected floatmaxValueprotected intNprotected intnextExceptionalprotected intnumExceptionalprotected intnumSplitsprotected float[]offprotected java.util.Randomrandprotected int[]splitsprotected inttotalStepsprotected org.ejml.data.FMatrixRMajUtprotected org.ejml.data.FMatrixRMajVtprotected intx1protected intx2
-
Constructor Summary
Constructors Constructor Description SvdImplicitQrAlgorithm_FDRM()SvdImplicitQrAlgorithm_FDRM(boolean fastValues)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean_process()protected booleancheckForAndHandleZeros()Checks to see if either the diagonal element or off diagonal element is zero.protected voidcomputeRotator(float rise, float run)Computes a rotator that will set run to zero (?)protected voidcreateBulge(int x1, float p, float scale, boolean byAngle)Performs a similar transform on BTB-pIprotected voideigenBB_2x2(int x1)Computes the eigenvalue of the 2 by 2 matrix BTBvoidexceptionShift()It is possible for the QR algorithm to get stuck in a loop because of symmetries.float[]getDiag()floatgetMaxValue()intgetNumberOfSingularValues()float[]getOff()floatgetSingularValue(int index)float[]getSingularValues()org.ejml.data.FMatrixRMajgetUt()org.ejml.data.FMatrixRMajgetVt()voidincrementSteps()voidinitParam(int M, int N)booleanisDiagonalZero(int i)booleanisOffZero(int i)booleannextSplit()Tells it to process the submatrix at the next split.voidperformImplicitSingleStep(float scale, float lambda, boolean byAngle)Given the lambda value perform an implicit QR step on the matrix.voidprintMatrix()booleanprocess()booleanprocess(float[] values)Perform a sequence of steps based off of the singular values provided.protected voidremoveBulgeLeft(int x1, boolean notLast)protected voidremoveBulgeRight(int x1)voidresetSteps()floatselectWilkinsonShift(float scale)Selects the Wilkinson's shift for BTB.voidsetFastValues(boolean b)voidsetMatrix(int numRows, int numCols, float[] diag, float[] off)voidsetMaxValue(float maxValue)voidsetSubmatrix(int x1, int x2)voidsetUt(org.ejml.data.FMatrixRMaj ut)voidsetVt(org.ejml.data.FMatrixRMaj vt)float[]swapDiag(float[] diag)float[]swapOff(float[] off)protected voidupdateRotator(org.ejml.data.FMatrixRMaj Q, int m, int n, float c, float s)Multiplied a transpose orthogonal matrix Q by the specified rotator.
-
-
-
Field Detail
-
rand
protected java.util.Random rand
-
Ut
protected org.ejml.data.FMatrixRMaj Ut
-
Vt
protected org.ejml.data.FMatrixRMaj Vt
-
totalSteps
protected int totalSteps
-
maxValue
protected float maxValue
-
N
protected int N
-
eigenSmall
protected EigenvalueSmall_F32 eigenSmall
-
numExceptional
protected int numExceptional
-
nextExceptional
protected int nextExceptional
-
diag
protected float[] diag
-
off
protected float[] off
-
x1
protected int x1
-
x2
protected int x2
-
splits
protected int[] splits
-
numSplits
protected int numSplits
-
-
Method Detail
-
getUt
public org.ejml.data.FMatrixRMaj getUt()
-
setUt
public void setUt(org.ejml.data.FMatrixRMaj ut)
-
getVt
public org.ejml.data.FMatrixRMaj getVt()
-
setVt
public void setVt(org.ejml.data.FMatrixRMaj vt)
-
setMatrix
public void setMatrix(int numRows, int numCols, float[] diag, float[] off)
-
swapDiag
public float[] swapDiag(float[] diag)
-
swapOff
public float[] swapOff(float[] off)
-
setMaxValue
public void setMaxValue(float maxValue)
-
initParam
public void initParam(int M, int N)
-
process
public boolean process()
-
process
public boolean process(float[] values)
Perform a sequence of steps based off of the singular values provided.- Parameters:
values-- Returns:
-
_process
public boolean _process()
-
incrementSteps
public void incrementSteps()
-
isOffZero
public boolean isOffZero(int i)
-
isDiagonalZero
public boolean isDiagonalZero(int i)
-
resetSteps
public void resetSteps()
-
nextSplit
public boolean nextSplit()
Tells it to process the submatrix at the next split. Should be called after the current submatrix has been processed.
-
performImplicitSingleStep
public void performImplicitSingleStep(float scale, float lambda, boolean byAngle)Given the lambda value perform an implicit QR step on the matrix. B^T*B-lambda*I- Parameters:
lambda- Stepping factor.
-
updateRotator
protected void updateRotator(org.ejml.data.FMatrixRMaj Q, int m, int n, float c, float s)Multiplied a transpose orthogonal matrix Q by the specified rotator. This is used to update the U and V matrices. Updating the transpose of the matrix is faster since it only modifies the rows.- Parameters:
Q- Orthogonal matrixm- Coordinate of rotator.n- Coordinate of rotator.c- cosine of rotator.s- sine of rotator.
-
createBulge
protected void createBulge(int x1, float p, float scale, boolean byAngle)Performs a similar transform on BTB-pI
-
computeRotator
protected void computeRotator(float rise, float run)Computes a rotator that will set run to zero (?)
-
removeBulgeLeft
protected void removeBulgeLeft(int x1, boolean notLast)
-
removeBulgeRight
protected void removeBulgeRight(int x1)
-
setSubmatrix
public void setSubmatrix(int x1, int x2)
-
selectWilkinsonShift
public float selectWilkinsonShift(float scale)
Selects the Wilkinson's shift for BTB. See page 410. It is guaranteed to converge and converges fast in practice.- Parameters:
scale- Scale factor used to help prevent overflow/underflow- Returns:
- Shifting factor lambda/(scale*scale)
-
eigenBB_2x2
protected void eigenBB_2x2(int x1)
Computes the eigenvalue of the 2 by 2 matrix BTB
-
checkForAndHandleZeros
protected boolean checkForAndHandleZeros()
Checks to see if either the diagonal element or off diagonal element is zero. If one is then it performs a split or pushes it off the matrix.- Returns:
- True if there was a zero.
-
exceptionShift
public void exceptionShift()
It is possible for the QR algorithm to get stuck in a loop because of symmetries. This happens more often with larger matrices. By taking a random step it can break the symmetry and finish.
-
printMatrix
public void printMatrix()
-
getNumberOfSingularValues
public int getNumberOfSingularValues()
-
getSingularValue
public float getSingularValue(int index)
-
setFastValues
public void setFastValues(boolean b)
-
getSingularValues
public float[] getSingularValues()
-
getDiag
public float[] getDiag()
-
getOff
public float[] getOff()
-
getMaxValue
public float getMaxValue()
-
-