當前位置: 首頁>>代碼示例>>Java>>正文


Java MatrixUtils.inverse方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.linear.MatrixUtils.inverse方法的典型用法代碼示例。如果您正苦於以下問題:Java MatrixUtils.inverse方法的具體用法?Java MatrixUtils.inverse怎麽用?Java MatrixUtils.inverse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.linear.MatrixUtils的用法示例。


在下文中一共展示了MatrixUtils.inverse方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public static void main(String[] args) {
          MihcConfigData conf = new MihcConfigData();
          RealMatrix inverse = MatrixUtils.inverse(MatrixUtils.createRealMatrix(conf.filterNewXeon4fake));
          printMat(inverse);

//        Array2DRowRealMatrix AsnInv = (Array2DRowRealMatrix) MatrixUtils.createRealMatrix(conf.inverse);
//        printMat(AsnInv);
//        double[] gain = new double[]{1,1,1,1,2,1};
//        for (int i=0; i<gain.length; i++) gain[i] = 1d/gain[i];
//        RealMatrix GiiInv = MatrixUtils.createRealDiagonalMatrix(gain);
//        printMat(GiiInv);
//        Array2DRowRealMatrix AsnInvNorm = (Array2DRowRealMatrix) AsnInv.multiply(GiiInv);
//        printMat(AsnInvNorm);
//        double[] out = new double[gain.length];
//
//        //double[] in = new double[]{0,000,0,0,100,39};
//        double[] in = new double[]{0,0,0,1.554,100,36.232};   // -> 0,0,0,0,100,0
//        fastMultiply(AsnInvNorm,in,out);
//        System.out.println(Arrays.toString(out));
    }
 
開發者ID:mstritt,項目名稱:orbit-image-analysis,代碼行數:21,代碼來源:DemoMihcComputation.java

示例2: inv

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 * Calculate inverse matrix
 *
 * @param a The matrix
 * @return Inverse matrix array
 */
public static Array inv(Array a) {
    double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
    RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
    RealMatrix invm = MatrixUtils.inverse(matrix);
    if (invm == null) {
        return null;
    }

    int m = invm.getRowDimension();
    int n = invm.getColumnDimension();
    Array r = Array.factory(DataType.DOUBLE, new int[]{m, n});
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            r.setDouble(i * n + j, invm.getEntry(i, j));
        }
    }

    return r;
}
 
開發者ID:meteoinfo,項目名稱:MeteoInfoLib,代碼行數:26,代碼來源:LinalgUtil.java

示例3: invertMatrix

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 * 
 * @param matrix
 * @return
 */
