List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix Array2DRowRealMatrix
public Array2DRowRealMatrix(final double[] v)
From source file:net.liuxuan.temp.filterTest.java
public static void main(String[] args) { double constantVoltage = 10d; double measurementNoise = 0.1d; double processNoise = 1e-5d; // A = [ 1 ]//from www. j a v a 2 s .co m RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d }); // B = null RealMatrix B = null; // H = [ 1 ] RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d }); // x = [ 10 ] RealVector x = new ArrayRealVector(new double[] { constantVoltage }); // Q = [ 1e-5 ] RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise }); // P = [ 1 ] RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1d }); // R = [ 0.1 ] RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise }); ProcessModel pm = new DefaultProcessModel(A, B, Q, x, P0); MeasurementModel mm = new DefaultMeasurementModel(H, R); KalmanFilter filter = new KalmanFilter(pm, mm); // process and measurement noise vectors RealVector pNoise = new ArrayRealVector(1); RealVector mNoise = new ArrayRealVector(1); RandomGenerator rand = new JDKRandomGenerator(); // iterate 60 steps for (int i = 0; i < 60; i++) { filter.predict(); // simulate the process // pNoise.setEntry(0, processNoise * rand.nextGaussian()); pNoise.setEntry(0, Math.sin(Math.PI * 2 * i / 6)); // System.out.println("============"); // System.out.println(Math.sin(Math.PI*2*i/6)); // x = A * x + p_noise x = A.operate(x).add(pNoise); // simulate the measurement // mNoise.setEntry(0, measurementNoise * rand.nextGaussian()); mNoise.setEntry(0, 0); // z = H * x + m_noise RealVector z = H.operate(x).add(mNoise); filter.correct(z); double voltage = filter.getStateEstimation()[0]; System.out.println(voltage); // state estimate shouldn't be larger than the measurement noise double diff = Math.abs(x.getEntry(0) - filter.getStateEstimation()[0]); System.out.println("diff = " + diff); } }
From source file:edu.oregonstate.eecs.mcplan.ml.SequentialProjectionHashLearner.java
public static void main(final String[] argv) { final double[][] a = new double[][] { { 1.0, 0.0 }, { 0.0, 1.0 } }; final RealMatrix M = new Array2DRowRealMatrix(a); System.out.println(a == M.getData()); }
From source file:com.github.thorbenlindhauer.test.util.LinearAlgebraUtil.java
public static RealMatrix asMatrix(double... values) { return new Array2DRowRealMatrix(new double[][] { values }); }
From source file:dataminning2.SVDDecomposition.java
public double[][] DecompositionU(double[][] Dataarraytest) { Array2DRowRealMatrix rmA = new Array2DRowRealMatrix(Dataarraytest); SingularValueDecomposition svdObj = new SingularValueDecomposition(rmA); double[][] DataU = svdObj.getU().getData(); return DataU; }
From source file:com.cloudera.oryx.common.math.LinearSystemSolverTest.java
@Test public void testSolveFToD() { RealMatrix a = new Array2DRowRealMatrix( new double[][] { { 1.3, -2.0, 3.0 }, { 2.0, 0.0, 5.0 }, { 0.0, -1.5, 5.5 }, }); Solver solver = new LinearSystemSolver().getSolver(a); assertNotNull(solver);// www .j av a 2 s.c om double[] y = solver.solveFToD(new float[] { 1.0f, 2.0f, 6.5f }); assertArrayEquals(new double[] { -1.9560439560439564, 0.002197802197802894, 1.1824175824175824 }, y); }
From source file:dataminning2.SVDDecomposition.java
public double[][] DecompositionV(double[][] Dataarraytest) { Array2DRowRealMatrix rmA = new Array2DRowRealMatrix(Dataarraytest); SingularValueDecomposition svdObj = new SingularValueDecomposition(rmA); double[][] DataV = svdObj.getV().getData(); return DataV; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.Ecef2EnuConverter.java
/** * Converts a vector represented by coordinates ecefX, ecefY, ecefZ in an * Earth-Centered Earth-Fixed (ECEF) Cartesian system into a vector in a * local east-north-up (ENU) Cartesian system. * * <p> For example it can be used to rotate a speed vector or position offset vector to ENU. * * @param ecefX X coordinates in ECEF/*from w w w. ja v a2 s . co m*/ * @param ecefY Y coordinates in ECEF * @param ecefZ Z coordinates in ECEF * @param refLat Latitude in Radians of the Reference Position * @param refLng Longitude in Radians of the Reference Position * @return the converted values in {@code EnuValues} */ public static EnuValues convertEcefToEnu(double ecefX, double ecefY, double ecefZ, double refLat, double refLng) { RealMatrix rotationMatrix = getRotationMatrix(refLat, refLng); RealMatrix ecefCoordinates = new Array2DRowRealMatrix(new double[] { ecefX, ecefY, ecefZ }); RealMatrix enuResult = rotationMatrix.multiply(ecefCoordinates); return new EnuValues(enuResult.getEntry(0, 0), enuResult.getEntry(1, 0), enuResult.getEntry(2, 0)); }
From source file:com.joptimizer.algebra.CholeskyDecompositionTest.java
/** * good decomposition./*from w w w . j a v a 2 s . co m*/ */ public void testDecomposition1() throws Exception { log.debug("testDecomposition1"); RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.08073550734687, 1.59028724315583 }, { 1.59028724315583, 0.3250861184011492 } }); CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1); log.debug("L: " + cFact1.getL()); log.debug("LT: " + cFact1.getLT()); // check L.LT-Q=0 RealMatrix P1Inv = cFact1.getL().multiply(cFact1.getLT()); double norm1 = P1Inv.subtract(P1).getNorm(); log.debug("norm1: " + norm1); assertTrue(norm1 < 1.E-12); }
From source file:dataminning2.SVDDecomposition.java
public double[][] DecompositionS(double[][] Dataarraytest) { Array2DRowRealMatrix rmA = new Array2DRowRealMatrix(Dataarraytest); SingularValueDecomposition svdObj = new SingularValueDecomposition(rmA); double[][] Sobj = svdObj.getS().getData(); return Sobj;/* w w w . j a va 2s.c o m*/ }
From source file:edu.cmu.sphinx.speakerid.SpeakerCluster.java
public SpeakerCluster(Segment s, Array2DRowRealMatrix featureMatrix, double bicValue) { this.segmentSet = new TreeSet<Segment>(); this.featureMatrix = new Array2DRowRealMatrix(featureMatrix.getData()); this.bicValue = bicValue; addSegment(s);//from w w w. ja v a 2 s .c o m }