Class SparseMatrix
- java.lang.Object
-
- WildMagic.LibFoundation.NumericalAnalysis.SparseMatrix
-
- All Implemented Interfaces:
java.io.Serializable
public class SparseMatrix extends java.lang.Object implements java.io.Serializable
Sparse matrix implemented with a hash map. All undefined entries are zero.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SparseMatrix.Index
Used to reference a single element in the matrix.
-
Field Summary
Fields Modifier and Type Field Description private SparseMatrix.Index
m_kIndexKeyTmp
Instantiate once instead of each time a value key (Index) is needed.private java.util.HashMap<SparseMatrix.Index,java.lang.Float>
m_kMap
Mapping of Index(row,col).private static float
ms_fTolerance
DOCUMENT ME!private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description SparseMatrix()
Matrix of undefined dimensions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static float
dot(int iSize, float[] afU, float[] afV)
conjugate gradient methods.float
getElement(int iRow, int iCol)
Get the element value at the specified row,col.java.util.Iterator<java.util.Map.Entry<SparseMatrix.Index,java.lang.Float>>
iterator()
Return iterator to non-zero elements in the matrix.private void
multiply(int iSize, float[] afX, float[] afProd)
DOCUMENT ME!void
setElement(int iRow, int iCol, float fValue)
Set the element value at the specified row,col.int
size()
return number of non-zero entries in the matrix.boolean
solveSymmetricCG(int iSize, float[] afB, float[] afX)
Conjugate gradient method for sparse, symmetric matrices.private static void
updateP(int iSize, float[] afP, float fBeta, float[] afR)
DOCUMENT ME!private static void
updateR(int iSize, float[] afR, float fAlpha, float[] afW)
DOCUMENT ME!private static void
updateX(int iSize, float[] afX, float fAlpha, float[] afP)
DOCUMENT ME!
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
ms_fTolerance
private static final float ms_fTolerance
DOCUMENT ME!- See Also:
- Constant Field Values
-
m_kIndexKeyTmp
private SparseMatrix.Index m_kIndexKeyTmp
Instantiate once instead of each time a value key (Index) is needed.
-
m_kMap
private java.util.HashMap<SparseMatrix.Index,java.lang.Float> m_kMap
Mapping of Index(row,col).
-
-
Method Detail
-
dot
private static float dot(int iSize, float[] afU, float[] afV)
conjugate gradient methods.- Parameters:
iSize
- DOCUMENT ME!afU
- DOCUMENT ME!afV
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
updateP
private static void updateP(int iSize, float[] afP, float fBeta, float[] afR)
DOCUMENT ME!- Parameters:
iSize
- DOCUMENT ME!afP
- DOCUMENT ME!fBeta
- DOCUMENT ME!afR
- DOCUMENT ME!
-
updateR
private static void updateR(int iSize, float[] afR, float fAlpha, float[] afW)
DOCUMENT ME!- Parameters:
iSize
- DOCUMENT ME!afR
- DOCUMENT ME!fAlpha
- DOCUMENT ME!afW
- DOCUMENT ME!
-
updateX
private static void updateX(int iSize, float[] afX, float fAlpha, float[] afP)
DOCUMENT ME!- Parameters:
iSize
- DOCUMENT ME!afX
- DOCUMENT ME!fAlpha
- DOCUMENT ME!afP
- DOCUMENT ME!
-
getElement
public float getElement(int iRow, int iCol)
Get the element value at the specified row,col.- Parameters:
iRow
- DOCUMENT ME!iCol
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
iterator
public java.util.Iterator<java.util.Map.Entry<SparseMatrix.Index,java.lang.Float>> iterator()
Return iterator to non-zero elements in the matrix. Each entry in the iterator is of Map.Entry type where the key is of Index type and the value is of Float type.- Returns:
- Set iterator of Index, Float pairs.
-
setElement
public void setElement(int iRow, int iCol, float fValue)
Set the element value at the specified row,col.- Parameters:
iRow
- DOCUMENT ME!iCol
- DOCUMENT ME!fValue
- DOCUMENT ME!
-
size
public int size()
return number of non-zero entries in the matrix.- Returns:
- DOCUMENT ME!
-
solveSymmetricCG
public boolean solveSymmetricCG(int iSize, float[] afB, float[] afX)
Conjugate gradient method for sparse, symmetric matrices. Input: The nonzero entries of the symmetrix matrix A are stored in a map whose keys are pairs (i,j) and whose values are real numbers. The pair (i,j) is the location of the value in the array. Only one of (i,j) and (j,i) should be stored since A is symmetric. The code assumes this is how you set up A. The column vector B is stored as an array of contiguous valuess. If B itself is sparse, another solver can be implemented which uses a map to store B. Output: B[iSize] is the solution x to Ax = B- Parameters:
iSize
- DOCUMENT ME!afB
- DOCUMENT ME!afX
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
multiply
private void multiply(int iSize, float[] afX, float[] afProd)
DOCUMENT ME!- Parameters:
iSize
- DOCUMENT ME!afX
- DOCUMENT ME!afProd
- DOCUMENT ME!
-
-