2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* Created on Oct 28, 2004 |
2 |
26 Feb 07 |
jari |
3 |
*/ |
2 |
26 Feb 07 |
jari |
4 |
package org.tigr.microarray.mev.cluster.gui.impl.usc; |
2 |
26 Feb 07 |
jari |
5 |
|
2 |
26 Feb 07 |
jari |
6 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
7 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
8 |
import java.util.StringTokenizer; |
2 |
26 Feb 07 |
jari |
9 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
12 |
import org.tigr.microarray.mev.r.ClassAssigner; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
/** |
2 |
26 Feb 07 |
jari |
* General loader. |
2 |
26 Feb 07 |
jari |
16 |
* |
2 |
26 Feb 07 |
jari |
* Handles the specific cases: |
2 |
26 Feb 07 |
jari |
* 1 Read all the data that was already loaded into MeV |
2 |
26 Feb 07 |
jari |
* 2 Read only the test hybs that were loaded into MeV |
2 |
26 Feb 07 |
jari |
* 3 Read a training file |
2 |
26 Feb 07 |
jari |
21 |
* |
2 |
26 Feb 07 |
jari |
* In every case, the data is formatted into USCHybSets |
2 |
26 Feb 07 |
jari |
23 |
* |
2 |
26 Feb 07 |
jari |
* @author vu |
2 |
26 Feb 07 |
jari |
25 |
*/ |
2 |
26 Feb 07 |
jari |
26 |
public class USCTrainFileLoader { |
2 |
26 Feb 07 |
jari |
//member variables |
2 |
26 Feb 07 |
jari |
28 |
private USCHybSet trainHybSet; |
2 |
26 Feb 07 |
jari |
29 |
private USCHybSet testHybSet; |
2 |
26 Feb 07 |
jari |
30 |
private double delta; |
2 |
26 Feb 07 |
jari |
31 |
private double rho; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a USCHybSet from an IData implementation |
2 |
26 Feb 07 |
jari |
* @param data |
2 |
26 Feb 07 |
jari |
* @param hybLabels [ String ] names of hybs that are "Unknown (Test)" |
2 |
26 Feb 07 |
jari |
38 |
*/ |
2 |
26 Feb 07 |
jari |
39 |
public USCTrainFileLoader( IData data, String[] hybLabels ) { |
2 |
26 Feb 07 |
jari |
//gene indices |
2 |
26 Feb 07 |
jari |
41 |
int[] sortedIndices = data.getSortedIndices( 0 ); |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
//get the hybIndices of the labeled (training) hybs |
2 |
26 Feb 07 |
jari |
44 |
Vector vInclude = new Vector(); |
2 |
26 Feb 07 |
jari |
45 |
Vector vTest = new Vector(); |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
//don't include the hybs labeled "Unknown (Test)" |
2 |
26 Feb 07 |
jari |
48 |
for( int i = 0; i < hybLabels.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
49 |
if( ! hybLabels[ i ].equals( ClassAssigner.TEST_CLASS_STRING ) ) { |
2 |
26 Feb 07 |
jari |
50 |
vInclude.add( new Integer( i ) ); |
2 |
26 Feb 07 |
jari |
51 |
} else { |
2 |
26 Feb 07 |
jari |
52 |
vTest.add( new Integer( i ) ); |
2 |
26 Feb 07 |
jari |
53 |
} |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
int hybKount = vInclude.size(); |
2 |
26 Feb 07 |
jari |
57 |
int testKount = vTest.size(); |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
//create a USCHyb[ numHybs ] |
2 |
26 Feb 07 |
jari |
60 |
USCHyb[] hybArray = new USCHyb[ hybKount ]; |
2 |
26 Feb 07 |
jari |
61 |
USCHyb[] testArray = new USCHyb[ testKount ]; |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
//ratios [ numHybs ][ numGenes ] |
2 |
26 Feb 07 |
jari |
64 |
double[][] ratios = USCGUI.castFloatToDoubleArray( this.transpose( data.getExperiment().getValues() ) ); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
for( int i = 0; i < ratios.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
67 |
for( int j = 0; j < ratios[ i ].length; j ++ ) { |
2 |
26 Feb 07 |
jari |
68 |
if( ratios[ i ][ j ] == Float.NaN ) { |
2 |
26 Feb 07 |
jari |
69 |
System.out.println( "Nan" ); |
2 |
26 Feb 07 |
jari |
70 |
} else if( ratios[ i ][ j ] == Float.NEGATIVE_INFINITY || ratios[ i ][ j ] == |
2 |
26 Feb 07 |
jari |
71 |
Float.POSITIVE_INFINITY ) { |
2 |
26 Feb 07 |
jari |
72 |
System.out.println( "Infinity" ); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
} |
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
//loop through the hybs, creating USCHyb objects and store in hybArray |
2 |
26 Feb 07 |
jari |
78 |
for( int h = 0; h < hybKount; h ++ ) { |
2 |
26 Feb 07 |
jari |
79 |
Integer I = ( Integer ) vInclude.elementAt( h ); |
2 |
26 Feb 07 |
jari |
80 |
int iIndex = I.intValue(); |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
String sHybName = data.getFullSampleName( iIndex ); |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
USCHyb hyb = new USCHyb( h, hybLabels[ iIndex ], sHybName, ratios[ iIndex ] ); |
2 |
26 Feb 07 |
jari |
85 |
hybArray[ h ] = hyb; |
2 |
26 Feb 07 |
jari |
86 |
}//end h (hybs) |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
//loop through the test |
2 |
26 Feb 07 |
jari |
89 |
for( int h = 0; h < testKount; h ++ ) { |
2 |
26 Feb 07 |
jari |
90 |
Integer I = ( Integer ) vTest.elementAt( h ); |
2 |
26 Feb 07 |
jari |
91 |
int iIndex = I.intValue(); |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
String sHybName = data.getFullSampleName( iIndex ); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
USCHyb hyb = new USCHyb( h, ClassAssigner.TEST_CLASS_STRING, sHybName, ratios[ iIndex ] ); |
2 |
26 Feb 07 |
jari |
96 |
testArray[ h ] = hyb; |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
//create the USCHybSet |
2 |
26 Feb 07 |
jari |
100 |
this.trainHybSet = new USCHybSet( hybArray, this.createGeneList( data ) ); |
2 |
26 Feb 07 |
jari |
101 |
this.testHybSet = new USCHybSet( testArray, this.createGeneList( data ) ); |
2 |
26 Feb 07 |
jari |
102 |
}//end USCTrainFileLoader(); |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a USCHybSet from an IData implementation. Used when getting test |
2 |
26 Feb 07 |
jari |
* data to test against Saved Train Data |
2 |
26 Feb 07 |
jari |
* @param data |
2 |
26 Feb 07 |
jari |
109 |
*/ |
2 |
26 Feb 07 |
jari |
110 |
public USCTrainFileLoader( IData data ) { |
2 |
26 Feb 07 |
jari |
//gene indices |
2 |
26 Feb 07 |
jari |
112 |
int[] sortedIndices = data.getSortedIndices( 0 ); |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
//all hybs will be tested |
2 |
26 Feb 07 |
jari |
115 |
int testKount = data.getFeaturesCount(); |
2 |
26 Feb 07 |
jari |
116 |
USCHyb[] testArray = new USCHyb[ testKount ]; |
2 |
26 Feb 07 |
jari |
117 |
|
2 |
26 Feb 07 |
jari |
//now, get all the ratios [ numGenes ][ numHybs ] |
2 |
26 Feb 07 |
jari |
119 |
float[][] tempRatios = data.getExperiment().getValues(); |
2 |
26 Feb 07 |
jari |
//pull out only those used for training and transpose [ numHybs ][ numGenes ] |
2 |
26 Feb 07 |
jari |
//double[][] ratios = USCGUI.castFloatToDoubleArray( this.transpose( this.condenseRatios( tempRatios, geneIndex ) ) ); |
2 |
26 Feb 07 |
jari |
122 |
double[][] ratios = USCGUI.castFloatToDoubleArray( this.transpose( tempRatios ) ); |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
//loop through the hybs |
2 |
26 Feb 07 |
jari |
125 |
for( int h = 0; h < ratios.length; h ++ ) { |
2 |
26 Feb 07 |
jari |
126 |
testArray[ h ] = new USCHyb( h, ClassAssigner.TEST_CLASS_STRING, |
2 |
26 Feb 07 |
jari |
127 |
data.getFullSampleName( h ), ratios[ h ] ); |
2 |
26 Feb 07 |
jari |
128 |
}//end h |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
this.testHybSet = new USCHybSet( testArray, this.createGeneList( data ) ); |
2 |
26 Feb 07 |
jari |
131 |
}//end USCTrainFileLoader(); |
2 |
26 Feb 07 |
jari |
132 |
|
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
/** |
2 |
26 Feb 07 |
jari |
* Parse the Training File into USCHybSet |
2 |
26 Feb 07 |
jari |
* <p> |
2 |
26 Feb 07 |
jari |
* 'GeneID' Hyb1Name Hyb2Name etc<br> |
2 |
26 Feb 07 |
jari |
* 'blank' Hyb1Label Hyb2Label etc<br> |
2 |
26 Feb 07 |
jari |
* GeneID1 UID1 ratio1 ratio2 etc<br> |
2 |
26 Feb 07 |
jari |
* GeneID2 UID2 ratio1 ratio2 etc<br> |
2 |
26 Feb 07 |
jari |
* etc etc etc etc<br> |
2 |
26 Feb 07 |
jari |
* <p> |
2 |
26 Feb 07 |
jari |
* Important: When the labels are unknown, 'blank' should be used in lieu of labels |
2 |
26 Feb 07 |
jari |
144 |
*/ |
2 |
26 Feb 07 |
jari |
145 |
public USCTrainFileLoader( File f ) throws IOException { |
2 |
26 Feb 07 |
jari |
146 |
int hybKount = 0; |
2 |
26 Feb 07 |
jari |
147 |
int geneKount = 0; |
2 |
26 Feb 07 |
jari |
148 |
String[] geneNames = null; |
2 |
26 Feb 07 |
jari |
149 |
String[] geneIndex = null; |
2 |
26 Feb 07 |
jari |
150 |
USCHyb[] hybs = null; |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
//read the file |
2 |
26 Feb 07 |
jari |
153 |
Reader r = new Reader(); |
2 |
26 Feb 07 |
jari |
154 |
r.readFile( f ); |
2 |
26 Feb 07 |
jari |
155 |
Vector v = r.getVNullLine( USCGUI.NULL_REPLACER ); |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
//loop through the lines of the File |
2 |
26 Feb 07 |
jari |
158 |
for( int i = 0; i < v.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
159 |
String line = ( String ) v.elementAt( i ); |
2 |
26 Feb 07 |
jari |
160 |
StringTokenizer st = new StringTokenizer( line, USCGUI.TAB ); |
2 |
26 Feb 07 |
jari |
161 |
int tokenKount = st.countTokens(); |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
163 |
if( i == 0 ) { |
2 |
26 Feb 07 |
jari |
//initialize stuff |
2 |
26 Feb 07 |
jari |
//there is 1 column of gene names, rest are hybs |
2 |
26 Feb 07 |
jari |
166 |
hybKount = tokenKount - 2; |
2 |
26 Feb 07 |
jari |
167 |
hybs = new USCHyb[ hybKount ]; |
2 |
26 Feb 07 |
jari |
//there are 2 rows of headers, rest are genes |
2 |
26 Feb 07 |
jari |
169 |
geneKount = v.size() - 2; |
2 |
26 Feb 07 |
jari |
170 |
geneNames = new String[ geneKount ]; |
2 |
26 Feb 07 |
jari |
171 |
geneIndex = new String[ geneKount ]; |
2 |
26 Feb 07 |
jari |
172 |
|
2 |
26 Feb 07 |
jari |
//this is the 1st header line |
2 |
26 Feb 07 |
jari |
174 |
for( int j = 0; j < tokenKount; j ++ ) { |
2 |
26 Feb 07 |
jari |
//these tokens are the hyb names |
2 |
26 Feb 07 |
jari |
176 |
String hybName = st.nextToken(); |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
if( j == 0 ) { |
2 |
26 Feb 07 |
jari |
//delta |
2 |
26 Feb 07 |
jari |
180 |
this.delta = this.parseDR( hybName ); |
2 |
26 Feb 07 |
jari |
181 |
} else if( j == 1 ) { |
2 |
26 Feb 07 |
jari |
//nothing here |
2 |
26 Feb 07 |
jari |
183 |
} else { |
2 |
26 Feb 07 |
jari |
//Instantiate the USCHyb objects |
2 |
26 Feb 07 |
jari |
185 |
USCHyb hyb = new USCHyb( ( j - 1 ), hybName, geneKount ); |
2 |
26 Feb 07 |
jari |
186 |
hybs[ ( j - 2 ) ] = hyb; |
2 |
26 Feb 07 |
jari |
187 |
} |
2 |
26 Feb 07 |
jari |
188 |
}//end j |
2 |
26 Feb 07 |
jari |
189 |
} else if( i == 1 ) { |
2 |
26 Feb 07 |
jari |
//this is the 2nd header line |
2 |
26 Feb 07 |
jari |
191 |
for( int j = 0; j < tokenKount; j ++ ) { |
2 |
26 Feb 07 |
jari |
//these tokens are the labels |
2 |
26 Feb 07 |
jari |
193 |
String s = st.nextToken(); |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
if( j == 0 ) { |
2 |
26 Feb 07 |
jari |
//rho |
2 |
26 Feb 07 |
jari |
197 |
this.rho = this.parseDR( s ); |
2 |
26 Feb 07 |
jari |
198 |
} else if( j == 1 ) { |
2 |
26 Feb 07 |
jari |
//nothing here |
2 |
26 Feb 07 |
jari |
200 |
} else { |
2 |
26 Feb 07 |
jari |
//set the labels for these hybs |
2 |
26 Feb 07 |
jari |
202 |
hybs[ ( j - 2 ) ].setHybLabel( s ); |
2 |
26 Feb 07 |
jari |
203 |
} |
2 |
26 Feb 07 |
jari |
204 |
}//end j |
2 |
26 Feb 07 |
jari |
205 |
} else { |
2 |
26 Feb 07 |
jari |
//these are rows of data |
2 |
26 Feb 07 |
jari |
207 |
for( int j = 0; j < tokenKount; j ++ ) { |
2 |
26 Feb 07 |
jari |
//these tokens are ratios |
2 |
26 Feb 07 |
jari |
209 |
String s = st.nextToken(); |
2 |
26 Feb 07 |
jari |
210 |
/* |
2 |
26 Feb 07 |
jari |
if( s.equals("M55998_s_at")) { |
2 |
26 Feb 07 |
jari |
System.out.println( "M55998_s_at = " + ( i - 2 ) ); |
2 |
26 Feb 07 |
jari |
213 |
} |
2 |
26 Feb 07 |
jari |
214 |
*/ |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
if( j == 0 ) { |
2 |
26 Feb 07 |
jari |
//(2,0) gene names |
2 |
26 Feb 07 |
jari |
218 |
geneNames[ ( i - 2 ) ] = s; |
2 |
26 Feb 07 |
jari |
219 |
} else if( j == 1 ) { |
2 |
26 Feb 07 |
jari |
//this is a uid |
2 |
26 Feb 07 |
jari |
221 |
geneIndex[ ( i - 2 ) ] = s; |
2 |
26 Feb 07 |
jari |
222 |
} else { |
2 |
26 Feb 07 |
jari |
223 |
Float FRatio = new Float( s ); |
2 |
26 Feb 07 |
jari |
224 |
if( FRatio.isNaN() ) { |
2 |
26 Feb 07 |
jari |
//if there is no ratio, enter a 0 |
2 |
26 Feb 07 |
jari |
226 |
hybs[ ( j - 2 ) ].setRatio( ( i - 2 ), 0.0f ); |
2 |
26 Feb 07 |
jari |
227 |
} else { |
2 |
26 Feb 07 |
jari |
//set the ratio for this gene for this hyb |
2 |
26 Feb 07 |
jari |
229 |
hybs[ ( j - 2 ) ].setRatio( ( i - 2 ), FRatio.doubleValue() ); |
2 |
26 Feb 07 |
jari |
230 |
} |
2 |
26 Feb 07 |
jari |
231 |
} |
2 |
26 Feb 07 |
jari |
232 |
}//end j |
2 |
26 Feb 07 |
jari |
233 |
} |
2 |
26 Feb 07 |
jari |
234 |
}//end i |
2 |
26 Feb 07 |
jari |
235 |
|
2 |
26 Feb 07 |
jari |
236 |
USCGene[] genes = new USCGene[ geneNames.length ]; |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
for( int i = 0; i < geneNames.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
239 |
genes[ i ] = new USCGene( geneNames[ i ], null ); |
2 |
26 Feb 07 |
jari |
240 |
} |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
int[] geneIndices = this.intifyStringArray( geneIndex ); |
2 |
26 Feb 07 |
jari |
243 |
this.trainHybSet = new USCHybSet( hybs, genes ); |
2 |
26 Feb 07 |
jari |
244 |
}//end USCTrainFileLoader() |
2 |
26 Feb 07 |
jari |
245 |
|
2 |
26 Feb 07 |
jari |
246 |
|
2 |
26 Feb 07 |
jari |
247 |
/** |
2 |
26 Feb 07 |
jari |
248 |
* |
2 |
26 Feb 07 |
jari |
* @param data |
2 |
26 Feb 07 |
jari |
* @param geneIndices |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
252 |
*/ |
2 |
26 Feb 07 |
jari |
253 |
private USCGene[] createGeneList( IData data ) { |
2 |
26 Feb 07 |
jari |
254 |
int numGenes = data.getFeaturesSize(); |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
256 |
USCGene[] genes = new USCGene[ numGenes ]; |
2 |
26 Feb 07 |
jari |
257 |
|
2 |
26 Feb 07 |
jari |
//which genes weren't specified, so do them all |
2 |
26 Feb 07 |
jari |
259 |
for( int i = 0; i < numGenes; i ++ ) { |
2 |
26 Feb 07 |
jari |
260 |
String geneName = data.getGeneName( i ); |
2 |
26 Feb 07 |
jari |
261 |
String[] extraFields = data.getSlideDataElement( 0, i ).getExtraFields(); |
2 |
26 Feb 07 |
jari |
262 |
USCGene gene = new USCGene( geneName, extraFields ); |
2 |
26 Feb 07 |
jari |
263 |
genes[ i ] = gene; |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
|
2 |
26 Feb 07 |
jari |
266 |
return genes; |
2 |
26 Feb 07 |
jari |
267 |
}//createGeneList() |
2 |
26 Feb 07 |
jari |
268 |
|
2 |
26 Feb 07 |
jari |
269 |
|
2 |
26 Feb 07 |
jari |
270 |
/** |
2 |
26 Feb 07 |
jari |
* Removes ratios that were not used during training and thus are not present in |
2 |
26 Feb 07 |
jari |
* the Training Result File and will not be used for classification |
2 |
26 Feb 07 |
jari |
* @param ratios |
2 |
26 Feb 07 |
jari |
* @param geneIndex |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
276 |
*/ |
2 |
26 Feb 07 |
jari |
277 |
private float[][] condenseRatios( float[][] ratios, int[] geneIndex ) { |
2 |
26 Feb 07 |
jari |
278 |
float[][] toReturn = new float[ geneIndex.length ][ ratios.length ]; |
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
280 |
for( int i = 0; i < geneIndex.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
281 |
toReturn[ i ] = ratios[ geneIndex[ i ] ]; |
2 |
26 Feb 07 |
jari |
282 |
} |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
return toReturn; |
2 |
26 Feb 07 |
jari |
285 |
}//condenseRatios() |
2 |
26 Feb 07 |
jari |
286 |
|
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
/** |
2 |
26 Feb 07 |
jari |
* Converst the String[] to an int[] |
2 |
26 Feb 07 |
jari |
* @param sInts |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
292 |
*/ |
2 |
26 Feb 07 |
jari |
293 |
private int[] intifyStringArray( String[] sInts ) { |
2 |
26 Feb 07 |
jari |
294 |
int[] toReturn = new int[ sInts.length ]; |
2 |
26 Feb 07 |
jari |
295 |
|
2 |
26 Feb 07 |
jari |
296 |
for( int i = 0; i < sInts.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
297 |
toReturn[ i ] = new Integer( sInts[ i ] ).intValue(); |
2 |
26 Feb 07 |
jari |
298 |
} |
2 |
26 Feb 07 |
jari |
299 |
|
2 |
26 Feb 07 |
jari |
300 |
return toReturn; |
2 |
26 Feb 07 |
jari |
301 |
}//intifyStringArray() |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
|
2 |
26 Feb 07 |
jari |
304 |
/** |
2 |
26 Feb 07 |
jari |
305 |
* |
2 |
26 Feb 07 |
jari |
* @param sDR |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
308 |
*/ |
2 |
26 Feb 07 |
jari |
309 |
private double parseDR( String sDR ) { |
2 |
26 Feb 07 |
jari |
310 |
int iEqual = sDR.indexOf( "=" ); |
2 |
26 Feb 07 |
jari |
311 |
Float F = new Float( sDR.substring( iEqual + 1 ) ); |
2 |
26 Feb 07 |
jari |
312 |
return F.doubleValue(); |
2 |
26 Feb 07 |
jari |
313 |
} |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
|
2 |
26 Feb 07 |
jari |
316 |
/** |
2 |
26 Feb 07 |
jari |
* Constructor for testing purposes |
2 |
26 Feb 07 |
jari |
* @param m |
2 |
26 Feb 07 |
jari |
319 |
*/ |
2 |
26 Feb 07 |
jari |
320 |
public USCTrainFileLoader( double[][] m ) { |
2 |
26 Feb 07 |
jari |
//this.transpose( m ); |
2 |
26 Feb 07 |
jari |
322 |
}//end USCTrainFileLoader(); |
2 |
26 Feb 07 |
jari |
323 |
|
2 |
26 Feb 07 |
jari |
324 |
|
2 |
26 Feb 07 |
jari |
325 |
/** |
2 |
26 Feb 07 |
jari |
* Transposes the ith and jth elements of a 2D double[ i ][ j ] matrix |
2 |
26 Feb 07 |
jari |
* @param m |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
329 |
*/ |
2 |
26 Feb 07 |
jari |
330 |
private float[][] transpose( float[][] m ) { |
2 |
26 Feb 07 |
jari |
331 |
float[][] toReturn = new float[ m[ 0 ].length ][ m.length ]; |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
333 |
for( int i = 0; i < m.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
334 |
for( int j = 0; j < m[ 0 ].length; j ++ ) { |
2 |
26 Feb 07 |
jari |
335 |
toReturn[ j ][ i ] = m[ i ][ j ]; |
2 |
26 Feb 07 |
jari |
336 |
} |
2 |
26 Feb 07 |
jari |
337 |
} |
2 |
26 Feb 07 |
jari |
338 |
|
2 |
26 Feb 07 |
jari |
339 |
return toReturn; |
2 |
26 Feb 07 |
jari |
340 |
}//end transpose() |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
|
2 |
26 Feb 07 |
jari |
343 |
public static void main( String[] args ) { |
2 |
26 Feb 07 |
jari |
344 |
double[][] m = new double[ 3 ][ 2 ]; |
2 |
26 Feb 07 |
jari |
345 |
|
2 |
26 Feb 07 |
jari |
346 |
m[ 0 ][ 0 ] = 0; |
2 |
26 Feb 07 |
jari |
347 |
m[ 1 ][ 0 ] = 1; |
2 |
26 Feb 07 |
jari |
348 |
m[ 2 ][ 0 ] = 2; |
2 |
26 Feb 07 |
jari |
349 |
m[ 0 ][ 1 ] = 3; |
2 |
26 Feb 07 |
jari |
350 |
m[ 1 ][ 1 ] = 4; |
2 |
26 Feb 07 |
jari |
351 |
m[ 2 ][ 1 ] = 5; |
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
for( int i = 0; i < m.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
354 |
for( int j = 0; j < m[ 0 ].length; j ++ ) { |
2 |
26 Feb 07 |
jari |
355 |
System.out.println( i + "," + j + " = " + m[ i ][ j ] ); |
2 |
26 Feb 07 |
jari |
356 |
} |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
|
2 |
26 Feb 07 |
jari |
359 |
USCTrainFileLoader loader = new USCTrainFileLoader( m ); |
2 |
26 Feb 07 |
jari |
360 |
} |
2 |
26 Feb 07 |
jari |
361 |
|
2 |
26 Feb 07 |
jari |
362 |
|
2 |
26 Feb 07 |
jari |
363 |
public USCHybSet getTrainHybSet() { |
2 |
26 Feb 07 |
jari |
364 |
return this.trainHybSet; |
2 |
26 Feb 07 |
jari |
365 |
} |
2 |
26 Feb 07 |
jari |
366 |
public USCHybSet getTestHybSet() { |
2 |
26 Feb 07 |
jari |
367 |
return this.testHybSet; |
2 |
26 Feb 07 |
jari |
368 |
} |
2 |
26 Feb 07 |
jari |
369 |
public double getDelta() { |
2 |
26 Feb 07 |
jari |
370 |
return this.delta; |
2 |
26 Feb 07 |
jari |
371 |
} |
2 |
26 Feb 07 |
jari |
372 |
public double getRho() { |
2 |
26 Feb 07 |
jari |
373 |
return this.rho; |
2 |
26 Feb 07 |
jari |
374 |
} |
2 |
26 Feb 07 |
jari |
375 |
}//end class |