Example usage for org.apache.commons.math3.exception DimensionMismatchException DimensionMismatchException

List of usage examples for org.apache.commons.math3.exception DimensionMismatchException DimensionMismatchException

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception DimensionMismatchException DimensionMismatchException.

Prototype

public DimensionMismatchException(int wrong, int expected) 

Source Link

Document

Construct an exception from the mismatched dimensions.

Usage

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void checkCompatibility(final IDSCompiler compiler) throws DimensionMismatchException {
    if (parameters != compiler.getFreeParameters()) {
        throw new DimensionMismatchException(parameters, compiler.getFreeParameters());
    }/*from  w  w w . ja va2  s  . c o m*/
    if (order != compiler.getOrder()) {
        throw new DimensionMismatchException(order, compiler.getOrder());
    }
}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable//www  .j  a  v  a2 s .c om
public void checkCompatibility(final IDSCompiler compiler) throws DimensionMismatchException {
    if (parameters != compiler.getFreeParameters()) {
        throw new DimensionMismatchException(parameters, compiler.getFreeParameters());
    }
    if (order != compiler.getOrder()) {
        throw new DimensionMismatchException(order, compiler.getOrder());
    }
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

public Neighborhood query(double[][] X, int k, boolean dualTree, boolean sort) {
    MatUtils.checkDims(X);/*ww  w .jav a  2s . c om*/

    final int n = data_arr[0].length, mPrime = X.length;

    if (n != X[0].length)
        throw new DimensionMismatchException(n, X[0].length);
    if (this.N_SAMPLES < k)
        throw new IllegalArgumentException(k + " is greater than rows in data");
    if (k < 1)
        throw new IllegalArgumentException(k + " must exceed 0");

    double[][] Xarr = X;

    // Initialize neighbor heap
    NeighborsHeap heap = new NeighborsHeap(mPrime, k);

    double[] bounds, pt;
    double reduced_dist_LB;

    this.n_trims = 0;
    this.n_leaves = 0;
    this.n_splits = 0;

    if (dualTree) {
        NearestNeighborHeapSearch other = newInstance(Xarr, leaf_size, dist_metric, logger);

        reduced_dist_LB = minRDistDual(this, 0, other, 0);
        bounds = VecUtils.rep(Double.POSITIVE_INFINITY, this.N_SAMPLES);
        queryDualDepthFirst(0, other, 0, bounds, heap, reduced_dist_LB);
    } else {
        int i;

        for (i = 0; i < mPrime; i++) {
            pt = Xarr[i];
            reduced_dist_LB = minRDist(this, 0, pt);
            querySingleDepthFirst(0, pt, i, heap, reduced_dist_LB);
        }
    }

    Neighborhood distances_indices = heap.getArrays(sort);
    int[][] indices = distances_indices.getValue();
    double[][] distances = distances_indices.getKey();
    rDistToDistInPlace(distances); // set back to dist

    return new Neighborhood(distances, indices);
}

From source file:com.clust4j.utils.MatUtils.java

/**
 * Stack two matrices A on top of B.// w  w w . j  a  va2s .c o m
 * @param a
 * @param b
 * @throws NonUniformMatrixException if either matrix is non-uniform
 * @throws IllegalArgumentException if either matrix is empty
 * @throws DimensionMismatchException if the col dims don't match
 * @return bound matrices
 */
public static double[][] rbind(double[][] a, double[][] b) {
    checkDimsForUniformity(a);
    checkDimsForUniformity(b);

    final int m = a.length + b.length, n = a[0].length;
    if (n != b[0].length)
        throw new DimensionMismatchException(n, b[0].length);

    final double[][] c = new double[m][n];

    int idx = 0;
    for (int i = 0; i < a.length; i++)
        c[idx++] = VecUtils.copy(a[i]);

    for (int i = 0; i < b.length; i++)
        c[idx++] = VecUtils.copy(b[i]);

    return c;
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

public Neighborhood queryRadius(double[][] X, double[] radius, boolean sort) {
    int i, m_prime = X.length;
    int[] idx_arr_i, counts_arr;
    double[] dist_arr_i, pt;

    // Assumes non-jagged rows but caught in dist ops...
    MatUtils.checkDims(X);/*from  w w  w .  j a  va  2  s  .  c  o m*/
    if (X[0].length != N_FEATURES)
        throw new DimensionMismatchException(X[0].length, N_FEATURES);

    VecUtils.checkDims(radius);
    if (m_prime != radius.length)
        throw new DimensionMismatchException(m_prime, radius.length);

    for (double rad : radius)
        ensurePositiveRadius(rad);

    // Prepare for iter
    int[][] indices = new int[m_prime][];
    double[][] dists = new double[m_prime][];

    idx_arr_i = new int[N_SAMPLES];
    dist_arr_i = new double[N_SAMPLES];
    counts_arr = new int[m_prime];

    // For each row in X
    for (i = 0; i < m_prime; i++) {
        // The current row
        pt = X[i];

        counts_arr[i] = queryRadiusSingle(0, pt, radius[i], idx_arr_i, dist_arr_i, 0, true);

        if (sort)
            NeighborsHeap.simultaneous_sort(dist_arr_i, idx_arr_i, counts_arr[i]);

        // There's a chance the length could be zero if there are no neighbors in the radius...
        indices[i] = counts_arr.length == 0 ? new int[] {} : VecUtils.slice(idx_arr_i, 0, counts_arr[i]);
        dists[i] = counts_arr.length == 0 ? new double[] {} : VecUtils.slice(dist_arr_i, 0, counts_arr[i]);
    }

    return new Neighborhood(dists, indices);
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

public Neighborhood queryRadius(double[][] X, double radius, boolean sort) {
    MatUtils.checkDims(X);/* ww  w .  j a v a  2s .co m*/
    ensurePositiveRadius(radius);

    int n = X[0].length;
    if (n != N_FEATURES)
        throw new DimensionMismatchException(n, N_FEATURES);

    return queryRadius(X, VecUtils.rep(radius, X.length), sort);
}

From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java

/**
 * extracts the l and u matrices from compact lu representation
 *///from w ww. j a va  2s .  c om
protected void splitLU(RealMatrix lu, double[][] lowerData, double[][] upperData) {
    if (!lu.isSquare()) {
        throw new NonSquareMatrixException(lu.getRowDimension(), lu.getColumnDimension());
    }
    if (lowerData.length != lowerData[0].length) {
        throw new DimensionMismatchException(lowerData.length, lowerData[0].length);
    }
    if (upperData.length != upperData[0].length) {
        throw new DimensionMismatchException(upperData.length, upperData[0].length);
    }
    if (lowerData.length != upperData.length) {
        throw new DimensionMismatchException(lowerData.length, upperData.length);
    }
    if (lowerData.length != lu.getRowDimension()) {
        throw new DimensionMismatchException(lowerData.length, lu.getRowDimension());
    }

    int n = lu.getRowDimension();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j < i) {
                lowerData[i][j] = lu.getEntry(i, j);
                upperData[i][j] = 0d;
            } else if (i == j) {
                lowerData[i][j] = 1d;
                upperData[i][j] = lu.getEntry(i, j);
            } else {
                lowerData[i][j] = 0d;
                upperData[i][j] = lu.getEntry(i, j);
            }
        }
    }
}

