当前位置: 首页>>代码示例>>Java>>正文


Java DecompositionSolver.solve方法代码示例

本文整理汇总了Java中org.apache.commons.math3.linear.DecompositionSolver.solve方法的典型用法代码示例。如果您正苦于以下问题:Java DecompositionSolver.solve方法的具体用法?Java DecompositionSolver.solve怎么用?Java DecompositionSolver.solve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.linear.DecompositionSolver的用法示例。


在下文中一共展示了DecompositionSolver.solve方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeSolve

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/**
 * Function to solve a given system of equations.
 * 
 * @param in1 matrix object 1
 * @param in2 matrix object 2
 * @return matrix block
 * @throws DMLRuntimeException if DMLRuntimeException occurs
 */
private static MatrixBlock computeSolve(MatrixObject in1, MatrixObject in2) 
	throws DMLRuntimeException 
{
	Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in1);
	Array2DRowRealMatrix vectorInput = DataConverter.convertToArray2DRowRealMatrix(in2);
	
	/*LUDecompositionImpl ludecompose = new LUDecompositionImpl(matrixInput);
	DecompositionSolver lusolver = ludecompose.getSolver();
	RealMatrix solutionMatrix = lusolver.solve(vectorInput);*/
	
	// Setup a solver based on QR Decomposition
	QRDecomposition qrdecompose = new QRDecomposition(matrixInput);
	DecompositionSolver solver = qrdecompose.getSolver();
	// Invoke solve
	RealMatrix solutionMatrix = solver.solve(vectorInput);
	
	return DataConverter.convertToMatrixBlock(solutionMatrix.getData());
}
 
开发者ID:apache,项目名称:systemml,代码行数:27,代码来源:LibCommonsMath.java

示例2: estimateCoefficients

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
@Override
public SlopeCoefficients estimateCoefficients(final DerivationEquation eq)
    throws EstimationException {
  final double[][] sourceTriangleMatrix = eq.getCovarianceLowerTriangularMatrix();
  // Copy matrix and enhance it to a full matrix as expected by CholeskyDecomposition
  // FIXME: Avoid copy job to speed-up the solving process e.g. by extending the CholeskyDecomposition constructor
  final int length = sourceTriangleMatrix.length;
  final double[][] matrix = new double[length][];
  for (int i = 0; i < length; i++) {
    matrix[i] = new double[length];
    final double[] s = sourceTriangleMatrix[i];
    final double[] t = matrix[i];
    for (int j = 0; j <= i; j++) {
      t[j] = s[j];
    }
    for (int j = i + 1; j < length; j++) {
      t[j] = sourceTriangleMatrix[j][i];
    }
  }
  final RealMatrix coefficients =
      new Array2DRowRealMatrix(matrix, false);
  try {
    final DecompositionSolver solver = new CholeskyDecomposition(coefficients).getSolver();
    final RealVector constants = new ArrayRealVector(eq.getConstraints(), true);
    final RealVector solution = solver.solve(constants);
    return new DefaultSlopeCoefficients(solution.toArray());
  } catch (final NonPositiveDefiniteMatrixException e) {
    throw new EstimationException("Matrix inversion error due to data is linearly dependent", e);
  }
}
 
开发者ID:scaleborn,项目名称:elasticsearch-linear-regression,代码行数:31,代码来源:CommonsMathSolver.java

