Class Givens
G(i, k, theta)
which, when left multiplied to a vector, represents
a counterclockwise rotation of theta
radians of the vector in the (i, j)
plane. Givens rotators
are a unitary transformation.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
get2x2Rotator
(double v0, double v1) Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.static CMatrix
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.static Matrix
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.static CMatrix
get2x2Rotator
(CNumber v0, CNumber v1) Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.static Matrix
getGeneralRotator
(int size, int i, int j, double theta) Constructs a general Givens rotation matrix.static Matrix
getRotator
(double[] v, int i) Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0.static CMatrix
getRotator
(CVector v, int i) Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0.static Matrix
getRotator
(Vector v, int i) Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0.static void
leftMult2x2Rotator
(CMatrix src, CMatrix G, int row, CNumber[] workArray) Left multiplies a 2x2 Givens rotator to a matrix at the specified row.static void
leftMult2x2Rotator
(Matrix src, Matrix G, int row, double[] workArray) Left multiplies a 2x2 Givens rotator to a matrix at the specified row.static void
rightMult2x2Rotator
(CMatrix src, CMatrix G, int row, CNumber[] workArray) Right multiplies a 2x2 Givens rotator to a matrix at the specified row.static void
rightMult2x2Rotator
(Matrix src, Matrix G, int row, double[] workArray) Right multiplies a 2x2 Givens rotator to a matrix at the specified row.private static double[]
stableTrigVals
(double a, double b) Computes the sine and cosine values for a Givens' rotation in a stable manner which avoids any possibility of overflow.
-
Constructor Details
-
Givens
private Givens()
-
-
Method Details
-
getGeneralRotator
Constructs a general Givens rotation matrix. This method can be numerically unstable. SeegetRotator(Vector, int)
if the goal is to zero an element of a vector using a Givens rotator. This method will produce more accurate results in general and is more robust to overflows.- Parameters:
size
- The size of the Givens' rotation matrix.i
- Index of the first axis to rotate through.j
- Index of the second axis to rotate through.theta
- Angle in radians of rotation through the(i, j)
plane.- Returns:
- A Givens' rotation matrix with specified
size
which, when left multiplied to a vector, represents a counterclockwise rotation oftheta
radians of the vector in the(i, j)
plane. - Throws:
IndexOutOfBoundsException
- Ifi
orj
is greater than or equal tosize
.
-
getRotator
Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. That is, when the rotatorG
is left multiplied to the vectorv
, it zeros out the entry at positioni
.- Parameters:
v
- Vector to construct Givens rotator for.i
- Position to zero out when applying the rotator to v.- Returns:
- A Givens rotator
G
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. - Throws:
IndexOutOfBoundsException
- Ifi
is not in the range[0, v.size)
.
-
getRotator
Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. That is, when the rotatorG
is left multiplied to the vectorv
, it zeros out the entry at positioni
.- Parameters:
v
- Vector to construct Givens rotator for.i
- Position to zero out when applying the rotator to v.- Returns:
- A Givens rotator
G
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. - Throws:
IndexOutOfBoundsException
- Ifi
is not in the range[0, v.size)
.
-
getRotator
Constructs a Givens rotatorG
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. That is, when the rotatorG
is left multiplied to the vectorv
, it zeros out the entry at positioni
.- Parameters:
v
- Vector to construct Givens rotator for.i
- Position to zero out when applying the rotator to v.- Returns:
- A Givens rotator
G
such that for a vectorv
,Gv = [r<sub>1</sub> ... r<sub>i</sub> ... r<sub>n</sub>]
where ri=0. - Throws:
IndexOutOfBoundsException
- Ifi
is not in the range[0, v.size)
.
-
get2x2Rotator
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.- Parameters:
v
- Vector of size 2 to construct Givens rotator for.- Returns:
- A Givens rotator
G
of size 2 such that for a vectorv = [a, b]
we haveGx = [r, 0]
. - Throws:
IllegalArgumentException
- If the vectorv
is not of size 2.
-
get2x2Rotator
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.- Parameters:
v0
- First entry in vector to construct rotator for.v1
- Second entry in vector to construct rotator for.- Returns:
- A Givens rotator
G
of size 2 such that for a vectorv = [a, b]
we haveGx = [r, 0]
. - Throws:
IllegalArgumentException
- If the vectorv
is not of size 2.
-
leftMult2x2Rotator
Left multiplies a 2x2 Givens rotator to a matrix at the specified row. This is done in place.
Specifically, computes
G*A[i-1:i+1][i-1:i+1]
wherei=row
,G
is the 2x2 Givens rotator,A
is the matrix to apply the reflector to, andA[i-1:i+1][i-1:]
represents the slice ofA
the reflector effects which has shape(2, A.numCols - i - 1)
.This method is likely to be faster than computing this multiplication explicitly.
- Parameters:
src
- The matrix to left multiply the rotator to (modified).G
- The 2x2 givens rotator. Note, the size is not explicitly checked.row
- The row to the rotator is being applied to.workArray
- Array to store temporary values. If null, a new array will be created (modified).- Throws:
ArrayIndexOutOfBoundsException
- If theworkArray
is not at least large enough to store the2*(A.numCols - i - 1)
entries.
-
rightMult2x2Rotator
Right multiplies a 2x2 Givens rotator to a matrix at the specified row. This is done in place
Specifically, computes
A[:][i-1:i+1]*G
H wherei=row
,G
is the 2x2 Givens rotator,A
is the matrix to apply the reflector to, andA[:i+1][i-1:i+1]
represents the slice ofA
the reflector effects which has shape(row+1, 2)
.This method is likely to be faster than computing this multiplication explicitly.
- Parameters:
src
- The matrix to left multiply the rotator to (modified).G
- The 2x2 givens rotator. Note, the size is not explicitly checked.row
- The row to the rotator is being applied to.workArray
- Array to store temporary values. If null, a new array will be created (modified). If theworkArray
is not at least large enough to store the2*(row+1)
entries.
-
leftMult2x2Rotator
Left multiplies a 2x2 Givens rotator to a matrix at the specified row. This is done in place.
Specifically, computes
G*A[i-1:i+1][i-1:i+1]
wherei=row
,G
is the 2x2 Givens rotator,A
is the matrix to apply the reflector to, andA[i-1:i+1][i-1:]
represents the slice ofA
the reflector effects which has shape(2, A.numCols - i - 1)
.This method is likely to be faster than computing this multiplication explicitly.
- Parameters:
src
- The matrix to left multiply the rotator to (modified).G
- The 2x2 givens rotator. Note, the size is not explicitly checked.row
- The row to the rotator is being applied to.workArray
- Array to store temporary values. If null, a new array will be created (modified). If theworkArray
is not at least large enough to store the2*(A.numCols - i - 1)
entries.
-
rightMult2x2Rotator
Right multiplies a 2x2 Givens rotator to a matrix at the specified row. This is done in place
Specifically, computes
A[:][i-1:i+1]*G
H wherei=row
,G
is the 2x2 Givens rotator,A
is the matrix to apply the reflector to, andA[:i +1][i -1:i+1]
represents the slice ofA
the reflector effects which has shape(row+1, 2)
.This method is likely to be faster than computing this multiplication explicitly.
- Parameters:
src
- The matrix to left multiply the rotator to (modified).G
- The 2x2 givens rotator. Note, the size is not explicitly checked.row
- The row to the rotator is being applied to.workArray
- Array to store temporary values. If null, a new array will be created (modified). If theworkArray
is not at least large enough to store the2*(row+1)
entries.
-
get2x2Rotator
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.- Parameters:
v
- Vector to construct Givens rotator for.- Returns:
- A Givens rotator
G
of size 2 such that for a vectorv = [a, b]
we haveGx = [r, 0]
. - Throws:
IllegalArgumentException
- If the vectorv
is not of size 2.
-
get2x2Rotator
Constructs a Givens rotatorG
of size 2 such that for a vectorv = [a, b]
we haveGv = [r, 0]
.- Parameters:
v0
- First entry in vector to construct rotator for.v1
- Second entry in vector to construct rotator for.- Returns:
- A Givens rotator
G
of size 2 such that for a vectorv = [a, b]
we haveGx = [r, 0]
. - Throws:
IllegalArgumentException
- If the vectorv
is not of size 2.
-
stableTrigVals
private static double[] stableTrigVals(double a, double b) Computes the sine and cosine values for a Givens' rotation in a stable manner which avoids any possibility of overflow.- Returns:
- An array of length two containing in order the cosine value and sine value for the Givens' rotation.
-