Logo Search packages:      
Sourcecode: jblas version File versions  Download package

org::jblas::la::DoubleMatrix Class Reference

List of all members.


Detailed Description

A general matrix class for double typed values.

Don't be intimidated by the large number of methods this function defines. Most are overloads provided for ease of use. For example, for each arithmetic operation, up to six overloaded versions exist to handle in-place computations, and scalar arguments.

Construction

To construct a two-dimensional matrices, you can use the following constructors and static methods.

MethodDescription
DoubleMatrix(m,n, [value1, value2, value3...])Values are filled in row by row.
DoubleMatrix(new double[][] {{value1, value2, ...}, ...}Inner arrays are columns.
DoubleMatrix.zeros(m,n) Initial values set to 0.0.
DoubleMatrix.ones(m,n) Initial values set to 1.0.
DoubleMatrix.rand(m,n) Values drawn at random between 0.0 and 1.0.
DoubleMatrix.randn(m,n) Values drawn from normal distribution.
DoubleMatrix.eye(n) Unit matrix (values 0.0 except for 1.0 on the diagonal).
DoubleMatrix.diag(array) Diagonal matrix with given diagonal elements.

Alternatively, you can construct (column) vectors, if you just supply the length using the following constructors and static methods.

MethodDescription
DoubleMatrix(m)Constructs a column vector.
DoubleMatrix(new double[] {value1, value2, ...})Constructs a column vector.
DoubleMatrix.zeros(m) Initial values set to 1.0.
DoubleMatrix.ones(m) Initial values set to 0.0.
DoubleMatrix.rand(m) Values drawn at random between 0.0 and 1.0.
DoubleMatrix.randn(m) Values drawn from normal distribution.

You can also construct new matrices by concatenating matrices either horziontally or vertically:

MethodDescription
x.concatHorizontally(y)New matrix will be x next to y.
x.concatVertically(y)New matrix will be x atop y.

Element Access, Copying and Duplication

To access individual elements, or whole rows and columns, use the following methods:

x.Method<th>Description
x.get(i,j)Get element in row i and column j.
x.put(i, j, v)Set element in row i and column j to value v
x.get(i)Get the ith element of the matrix (traversing rows first).
x.put(i, v)Set the ith element of the matrix (traversing rows first).
x.getColumn(i)Get a copy of column i.
x.putColumn(i, c)Put matrix c into column i.
x.getRow(i)Get a copy of row i.
x.putRow(i, c)Put matrix c into row i.
x.swapColumns(i, j)Swap the contents of columns i and j.
x.swapRows(i, j)Swap the contents of columns i and j.

For get and put, you can also pass integer arrays, DoubleMatrix objects, or Range objects, which then specify the indices used as follows:

When using put with multiple indices, the assigned object must have the correct size or be a scalar.

There exist the following Range objects. The Class RangeUtils also contains the a number of handy helper methods for constructing these ranges.
Class RangeUtils method Indices
AllRange all() All legal indices.
PointRange point(i) A single point.
IntervalRange interval(a, b)All indices from a to b (inclusive)
IndicesRange indices(int[])The specified indices.
indices(DoubleMatrix)The specified indices.
find(DoubleMatrix)The non-zero entries of the matrix.

The following methods can be used for duplicating and copying matrices.

MethodDescription
x.dup()Get a copy of x.
x.copy(y)Copy the contents of y to x (possible resizing x).

Size and Shape

The following methods permit to acces the size of a matrix and change its size or shape.

x.Method<th>Description
x.rows<td>Number of rows.
x.columns<td>Number of columns.
x.length<td>Total number of elements.
x.isEmpty()Checks whether rows == 0 and columns == 0.
x.isRowVector()Checks whether rows == 1.
x.isColumnVector()Checks whether columns == 1.
x.isVector()Checks whether rows == 1 or columns == 1.
x.isSquare()Checks whether rows == columns.
x.isScalar()Checks whether length == 1.
x.resize(r, c)Resize the matrix to r rows and c columns, discarding the content.
x.reshape(r, c)Resize the matrix to r rows and c columns.
Number of elements must not change.

The size is stored in the rows and columns member variables. The total number of elements is stored in length. Do not change these values unless you know what you're doing!

Arithmetics

The usual arithmetic operations are implemented. Each operation exists in a in-place version, recognizable by the suffix "i", to which you can supply the result matrix (or this is used, if missing). Using in-place operations can also lead to a smaller memory footprint, as the number of temporary objects which are directly garbage collected again is reduced.

Whenever you specify a result vector, the result vector must already have the correct dimensions.

For example, you can add two matrices using the add method. If you want to store the result in of x + y in z, type x.addi(y, z) // computes x = y + z. Even in-place methods return the result, such that you can easily chain in-place methods, for example: x.addi(y).addi(z) // computes x += y; x += z

Methods which operate element-wise only make sure that the length of the matrices is correct. Therefore, you can add a 3 * 3 matrix to a 1 * 9 matrix, for example.

Finally, there exist versions which take doubles instead of DoubleMatrix Objects as arguments. These then compute the operation with the same value as the right-hand-side. The same effect can be achieved by passing a DoubleMatrix with exactly one element.

Operation Method Comment
x + y x.add(y)
x - y x.sub(y), y.rsub(x) rsub subtracts left from right hand side
x * y x.mul(y) element-wise multiplication
x.mmul(y)matrix-matrix multiplication
x.dot(y) scalar-product
x / y x.div(y), y.rdiv(x) rdiv divides right hand side by left hand side.
- x x.neg()

There also exist operations which work on whole columns or rows.

Method Description
x.addRowVector<td>adds a vector to each row (addiRowVector works in-place)
x.addColumnVector<td>adds a vector to each column
x.subRowVector<td>subtracts a vector from each row
x.subColumnVector<td>subtracts a vector from each column
x.mulRow<td>Multiplies a row by a scalar
x.mulColumn<td>multiplies a row by a column

In principle, you could achieve the same result by first calling getColumn(), adding, and then calling putColumn, but these methods are much faster.

The following comparison operations are available

Operation Method
x < y x.lt(y)
x <= y x.le(y)
x > y x.gt(y)
x >= y x.ge(y)
x == y x.eq(y)
x != y x.ne(y)

Logical operations are also supported. For these operations, a value different from zero is treated as "true" and zero is treated as "false". All operations are carried out elementwise.

Operation Method
x & y x.and(y)
x | y x.or(y)
x ^ y x.xor(y)
! x x.not()

Finally, there are a few more methods to compute various things:

Method Description
x.max() Return maximal element
x.argmax() Return index of largest element
x.min() Return minimal element
x.argmin() Return index of largest element
x.columnMins() Return column-wise minima
x.columnArgmins() Return column-wise index of minima
x.columnMaxs() Return column-wise maxima
x.columnArgmaxs() Return column-wise index of maxima

Author:
Mikio Braun, Johannes Schaback

Definition at line 274 of file DoubleMatrix.java.


Public Member Functions

DoubleMatrix add (double v)
DoubleMatrix add (DoubleMatrix other)
DoubleMatrix addColumnVector (DoubleMatrix x)
DoubleMatrix addi (double v)
DoubleMatrix addi (DoubleMatrix other)
DoubleMatrix addi (double v, DoubleMatrix result)
DoubleMatrix addi (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix addiColumnVector (DoubleMatrix x)
DoubleMatrix addiRowVector (DoubleMatrix x)
DoubleMatrix addRowVector (DoubleMatrix x)
DoubleMatrix and (double value)
DoubleMatrix and (DoubleMatrix other)
DoubleMatrix andi (double value)
DoubleMatrix andi (double value, DoubleMatrix result)
DoubleMatrix andi (DoubleMatrix other)
DoubleMatrix andi (DoubleMatrix other, DoubleMatrix result)
int argmax ()
int argmin ()
void assertMultipliesWith (DoubleMatrix a)
void assertSameLength (DoubleMatrix a)
void assertSameSize (DoubleMatrix a)
void assertSquare ()
void checkColumns (int c)
void checkLength (int l)
void checkRows (int r)
int[] columnArgmaxs ()
int[] columnArgmins ()
DoubleMatrix columnMaxs ()
DoubleMatrix columnMeans ()
DoubleMatrix columnMins ()
int[][] columnSortingPermutations ()
DoubleMatrix columnSums ()
DoubleMatrix copy (DoubleMatrix a)
DoubleMatrix cumulativeSum ()
DoubleMatrix cumulativeSumi ()
DoubleMatrix diag ()
DoubleMatrix div (double v)
DoubleMatrix div (DoubleMatrix other)
DoubleMatrix divi (double v)
DoubleMatrix divi (DoubleMatrix other)
DoubleMatrix divi (double a, DoubleMatrix result)
DoubleMatrix divi (DoubleMatrix other, DoubleMatrix result)
double dot (DoubleMatrix other)
 DoubleMatrix (double[][] data)
 DoubleMatrix (String filename) throws IOException
 DoubleMatrix (double[] newData)
 DoubleMatrix (int len)
 DoubleMatrix ()
 DoubleMatrix (int newRows, int newColumns)
 DoubleMatrix (int newRows, int newColumns, double...newData)
DoubleMatrix dup ()
DoubleMatrix eq (double value)
DoubleMatrix eq (DoubleMatrix other)
DoubleMatrix eqi (double value)
DoubleMatrix eqi (double value, DoubleMatrix result)
DoubleMatrix eqi (DoubleMatrix other)
DoubleMatrix eqi (DoubleMatrix other, DoubleMatrix result)
boolean equals (Object o)
DoubleMatrix fill (double value)
int[] findIndices ()
DoubleMatrix ge (double value)
DoubleMatrix ge (DoubleMatrix other)
DoubleMatrix gei (double value)
DoubleMatrix gei (double value, DoubleMatrix result)
DoubleMatrix gei (DoubleMatrix other)
DoubleMatrix gei (DoubleMatrix other, DoubleMatrix result)
double get (int i)
double get (int rowIndex, int columnIndex)
DoubleMatrix get (DoubleMatrix rindices, DoubleMatrix cindices)
DoubleMatrix get (DoubleMatrix indices, int c)
DoubleMatrix get (int r, DoubleMatrix indices)
DoubleMatrix get (DoubleMatrix indices)
DoubleMatrix get (Range rs, Range cs)
DoubleMatrix get (int[] rindices, int[] cindices)
DoubleMatrix get (int[] indices, int c)
DoubleMatrix get (int r, int[] indices)
DoubleMatrix get (int[] indices)
DoubleMatrix getColumn (int c, DoubleMatrix result)
DoubleMatrix getColumn (int c)
DoubleMatrix getColumnRange (int r, int a, int b)
int getColumns ()
DoubleMatrix getColumns (DoubleMatrix cindices)
DoubleMatrix getColumns (int[] cindices)
int getLength ()
DoubleMatrix getRange (int ra, int rb, int ca, int cb)
DoubleMatrix getRange (int a, int b)
DoubleMatrix getRow (int r, DoubleMatrix result)
DoubleMatrix getRow (int r)
DoubleMatrix getRowRange (int a, int b, int c)
int getRows ()
DoubleMatrix getRows (DoubleMatrix rindices)
DoubleMatrix getRows (int[] rindices)
DoubleMatrix gt (double value)
DoubleMatrix gt (DoubleMatrix other)
DoubleMatrix gti (double value)
DoubleMatrix gti (double value, DoubleMatrix result)
DoubleMatrix gti (DoubleMatrix other)
DoubleMatrix gti (DoubleMatrix other, DoubleMatrix result)
void in (DataInputStream dis) throws IOException
int index (int rowIndex, int columnIndex)
int indexColumns (int i)
int indexRows (int i)
boolean isColumnVector ()
boolean isEmpty ()
boolean isRowVector ()
boolean isScalar ()
boolean isSquare ()
boolean isVector ()
DoubleMatrix le (double value)
DoubleMatrix le (DoubleMatrix other)
DoubleMatrix lei (double value)
DoubleMatrix lei (double value, DoubleMatrix result)
DoubleMatrix lei (DoubleMatrix other)
DoubleMatrix lei (DoubleMatrix other, DoubleMatrix result)
void load (String filename) throws IOException
DoubleMatrix lt (double value)
DoubleMatrix lt (DoubleMatrix other)
DoubleMatrix lti (double value)
DoubleMatrix lti (double value, DoubleMatrix result)
DoubleMatrix lti (DoubleMatrix other)
DoubleMatrix lti (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix max (double v)
DoubleMatrix max (DoubleMatrix other)
double max ()
DoubleMatrix maxi (double v)
DoubleMatrix maxi (double v, DoubleMatrix result)
DoubleMatrix maxi (DoubleMatrix other)
DoubleMatrix maxi (DoubleMatrix other, DoubleMatrix result)
double mean ()
DoubleMatrix min (double v)
DoubleMatrix min (DoubleMatrix other)
double min ()
DoubleMatrix mini (double v)
DoubleMatrix mini (double v, DoubleMatrix result)
DoubleMatrix mini (DoubleMatrix other)
DoubleMatrix mini (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix mmul (double v)
DoubleMatrix mmul (DoubleMatrix other)
DoubleMatrix mmuli (double v)
DoubleMatrix mmuli (DoubleMatrix other)
DoubleMatrix mmuli (double v, DoubleMatrix result)
DoubleMatrix mmuli (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix mul (double v)
DoubleMatrix mul (DoubleMatrix other)
DoubleMatrix mulColumn (int c, double scale)
DoubleMatrix mulColumnVector (DoubleMatrix x)
DoubleMatrix muli (double v)
DoubleMatrix muli (DoubleMatrix other)
DoubleMatrix muli (double v, DoubleMatrix result)
DoubleMatrix muli (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix muliColumnVector (DoubleMatrix x)
DoubleMatrix muliRowVector (DoubleMatrix x)
DoubleMatrix mulRow (int r, double scale)
DoubleMatrix mulRowVector (DoubleMatrix x)
boolean multipliesWith (DoubleMatrix a)
DoubleMatrix ne (double value)
DoubleMatrix ne (DoubleMatrix other)
DoubleMatrix neg ()
DoubleMatrix negi ()
DoubleMatrix nei (double value)
DoubleMatrix nei (double value, DoubleMatrix result)
DoubleMatrix nei (DoubleMatrix other)
DoubleMatrix nei (DoubleMatrix other, DoubleMatrix result)
double norm1 ()
double norm2 ()
double normmax ()
DoubleMatrix not ()
DoubleMatrix noti ()
DoubleMatrix or (double value)
DoubleMatrix or (DoubleMatrix other)
DoubleMatrix ori (double value)
DoubleMatrix ori (double value, DoubleMatrix result)
DoubleMatrix ori (DoubleMatrix other)
DoubleMatrix ori (DoubleMatrix other, DoubleMatrix result)
void out (DataOutputStream dos) throws IOException
void print ()
DoubleMatrix put (int i, double v)
DoubleMatrix put (int rowIndex, int columnIndex, double value)
DoubleMatrix put (DoubleMatrix rindices, DoubleMatrix cindices, double v)
DoubleMatrix put (DoubleMatrix indices, int c, double v)
DoubleMatrix put (int r, DoubleMatrix indices, double v)
DoubleMatrix put (DoubleMatrix indices, double v)
DoubleMatrix put (DoubleMatrix rindices, DoubleMatrix cindices, DoubleMatrix v)
DoubleMatrix put (DoubleMatrix indices, int c, DoubleMatrix v)
DoubleMatrix put (int r, DoubleMatrix indices, DoubleMatrix v)
DoubleMatrix put (DoubleMatrix indices, DoubleMatrix v)
DoubleMatrix put (int[] rindices, int[] cindices, double v)
DoubleMatrix put (int[] indices, int c, double v)
DoubleMatrix put (int r, int[] indices, double v)
DoubleMatrix put (int[] indices, double v)
DoubleMatrix put (Range rs, Range cs, DoubleMatrix x)
DoubleMatrix put (int[] rindices, int[] cindices, DoubleMatrix x)
DoubleMatrix put (int[] indices, int c, DoubleMatrix x)
DoubleMatrix put (int r, int[] indices, DoubleMatrix x)
DoubleMatrix put (int[] indices, DoubleMatrix x)
void putColumn (int c, DoubleMatrix v)
void putRow (int r, DoubleMatrix v)
DoubleMatrix rankOneUpdate (DoubleMatrix x, DoubleMatrix y)
DoubleMatrix rankOneUpdate (DoubleMatrix x)
DoubleMatrix rankOneUpdate (double alpha, DoubleMatrix x)
DoubleMatrix rankOneUpdate (double alpha, DoubleMatrix x, DoubleMatrix y)
DoubleMatrix rdiv (double v)
DoubleMatrix rdiv (DoubleMatrix other)
DoubleMatrix rdivi (double v)
DoubleMatrix rdivi (DoubleMatrix other)
DoubleMatrix rdivi (double a, DoubleMatrix result)
DoubleMatrix rdivi (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix repmat (int rowMult, int columnMult)
DoubleMatrix reshape (int newRows, int newColumns)
void resize (int newRows, int newColumns)
int[] rowArgmaxs ()
int[] rowArgmins ()
DoubleMatrix rowMaxs ()
DoubleMatrix rowMeans ()
DoubleMatrix rowMins ()
int[][] rowSortingPermutations ()
DoubleMatrix rowSums ()
DoubleMatrix rsub (double v)
DoubleMatrix rsub (DoubleMatrix other)
DoubleMatrix rsubi (double v)
DoubleMatrix rsubi (DoubleMatrix other)
DoubleMatrix rsubi (double a, DoubleMatrix result)
DoubleMatrix rsubi (DoubleMatrix other, DoubleMatrix result)
boolean sameLength (DoubleMatrix a)
boolean sameSize (DoubleMatrix a)
void save (String filename) throws IOException
double scalar ()
DoubleMatrix sort ()
DoubleMatrix sortColumns ()
DoubleMatrix sortColumnsi ()
DoubleMatrix sorti ()
int[] sortingPermutation ()
DoubleMatrix sortRows ()
DoubleMatrix sortRowsi ()
DoubleMatrix sub (double v)
DoubleMatrix sub (DoubleMatrix other)
DoubleMatrix subColumnVector (DoubleMatrix x)
DoubleMatrix subi (double v)
DoubleMatrix subi (DoubleMatrix other)
DoubleMatrix subi (double v, DoubleMatrix result)
DoubleMatrix subi (DoubleMatrix other, DoubleMatrix result)
DoubleMatrix subiColumnVector (DoubleMatrix x)
DoubleMatrix subiRowVector (DoubleMatrix x)
DoubleMatrix subRowVector (DoubleMatrix x)
double sum ()
DoubleMatrix swapColumns (int i, int j)
DoubleMatrix swapRows (int i, int j)
double[] toArray ()
double[][] toArray2 ()
boolean[] toBooleanArray ()
boolean[][] toBooleanArray2 ()
FloatMatrix toFloatMatrix ()
int[] toIntArray ()
int[][] toIntArray2 ()
String toString (String fmt)
String toString ()
DoubleMatrix transpose ()
DoubleMatrix truth ()
DoubleMatrix truthi ()
DoubleMatrix xor (double value)
DoubleMatrix xor (DoubleMatrix other)
DoubleMatrix xori (double value)
DoubleMatrix xori (double value, DoubleMatrix result)
DoubleMatrix xori (DoubleMatrix other)
DoubleMatrix xori (DoubleMatrix other, DoubleMatrix result)

Static Public Member Functions

static DoubleMatrix concatHorizontally (DoubleMatrix A, DoubleMatrix B)
static DoubleMatrix concatVertically (DoubleMatrix A, DoubleMatrix B)
static DoubleMatrix diag (DoubleMatrix x)
static DoubleMatrix eye (int n)
static DoubleMatrix loadAsciiFile (String filename) throws IOException
static DoubleMatrix ones (int length)
static DoubleMatrix ones (int rows, int columns)
static DoubleMatrix rand (int len)
static DoubleMatrix rand (int rows, int columns)
static DoubleMatrix randn (int len)
static DoubleMatrix randn (int rows, int columns)
static DoubleMatrix scalar (double s)
static DoubleMatrix zeros (int length)
static DoubleMatrix zeros (int rows, int columns)

Public Attributes

int columns
double[] data = null
int length
int rows

Static Public Attributes

static final DoubleMatrix EMPTY = new DoubleMatrix()

Private Member Functions

void ensureResultLength (DoubleMatrix other, DoubleMatrix result)

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index