protected double[] libsvmToArray(String row){
  double[] result;
  StringTokenizer tok;
  int index;
  int max;
  String col;
  double value;
  max=0;
  tok=new StringTokenizer(row," \t");
  tok.nextToken();
  while (tok.hasMoreTokens()) {
    col=tok.nextToken();
    index=Integer.parseInt(col.substring(0,col.indexOf(":")));
    if (index > max)     max=index;
  }
  tok=new StringTokenizer(row," \t");
  result=new double[max + 1];
  result[result.length - 1]=Double.parseDouble(tok.nextToken());
  while (tok.hasMoreTokens()) {
    col=tok.nextToken();
    index=Integer.parseInt(col.substring(0,col.indexOf(":")));
    value=Double.parseDouble(col.substring(col.indexOf(":") + 1));
    result[index - 1]=value;
  }
  return result;
}

protected double [ ] libsvmToArray ( String row ) { double [ ] result ; StringTokenizer tok ; int index ; int max ; String col ; double value ; max = 0 ; tok = new StringTokenizer ( row , " \t" ) ; tok . nextToken ( ) ; while ( tok . hasMoreTokens ( ) ) { col = tok . nextToken ( ) ; index = Integer . parseInt ( col . substring ( 0 , col . indexOf ( ":" ) ) ) ; if ( index > max ) max = index ; } tok = new StringTokenizer ( row , " \t" ) ; result = new double [ max + 1 ] ; result [ result . length - 1 ] = Double . parseDouble ( tok . nextToken ( ) ) ; while ( tok . hasMoreTokens ( ) ) { col = tok . nextToken ( ) ; index = Integer . parseInt ( col . substring ( 0 , col . indexOf ( ":" ) ) ) ; value = Double . parseDouble ( col . substring ( col . indexOf ( ":" ) + 1 ) ) ; result [ index - 1 ] = value ; } return result ; }
turns a libsvm row into a double array with the class as the last entry .
