Class DComplexFactory2D
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.colt.matrix.tdcomplex.DComplexFactory2D
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class DComplexFactory2D extends PersistentObject
Factory for convenient construction of 2-d matrices holding complex cells. Also provides convenient methods to compose (concatenate) and decompose (split) matrices from/to constituent blocks.Construction Use idioms like ComplexFactory2D.dense.make(4,4) to construct dense matrices, ComplexFactory2D.sparse.make(4,4) to construct sparse matrices. Construction with initial values Use other make methods to construct matrices with given initial values. Appending rows and columns Use methods appendColumns,appendRowsandrepeatto append rows and columns.General block matrices Use methods composeanddecomposeto work with general block matrices.Diagonal matrices Use methods diagonal(vector),diagonal(matrix)andidentityto work with diagonal matrices.Diagonal block matrices Use method composeDiagonalto work with diagonal block matrices.Random Use methods randomandsampleto construct random matrices.If the factory is used frequently it might be useful to streamline the notation. For example by aliasing:
ComplexFactory2D F = ComplexFactory2D.dense; F.make(4,4); F.random(4,4); ...
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static DComplexFactory2DdenseA factory producing dense matrices.static DComplexFactory2DsparseA factory producing sparse hash matrices.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description DComplexMatrix2DappendColumn(DComplexMatrix2D A, DComplexMatrix1D b)C = A||b; Constructs a new matrix which is the column-wise concatenation of two other matrices.DComplexMatrix2DappendColumns(DComplexMatrix2D A, DComplexMatrix2D B)C = A||B; Constructs a new matrix which is the column-wise concatenation of two other matrices.DComplexMatrix2DappendRow(DComplexMatrix2D A, DComplexMatrix1D b)C = A||b; Constructs a new matrix which is the row-wise concatenation of two other matrices.DComplexMatrix2DappendRows(DComplexMatrix2D A, DComplexMatrix2D B)C = A||B; Constructs a new matrix which is the row-wise concatenation of two other matrices.DComplexMatrix2Dcompose(DComplexMatrix2D[][] parts)Constructs a block matrix made from the given parts.DComplexMatrix2DcomposeBidiagonal(DComplexMatrix2D A, DComplexMatrix2D B)Constructs a bidiagonal block matrix from the given parts.DComplexMatrix2DcomposeDiagonal(DComplexMatrix2D A, DComplexMatrix2D B)Constructs a diagonal block matrix from the given parts (the direct sum of two matrices).DComplexMatrix2DcomposeDiagonal(DComplexMatrix2D A, DComplexMatrix2D B, DComplexMatrix2D C)Constructs a diagonal block matrix from the given parts.voiddecompose(DComplexMatrix2D[][] parts, DComplexMatrix2D matrix)Splits a block matrix into its constituent blocks; Copies blocks of a matrix into the given parts.voiddemo1()Demonstrates usage of this class.voiddemo2()Demonstrates usage of this class.DComplexMatrix2Ddiagonal(DComplexMatrix1D vector)Constructs a new diagonal matrix whose diagonal elements are the elements of vector.DComplexMatrix1Ddiagonal(DComplexMatrix2D A)Constructs a new vector consisting of the diagonal elements of A .DComplexMatrix2Didentity(int rowsAndColumns)Constructs an identity matrix (having ones on the diagonal and zeros elsewhere).DComplexMatrix2Dmake(double[][] values)Constructs a matrix with the given cell values.DComplexMatrix2Dmake(int rows, int columns)Constructs a matrix with the given shape, each cell initialized with zero.DComplexMatrix2Dmake(int rows, int columns, double[] initialValue)Constructs a matrix with the given shape, each cell initialized with the given value.DComplexMatrix2Drandom(int rows, int columns)Constructs a matrix with uniformly distributed values in (0,1) (exclusive).DComplexMatrix2Drepeat(DComplexMatrix2D A, int rowRepeat, int columnRepeat)C = A||A||..||A; Constructs a new matrix which is duplicated both along the row and column dimension.DComplexMatrix2Dsample(DComplexMatrix2D matrix, double[] value, double nonZeroFraction)Modifies the given matrix to be a randomly sampled matrix.DComplexMatrix2Dsample(int rows, int columns, double[] value, double nonZeroFraction)Constructs a randomly sampled matrix with the given shape.-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Field Detail
-
dense
public static final DComplexFactory2D dense
A factory producing dense matrices.
-
sparse
public static final DComplexFactory2D sparse
A factory producing sparse hash matrices.
-
-
Method Detail
-
appendColumns
public DComplexMatrix2D appendColumns(DComplexMatrix2D A, DComplexMatrix2D B)
C = A||B; Constructs a new matrix which is the column-wise concatenation of two other matrices.0 1 2 3 4 5 appendColumns 6 7 8 9 --> 0 1 2 6 7 3 4 5 8 9
-
appendColumn
public DComplexMatrix2D appendColumn(DComplexMatrix2D A, DComplexMatrix1D b)
C = A||b; Constructs a new matrix which is the column-wise concatenation of two other matrices.0 1 2 3 4 5 appendColumn 6 8 --> 0 1 2 6 3 4 5 8
-
appendRows
public DComplexMatrix2D appendRows(DComplexMatrix2D A, DComplexMatrix2D B)
C = A||B; Constructs a new matrix which is the row-wise concatenation of two other matrices.
-
appendRow
public DComplexMatrix2D appendRow(DComplexMatrix2D A, DComplexMatrix1D b)
C = A||b; Constructs a new matrix which is the row-wise concatenation of two other matrices.
-
compose
public DComplexMatrix2D compose(DComplexMatrix2D[][] parts)
Constructs a block matrix made from the given parts. The inverse to methoddecompose(DComplexMatrix2D[][], DComplexMatrix2D).All matrices of a given column within parts must have the same number of columns. All matrices of a given row within parts must have the same number of rows. Otherwise an IllegalArgumentException is thrown. Note that nulls within parts[row,col] are an exception to this rule: they are ignored. Cells are copied.
- Throws:
java.lang.IllegalArgumentException- subject to the conditions outlined above.
-
composeDiagonal
public DComplexMatrix2D composeDiagonal(DComplexMatrix2D A, DComplexMatrix2D B)
Constructs a diagonal block matrix from the given parts (the direct sum of two matrices). That is the concatenationA 0 0 B(The direct sum has A.rows()+B.rows() rows and A.columns()+B.columns() columns). Cells are copied.- Returns:
- a new matrix which is the direct sum.
-
composeDiagonal
public DComplexMatrix2D composeDiagonal(DComplexMatrix2D A, DComplexMatrix2D B, DComplexMatrix2D C)
Constructs a diagonal block matrix from the given parts. The concatenation has the formA 0 0 0 B 0 0 0 Cfrom the given parts. Cells are copied.
-
composeBidiagonal
public DComplexMatrix2D composeBidiagonal(DComplexMatrix2D A, DComplexMatrix2D B)
Constructs a bidiagonal block matrix from the given parts. from the given parts. Cells are copied.
-
decompose
public void decompose(DComplexMatrix2D[][] parts, DComplexMatrix2D matrix)
Splits a block matrix into its constituent blocks; Copies blocks of a matrix into the given parts. The inverse to methodcompose(DComplexMatrix2D[][]).All matrices of a given column within parts must have the same number of columns. All matrices of a given row within parts must have the same number of rows. Otherwise an IllegalArgumentException is thrown. Note that nulls within parts[row,col] are an exception to this rule: they are ignored. Cells are copied.
- Throws:
java.lang.IllegalArgumentException- subject to the conditions outlined above.
-
demo1
public void demo1()
Demonstrates usage of this class.
-
demo2
public void demo2()
Demonstrates usage of this class.
-
diagonal
public DComplexMatrix2D diagonal(DComplexMatrix1D vector)
Constructs a new diagonal matrix whose diagonal elements are the elements of vector. Cells values are copied. The new matrix is not a view.- Returns:
- a new matrix.
-
diagonal
public DComplexMatrix1D diagonal(DComplexMatrix2D A)
Constructs a new vector consisting of the diagonal elements of A . Cells values are copied. The new vector is not a view.- Parameters:
A- the matrix, need not be square.- Returns:
- a new vector.
-
identity
public DComplexMatrix2D identity(int rowsAndColumns)
Constructs an identity matrix (having ones on the diagonal and zeros elsewhere).
-
make
public DComplexMatrix2D make(double[][] values)
Constructs a matrix with the given cell values. values is required to have the form values[row][column] and have exactly the same number of columns in every row.The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
- Parameters:
values- The values to be filled into the new matrix.- Throws:
java.lang.IllegalArgumentException- if for any 1 <= row < values.length: values[row].length != values[row-1].length .
-
make
public DComplexMatrix2D make(int rows, int columns)
Constructs a matrix with the given shape, each cell initialized with zero.
-
make
public DComplexMatrix2D make(int rows, int columns, double[] initialValue)
Constructs a matrix with the given shape, each cell initialized with the given value.
-
random
public DComplexMatrix2D random(int rows, int columns)
Constructs a matrix with uniformly distributed values in (0,1) (exclusive).
-
repeat
public DComplexMatrix2D repeat(DComplexMatrix2D A, int rowRepeat, int columnRepeat)
C = A||A||..||A; Constructs a new matrix which is duplicated both along the row and column dimension.
-
sample
public DComplexMatrix2D sample(int rows, int columns, double[] value, double nonZeroFraction)
Constructs a randomly sampled matrix with the given shape. Randomly picks exactly Math.round(rows*columns*nonZeroFraction) cells and initializes them to value, all the rest will be initialized to zero. Note that this is not the same as setting each cell with probability nonZeroFraction to value. Note: The random seed is a constant.- Throws:
java.lang.IllegalArgumentException- if nonZeroFraction < 0 || nonZeroFraction > 1.- See Also:
DoubleRandomSampler
-
sample
public DComplexMatrix2D sample(DComplexMatrix2D matrix, double[] value, double nonZeroFraction)
Modifies the given matrix to be a randomly sampled matrix. Randomly picks exactly Math.round(rows*columns*nonZeroFraction) cells and initializes them to value, all the rest will be initialized to zero. Note that this is not the same as setting each cell with probability nonZeroFraction to value. Note: The random seed is a constant.- Throws:
java.lang.IllegalArgumentException- if nonZeroFraction < 0 || nonZeroFraction > 1.- See Also:
DoubleRandomSampler
-
-
DMelt 3.0 © DataMelt by jWork.ORG