List of usage examples for org.apache.commons.math3.exception DimensionMismatchException DimensionMismatchException
public DimensionMismatchException(int wrong, int expected)
From source file:es.csic.iiia.planes.util.MultivariateUniformDistribution.java
public MultivariateUniformDistribution(double[] lowers, double[] uppers) { super(new Well19937c(), lowers.length); final int n_vars = getDimension(); if (uppers.length != n_vars) { throw new DimensionMismatchException(uppers.length, n_vars); }/*from ww w . ja v a 2s.c o m*/ distributions = new UniformRealDistribution[n_vars]; for (int i = 0; i < n_vars; i++) { distributions[i] = new UniformRealDistribution(random, lowers[i], uppers[i]); } }
From source file:com.clust4j.algo.preprocess.WeightTransformer.java
/** * Inverse transform the incoming data. If the corresponding weight is 0.0, * will coerce the column to positive infinity rather than NaN. */// w w w .jav a 2 s . c om @Override public RealMatrix inverseTransform(RealMatrix data) { checkFit(); final int m = data.getRowDimension(); if (data.getColumnDimension() != n) throw new DimensionMismatchException(n, data.getColumnDimension()); double[][] X = data.getData(); double weight, val; for (int j = 0; j < n; j++) { weight = weights[j]; for (int i = 0; i < m; i++) { // sometimes, weight can be 0.0 if the user is masochistic... val = X[i][j] / weight; X[i][j] = Double.isNaN(val) ? Inf : val; } } // assign -- already copied in getData() return new Array2DRowRealMatrix(X, false); }
From source file:edu.ucsf.valelab.saim.calculations.SaimErrorFunction.java
/** * For each observedPoint.getX calculates the predicted intensity * Returns the sum of absolute errors/*w ww. j av a 2 s .c o m*/ * @param point {A, B, h} * @return sum of absolute errors */ @Override public double value(double[] point) { if (point.length != 3) { throw new DimensionMismatchException(point.length, 3); } double A = point[0]; double B = point[1]; double h = point[2]; double error = 0.0; for (WeightedObservedPoint observedPoint : observedPoints_) { double angle = observedPoint.getX(); Complex rTE = fresnelTE_.get(angle); double phaseDiff = SaimCalc.PhaseDiff(data_.wavelength_, angle, data_.nSample_, h); double c = rTE.getReal(); double d = rTE.getImaginary(); double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d; error += Math.abs(A * val + B - observedPoint.getY()); } return error; }
From source file:com.clust4j.algo.preprocess.MeanCenterer.java
@Override public double[][] transform(double[][] data) { checkFit();//www . java 2 s . c o m MatUtils.checkDimsForUniformity(data); final int m = data.length; final int n = data[0].length; if (n != means.length) throw new DimensionMismatchException(n, means.length); double[][] X = new double[m][n]; // second pass, subtract to center: for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { X[i][j] = data[i][j] - means[j]; } } // assign return X; }
From source file:com.itemanalysis.psychometrics.irt.model.AbstractItemResponseModel.java
public void setScoreWeights(double[] scoreWeight) throws DimensionMismatchException { if (scoreWeight.length != ncat) throw new DimensionMismatchException(scoreWeight.length, ncat); this.scoreWeight = scoreWeight; for (int i = 0; i < scoreWeight.length; i++) { minWeight = Math.min(minWeight, scoreWeight[i]); maxWeight = Math.max(maxWeight, scoreWeight[i]); }//from w w w . j a v a2 s . c o m }
From source file:gedi.util.math.function.KnotFunction.java
/** * Builds a knot function from a list of arguments and the corresponding * values. Specifically, returns the function h(x) defined by <pre><code> * h(x) = y[0] for all x < x[1]/* w w w . j a v a 2 s .c o m*/ * y[1] for x[1] <= x < x[2] * ... * y[y.length - 1] for x >= x[x.length - 1] * </code></pre> * The value of {@code x[0]} is ignored, but it must be strictly less than * {@code x[1]}. * * x and y are not copied! * if x and y are not strictly monotonically increasing, the mean of the y values is computed for equal x values * It has to be increasing! * * @param x Domain values where the function changes value. * @param y Values of the function. * @throws NullArgumentException if {@code x} or {@code y} are {@code null}. * @throws NoDataException if {@code x} or {@code y} are zero-length. * @throws DimensionMismatchException if {@code x} and {@code y} do not * have the same length. */ public KnotFunction(double[] x, double[] y) throws NullArgumentException, NoDataException, DimensionMismatchException { if (x == null || y == null) { throw new NullArgumentException(); } if (x.length == 0 || y.length == 0) { throw new NoDataException(); } if (y.length != x.length) { throw new DimensionMismatchException(y.length, x.length); } MathArrays.checkOrder(x, OrderDirection.INCREASING, false); int index = 0; double sumy = 0; int ny = 0; for (int i = 0; i < x.length; i++) { if (x[i] != x[index]) { index++; ny = 1; sumy = y[i]; } else { ny++; sumy += y[i]; } x[index] = x[i]; y[index] = sumy / ny; } if (index + 1 != x.length) { x = Arrays.copyOf(x, index + 1); y = Arrays.copyOf(y, index + 1); } this.x = x; this.y = y; }
From source file:com.itemanalysis.psychometrics.irt.model.AbstractItemResponseModelWithGradient.java
public void setScoreWeights(double[] scoreWeight) throws DimensionMismatchException { if (scoreWeight.length != ncat) throw new DimensionMismatchException(scoreWeight.length, 2); this.scoreWeight = scoreWeight; for (int i = 0; i < scoreWeight.length; i++) { minWeight = Math.min(minWeight, scoreWeight[i]); maxWeight = Math.max(maxWeight, scoreWeight[i]); }/*from ww w . ja v a 2 s . c om*/ }
From source file:com.clust4j.algo.preprocess.MedianCenterer.java
@Override public double[][] transform(double[][] data) { checkFit();//from ww w .j a va 2 s . co m MatUtils.checkDimsForUniformity(data); final int m = data.length; final int n = data[0].length; if (n != medians.length) throw new DimensionMismatchException(n, medians.length); double[][] X = new double[m][n]; // subtract to center: for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { X[i][j] = data[i][j] - medians[j]; } } // assign return X; }
From source file:com.clust4j.algo.preprocess.BoxCoxTransformer.java
/** * Inverse transform your matrix. Note: this suffers some * accuracy issues due to the log base//from w ww . ja v a 2 s . c om */ @Override public RealMatrix inverseTransform(RealMatrix X) { checkFit(); final int m = X.getRowDimension(); final int n = X.getColumnDimension(); if (n != shift.length) throw new DimensionMismatchException(n, shift.length); double[][] x = X.getData(); for (int j = 0; j < n; j++) { double lam = lambdas[j]; double ool = 1.0 / lam; for (int i = 0; i < m; i++) { // If the lambda is near zero, exp to reverse the log: if (lam < zero) { x[i][j] = FastMath.exp(x[i][j]); } else { x[i][j] *= lam; x[i][j] += 1; x[i][j] = FastMath.pow(x[i][j], ool); } // Add back the shift value: x[i][j] += shift[j]; } } // Implicit copy in the getData() return new Array2DRowRealMatrix(x, false); }
From source file:com.clust4j.algo.preprocess.WeightTransformer.java
@Override public WeightTransformer fit(RealMatrix X) { synchronized (fitLock) { // Only enforce this to prevent accidental exceptions later if the user // tries a fit(X).transform(X) and later gets a dim mismatch... if (X.getColumnDimension() != n) throw new DimensionMismatchException(n, X.getColumnDimension()); return this; }//from ww w . j a v a2s.c om }