public static double[][] invertMatrix(double[][] matrix){
	Array2DRowRealMatrix rMatrix=new Array2DRowRealMatrix(matrix);
	RealMatrix inv=MatrixUtils.inverse(rMatrix);
	double[][]invHermite=inv.getData();
	return invHermite;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:12,代碼來源:HermiteInterpolation.java

示例4: updateReward

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public void updateReward(User user, Article a, boolean clicked) {
	String aId = a.getId();
	// Collect Variables
	RealMatrix xta = MatrixUtils.createColumnRealMatrix(a.getFeatures());
	RealMatrix zta = makeZta(
			MatrixUtils.createColumnRealMatrix(user.getFeatures()), xta);

	RealMatrix Aa = AMap.get(aId);
	RealMatrix ba = bMap.get(aId);
	RealMatrix Ba = BMap.get(aId);

	// Find common transpose/inverse to save computation
	RealMatrix AaInverse = MatrixUtils.inverse(Aa);
	RealMatrix BaTranspose = Ba.transpose();
	RealMatrix xtaTranspose = xta.transpose();
	RealMatrix ztaTranspose = zta.transpose();

	// Update
	A0 = A0.add(BaTranspose.multiply(AaInverse).multiply(Ba));
	b0 = b0.add(BaTranspose.multiply(AaInverse).multiply(ba));
	Aa = Aa.add(xta.multiply(xtaTranspose));
	AMap.put(aId, Aa);
	Ba = Ba.add(xta.multiply(ztaTranspose));
	BMap.put(aId, Ba);
	if (clicked) {
		ba = ba.add(xta);
		bMap.put(aId, ba);
	}

	// Update A0 and b0 with the new values
	A0 = A0.add(zta.multiply(ztaTranspose)).subtract(
			Ba.transpose().multiply(MatrixUtils.inverse(Aa).multiply(Ba)));
	b0 = b0.subtract(Ba.transpose().multiply(MatrixUtils.inverse(Aa))
			.multiply(ba));
	if (clicked) {
		b0 = b0.add(zta);
	}
}
 
開發者ID:tankle,項目名稱:Bandit4J,代碼行數:39,代碼來源:HybridLinUCB.java

示例5: inverse

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 * @param A a square matrix.
 * @return the inverse of A or null if A is non-square or singular.
 */
public static double[][] inverse(final double[][] A) {
	RealMatrix M = MatrixUtils.createRealMatrix(A);
	if (!M.isSquare())
		return null;
	else {
		double[][] Ai = null;
		try {
			RealMatrix Mi = MatrixUtils.inverse(M); //new LUDecomposition(M).getSolver().getInverse();
			Ai = Mi.getData();
		} catch (SingularMatrixException e) {}
		return Ai;
	}
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:18,代碼來源:Matrix.java

示例6: weightedLinearCorr

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 *
 * @param y
 * @param x
 * @param sigmaRhoY
 * @return
 */
public static WeightedLinearCorrResults weightedLinearCorr(double[] y, double[] x, double[][] sigmaRhoY) {
    WeightedLinearCorrResults weightedLinearCorrResults = new WeightedLinearCorrResults();

    RealMatrix omega = new BlockRealMatrix(convertCorrelationsToCovariances(sigmaRhoY));
    RealMatrix invOmega = MatrixUtils.inverse(omega);
    int n = y.length;

    double mX = 0;
    double pX = 0;
    double pY = 0;
    double pXY = 0;
    double w = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            double invOm = invOmega.getEntry(i, j);
            w += invOm;
            pX += (invOm * (x[i] + x[j]));
            pY += (invOm * (y[i] + y[j]));
            pXY += (invOm * (((x[i] * y[j]) + (x[j] * y[i]))));
            mX += (invOm * x[i] * x[j]);
        }
    }       
    double slope = ((2 * pXY * w) - (pX * pY)) / ((4 * mX * w) - (pX * pX));
    double intercept = (pY - (slope * pX)) / (2 * w);

    RealMatrix fischer = new BlockRealMatrix(new double[][]{{mX, pX / 2.0}, {pX / 2.0, w}});
    RealMatrix fischerInv = MatrixUtils.inverse(fischer);

    double slopeSig = Math.sqrt(fischerInv.getEntry(0, 0));
    double interceptSig = Math.sqrt(fischerInv.getEntry(1, 1));
    double slopeInterceptCov = fischerInv.getEntry(0, 1);
    
    RealMatrix resid = new BlockRealMatrix(n, 1);
    for (int i = 0; i < n; i++) {
        resid.setEntry(i, 0, y[i] - (slope * x[i]) - intercept);
    }

    RealMatrix residT = resid.transpose();
    RealMatrix mM = residT.multiply(invOmega).multiply(resid);

    double sumSqWtdResids = mM.getEntry(0, 0);
    double mswd = sumSqWtdResids / (n - 2);

    // http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/FDistribution.html
    FDistribution fdist = new org.apache.commons.math3.distribution.FDistribution((n - 2), 1E9);
    double prob = 1.0 - fdist.cumulativeProbability(mswd);
    
    weightedLinearCorrResults.setBad(false);
    weightedLinearCorrResults.setSlope(slope);
    weightedLinearCorrResults.setIntercept(intercept);
    weightedLinearCorrResults.setSlopeSig(slopeSig);
    weightedLinearCorrResults.setInterceptSig(interceptSig);
    weightedLinearCorrResults.setSlopeInterceptCov(slopeInterceptCov);
    weightedLinearCorrResults.setMswd(mswd);
    weightedLinearCorrResults.setProb(prob);

    return weightedLinearCorrResults;
}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:67,代碼來源:WeightedMeanCalculators.java

示例7: wtdAvCorr

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 *
 * @param values
 * @param varCov
 * @return
 */
