public void addAttribute(String name) { attributes.add(name); DenseDoubleMatrix2D m2 = new DenseDoubleMatrix2D(attributes.size(), attributes.size()); for (int i = 0; i < matrix.rows(); i++) for (int j = 0; j < matrix.columns(); j++) m2.set(i, j, matrix.get(i, j)); m2.set(attributes.size() - 1, attributes.size() - 1, 1.0d); matrix = m2; fireTableStructureChanged(); }
public CovarianceTable(List<String> attr) { attributes = new ArrayList<String>(attr); matrix = new DenseDoubleMatrix2D(attributes.size(), attributes.size()); for (int i = 0; i < matrix.rows(); i++) for (int j = 0; j < matrix.columns(); j++) { if (i == j) matrix.set(i, j, 1.0d); else matrix.set(i, j, matrix.get(i, j)); } fireTableStructureChanged(); }
public static DenseDoubleMatrix2D createUniMatrix( DenseDoubleMatrix2D rot, DenseDoubleMatrix1D trl) { DenseDoubleMatrix2D res = new DenseDoubleMatrix2D(4, 4); for (int i = 0; i != 3; i++) { for (int j = 0; j != 3; j++) { res.set(i, j, rot.get(i, j)); } } for (int i = 0; i != 3; i++) { res.set(i, 3, trl.get(i)); } for (int i = 0; i != 3; i++) { res.set(3, i, 0); } res.set(3, 3, 1); return res; }
/** @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) */ @Override public void setValueAt(Object arg0, int arg1, int arg2) { matrix.set(arg1, arg2, new Double(arg0.toString())); matrix.set(arg2, arg1, new Double(arg0.toString())); this.fireTableRowsUpdated(arg1, arg1); this.fireTableCellUpdated(arg2, arg2); CholeskyDecomposition cholesky = new CholeskyDecomposition(matrix); System.out.println("cholesky.is symm+pos def? " + cholesky.isSymmetricPositiveDefinite()); System.out.println("L:\n" + cholesky.getL()); }
public static DenseDoubleMatrix2D movePoints( DenseDoubleMatrix2D unifourxfour, DenseDoubleMatrix2D points) { Algebra alg = new Algebra(); DenseDoubleMatrix2D result = new DenseDoubleMatrix2D(points.rows(), 4); double tmp = 0.0d; DenseDoubleMatrix2D pointsfourxn = new DenseDoubleMatrix2D(points.rows(), 4); for (int i = 0; i != points.rows(); i++) { for (int j = 0; j != 3; j++) { pointsfourxn.set(i, j, points.get(i, j)); } pointsfourxn.set(i, 3, 1); for (int j = 0; j != 4; j++) { tmp = 0.0d; for (int k = 0; k != 4; k++) { tmp += pointsfourxn.get(i, j) * unifourxfour.get(k, j); } result.set(i, j, tmp); } } return result; // return (DenseDoubleMatrix2D)alg.mult(pointsfourxn, unifourxfour); }
/** Creates a new instance of testmatrix */ public GLSsolver(double[][] p_MatrixgleichNull) throws IllegalArgumentException { // -------------------------------------- // Kontrolle, ob Eingabematrix rechteckig // -------------------------------------- int nplus1 = p_MatrixgleichNull[0].length; for (int i = 1; i < p_MatrixgleichNull.length; i++) { // Zeilen i if (p_MatrixgleichNull[i].length != nplus1) { System.err.println( "Programmfehler: Matrix des GLS ist nicht rechteckig! (im solver entdeckt)"); throw new IllegalArgumentException(); } } if (nplus1 <= 1) throw new IllegalArgumentException("keine Unbekannte"); // keine Unbekannte!!! // Umgeht einen Fehler in der colt-Bibliothek // TODO wenn behoben, Workaround entfernen // ------ int anzGl = p_MatrixgleichNull.length; if (anzGl < nplus1 - 1) { // anzGleichungen < anz Unbekannte if (debug) System.out.println("WorkAround fuer Fehler in colt: 0 = 0 Gleichungen anhaengen"); anzGl = nplus1 - 1; // = Anzahl Unbek, 0 0 0 ... 0 = 0 Zeile angehängt } // ------------------------- // Daten in A und b einlesen // ------------------------- // so dass A*x = b A = new DenseDoubleMatrix2D(anzGl, (nplus1 - 1)); DenseDoubleMatrix2D b = new DenseDoubleMatrix2D(anzGl, 1); for (int i = 0; i < p_MatrixgleichNull.length; i++) { // Zeilen i for (int j = 0; j < nplus1 - 1; j++) { // Spalten A.set(i, j, p_MatrixgleichNull[i][j]); } b.set(i, 0, -p_MatrixgleichNull[i][nplus1 - 1]); } if (debug) { System.out.println(" A = " + A.toString()); System.out.println(" b = " + b.toString()); System.out.println(""); } // -------------- // LR - Zerlegung // -------------- LUDecomposition ALU = new LUDecomposition(A); if (debug) System.out.println(ALU.toString()); DoubleMatrix2D L = ALU.getL(); R = ALU.getU(); int[] piv = ALU.getPivot(); Algebra alg = new Algebra(); // if (debug) System.out.println("L = " + L.toString()); // if (debug) System.out.println("Kontrolle L*R = " + alg.mult(L,R).toString()); // if (debug) System.out.println("Kontrolle P*b = " + alg.permute(b, piv, null) ); // // if (debug) System.out.println("Rx = c: R = " + R.toString()); // if (debug) System.out.println("alg.permute(b, piv, null) = " + alg.permute(b, piv, // null).toString()); c = alg.solve(L, alg.permute(b, piv, null)); // TODO: kann zu Problemen führen, // wenn weniger Gleichungen als Unbek --> s.Workaround oben if (debug) System.out.println("Lc = Pb: c = " + c.toString()); if (debug) { System.out.println("Rang A: " + alg.rank(A)); System.out.println("Rang R: " + alg.rank(R)); } assert (alg.rank(A) == alg.rank(R)) : "Rang von A ungleich Rang von R --> Programmfehler"; anzUnbestParam = A.columns() - alg.rank(A); if (debug) System.out.println("Anz unbest Parameter: " + anzUnbestParam); }