public class SparseCostMatrix extends Object
This class aims at representing in a memory-efficient way a possibly rectangular double matrix used in linear assignment problems (LAP). It is useful when the number of sources (rows of the matrix) and the number of targets (columns of the matrix) are large, but only a fraction of the costs are not infinite (assignment forbidden). In this case, infinite cost can be omitted and it is implicitly understood that missing values of the matrix represent infinite costs. This situation is very common in single-particle tracking for Life-Sciences, and this class is especially designed for these problems.
This class does not do much. It just stores the arrays (described below) that
represent the matrix. It is the caller responsibility to ensure they are
properly arranged and that they represent the desired cost matrix. The arrays
are accessible via default
visibility.
This matrix follow the row compressed storage convention, taken from the
Volgenant paper: Volgenant. Linear and semi-assignment problems: A core
oriented approach. Computers & Operations Research (1996) vol. 23 (10) pp.
917-932
Constructor and Description |
---|
SparseCostMatrix(double[] cc,
int[] kk,
int[] number,
int nCols)
Instantiate a new sparse cost matrix.
|
Modifier and Type | Method and Description |
---|---|
void |
fillWith(double value)
Replace all the non-infinite values of this matrix by the specified
value.
|
double |
get(int i,
int j,
double missingValue)
Returns the value stored by this matrix at the specified row and column.
|
double[] |
getCosts()
Exposes the array of all the non-infinite costs.
|
int |
getNCols() |
int |
getNRows() |
SparseCostMatrix |
hcat(SparseCostMatrix B)
Returns the horizontal concatenation of this matrix with the specified
one.
|
double[][] |
toFullMatrix()
Creates and returns a new
double[][] matrix representing a
non-sparse version of this cost matrix. |
String |
toString() |
String |
toString(List<?> rows,
List<?> columns) |
double |
totalAssignmentCost(int[] rowAssignment)
Computes the total cost for an assignment specified by row.
|
SparseCostMatrix |
transpose()
Returns the transpose of this matrix.
|
SparseCostMatrix |
vcat(SparseCostMatrix B)
Returns the vertical concatenation of this matrix with the specified one.
|
public SparseCostMatrix(double[] cc, int[] kk, int[] number, int nCols)
cc
, the double[]
array containing all the
non-infinite costs.
kk
, an int[]
array of the same length that
cc
, and that contains the columns of the cost.
IllegalArgumentException
is thrown.
number
an int[]
array, with one element per
row, that contains the number of non infinite cost for a row.
cc
- the cost array.kk
- the column index of each cost.number
- the number of element for each row.IllegalArgumentException
- if the cost and column arrays are not of the same size, if
the column array is not sorted row by row, of if one row has
0 non-infinite costs.public double totalAssignmentCost(int[] rowAssignment)
i
is assigned to column
rowAssignment[i]
.rowAssignment
- the assignment, specified by row.public double[][] toFullMatrix()
double[][]
matrix representing a
non-sparse version of this cost matrix. Missing costs are replace by
Double.MAX_VALUE
.double[][]
public final double get(int i, int j, double missingValue)
i
- the row.j
- the column.missingValue
- what to return if the sparse matrix does not store a value at
the specified row and column.public double[] getCosts()
public int getNCols()
public int getNRows()
public final SparseCostMatrix vcat(SparseCostMatrix B)
----- | A | | B | -----
B
- the matrix to concatenate this matrix withIllegalArgumentException
- if B does not have the same number of columns as this matrix.public final SparseCostMatrix hcat(SparseCostMatrix B)
------- | A B | -------
B
- the matrix to concatenate this matrix withIllegalArgumentException
- if B does not have the same number of rows as this matrix.public final SparseCostMatrix transpose()
public void fillWith(double value)
value
- the value to write in this matrix.Copyright © 2015–2021 Fiji. All rights reserved.