From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java

/**
 * Returns the result of applying the given row permutation to the matrix
 *//*from w  ww  .  j a v a 2 s  .  co  m*/
protected RealMatrix permuteRows(RealMatrix matrix, int[] permutation) {
    if (!matrix.isSquare()) {
        throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension());
    }
    if (matrix.getRowDimension() != permutation.length) {
        throw new DimensionMismatchException(matrix.getRowDimension(), permutation.length);
    }

    int n = matrix.getRowDimension();
    int m = matrix.getColumnDimension();
    double out[][] = new double[m][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            out[i][j] = matrix.getEntry(permutation[i], j);
        }
    }
    return new BigSparseRealMatrix(out);
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

public int[] twoPointCorrelation(double[][] X, double[] r, boolean dual) {
    int i;//from w ww.  ja v a 2 s .c  o  m

    MatUtils.checkDims(X);
    if (X[0].length != N_FEATURES)
        throw new DimensionMismatchException(X[0].length, N_FEATURES);

    double[][] Xarr = MatUtils.copy(X);
    double[] rarr = VecUtils.reorder(r, VecUtils.argSort(r));

    // count array
    int[] carr = new int[r.length];

    if (dual) {
        NearestNeighborHeapSearch other = newInstance(Xarr, leaf_size, dist_metric, logger);
        this.twoPointDual(0, other, 0, rarr, carr, 0, rarr.length);
    } else {
        for (i = 0; i < Xarr.length; i++)
            this.twoPointSingle(0, Xarr[i], rarr, carr, 0, rarr.length);
    }

    return carr;
}

From source file:com.clust4j.utils.VecUtils.java

public static double[] where(final DoubleSeries series, final double[] x, final double[] y) {
    checkDims(x, y);//from  www. ja  v  a 2s. com

    final int n = x.length;
    final boolean[] ser = series.get();
    if (ser.length != n)
        throw new DimensionMismatchException(ser.length, n);

    final double[] result = new double[n];
    for (int i = 0; i < n; i++)
        result[i] = ser[i] ? x[i] : y[i];

    return result;
}