Skip to content

Commit 54503ed

Browse files
committed
Merge branch 'release-1.0.23'
2 parents 88ef927 + 7eaf979 commit 54503ed

19 files changed

Lines changed: 969 additions & 158 deletions

lmtest.weights1.txt

Lines changed: 151 additions & 0 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>baseCode</name>
66
<groupId>baseCode</groupId>
77
<artifactId>baseCode</artifactId>
8-
<version>1.0.22</version>
8+
<version>1.0.23</version>
99
<inceptionYear>2003</inceptionYear>
1010
<description>
1111
<![CDATA[Data structures, math and statistics tools, and utilities that are often needed across projects.]]>

src/ubic/basecode/datafilter/RowMissingFilter.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* The baseCode project
3-
*
3+
*
44
* Copyright (c) 2006 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
@@ -21,15 +21,14 @@
2121
import java.util.List;
2222
import java.util.Vector;
2323

24+
import cern.colt.list.IntArrayList;
2425
import ubic.basecode.dataStructure.matrix.Matrix2D;
2526
import ubic.basecode.dataStructure.matrix.MatrixUtil;
26-
import cern.colt.list.IntArrayList;
2727

2828
/**
2929
* Remove rows from a matrix that are missing too many points.
30-
*
30+
*
3131
* @author Paul Pavlidis
32-
* @version $Id$
3332
*/
3433
public class RowMissingFilter<M extends Matrix2D<R, C, V>, R, C, V> extends AbstractFilter<M, R, C, V> {
3534

@@ -42,8 +41,8 @@ public class RowMissingFilter<M extends Matrix2D<R, C, V>, R, C, V> extends Abst
4241

4342
@Override
4443
public M filter( M data ) {
45-
List<V[]> MTemp = new Vector<V[]>();
46-
List<R> rowNames = new Vector<R>();
44+
List<V[]> MTemp = new Vector<>();
45+
List<R> rowNames = new Vector<>();
4746
int numRows = data.rows();
4847
int numCols = data.columns();
4948
IntArrayList present = new IntArrayList( numRows );
@@ -117,8 +116,9 @@ public M filter( M data ) {
117116
returnval.setColumnNames( data.getColNames() );
118117
returnval.setRowNames( rowNames );
119118

120-
log.info( "There are " + kept + " rows after removing rows which have fewer than " + minPresentCount
121-
+ " values (or fewer than " + ABSOLUTEMINPRESENT + ")" );
119+
if ( kept < numRows )
120+
log.info( "There are " + kept + " rows after removing rows which have fewer than " + Math.max( ABSOLUTEMINPRESENT, minPresentCount )
121+
+ " values" );
122122

123123
return returnval;
124124

@@ -127,7 +127,7 @@ public M filter( M data ) {
127127
/**
128128
* Set the maximum fraction of rows which will be removed from the data set. The default value is 0.3 Set it to 1.0
129129
* to remove this restriction.
130-
*
130+
*
131131
* @param f double
132132
*/
133133
public void setMaxFractionRemoved( double f ) {
@@ -140,7 +140,7 @@ public void setMaxFractionRemoved( double f ) {
140140
* Set the minimum number of values that must be present in each row. The default value is 5. This is always
141141
* overridden by a hard-coded value (currently 2) that must be present for a row to be kept; but this value is in
142142
* turn overridden by the maxfractionRemoved.
143-
*
143+
*
144144
* @param m int
145145
*/
146146
public void setMinPresentCount( int m ) {

src/ubic/basecode/io/writer/MatrixWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void setTopLeft( String topLeft ) {
127127
/**
128128
* @param <V>
129129
* @param matrix
130-
* @param printNames Should the row and column names be included
130+
* @param printNames Should the row and column names be included; FIXME this fails if names aren't provided
131131
* @throws IOException
132132
*/
133133
public <V> void writeMatrix( Matrix2D<R, C, V> matrix, boolean printNames ) throws IOException {

src/ubic/basecode/math/RandomChooser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static int[] chooserandomWrep( int max, int n ) {
154154
}
155155

156156
/**
157-
* Initialized the random number generator witha given seed.
157+
* Initialized the random number generator with a given seed.
158158
*
159159
* @param seed
160160
*/

src/ubic/basecode/math/linalg/QRDecomposition.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public class QRDecomposition {
9292
*/
9393
private DoubleMatrix2D Qcached = null;
9494

95+
private DoubleMatrix2D effects;
96+
9597
/**
9698
* @param A the matrix to decompose, pivoting will be used.
9799
*/
@@ -227,39 +229,41 @@ public DoubleMatrix2D chol2inv() {
227229
}
228230

229231
/**
230-
* Compute effects matrix Q'y (as in Rb = Q'y). Returns only
231-
* the aspect associated with the parameters - the first <tt>rank</tt> elements.
232+
* Compute effects matrix Q'y (as in Rb = Q'y).
233+
*
234+
* <p>
235+
* "Tthe effects are the uncorrelated single-degree-of-freedom values obtained by projecting the data onto the
236+
* successive orthogonal subspaces generated by the QR decomposition during the fitting process. The first r (the
237+
* rank of the model) are associated with coefficients and the remainder span the space of residuals (but are not
238+
* associated with particular residuals)."
232239
*
233240
* @param y vector Missing values are ignored, otherwise assumed to be of the right size
234241
* @return vector of effects - these are the projections of y into Q column space
235242
*/
236243
public DoubleMatrix1D effects( DoubleMatrix1D y ) {
237244

238-
Algebra solver = new Algebra();
239-
// Inefficient due to getting Q explicitly
240-
return solver.mult( solver.transpose( this.getQ() ), MatrixUtil.removeMissing( y ) ).viewPart( 0, this.rank );
241-
242-
// Could do it this way, but QR.toArray() makes a copy...
243-
// double[] qty = new double[y.size()];
244-
// double[] junk = new double[y.size()];
245-
// ubic.basecode.math.linalg.Dqrsl.dqrsl_j( QR.toArray(), QR.rows(), QR.columns(), qraux.toArray(), y.toArray(),
246-
// junk, qty,
247-
// junk, junk, junk, 1000 );
248-
// return new DenseDoubleMatrix1D( qty );
245+
double[] qty = new double[y.size()];
246+
double[] junk = new double[y.size()];
247+
ubic.basecode.math.linalg.Dqrsl.dqrsl_j( QR.toArray(), QR.rows(), QR.columns(), qraux.toArray(), MatrixUtil.removeMissing( y ).toArray(),
248+
junk, qty,
249+
junk, junk, junk, 1000 );
250+
return new DenseDoubleMatrix1D( qty );
249251
}
250252

251253
/**
252-
* Compute effects matrix Q'y (as in Rb = Q'y) Returns only the aspect associated with the parameters - the first
253-
* <tt>rank</tt> elements.
254+
* Compute effects matrix Q'y (as in Rb = Q'y)
254255
*
255256
* @param y matrix of data, assumed to be of right size, missing values are not supported
256257
* @return matrix of effects - these are the projections of y's columns into Q column subspace associated with the
257258
* parameters,
258259
* so values are "effects" each basis vector on the data
259260
*/
260261
public DoubleMatrix2D effects( DoubleMatrix2D y ) {
261-
Algebra solver = new Algebra();
262-
return solver.mult( solver.transpose( this.getQ() ), y );
262+
double[][] efa = new double[y.columns()][y.rows()];
263+
for ( int i = 0; i < y.columns(); i++ ) {
264+
efa[i] = effects( y.viewColumn( i ) ).toArray();
265+
}
266+
return new DenseDoubleMatrix2D( efa ).viewDice();
263267
}
264268

265269
/**
@@ -387,11 +391,7 @@ public DoubleMatrix2D solve( DoubleMatrix2D y ) {
387391
throw new IllegalArgumentException( "Matrix is rank deficient; try using pivoting" );
388392
}
389393

390-
/*
391-
* Direct computation of Q'y can be avoided by manipulation of the compact QR instead (see dqrsl).
392-
*
393-
*/
394-
DoubleMatrix2D qTy = effects( y ); // will be modified by this call.
394+
DoubleMatrix2D qTy = effects( y ); // FIXME we use this again later, but we recompute it. Try to cache it.
395395

396396
// Solve R*X = Y => X = RinvY; backsubstitution
397397
for ( int k1 = rank - 1; k1 >= 0; k1-- ) {
@@ -421,7 +421,7 @@ public DoubleMatrix2D solve( DoubleMatrix2D y ) {
421421
*/
422422
DoubleMatrix2D coeff = qTy.like( p, y.columns() );
423423
coeff.assign( Double.NaN );
424-
for ( int i = 0; i < qTy.rows(); i++ ) {
424+
for ( int i = 0; i < this.rank; i++ ) {
425425
int piv = jpvt[i]; // where the value should go.
426426
for ( int j = 0; j < qTy.columns(); j++ ) {
427427
coeff.setQuick( piv, j, qTy.getQuick( i, j ) );

0 commit comments

Comments
 (0)