use of org.apache.ignite.ml.math.exceptions.math.CardinalityException in project ignite by apache.
the class LUDecomposition method solve.
/**
* @param b Vector to solve using this decomposition.
* @return Solution vector.
*/
public Vector solve(Vector b) {
final int m = pivot.size();
if (b.size() != m)
throw new CardinalityException(b.size(), m);
if (singular)
throw new SingularMatrixException();
final double[] bp = new double[m];
// Apply permutations to b
for (int row = 0; row < m; row++) bp[row] = b.get((int) pivot.get(row));
// Solve LY = b
for (int col = 0; col < m; col++) {
final double bpCol = bp[col];
for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col);
}
// Solve UX = Y
for (int col = m - 1; col >= 0; col--) {
bp[col] /= lu.get(col, col);
final double bpCol = bp[col];
for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col);
}
return b.like(m).assign(bp);
}
use of org.apache.ignite.ml.math.exceptions.math.CardinalityException in project ignite by apache.
the class Blas method syr.
/**
* A := alpha * x * x^T + A.
*
* @param alpha a real scalar that will be multiplied to x * x^T^.
* @param x the vector x that contains the n elements.
* @param a the symmetric matrix A. Size of n x n.
*/
void syr(Double alpha, Vector x, DenseMatrix a) {
int mA = a.rowSize();
int nA = a.columnSize();
if (mA != nA)
throw new NonSquareMatrixException(mA, nA);
if (mA != x.size())
throw new CardinalityException(x.size(), mA);
// TODO: IGNITE-5535, Process DenseLocalOffHeapVector
if (x instanceof DenseVector)
syr(alpha, x, a);
else if (x instanceof SparseVector)
syr(alpha, x, a);
else
throw new IllegalArgumentException("Operation 'syr' does not support vector [class=" + x.getClass().getName() + "].");
}
use of org.apache.ignite.ml.math.exceptions.math.CardinalityException in project ignite by apache.
the class AbstractMatrix method setColumn.
/**
* {@inheritDoc}
*/
@Override
public Matrix setColumn(int col, double[] data) {
checkColumnIndex(col);
int rows = rowSize();
if (rows != data.length)
throw new CardinalityException(rows, data.length);
for (int x = 0; x < rows; x++) setX(x, col, data[x]);
return this;
}
use of org.apache.ignite.ml.math.exceptions.math.CardinalityException in project ignite by apache.
the class AbstractMatrix method times.
/**
* {@inheritDoc}
*/
@Override
public Matrix times(Matrix mtx) {
int cols = columnSize();
if (cols != mtx.rowSize())
throw new CardinalityException(cols, mtx.rowSize());
Matrix res = like(rowSize(), mtx.columnSize());
Blas.gemm(1, this, mtx, 0, res);
return res;
}
use of org.apache.ignite.ml.math.exceptions.math.CardinalityException in project ignite by apache.
the class LabeledDatasetLoader method parseFeatures.
/**
*/
@NotNull
private static Vector parseFeatures(Path pathToFile, boolean isFallOnBadData, int colSize, int rowIdx, String[] rowData) {
final Vector vec = LabeledVectorSet.emptyVector(colSize);
if (isFallOnBadData && rowData.length != colSize + 1)
throw new CardinalityException(colSize + 1, rowData.length);
double missedData = fillMissedData();
for (int j = 0; j < colSize; j++) {
try {
double feature = Double.parseDouble(rowData[j + 1]);
vec.set(j, feature);
} catch (NumberFormatException e) {
if (isFallOnBadData)
throw new FileParsingException(rowData[j + 1], rowIdx, pathToFile);
else
vec.set(j, missedData);
} catch (ArrayIndexOutOfBoundsException e) {
vec.set(j, missedData);
}
}
return vec;
}
Aggregations