|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DenseDoubleMatrix2DNamed.java | 7.1% | 27.9% | 56.5% | 28.6% |
|
||||||||||||||
| 1 |
package baseCode.dataStructure.matrix;
|
|
| 2 |
|
|
| 3 |
import cern.colt.list.DoubleArrayList;
|
|
| 4 |
import cern.colt.matrix.DoubleMatrix1D;
|
|
| 5 |
import cern.colt.matrix.impl.DenseDoubleMatrix2D;
|
|
| 6 |
import corejava.Format;
|
|
| 7 |
|
|
| 8 |
/**
|
|
| 9 |
* A matrix of doubles that knows about row and column names.
|
|
| 10 |
* </p>
|
|
| 11 |
* <p>
|
|
| 12 |
* Copyright (c) 2004
|
|
| 13 |
* </p>
|
|
| 14 |
* <p>
|
|
| 15 |
* Columbia University
|
|
| 16 |
* </p>
|
|
| 17 |
*
|
|
| 18 |
* @author Paul Pavlidis
|
|
| 19 |
* @version $Id: DenseDoubleMatrix2DNamed.java,v 1.7 2005/01/05 02:01:02 pavlidis Exp $
|
|
| 20 |
*/
|
|
| 21 |
public class DenseDoubleMatrix2DNamed extends AbstractNamedDoubleMatrix { |
|
| 22 |
|
|
| 23 |
private DenseDoubleMatrix2D matrix;
|
|
| 24 |
|
|
| 25 |
/**
|
|
| 26 |
* @param T double[][]
|
|
| 27 |
*/
|
|
| 28 | 0 |
public DenseDoubleMatrix2DNamed( double T[][] ) { |
| 29 | 0 |
super();
|
| 30 | 0 |
matrix = new DenseDoubleMatrix2D( T );
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
/**
|
|
| 34 |
* @param rows int
|
|
| 35 |
* @param cols int
|
|
| 36 |
*/
|
|
| 37 | 151 |
public DenseDoubleMatrix2DNamed( int rows, int cols ) { |
| 38 | 151 |
super();
|
| 39 | 151 |
matrix = new DenseDoubleMatrix2D( rows, cols );
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
/**
|
|
| 43 |
* Return a reference to a specific row.
|
|
| 44 |
*
|
|
| 45 |
* @param row int
|
|
| 46 |
* @return double[]
|
|
| 47 |
*/
|
|
| 48 | 615 |
public double[] getRow( int row ) { |
| 49 | 615 |
return viewRow( row ).toArray();
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
|
|
| 53 |
/**
|
|
| 54 |
* Return a reference to a specific row.
|
|
| 55 |
* @param s String
|
|
| 56 |
* @return double[]
|
|
| 57 |
*/
|
|
| 58 | 0 |
public double[] getRowByName( String s ) { |
| 59 | 0 |
return getRow( getRowIndexByName( s ) );
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
/**
|
|
| 63 |
* Return a copy of a given column.
|
|
| 64 |
*
|
|
| 65 |
* @param col int
|
|
| 66 |
* @return double[]
|
|
| 67 |
*/
|
|
| 68 | 0 |
public double[] getCol( int col ) { |
| 69 | 0 |
double[] result = new double[rows()]; |
| 70 | 0 |
for ( int i = 0; i < rows(); i++ ) { |
| 71 | 0 |
result[i] = get( i, col ); |
| 72 |
} |
|
| 73 | 0 |
return result;
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
|
|
| 77 |
/**
|
|
| 78 |
* Return a copy of a given column.
|
|
| 79 |
*
|
|
| 80 |
* @param col int
|
|
| 81 |
* @return double[]
|
|
| 82 |
*/
|
|
| 83 | 0 |
public double[] getColByName( String s ) { |
| 84 | 0 |
int col = getColIndexByName(s);
|
| 85 | 0 |
double[] result = new double[rows()]; |
| 86 | 0 |
for ( int i = 0; i < rows(); i++ ) { |
| 87 | 0 |
result[i] = get( i, col ); |
| 88 |
} |
|
| 89 | 0 |
return result;
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 | 1302 |
public Object[] getRowObj( int row ) { |
| 95 | 1302 |
Double[] result = new Double[columns()];
|
| 96 | 1302 |
for ( int i = 0; i < columns(); i++ ) { |
| 97 | 15624 |
result[i] = new Double( get( row, i ) );
|
| 98 |
} |
|
| 99 | 1302 |
return result;
|
| 100 |
} |
|
| 101 |
|
|
| 102 | 0 |
public Object[] getColObj( int col ) { |
| 103 | 0 |
Double[] result = new Double[rows()];
|
| 104 | 0 |
for ( int i = 0; i < rows(); i++ ) { |
| 105 | 0 |
result[i] = new Double( get( i, col ) );
|
| 106 |
} |
|
| 107 | 0 |
return result;
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/**
|
|
| 111 |
* @return java.lang.String
|
|
| 112 |
*/
|
|
| 113 | 0 |
public String toString() {
|
| 114 | 0 |
Format nf = new Format( "%.4g" ); |
| 115 | 0 |
StringBuffer result = new StringBuffer( this.rows() * this.columns() ); |
| 116 | 0 |
if ( this.hasColNames() || this.hasRowNames() ) { |
| 117 | 0 |
result.append( "label" );
|
| 118 |
} |
|
| 119 |
|
|
| 120 | 0 |
if ( this.hasColNames() ) { |
| 121 | 0 |
for ( int i = 0; i < columns(); i++ ) { |
| 122 | 0 |
result.append( "\t" + getColName( i ) );
|
| 123 |
} |
|
| 124 | 0 |
result.append( "\n" );
|
| 125 |
} |
|
| 126 |
|
|
| 127 | 0 |
for ( int i = 0; i < rows(); i++ ) { |
| 128 | 0 |
if ( this.hasRowNames() ) { |
| 129 | 0 |
result.append( getRowName( i ) ); |
| 130 |
} |
|
| 131 | 0 |
for ( int j = 0; j < columns(); j++ ) { |
| 132 | 0 |
if ( Double.isNaN( get( i, j ) ) ) {
|
| 133 | 0 |
result.append( "\t" );
|
| 134 |
} else {
|
|
| 135 | 0 |
result.append( "\t" + nf.format( get( i, j ) ) );
|
| 136 |
} |
|
| 137 |
} |
|
| 138 | 0 |
result.append( "\n" );
|
| 139 |
} |
|
| 140 | 0 |
return result.toString();
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 | 3456 |
public void set( int row, int col, Object value ) { |
| 146 | 3456 |
set( row, col, ( ( Double ) value ).doubleValue() ); |
| 147 |
} |
|
| 148 |
|
|
| 149 |
/**
|
|
| 150 |
* Make a copy of a matrix.
|
|
| 151 |
* @return baseCode.dataStructure.DenseDoubleMatrix2DNamed
|
|
| 152 |
*/
|
|
| 153 | 0 |
public DenseDoubleMatrix2DNamed copy() {
|
| 154 | 0 |
DenseDoubleMatrix2DNamed returnval = new DenseDoubleMatrix2DNamed( this |
| 155 |
.rows(), this.columns() );
|
|
| 156 | 0 |
for ( int i = 0, n = this.rows(); i < n; i++ ) { |
| 157 | 0 |
returnval.addRowName( this.getRowName( i ), i );
|
| 158 | 0 |
for ( int j = 0, m = this.columns(); j < m; j++ ) { |
| 159 | 0 |
if ( i == 0 ) {
|
| 160 | 0 |
returnval.addColumnName( this.getColName( j ), j );
|
| 161 |
} |
|
| 162 | 0 |
returnval.set( i, j, this.get( i, j ) );
|
| 163 |
} |
|
| 164 |
} |
|
| 165 | 0 |
return returnval;
|
| 166 |
} |
|
| 167 |
|
|
| 168 | 3960 |
public boolean isMissing( int i, int j ) { |
| 169 | 3960 |
return Double.isNaN( get( i, j ) );
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
/**
|
|
| 173 |
* @param row int
|
|
| 174 |
* @param column int
|
|
| 175 |
* @return @see DoubleMatrix2D#get(int, int)
|
|
| 176 |
*/
|
|
| 177 | 19944 |
public double get( int row, int column ) { |
| 178 | 19944 |
return matrix.get( row, column );
|
| 179 |
} |
|
| 180 |
|
|
| 181 |
/**
|
|
| 182 |
* @param row int
|
|
| 183 |
* @param column int
|
|
| 184 |
* @return double
|
|
| 185 |
* @see DenseDoubleMatrix2D#getQuick(int, int)
|
|
| 186 |
*/
|
|
| 187 | 2520 |
public double getQuick( int row, int column ) { |
| 188 | 2520 |
return matrix.getQuick( row, column );
|
| 189 |
} |
|
| 190 |
|
|
| 191 |
/**
|
|
| 192 |
* @param row int
|
|
| 193 |
* @param column int
|
|
| 194 |
* @param value double
|
|
| 195 |
*/
|
|
| 196 | 50112 |
public void set( int row, int column, double value ) { |
| 197 | 50112 |
matrix.set( row, column, value ); |
| 198 |
} |
|
| 199 |
|
|
| 200 |
/**
|
|
| 201 |
* @param row int
|
|
| 202 |
* @param column int
|
|
| 203 |
* @param value double
|
|
| 204 |
* @see DenseDoubleMatrix2D#setQuick(int, int, double)
|
|
| 205 |
*/
|
|
| 206 | 870 |
public void setQuick( int row, int column, double value ) { |
| 207 | 870 |
matrix.setQuick( row, column, value ); |
| 208 |
} |
|
| 209 |
|
|
| 210 |
/**
|
|
| 211 |
* @param column int
|
|
| 212 |
* @return cern.colt.matrix.DoubleMatrix1D
|
|
| 213 |
*/
|
|
| 214 | 0 |
public DoubleMatrix1D viewColumn( int column ) { |
| 215 | 0 |
return matrix.viewColumn( column );
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
/**
|
|
| 219 |
* @param row int
|
|
| 220 |
* @return DoubleMatrix1D
|
|
| 221 |
* @see DenseDoubleMatrix2D#viewRow(int)
|
|
| 222 |
*/
|
|
| 223 | 645 |
public DoubleMatrix1D viewRow( int row ) { |
| 224 | 645 |
return matrix.viewRow( row );
|
| 225 |
} |
|
| 226 |
|
|
| 227 |
/**
|
|
| 228 |
* @return the number of columns in the matrix
|
|
| 229 |
* @see cern.colt.matrix.impl.AbstractMatrix2D#columns()
|
|
| 230 |
*/
|
|
| 231 | 64597 |
public int columns() { |
| 232 | 64597 |
return matrix.columns();
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
/**
|
|
| 236 |
* @return the number of rows in the matrix
|
|
| 237 |
* @see AbstractMatrix2D#rows()
|
|
| 238 |
*/
|
|
| 239 | 4372 |
public int rows() { |
| 240 | 4372 |
return matrix.rows();
|
| 241 |
} |
|
| 242 |
|
|
| 243 |
/**
|
|
| 244 |
* @return int
|
|
| 245 |
* @see AbstractMatrix2D#size()
|
|
| 246 |
*/
|
|
| 247 | 1 |
public int size() { |
| 248 | 1 |
return matrix.size();
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
/**
|
|
| 252 |
* @return double[][]
|
|
| 253 |
*/
|
|
| 254 | 0 |
public double[][] toArray() { |
| 255 | 0 |
return matrix.toArray();
|
| 256 |
} |
|
| 257 |
|
|
| 258 |
/* (non-Javadoc)
|
|
| 259 |
* @see baseCode.dataStructure.matrix.AbstractNamedDoubleMatrix#getRowArrayList(int)
|
|
| 260 |
*/
|
|
| 261 | 0 |
public DoubleArrayList getRowArrayList( int i ) { |
| 262 | 0 |
return new DoubleArrayList(getRow(i)); |
| 263 |
} |
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
} |
|
||||||||||