JAL-2738 copy to spikes/mungo
[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, colum 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   MatrixI copy();
67
68   MatrixI transpose();
69
70   MatrixI preMultiply(MatrixI m);
71
72   MatrixI postMultiply(MatrixI m);
73
74   double[] getD();
75
76   double[] getE();
77
78   void print(PrintStream ps, String format);
79
80   void printD(PrintStream ps, String format);
81
82   void printE(PrintStream ps, String format);
83
84   void tqli() throws Exception;
85
86   void tred();
87
88   /**
89    * Reverses the range of the matrix values, so that the smallest values become
90    * the largest, and the largest become the smallest. This operation supports
91    * using a distance measure as a similarity measure, or vice versa.
92    * <p>
93    * If parameter <code>maxToZero</code> is true, then the maximum value becomes
94    * zero, i.e. all values are subtracted from the maximum. This is consistent
95    * with converting an identity similarity score to a distance score - the most
96    * similar (identity) corresponds to zero distance. However note that the
97    * operation is not reversible (unless the original minimum value is zero).
98    * For example a range of 10-40 would become 30-0, which would reverse a
99    * second time to 0-30. Also note that a general similarity measure (such as
100    * BLOSUM) may give different 'identity' scores for different sequences, so
101    * they cannot all convert to zero distance.
102    * <p>
103    * If parameter <code>maxToZero</code> is false, then the values are reflected
104    * about the average of {min, max} (effectively swapping min and max). This
105    * operation <em>is</em> reversible.
106    * 
107    * @param maxToZero
108    */
109   void reverseRange(boolean maxToZero);
110
111   /**
112    * Multiply all entries by the given value
113    * 
114    * @param d
115    */
116   void multiply(double d);
117 }