public class DenseMatrix extends Object implements Matrix
Modifier and Type | Field and Description |
---|---|
protected int |
dim1 |
protected int |
dim2 |
protected double[][] |
values |
Constructor and Description |
---|
DenseMatrix(DenseMatrix other)
Copies the supplied matrix.
|
DenseMatrix(int dim1,
int dim2)
Creates a dense matrix full of zeros.
|
DenseMatrix(Matrix other)
Copies the supplied matrix, densifying it if it's sparse.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int i,
int j,
double value)
Adds the argument value to the value at the supplied index.
|
void |
addAcrossDim1(int[] indices,
double value) |
void |
addAcrossDim2(int[] indices,
double value) |
void |
broadcastIntersectAndAddInPlace(SGDVector input,
boolean broadcastOverDim1)
Broadcasts the input vector and adds it to each row/column of the matrix.
|
DenseVector |
columnSum()
Returns the dense vector containing each column sum.
|
double |
columnSum(int columnIndex)
Calculates the sum of the specified column.
|
DenseMatrix |
copy()
Copies the matrix.
|
static DenseMatrix |
createDenseMatrix(double[][] values)
Defensively copies the values before construction.
|
boolean |
equals(Object o) |
void |
foreachInPlace(DoubleUnaryOperator f)
Applies a
DoubleUnaryOperator elementwise to this Tensor . |
DenseVector |
gatherAcrossDim1(int[] elements) |
DenseVector |
gatherAcrossDim2(int[] elements) |
double |
get(int i,
int j)
Gets an element from this
Matrix . |
DenseVector |
getColumn(int index)
Returns a copy of the specified column.
|
int |
getDimension1Size()
The size of the first dimension.
|
int |
getDimension2Size()
The size of the second dimension.
|
DenseVector |
getRow(int i)
Extract a row as an
SGDVector . |
int[] |
getShape()
Returns an int array specifying the shape of this
Tensor . |
void |
hadamardProductInPlace(Tensor other,
DoubleUnaryOperator f)
Updates this
Tensor with the Hadamard product
(i.e., a term by term multiply) of this and other . |
int |
hashCode() |
void |
intersectAndAddInPlace(Tensor other,
DoubleUnaryOperator f)
Updates this
Tensor by adding all the values from the intersection with other . |
MatrixIterator |
iterator() |
DenseVector |
leftMultiply(SGDVector input)
Multiplies this Matrix by a
SGDVector returning a vector of the appropriate size. |
DenseMatrix |
matrixMultiply(Matrix other)
Multiplies this Matrix by another
Matrix returning a matrix of the appropriate size. |
DenseMatrix |
matrixMultiply(Matrix other,
boolean transposeThis,
boolean transposeOther)
Multiplies this Matrix by another
Matrix returning a matrix of the appropriate size. |
void |
normalizeRows(VectorNormalizer normalizer)
Normalizes each row using the supplied normalizer in place.
|
int |
numActiveElements(int row)
The number of non-zero elements in that row.
|
Tensor |
reshape(int[] newShape)
Reshapes the Tensor to the supplied shape.
|
DenseVector |
rightMultiply(SGDVector input)
Multiplies this Matrix by a
SGDVector returning a vector of the appropriate size. |
void |
rowScaleInPlace(DenseVector scalingCoefficients)
Scales each row by the appropriate value in the
DenseVector . |
DenseVector |
rowSum()
Generates a
DenseVector representing the sum of each row. |
double |
rowSum(int rowIndex)
Calculates the sum of the specified row.
|
void |
set(int i,
int j,
double value)
Sets an element at the supplied location.
|
String |
toString() |
DenseMatrix |
transpose()
Returns a transposed copy of this matrix.
|
double |
twoNorm()
Calculates the euclidean norm for this vector.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
hadamardProductInPlace, intersectAndAddInPlace, scalarAddInPlace, scaleInPlace, shapeCheck, shapeSum
forEach, spliterator
protected final double[][] values
protected final int dim1
protected final int dim2
public DenseMatrix(int dim1, int dim2)
dim1
- The first dimension.dim2
- The second dimension.public DenseMatrix(DenseMatrix other)
other
- The matrix to copy.public DenseMatrix(Matrix other)
other
- The matrix to copy.public static DenseMatrix createDenseMatrix(double[][] values)
Throws IllegalArgumentException if the supplied values are a ragged array.
values
- The values of this dense matrix.public int[] getShape()
Tensor
Tensor
.public Tensor reshape(int[] newShape)
Tensor
IllegalArgumentException
if the shape isn't compatible.public DenseMatrix copy()
public double get(int i, int j)
Matrix
Matrix
.public DenseVector gatherAcrossDim1(int[] elements)
public DenseVector gatherAcrossDim2(int[] elements)
public DenseMatrix transpose()
public void set(int i, int j, double value)
Matrix
public int getDimension1Size()
Matrix
getDimension1Size
in interface Matrix
public int getDimension2Size()
Matrix
getDimension2Size
in interface Matrix
public DenseVector leftMultiply(SGDVector input)
Matrix
SGDVector
returning a vector of the appropriate size.
The input must have dimension equal to Matrix.getDimension2Size()
.
leftMultiply
in interface Matrix
input
- The input vector.SGDVector
of size Matrix.getDimension1Size()
.public DenseVector rightMultiply(SGDVector input)
Matrix
SGDVector
returning a vector of the appropriate size.
The input must have dimension equal to Matrix.getDimension1Size()
.
rightMultiply
in interface Matrix
input
- The input vector.SGDVector
of size Matrix.getDimension2Size()
.public DenseMatrix matrixMultiply(Matrix other)
Matrix
Matrix
returning a matrix of the appropriate size.
The input must have dimension 1 equal to Matrix.getDimension2Size()
.
matrixMultiply
in interface Matrix
other
- The input matrix.Matrix
of size Matrix.getDimension1Size()
, input.getDimension2Size()
.public DenseMatrix matrixMultiply(Matrix other, boolean transposeThis, boolean transposeOther)
Matrix
Matrix
returning a matrix of the appropriate size.
Must obey the rules of matrix multiplication after the transposes are applied.
matrixMultiply
in interface Matrix
other
- The input matrix.transposeThis
- Implicitly transposes this matrix just for the multiplication.transposeOther
- Implicitly transposes other just for the multiplication.Matrix
.public DenseVector rowSum()
Matrix
DenseVector
representing the sum of each row.rowSum
in interface Matrix
DenseVector
of size Matrix.getDimension1Size()
.public void rowScaleInPlace(DenseVector scalingCoefficients)
Matrix
DenseVector
.rowScaleInPlace
in interface Matrix
scalingCoefficients
- A DenseVector
with size Matrix.getDimension1Size()
.public void add(int i, int j, double value)
Matrix
public void addAcrossDim1(int[] indices, double value)
public void addAcrossDim2(int[] indices, double value)
public void intersectAndAddInPlace(Tensor other, DoubleUnaryOperator f)
Tensor
Tensor
by adding all the values from the intersection with other
.
The function f
is applied to all values from other
before the
addition.
Each value is updated as value += f(otherValue).
intersectAndAddInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void hadamardProductInPlace(Tensor other, DoubleUnaryOperator f)
Tensor
Tensor
with the Hadamard product
(i.e., a term by term multiply) of this and other
.
The function f
is applied to all values from other
before the addition.
Each value is updated as value *= f(otherValue).
hadamardProductInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void foreachInPlace(DoubleUnaryOperator f)
Tensor
DoubleUnaryOperator
elementwise to this Tensor
.foreachInPlace
in interface Tensor
f
- The function to apply.public void broadcastIntersectAndAddInPlace(SGDVector input, boolean broadcastOverDim1)
input
- The input vector.broadcastOverDim1
- If true broadcasts over the first dimension, else broadcasts over the second.public int numActiveElements(int row)
Matrix
An element could be active and zero, if it was active on construction.
numActiveElements
in interface Matrix
row
- The index of the row.public DenseVector getRow(int i)
Matrix
SGDVector
.
This refers to the same values as the matrix, so updating this vector will update the matrix.
public DenseVector getColumn(int index)
index
- The column index.public double rowSum(int rowIndex)
rowIndex
- The index of the row to sum.public double columnSum(int columnIndex)
columnIndex
- The index of the column to sum.public double twoNorm()
Tensor
public MatrixIterator iterator()
iterator
in interface Iterable<MatrixTuple>
public void normalizeRows(VectorNormalizer normalizer)
normalizer
- The vector normalizer to use.public DenseVector columnSum()
Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.