Merge remote-tracking branch 'origin/develop' into kjvdh/features/PhylogenyViewer
[jalview.git] / src / jalview / math / MatrixI.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.math;
22
23 import java.io.PrintStream;
24
25 public interface MatrixI
26 {
27   /**
28    * Answers the number of columns
29    * 
30    * @return
31    */
32   int width();
33
34   /**
35    * Answers the number of rows
36    * 
37    * @return
38    */
39   int height();
40
41   /**
42    * Answers the value at row i, column j
43    * 
44    * @param i
45    * @param j
46    * @return
47    */
48   double getValue(int i, int j);
49
50   /**
51    * Sets the value at row i, column j
52    * 
53    * @param i
54    * @param j
55    * @param d
56    */
57   void setValue(int i, int j, double d);
58
59   /**
60    * Answers a copy of the values in the i'th row
61    * 
62    * @return
63    */
64   double[] getRow(int i);
65
66   /**
67    * Answers all values present in the Matrix ordered by row,column
68    * 
69    * @return the double array containing the values ordered in {row values} per
70    *         column
71    */
72   double[][] getValues();
73
74
75   MatrixI copy();
76
77   MatrixI transpose();
78
79   MatrixI preMultiply(MatrixI m);
80
81   MatrixI postMultiply(MatrixI m);
82
83   double[] getD();
84
85   double[] getE();
86
87   void print(PrintStream ps, String format);
88
89   void printD(PrintStream ps, String format);
90
91   void printE(PrintStream ps, String format);
92
93   void tqli() throws Exception;
94
95   void tred();
96
97   /**
98    * Reverses the range of the matrix values, so that the smallest values become
99    * the largest, and the largest become the smallest. This operation supports
100    * using a distance measure as a similarity measure, or vice versa.
101    * <p>
102    * If parameter <code>maxToZero</code> is true, then the maximum value becomes
103    * zero, i.e. all values are subtracted from the maximum. This is consistent
104    * with converting an identity similarity score to a distance score - the most
105    * similar (identity) corresponds to zero distance. However note that the
106    * operation is not reversible (unless the original minimum value is zero).
107    * For example a range of 10-40 would become 30-0, which would reverse a
108    * second time to 0-30. Also note that a general similarity measure (such as
109    * BLOSUM) may give different 'identity' scores for different sequences, so
110    * they cannot all convert to zero distance.
111    * <p>
112    * If parameter <code>maxToZero</code> is false, then the values are reflected
113    * about the average of {min, max} (effectively swapping min and max). This
114    * operation <em>is</em> reversible.
115    * 
116    * @param maxToZero
117    */
118   void reverseRange(boolean maxToZero);
119
120   /**
121    * Multiply all entries by the given value
122    * 
123    * @param d
124    */
125   void multiply(double d);
126 }