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


Java Array2DRowRealMatrix類代碼示例

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


Array2DRowRealMatrix類屬於org.apache.commons.math3.linear包,在下文中一共展示了Array2DRowRealMatrix類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: apacheCommonsExample

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
public void apacheCommonsExample() {
    double[][] A = {
        {0.1950, 0.0311},
        {0.3588, 0.2203},
        {0.1716, 0.5931},
        {0.2105, 0.3242}};

    double[][] B = {
        {0.0502, 0.9823, 0.9472},
        {0.5732, 0.2694, 0.916}};

    RealMatrix aRealMatrix = new Array2DRowRealMatrix(A);
    RealMatrix bRealMatrix = new Array2DRowRealMatrix(B);

    RealMatrix cRealMatrix = aRealMatrix.multiply(bRealMatrix);
    System.out.println();
    for (int i = 0; i < cRealMatrix.getRowDimension(); i++) {
        System.out.println(cRealMatrix.getRowVector(i));
    }
}
 
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:21,代碼來源:MathExamples.java

示例2: RotationMeasurementModel

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
public RotationMeasurementModel()
{
	super();

	// H = measurementMatrix
	measurementMatrix = new Array2DRowRealMatrix(new double[][]
	{
	{ 1, 0, 0, 0 },
	{ 0, 1, 0, 0 },
	{ 0, 0, 1, 0 },
	{ 0, 0, 0, 1 } });

	// R = measurementNoise
	measurementNoise = new Array2DRowRealMatrix(new double[][]
	{
	{ noiseCoefficient, 0, 0, 0 },
	{ 0, noiseCoefficient, 0, 0 },
	{ 0, 0, noiseCoefficient, 0 },
	{ 0, 0, 0, noiseCoefficient } });
}
 
開發者ID:KalebKE,項目名稱:FSensor,代碼行數:21,代碼來源:RotationMeasurementModel.java

