/** * Creates and returns a clone of this object. * * @return a clone of this instance. * @throws Exception if an error occurs */ @Override public Object clone() { try { return new Matrix(m_Matrix.getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Creates and returns a clone of this object. * * @return a clone of this instance. * @throws Exception if an error occurs */ @Override public Object clone() { try { return new Matrix(m_Matrix.getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Returns the transpose of a matrix. * * @return the transposition of this instance. */ public final Matrix transpose() { try { return new Matrix(m_Matrix.transpose().getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Returns the transpose of a matrix. * * @return the transposition of this instance. */ public final Matrix transpose() { try { return new Matrix(m_Matrix.transpose().getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * creates a matrix from the given Matlab string. * * @param matlab the matrix in matlab format * @return the matrix represented by the given string * @see #toMatlab() */ public static Matrix parseMatlab(String matlab) throws Exception { return new Matrix(weka.core.matrix.Matrix.parseMatlab(matlab).getArray()); }
/** * creates a matrix from the given Matlab string. * * @param matlab the matrix in matlab format * @return the matrix represented by the given string * @see #toMatlab() */ public static Matrix parseMatlab(String matlab) throws Exception { return new Matrix(weka.core.matrix.Matrix.parseMatlab(matlab).getArray()); }
/** * Returns the sum of this matrix with another. * * @return a matrix containing the sum. */ public final Matrix add(Matrix other) { try { return new Matrix(m_Matrix.plus(other.getMatrix()).getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Returns the sum of this matrix with another. * * @return a matrix containing the sum. */ public final Matrix add(Matrix other) { try { return new Matrix(m_Matrix.plus(other.getMatrix()).getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * builds the Matrix (old) from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails * @see weka.core.Matrix */ @SuppressWarnings("deprecation") public Object readMatrixOld(Element node) throws Exception { weka.core.Matrix matrix; weka.core.matrix.Matrix matrixNew; // for debugging only if (DEBUG) { trace(new Throwable(), node.getAttribute(ATT_NAME)); } m_CurrentNode = node; matrixNew = (weka.core.matrix.Matrix) readMatrix(node); matrix = new weka.core.Matrix(matrixNew.getArrayCopy()); return matrix; }
/** * builds the Matrix (old) from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails * @see weka.core.Matrix */ @SuppressWarnings("deprecation") public Object readMatrixOld(Element node) throws Exception { weka.core.Matrix matrix; weka.core.matrix.Matrix matrixNew; // for debugging only if (DEBUG) { trace(new Throwable(), node.getAttribute(ATT_NAME)); } m_CurrentNode = node; matrixNew = (weka.core.matrix.Matrix) readMatrix(node); matrix = new weka.core.Matrix(matrixNew.getArrayCopy()); return matrix; }
/** * Returns the multiplication of two matrices * * @param b the multiplication matrix * @return the product matrix */ public final Matrix multiply(Matrix b) { try { return new Matrix(getMatrix().times(b.getMatrix()).getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Returns the multiplication of two matrices * * @param b the multiplication matrix * @return the product matrix */ public final Matrix multiply(Matrix b) { try { return new Matrix(getMatrix().times(b.getMatrix()).getArrayCopy()); } catch (Exception e) { e.printStackTrace(); return null; } }
Matrix M = new Matrix(m); int n = M.numRows(); double[][] V = new double[n][n]; M.eigenvalueDecomposition(V, d); Matrix a = new Matrix(2, 3); Matrix b = new Matrix(3, 2); System.out.println("Number of columns for a: " + a.numColumns()); System.out.println("Number of rows for a: " + a.numRows()); System.out.println("a transposed:\n " + a.transpose()); System.out.println("a * b:\n " + a.multiply(b)); Matrix r = new Matrix(3, 1); r.setColumn(0, response); System.out.println("r:\n " + r); a.write(new java.io.FileWriter("main.matrix")); System.out.println("wrote matrix to \"main.matrix\"\n" + a); a = new Matrix(new java.io.FileReader("main.matrix")); System.out.println("read matrix from \"main.matrix\"\n" + a); } catch (Exception e) {
Matrix M = new Matrix(m); int n = M.numRows(); double[][] V = new double[n][n]; M.eigenvalueDecomposition(V, d); Matrix a = new Matrix(2, 3); Matrix b = new Matrix(3, 2); System.out.println("Number of columns for a: " + a.numColumns()); System.out.println("Number of rows for a: " + a.numRows()); System.out.println("a transposed:\n " + a.transpose()); System.out.println("a * b:\n " + a.multiply(b)); Matrix r = new Matrix(3, 1); r.setColumn(0, response); System.out.println("r:\n " + r); a.write(new java.io.FileWriter("main.matrix")); System.out.println("wrote matrix to \"main.matrix\"\n" + a); a = new Matrix(new java.io.FileReader("main.matrix")); System.out.println("read matrix from \"main.matrix\"\n" + a); } catch (Exception e) {
/** * Returns the U part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the U part of a matrix; * @see #LUDecomposition() */ public Matrix getU() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ud = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = i; j < nc; j++) { ud[i][j] = getElement(i, j); } } Matrix u = new Matrix(ud); return u; }
/** * Returns the U part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the U part of a matrix; * @see #LUDecomposition() */ public Matrix getU() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ud = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = i; j < nc; j++) { ud[i][j] = getElement(i, j); } } Matrix u = new Matrix(ud); return u; }
/** * Returns the L part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the L part of the matrix; * @see #LUDecomposition() */ public Matrix getL() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ld = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = 0; (j < i) && (j < nc); j++) { ld[i][j] = getElement(i, j); } if (i < nc) { ld[i][i] = 1; } } Matrix l = new Matrix(ld); return l; }
/** * Returns the L part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the L part of the matrix; * @see #LUDecomposition() */ public Matrix getL() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ld = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = 0; (j < i) && (j < nc); j++) { ld[i][j] = getElement(i, j); } if (i < nc) { ld[i][i] = 1; } } Matrix l = new Matrix(ld); return l; }