当前位置: 首页>>代码示例>>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;未经允许,请勿转载。