示例3: nextWishart

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
public RealMatrix nextWishart(double df, Cholesky invscale) {
  int d = invscale.getL().getColumnDimension();
  Array2DRowRealMatrix A = new Array2DRowRealMatrix(d,d);
  ArrayRealVector v = new ArrayRealVector(d);
  for (int i=0; i<d; i++) {
    v.setEntry(i, sqrt(nextChiSquared(df-i)));
    for (int j=0; j<i; j++) {
      v.setEntry(j, 0.0);
    }
    for (int j=i+1; j<d; j++) {
      v.setEntry(j, nextGaussian());
    }
    A.setColumnVector(i, invscale.solveLT(v));
  }
  return A.multiply(A.transpose());
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:17,代碼來源:Generator.java

示例4: main

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
public static void main(String[] args) {
  // test wishart
  double[][] s = {{2.0,1.0,0.0},{1.0,2.0,1.0},{0.0,1.0,2.0}};
  RealMatrix S = new Array2DRowRealMatrix(s);
  Cholesky C = new Cholesky(S);
  double df = 2.4;
  RealMatrix sum = new Array2DRowRealMatrix(3,3);
  for (int i=0; i<100000; i++) {
    RealMatrix sample = generator.nextWishart(df, C);
    sum = sum.add(sample);
  }
  sum = sum.scalarMultiply(1.0/100000.0);
  System.out.println(sum.getRowVector(0));
  System.out.println(sum.getRowVector(1));
  System.out.println(sum.getRowVector(2));
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:17,代碼來源:Generator.java

示例5: getSolver

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
/**
 * @param data dense matrix represented in row-major form
 * @return solver for the system Ax = b
 */
static Solver getSolver(double[][] data) {
  if (data == null) {
    return null;
  }
  RealMatrix M = new Array2DRowRealMatrix(data, false);
  double infNorm = M.getNorm();
  double singularityThreshold = infNorm * SINGULARITY_THRESHOLD_RATIO;
  RRQRDecomposition decomposition = new RRQRDecomposition(M, singularityThreshold);
  DecompositionSolver solver = decomposition.getSolver();
  if (solver.isNonSingular()) {
    return new Solver(solver);
  }
  // Otherwise try to report apparent rank
  int apparentRank = decomposition.getRank(0.01); // Better value?
  log.warn("{} x {} matrix is near-singular (threshold {}). Add more data or decrease the " +
           "number of features, to <= about {}",
           M.getRowDimension(), 
           M.getColumnDimension(),
           singularityThreshold,
           apparentRank);
  throw new SingularMatrixSolverException(apparentRank, "Apparent rank: " + apparentRank);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:27,代碼來源:LinearSystemSolver.java

示例6: createX

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
/**
 * Creates the X design matrix for this regression model
 * @return  the X design matrix
 */
RealMatrix createX() {
    final int n = frame.rows().count();
    final int offset = hasIntercept() ? 1 : 0;
    final int p = hasIntercept() ? regressors.size() + 1 : regressors.size();
    final int[] colIndexes = regressors.stream().mapToInt(k -> frame.cols().ordinalOf(k)).toArray();
    final RealMatrix x = new Array2DRowRealMatrix(n, p);
    for (int i = 0; i < n; ++i) {
        x.setEntry(i, 0, 1d);
        for (int j = offset; j < p; ++j) {
            final double value = frame.data().getDouble(i, colIndexes[j - offset]);
            x.setEntry(i, j, value);
        }
    }
    return x;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:20,代碼來源:XDataFrameLeastSquares.java

示例7: testCreateLargeMatrix

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testCreateLargeMatrix(){
    // Creates a large PoN of junk values and simply tests that these can be written and read.

    // Make a big, fake set of read counts.
    final int numRows = 2500000;
    final int numCols = 10;
    final double mean = 3e-7;
    final double sigma = 1e-9;

    final RealMatrix bigCounts = createMatrixOfGaussianValues(numRows, numCols, mean, sigma);
    final File tempOutputHD5 = Utils.createTempFile("big-ol-", ".hd5");
    final HDF5File hdf5File = new HDF5File(tempOutputHD5, HDF5File.OpenMode.CREATE);
    final String hdf5Path = "/test/m";
    hdf5File.makeDoubleMatrix(hdf5Path, bigCounts.getData());
    hdf5File.close();

    final HDF5File hdf5FileForReading = new HDF5File(tempOutputHD5, HDF5File.OpenMode.READ_ONLY);
    final double[][] result = hdf5FileForReading.readDoubleMatrix(hdf5Path);
    final RealMatrix resultAsRealMatrix = new Array2DRowRealMatrix(result);
    Assert.assertTrue(resultAsRealMatrix.getRowDimension() == numRows);
    Assert.assertTrue(resultAsRealMatrix.getColumnDimension() == numCols);
    final RealMatrix readMatrix = new Array2DRowRealMatrix(result);
    assertEqualsMatrix(readMatrix, bigCounts, false);
}
 
開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:26,代碼來源:HDF5LibraryUnitTest.java

示例8: getCorrelationCoefficients

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
/**
 * Gets the correlation coefficients.
 * 
 * @param data the data
 * @return the correlation coefficients
 */
protected List<Double> getCorrelationCoefficients(final double[][] data) {
	int n = data.length;
	int m = data[0].length;
	List<Double> correlationCoefficients = new LinkedList<Double>();
	for (int i = 0; i < n; i++) {
		double[][] x = new double[n - 1][m];
		int k = 0;
		for (int j = 0; j < n; j++) {
			if (j != i) {
				x[k++] = data[j];
			}
		}

		// Transpose the matrix so that it fits the linear model
		double[][] xT = new Array2DRowRealMatrix(x).transpose().getData();

		// RSquare is the "coefficient of determination"
		correlationCoefficients.add(MathUtil.createLinearRegression(xT,
				data[i]).calculateRSquared());
	}
	return correlationCoefficients;
}
 
開發者ID:gmartinezramirez,項目名稱:Fog-Computing-Mobile-Architecture,代碼行數:29,代碼來源:PowerVmSelectionPolicyMaximumCorrelation.java

示例9: testToeplitz

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testToeplitz() {
    RealMatrix[] c = new RealMatrix[] {new Array2DRowRealMatrix(new double[] {1}),
            new Array2DRowRealMatrix(new double[] {2}),
            new Array2DRowRealMatrix(new double[] {3})};
    RealMatrix[][] A = MatrixUtils.toeplitz(c, 3);
    // 1  2  3
    // 2  1  2
    // 3  2  1
    Assert.assertArrayEquals(new RealMatrix[] {new Array2DRowRealMatrix(new double[] {1}),
            new Array2DRowRealMatrix(new double[] {2}),
            new Array2DRowRealMatrix(new double[] {3})}, A[0]);
    Assert.assertArrayEquals(new RealMatrix[] {new Array2DRowRealMatrix(new double[] {2}),
            new Array2DRowRealMatrix(new double[] {1}),
            new Array2DRowRealMatrix(new double[] {2})}, A[1]);
    Assert.assertArrayEquals(new RealMatrix[] {new Array2DRowRealMatrix(new double[] {3}),
            new Array2DRowRealMatrix(new double[] {2}),
            new Array2DRowRealMatrix(new double[] {1})}, A[2]);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:20,代碼來源:MatrixUtilsTest.java

示例10: testFlatten2D

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testFlatten2D() {
    RealMatrix[] m1 = new RealMatrix[] {
            new Array2DRowRealMatrix(new double[][] {new double[] {1, 2, 3},
                    new double[] {4, 5, 6}}),
            new Array2DRowRealMatrix(new double[][] {new double[] {7, 8, 9},
                    new double[] {10, 11, 12}}),
            new Array2DRowRealMatrix(new double[][] {new double[] {13, 14, 15},
                    new double[] {16, 17, 18}})};
    double[] actual = MatrixUtils.flatten(m1);
    double[] expected = new double[18];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = i + 1;
    }
    Assert.assertArrayEquals(expected, actual, 0.d);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:17,代碼來源:MatrixUtilsTest.java

示例11: testUnflatten2D

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testUnflatten2D() {
    double[] data = new double[24];
    for (int i = 0; i < data.length; i++) {
        data[i] = i + 1;
    }
    RealMatrix[] actual = MatrixUtils.unflatten(data, 2, 3, 4);

    RealMatrix[] expected = new RealMatrix[] {
            new Array2DRowRealMatrix(new double[][] {new double[] {1, 2, 3},
                    new double[] {4, 5, 6}}),
            new Array2DRowRealMatrix(new double[][] {new double[] {7, 8, 9},
                    new double[] {10, 11, 12}}),
            new Array2DRowRealMatrix(new double[][] {new double[] {13, 14, 15},
                    new double[] {16, 17, 18}}),
            new Array2DRowRealMatrix(new double[][] {new double[] {19, 20, 21},
                    new double[] {22, 23, 24}})};

    Assert.assertArrayEquals(expected, actual);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:21,代碼來源:MatrixUtilsTest.java

示例12: testPower1

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testPower1() {
    RealMatrix A = new Array2DRowRealMatrix(new double[][] {new double[] {1, 2, 3},
            new double[] {4, 5, 6}});

    double[] x = new double[3];
    x[0] = Math.random();
    x[1] = Math.random();
    x[2] = Math.random();

    double[] u = new double[2];
    double[] v = new double[3];

    double s = MatrixUtils.power1(A, x, 2, u, v);

    SingularValueDecomposition svdA = new SingularValueDecomposition(A);

    Assert.assertArrayEquals(svdA.getU().getColumn(0), u, 0.001d);
    Assert.assertArrayEquals(svdA.getV().getColumn(0), v, 0.001d);
    Assert.assertEquals(svdA.getSingularValues()[0], s, 0.001d);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:22,代碼來源:MatrixUtilsTest.java

示例13: testLanczosTridiagonalization

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testLanczosTridiagonalization() {
    // Symmetric matrix
    RealMatrix C = new Array2DRowRealMatrix(new double[][] {new double[] {1, 2, 3, 4},
            new double[] {2, 1, 4, 3}, new double[] {3, 4, 1, 2}, new double[] {4, 3, 2, 1}});

    // naive initial vector
    double[] a = new double[] {1, 1, 1, 1};

    RealMatrix actual = new Array2DRowRealMatrix(new double[4][4]);
    MatrixUtils.lanczosTridiagonalization(C, a, actual);

    RealMatrix expected = new Array2DRowRealMatrix(new double[][] {new double[] {40, 60, 0, 0},
            new double[] {60, 10, 120, 0}, new double[] {0, 120, 10, 120},
            new double[] {0, 0, 120, 10}});

    Assert.assertEquals(expected, actual);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:19,代碼來源:MatrixUtilsTest.java

示例14: testTridiagonalEigen

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
@Test
public void testTridiagonalEigen() {
    // Tridiagonal Matrix
    RealMatrix T = new Array2DRowRealMatrix(new double[][] {new double[] {40, 60, 0, 0},
            new double[] {60, 10, 120, 0}, new double[] {0, 120, 10, 120},
            new double[] {0, 0, 120, 10}});

    double[] eigvals = new double[4];
    RealMatrix eigvecs = new Array2DRowRealMatrix(new double[4][4]);

    MatrixUtils.tridiagonalEigen(T, 2, eigvals, eigvecs);

    RealMatrix actual = eigvecs.multiply(eigvecs.transpose());

    RealMatrix expected = new Array2DRowRealMatrix(new double[4][4]);
    for (int i = 0; i < 4; i++) {
        expected.setEntry(i, i, 1);
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            Assert.assertEquals(expected.getEntry(i, j), actual.getEntry(i, j), 0.001d);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:26,代碼來源:MatrixUtilsTest.java

示例15: value

import org.apache.commons.math3.linear.Array2DRowRealMatrix; //導入依賴的package包/類
public Pair<RealVector, RealMatrix> value(final RealVector aprioriApproximation) {

            int maskCount = allMaskValues.size();
            int groupCount = table.getGroupsNames().size();

            RealMatrix aprioriApproximationMatrix = new Array2DRowRealMatrix(aprioriApproximation.getDimension(), 1);
            aprioriApproximationMatrix.setColumn(0, aprioriApproximation.toArray());

            RealVector approximation = maskProbabilitiesForSources.multiply(aprioriApproximationMatrix).getColumnVector(0);
            approximation = normalizeVector(approximation);
            RealVector differences = observedFrequencies.subtract(approximation);

            RealMatrix jacobian = new Array2DRowRealMatrix(maskCount, groupCount);
            for (int i = 0; i < groupCount; i++) {
                RealVector partialDifferences = observedFrequencies.subtract(maskProbabilitiesForSources.getColumnVector(i).mapMultiply(aprioriApproximation.getEntry(i)));
                jacobian.setColumn(i, partialDifferences.toArray());//.ebeDivide(differences).toArray());
                //if (i == 0) System.out.println(partialDifferences);
            }

            return new Pair<>(differences, jacobian);
        }
 
開發者ID:crocs-muni,項目名稱:classifyRSAkey,代碼行數:22,代碼來源:LeastSquaresFitPriorProbabilityEstimator.java


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