示例3: fit

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
@Override
public void fit(List<double[]> X, List<double[]> Y) {	// fits n-dimensional data sets with affine model
	if (X.size() != Y.size())
		throw new IllegalArgumentException("point sequences X, Y must have same length");
	this.m = X.size();
	this.n = X.get(0).length;
	
	RealMatrix M = MatrixUtils.createRealMatrix(2 * m, 2 * (n + 1));
	RealVector b = new ArrayRealVector(2 * m);
	
	// mount matrix M:
	int row = 0;
	for (double[] x : X) {
		for (int j = 0; j < n; j++) {
			M.setEntry(row, j, x[j]);
			M.setEntry(row, n, 1);
			row++;
		}
		for (int j = 0; j < n; j++) {
			M.setEntry(row, j + n + 1, x[j]);
			M.setEntry(row, 2 * n + 1, 1);
			row++;
		}
	}
	
	// mount vector b
	row = 0;
	for (double[] y : Y) {
		for (int j = 0; j < n; j++) {
			b.setEntry(row, y[j]);
			row++;
		}
	}
	
	SingularValueDecomposition svd = new SingularValueDecomposition(M);
	DecompositionSolver solver = svd.getSolver();
	RealVector a = solver.solve(b);
	A = makeTransformationMatrix(a);
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:40,代码来源:AffineFit.java

示例4: ProjectiveMapping

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/**
 * Constructor for more than 4 point pairs, finds a least-squares solution
 * for the homography parameters.
 * NOTE: this is UNFINISHED code!
 * @param P sequence of points (source)
 * @param Q sequence of points (target)
 * @param dummy unused (only to avoid duplicate signature)
 */
public ProjectiveMapping(Point2D[] P, Point2D[] Q, boolean dummy) {
	final int n = P.length;
	double[] ba = new double[2 * n];
	double[][] Ma = new double[2 * n][];
	for (int i = 0; i < n; i++) {
		double x = P[i].getX();
		double y = P[i].getY();
		double u = Q[i].getX();
		double v = Q[i].getY();
		ba[2 * i + 0] = u;
		ba[2 * i + 1] = v;
		Ma[2 * i + 0] = new double[] { x, y, 1, 0, 0, 0, -u * x, -u * y };
		Ma[2 * i + 1] = new double[] { 0, 0, 0, x, y, 1, -v * x, -v * y };
	}
	
	RealMatrix M = MatrixUtils.createRealMatrix(Ma);
	RealVector b = MatrixUtils.createRealVector(ba);
	DecompositionSolver solver = new SingularValueDecomposition(M).getSolver();
	RealVector h = solver.solve(b);
	a00 = h.getEntry(0);
	a01 = h.getEntry(1);
	a02 = h.getEntry(2);
	a10 = h.getEntry(3);
	a11 = h.getEntry(4);
	a12 = h.getEntry(5);
	a20 = h.getEntry(6);
	a21 = h.getEntry(7);
	a22 = 1;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:38,代码来源:ProjectiveMapping.java

示例5: solve

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/**
 * @see AbstractSolver#solve(AbstractMatrix, AbstractVector)
 */
@Override
public AbstractVector solve(AbstractMatrix m, AbstractVector b) {
  if (m instanceof ApacheMatrix && b instanceof ApacheVector) {
    DecompositionSolver solver = new LUDecomposition(((ApacheMatrix) m).getMatrix()).getSolver();
    RealVector bApache = ((ApacheVector) b).getVector();
    RealVector solution = solver.solve(bApache);
    return new ApacheVector(solution);
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:14,代码来源:ApacheSolver.java

示例6: guessStartLine

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/** Guess a start line using the last four results.
 * @param n number of cached results available
 * @param target target ground point
 * @return guessed start line
 */
private double guessStartLine(final int n, final Vector3D target) {
    try {

        // assume a linear model of the form: l = ax + by + cz + d
        final RealMatrix m = new Array2DRowRealMatrix(n, 4);
        final RealVector v = new ArrayRealVector(n);
        for (int i = 0; i < n; ++i) {
            m.setEntry(i, 0, cachedResults[i].getTarget().getX());
            m.setEntry(i, 1, cachedResults[i].getTarget().getY());
            m.setEntry(i, 2, cachedResults[i].getTarget().getZ());
            m.setEntry(i, 3, 1.0);
            v.setEntry(i, cachedResults[i].getLine());
        }

        final DecompositionSolver solver = new QRDecomposition(m, Precision.SAFE_MIN).getSolver();
        final RealVector coefficients = solver.solve(v);

        // apply the linear model
        return target.getX() * coefficients.getEntry(0) +
               target.getY() * coefficients.getEntry(1) +
               target.getZ() * coefficients.getEntry(2) +
               coefficients.getEntry(3);

    } catch (SingularMatrixException sme) {
        // the points are not independent
        return Double.NaN;
    }
}
 
开发者ID:CS-SI,项目名称:Rugged,代码行数:34,代码来源:SensorMeanPlaneCrossing.java

示例7: solve

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/**
 * Solve a linear matrix equation, or system of linear scalar equations.
 *
 * @param a Coefficient matrix.
 * @param b Ordinate or “dependent variable” values.
 * @return Solution to the system a x = b. Returned shape is identical to b.
 */
public static Array solve(Array a, Array b) {
    Array r = Array.factory(DataType.DOUBLE, b.getShape());
    double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
    RealMatrix coefficients = new Array2DRowRealMatrix(aa, false);
    DecompositionSolver solver = new LUDecomposition(coefficients).getSolver();
    double[] bb = (double[]) ArrayUtil.copyToNDJavaArray(b);
    RealVector constants = new ArrayRealVector(bb, false);
    RealVector solution = solver.solve(constants);
    for (int i = 0; i < r.getSize(); i++) {
        r.setDouble(i, solution.getEntry(i));
    }

    return r;
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:22,代码来源:LinalgUtil.java

示例8: calculateParameters

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
/**
 * Calculates the parameters of a bivariate quadratic equation.
 * 
 * @param elevationValues the window of points to use.
 * @return the parameters of the bivariate quadratic equation as [a, b, c, d, e, f]
 */
private static double[] calculateParameters( final double[][] elevationValues ) {
    int rows = elevationValues.length;
    int cols = elevationValues[0].length;
    int pointsNum = rows * cols;

    final double[][] xyMatrix = new double[pointsNum][6];
    final double[] valueArray = new double[pointsNum];

    // TODO check on resolution
    int index = 0;
    for( int y = 0; y < rows; y++ ) {
        for( int x = 0; x < cols; x++ ) {
            xyMatrix[index][0] = x * x; // x^2
            xyMatrix[index][1] = y * y; // y^2
            xyMatrix[index][2] = x * y; // xy
            xyMatrix[index][3] = x; // x
            xyMatrix[index][4] = y; // y
            xyMatrix[index][5] = 1;
            valueArray[index] = elevationValues[y][x];
            index++;
        }
    }

    RealMatrix A = MatrixUtils.createRealMatrix(xyMatrix);
    RealVector z = MatrixUtils.createRealVector(valueArray);

    DecompositionSolver solver = new RRQRDecomposition(A).getSolver();
    RealVector solution = solver.solve(z);

    // start values for a, b, c, d, e, f, all set to 0.0
    final double[] parameters = solution.toArray();
    return parameters;
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:40,代码来源:OmsCurvaturesBivariate.java

示例9: getHomography3

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
public static Matrix4d getHomography3(final double[][] srcPoints, final double[][] dstPoints) {

		// see :
		// http://math.stackexchange.com/questions/494238/how-to-compute-homography-matrix-h-from-corresponding-points-2d-2d-planar-homog

		final double sx1 = srcPoints[0][0];
		final double sy1 = srcPoints[0][1];
		final double sx2 = srcPoints[1][0];
		final double sy2 = srcPoints[1][1];
		final double sx3 = srcPoints[2][0];
		final double sy3 = srcPoints[2][1];
		final double sx4 = srcPoints[3][0];
		final double sy4 = srcPoints[3][1];

		final double dx1 = dstPoints[0][0];
		final double dy1 = dstPoints[0][1];
		final double dx2 = dstPoints[1][0];
		final double dy2 = dstPoints[1][1];
		final double dx3 = dstPoints[2][0];
		final double dy3 = dstPoints[2][1];
		final double dx4 = dstPoints[3][0];
		final double dy4 = dstPoints[3][1];

		final RealMatrix coefficients = new Array2DRowRealMatrix(new double[][] {
				{ -sx1, -sy1, -1, 0, 0, 0, sx1 * dx1, sy1 * dx1 }, { 0, 0, 0, -dx1, -dy1, -1, sx1 * dy1, sy1 * dy1 },
				{ -sx2, -sy2, -1, 0, 0, 0, sx2 * dx2, sy2 * dx2 }, { 0, 0, 0, -dx2, -dy2, -1, sx2 * dy2, sy2 * dy2 },
				{ -sx3, -sy3, -1, 0, 0, 0, sx3 * dx3, sy3 * dx3 }, { 0, 0, 0, -dx3, -dy3, -1, sx3 * dy3, sy3 * dy3 },
				{ -sx4, -sy4, -1, 0, 0, 0, sx4 * dx4, sy4 * dx4 }, { 0, 0, 0, -dx4, -dy4, -1, sx4 * dy4, sy4 * dy4 } },
				false);
		final DecompositionSolver solver = new LUDecomposition(coefficients).getSolver();

		final RealVector constants = new ArrayRealVector(new double[] { dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4 },
				false);
		final RealVector solution = solver.solve(constants);

		final Matrix4d Result = new Matrix4d();
		Result.m00 = solution.getEntry(0);
		Result.m01 = solution.getEntry(1);
		Result.m02 = 0;
		Result.m03 = solution.getEntry(2);
		Result.m10 = solution.getEntry(3);
		Result.m11 = solution.getEntry(4);
		Result.m12 = 0;
		Result.m13 = solution.getEntry(5);
		Result.m20 = 0;
		Result.m21 = 0;
		Result.m22 = 1;
		Result.m23 = 0;
		Result.m30 = solution.getEntry(6);
		Result.m31 = solution.getEntry(7);
		Result.m32 = 0;
		Result.m33 = 1;

		return Result;

	}
 
开发者ID:gama-platform,项目名称:gama,代码行数:57,代码来源:GeomMathUtils.java

示例10: correctIllumination

import org.apache.commons.math3.linear.DecompositionSolver; //导入方法依赖的package包/类
public static Map<String, float[]> correctIllumination(Map<String, float[]> patchYUVMap, DecodeData decodeData, CalibrationCardData calCardData) {

        float[][] whitePoints = decodeData.getWhitePointArray();
        int numRows = whitePoints.length;
        RealMatrix coef = new Array2DRowRealMatrix(numRows, 6);
        RealVector Y = new ArrayRealVector(numRows);

        //create constant, x, y, x^2, y^2 and xy terms
        float x, y;
        for (int i = 0; i < numRows; i++) {
            x = whitePoints[i][0];
            y = whitePoints[i][1];
            coef.setEntry(i, 0, x);
            coef.setEntry(i, 1, y);
            coef.setEntry(i, 2, x * x);
            coef.setEntry(i, 3, y * y);
            coef.setEntry(i, 4, x * y);
            coef.setEntry(i, 5, 1.0f); // constant term

            Y.setEntry(i, whitePoints[i][2]);
        }

        // solve the least squares problem
        DecompositionSolver solver = new SingularValueDecomposition(coef).getSolver();
        RealVector solutionL = solver.solve(Y);

        // get individual coefficients
        float Ya = (float) solutionL.getEntry(0); // x
        float Yb = (float) solutionL.getEntry(1); // y
        float Yc = (float) solutionL.getEntry(2); // x^2
        float Yd = (float) solutionL.getEntry(3); // y^2
        float Ye = (float) solutionL.getEntry(4); // x y
        float Yf = (float) solutionL.getEntry(5); // constant

        // we now have a model:
        // Y = a x + b y + c x^2 + d y^2 + e x y + constant

        // Next step is to choose the Y level we will use for the whole image. For this, we
        // compute the mean luminosity of the whole image. To compute this, we compute the volume
        // underneath the curve, which gives us the average.

        float xmax = calCardData.hSize;
        float ymax = calCardData.vSize;

        float Ymean = (float) (0.5 * Ya * xmax + 0.5 * Yb * ymax + Yc * xmax * xmax / 3.0
                + Yd * ymax * ymax / 3.0 + Ye * 0.25 * xmax * ymax + Yf);

        float[] illumData = new float[]{Ya, Yb, Yc, Yd, Ye, Yf, Ymean};
        decodeData.setIllumData(illumData);

        // now we create a new map with corrected values. U and V are unchanged
        float Ynew;
        Map<String, float[]> resultYUVMap = new HashMap<>();

        for (String label : calCardData.getCalValues().keySet()) {
            CalibrationCardData.Location loc = calCardData.getLocations().get(label);
            float[] YUV = patchYUVMap.get(label);
            x = loc.x;
            y = loc.y;
            Ynew = capValue(YUV[0] - (Ya * x + Yb * y + Yc * x * x + Yd * y * y
                    + Ye * x * y + Yf) + Ymean, 0.0f, 255.0f);
            resultYUVMap.put(label, new float[]{Ynew, YUV[1], YUV[2]});
        }
        return resultYUVMap;
    }
 
开发者ID:akvo,项目名称:akvo-caddisfly,代码行数:66,代码来源:CalibrationUtils.java


注:本文中的org.apache.commons.math3.linear.DecompositionSolver.solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。