public static WtdAvCorrResults wtdAvCorr(double[] values, double[][] varCov) {
    // assume varCov is variance-covariance matrix (i.e. SigRho = false)

    WtdAvCorrResults results = new WtdAvCorrResults();

    int n = varCov.length;
    RealMatrix omegaInv = new BlockRealMatrix(varCov);
    RealMatrix omega = MatrixUtils.inverse(omegaInv);

    double numer = 0.0;
    double denom = 0.0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            numer += (values[i] + values[j]) * omega.getEntry(i, j);
            denom += omega.getEntry(i, j);
        }
    }

    // test denom
    if (denom > 0.0) {
        double meanVal = numer / denom / 2.0;
        double meanValSigma = Math.sqrt(1.0 / denom);

        double[][] unwtdResidsArray = new double[n][1];
        for (int i = 0; i < n; i++) {
            unwtdResidsArray[i][0] = values[i] - meanVal;
        }

        RealMatrix unwtdResids = new BlockRealMatrix(unwtdResidsArray);
        RealMatrix transUnwtdResids = unwtdResids.transpose();
        RealMatrix product = transUnwtdResids.multiply(omega);
        RealMatrix sumWtdResids = product.multiply(unwtdResids);

        double mswd = 0.0;
        double prob = 0.0;
        if (n > 1) {
            mswd = sumWtdResids.getEntry(0, 0) / (n - 1);

            // http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/FDistribution.html
            FDistribution fdist = new org.apache.commons.math3.distribution.FDistribution((n - 1), 1E9);
            prob = 1.0 - fdist.cumulativeProbability(mswd);
        }

        results.setBad(false);
        results.setMeanVal(meanVal);
        results.setSigmaMeanVal(meanValSigma);
        results.setMswd(mswd);
        results.setProb(prob);
    }

    return results;

}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:61,代碼來源:WeightedMeanCalculators.java

示例8: chooseArm

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public Article chooseArm(User user, List<Article> articles) {
	Article bestA = null;
	double bestArmP = Double.MIN_VALUE;

	RealMatrix Aa;
	RealMatrix Ba;
	RealMatrix ba;

	for (Article a : articles) {
		String aId = a.getId();
		if (!AMap.containsKey(aId)) {
			Aa = MatrixUtils.createRealIdentityMatrix(6);
			AMap.put(aId, Aa); // set as identity for now and we will update
								// in reward

			double[] zeros = { 0, 0, 0, 0, 0, 0 };
			ba = MatrixUtils.createColumnRealMatrix(zeros);
			bMap.put(aId, ba);

			double[][] BMapZeros = new double[6][36];
			for (double[] row : BMapZeros) {
				Arrays.fill(row, 0.0);
			}
			Ba = MatrixUtils.createRealMatrix(BMapZeros);
			BMap.put(aId, Ba);
		} else {
			Aa = AMap.get(aId);
			ba = bMap.get(aId);
			Ba = BMap.get(aId);
		}

		// Make column vector out of features
		RealMatrix xta = MatrixUtils
				.createColumnRealMatrix(a.getFeatures());
		RealMatrix zta = makeZta(
				MatrixUtils.createColumnRealMatrix(user.getFeatures()), xta);

		// Set up common variables
		RealMatrix A0Inverse = MatrixUtils.inverse(A0);
		RealMatrix AaInverse = MatrixUtils.inverse(Aa);
		RealMatrix ztaTranspose = zta.transpose();
		RealMatrix BaTranspose = Ba.transpose();
		RealMatrix xtaTranspose = xta.transpose();

		// Find theta
		RealMatrix theta = AaInverse.multiply(ba.subtract(Ba
				.multiply(BetaHat)));
		// Find sta
		RealMatrix staMatrix = ztaTranspose.multiply(A0Inverse).multiply(
				zta);
		staMatrix = staMatrix.subtract(ztaTranspose.multiply(A0Inverse)
				.multiply(BaTranspose).multiply(AaInverse).multiply(xta)
				.scalarMultiply(2));
		staMatrix = staMatrix.add(xtaTranspose.multiply(AaInverse)
				.multiply(xta));
		staMatrix = staMatrix.add(xtaTranspose.multiply(AaInverse)
				.multiply(Ba).multiply(A0Inverse).multiply(BaTranspose)
				.multiply(AaInverse).multiply(xta));

		// Find pta for arm
		RealMatrix ptaMatrix = ztaTranspose.multiply(BetaHat);
		ptaMatrix = ptaMatrix.add(xtaTranspose.multiply(theta));
		double ptaVal = ptaMatrix.getData()[0][0];
		double staVal = staMatrix.getData()[0][0];
		ptaVal = ptaVal + alpha * Math.sqrt(staVal);

		// Update argmax
		if (ptaVal > bestArmP) {
			bestArmP = ptaVal;
			bestA = a;
		}
	}
	return bestA;
}
 
開發者ID:tankle,項目名稱:Bandit4J,代碼行數:75,代碼來源:HybridLinUCB.java


注:本文中的org.apache.commons.math3.linear.MatrixUtils.inverse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。