Merge branch 'develop' into features/JAL-4219_extended_fasta_rna_ss
[jalview.git] / src / jalview / math / MatrixI.java
index e98007e..7faac73 100644 (file)
@@ -61,6 +61,13 @@ public interface MatrixI
   void setValue(int i, int j, double d);
 
   /**
+  * Returns the matrix as a double[][] array
+  *
+  * @return
+  */
+  double[][] asArray();
+
+  /**
    * Answers a copy of the values in the i'th row
    * 
    * @return
@@ -68,6 +75,13 @@ public interface MatrixI
   double[] getRow(int i);
 
   /**
+   * Answers a copy of the values in the i'th column
+   * 
+   * @return
+   */
+  double[] getColumn(int i);
+
+  /**
    * Answers a new matrix with a copy of the values in this one
    * 
    * @return
@@ -161,6 +175,13 @@ public interface MatrixI
   void multiply(double d);
 
   /**
+  * Add d to all entries of this matrix
+  *
+  * @param d ~ value to add
+  */
+  void add(double d);
+
+  /**
    * Answers true if the two matrices have the same dimensions, and
    * corresponding values all differ by no more than delta (which should be a
    * positive value), else false
@@ -170,4 +191,127 @@ public interface MatrixI
    * @return
    */
   boolean equals(MatrixI m2, double delta);
+
+  /**
+   * Returns a copy in which  every value in the matrix is its absolute
+   */
+  MatrixI absolute();
+
+  /**
+   * Returns the mean of each row
+   */
+  double[] meanRow();
+
+  /**
+   * Returns the mean of each column
+   */
+  double[] meanCol();
+
+  /**
+  * Returns a flattened matrix containing the sum of each column
+  *
+  * @return
+  */
+  double[] sumCol();
+
+  /**
+  * returns the mean value of the complete matrix
+  */
+  double mean();
+
+  /**
+  * fills up a diagonal matrix with its transposed copy
+  * !other side should be filled with either 0 or Double.NaN
+  */
+  void fillDiagonal();
+
+  /**
+  * counts the number of Double.NaN in the matrix
+  *
+  * @return
+  */
+  int countNaN();
+
+  /**
+  * performs an element-wise addition of this matrix by another matrix
+  * !matrices have to be the same size
+  * @param m ~ other matrix
+  * 
+  * @return
+  * @throws IllegalArgumentException
+  *           if this and m do not have the same dimensions
+  */
+  MatrixI add(MatrixI m);
+
+  /**
+  * performs an element-wise subtraction of this matrix by another matrix
+  * !matrices have to be the same size
+  * @param m ~ other matrix
+  * 
+  * @return
+  * @throws IllegalArgumentException
+  *           if this and m do not have the same dimensions
+  */
+  MatrixI subtract(MatrixI m);
+  /**
+  * performs an element-wise multiplication of this matrix by another matrix ~ this * m
+  * !matrices have to be the same size
+  * @param m ~ other matrix
+  *
+  * @return
+  * @throws IllegalArgumentException
+  *    if this and m do not have the same dimensions
+  */
+  MatrixI elementwiseMultiply(MatrixI m);
+
+  /**
+  * performs an element-wise division of this matrix by another matrix ~ this / m
+  * !matrices have to be the same size
+  * @param m ~ other matrix
+  *
+  * @return
+  * @throws IllegalArgumentException
+  *    if this and m do not have the same dimensions
+  */
+  MatrixI elementwiseDivide(MatrixI m);
+
+  /**
+  * calculates the root-mean-square for two matrices
+  * @param m ~ other matrix
+  *  
+  * @return
+  */
+  double rmsd(MatrixI m);
+
+  /**
+  * calculates the Frobenius norm of this matrix
+  *
+  * @return
+  */
+  double norm();
+  
+  /**
+  * returns the sum of all values in this matrix
+  *
+  * @return
+  */
+  double sum();
+
+  /**
+  * returns the sum-product of this matrix with vector v
+  * @param v ~ vector
+  *
+  * @return
+  * @throws IllegalArgumentException
+  *    if this.cols and v do not have the same length
+  */
+  double[] sumProduct(double[] v);
+
+  /**
+  * mirrors the columns of this matrix
+  *
+  * @return
+  */
+  MatrixI mirrorCol();
 }