List of usage examples for org.apache.commons.math.linear Array2DRowRealMatrix Array2DRowRealMatrix
public Array2DRowRealMatrix(final double[] v)
v as the data for the unique column of the v.length x 1 matrix created. From source file:com.cloudera.science.ml.core.matrix.MatrixUtils.java
public static RealMatrix toRealMatrix(int rows, int columns, Iterable<MLMatrixEntry> entries, boolean symmetric) { double[][] data = new double[rows][columns]; for (MLMatrixEntry e : entries) { data[e.getRow()][e.getColumn()] = e.getValue(); if (symmetric) { data[e.getColumn()][e.getRow()] = e.getValue(); }/* ww w. j av a2s .c om*/ } return new Array2DRowRealMatrix(data); }
From source file:com.zinnia.nectar.util.math.MatrixSolver.java
public static double[] solveMatrix(double[][] coefficientMatrix, double[] rhsVector) { RealVector x = null;//from w w w . j a va 2 s . c om try { RealMatrix a = new Array2DRowRealMatrix(coefficientMatrix); RealVector b = new ArrayRealVector(rhsVector); DecompositionSolver solver = new LUDecompositionImpl(a).getSolver(); x = solver.solve(b); } catch (Exception e) { e.printStackTrace(); } double[] result; result = x.toArray(); return result; }
From source file:fi.smaa.libror.RORSMAATest.java
@BeforeClass public static void setUpForAll() throws InfeasibleConstraintsException, SamplingException { double[][] data = new double[][] { { 82, 94, 80, 91 }, { 74, 91, 96, 82 }, { 59, 73, 72, 67 }, { 47, 77, 90, 46 }, { 50, 73, 88, 47 }, { 51, 50, 84, 55 }, { 42, 59, 88, 39 }, { 44, 57, 84, 41 }, { 42, 53, 88, 38 }, { 42, 61, 68, 39 }, { 45, 37, 80, 44 }, { 41, 43, 80, 40 }, { 41, 41, 60, 40 }, { 38, 37, 72, 34 }, { 40, 40, 60, 34 }, { 39, 34, 48, 38 }, { 38, 36, 44, 34 }, { 39, 28, 40, 34 }, { 39, 26, 36, 37 }, { 37, 21, 8, 37 } }; perfMat = new Array2DRowRealMatrix(data); RORModel model = new RORModel(new PerformanceMatrix(perfMat)); ror = new RORSMAA(model, new RejectionValueFunctionSampler(model, 10000)); ror.getModel().addPreference(9, 8); // DEN > AUT ror.getModel().addPreference(2, 3); // SPA > SWE ror.getModel().addPreference(10, 11); // FRA > CZE ror.compute();// ww w . j a v a 2s . c om }
From source file:de.mpicbg.knime.hcs.base.utils.Table2Matrix.java
public static RealMatrix extractMatrix(List<DataRow> rows, List<Attribute> params) { double[][] matrix = new double[rows.size()][params.size()]; int nbparams = params.size(); int m = 0;/* ww w. j a v a 2 s . co m*/ for (DataRow row : rows) { int n = 0; for (Attribute readout : params) { Double val = readout.getDoubleAttribute(row); if ((val == null) || Double.isInfinite(val) || Double.isNaN(val)) { break; } matrix[m][n] = val; n += 1; } if (n == nbparams) { m += 1; } } // remove the unused rows. RealMatrix rmatrix = new Array2DRowRealMatrix(matrix); if (m > 0) { rmatrix = rmatrix.getSubMatrix(0, m - 1, 0, nbparams - 1); } return rmatrix; }
From source file:fi.smaa.libror.MaximalVectorComputationTest.java
@Before public void setUp() { data = new Array2DRowRealMatrix(new double[][] { { 1.0, 2.0, 3.0 }, { 1.0, 2.0, 2.0 }, { 2.0, 1.0, 3.0 } }); }
From source file:fi.smaa.libror.eff.FastRORTest.java
@Before public void setUp() { perf = new Array2DRowRealMatrix(new double[][] { { 1.0, 2.0, 3.0 }, { 2.0, 2.0, 2.0 }, { 3.0, 1.0, 2.0 }, { 1.0, 3.0, 2.0 }, { 1.0, 1.0, 1.0 } }); RORModel model = new RORModel(new PerformanceMatrix(perf)); model.addPreference(0, 1);//w w w .j a v a 2s .c om ror = new FastROR(model); }
From source file:fi.smaa.libror.MaximalVectorComputationTest.java
@Test public void testCompute() { RealMatrix exp = new Array2DRowRealMatrix(new double[][] { { 1.0, 2.0, 3.0 }, { 2.0, 1.0, 3.0 } }); assertEquals(exp, MaximalVectorComputation.computeBEST(data)); }
From source file:fi.smaa.libror.MaximalVectorComputationTest.java
@Test public void testBug() { RealMatrix data = new Array2DRowRealMatrix( new double[][] { { 0.1823507, 0.5232321, 0.7595968, 0.2964752, 0.1676054 }, { 0.5408093, 0.1604821, 0.4699517, 0.4170541, 0.5357071 }, { 0.1292226, 0.2366909, 0.7583132, 0.3765545, 0.4587448 } }); assertArrayEquals(new int[] { 0, 1, 2 }, MaximalVectorComputation.computeBESTindices(data)); }
From source file:fi.smaa.libror.GibbsValueFunctionSamplerTest.java
@Before public void setUp() throws InvalidStartingPointException { double[][] data = new double[][] { { 1, 2, 3 }, { 2, 1, 2 } }; perfMat = new Array2DRowRealMatrix(data); ror = new RORModel(new PerformanceMatrix(perfMat)); spoint = new FullValueFunction(); vf1 = new PartialValueFunction(2); vf2 = new PartialValueFunction(2); vf3 = new PartialValueFunction(2); spoint.addValueFunction(vf1);/*ww w. j av a 2 s.c o m*/ spoint.addValueFunction(vf2); spoint.addValueFunction(vf3); ror.addPreference(0, 1); spoint.setWeight(0, 0.0); spoint.setWeight(1, 1.0); spoint.setWeight(2, 0.0); a1inds = new int[] { 0, 1, 1 }; a2inds = new int[] { 1, 0, 0 }; s = new GibbsValueFunctionSampler(ror, 10, 2, spoint); }
From source file:fi.smaa.libror.PerformanceMatrixTest.java
@Before public void setUp() { double[][] data = new double[][] { { 82, 94, 80, 91 }, { 74, 91, 96, 82 }, { 59, 73, 72, 67 }, { 47, 77, 90, 46 }, { 50, 73, 88, 47 }, { 51, 50, 84, 55 }, { 42, 59, 88, 39 }, { 44, 57, 84, 41 }, { 42, 53, 88, 38 }, { 42, 61, 68, 39 }, { 45, 37, 80, 44 }, { 41, 43, 80, 40 }, { 41, 41, 60, 40 }, { 38, 37, 72, 34 }, { 40, 40, 60, 34 }, { 39, 34, 48, 38 }, { 38, 36, 44, 34 }, { 39, 28, 40, 34 }, { 39, 26, 36, 37 }, { 37, 21, 8, 37 } }; matrix = new PerformanceMatrix(new Array2DRowRealMatrix(data)); }