public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java LR examplefile numexamples numfeatures"); System.exit(1); } numfeatures = Integer.parseInt(args[2]); exsize = Integer.parseInt(args[1]); try { Scanner infile = new Scanner(new FileReader(args[0])); FileWriter outfile = new FileWriter("weights.txt"); int index = 0; while (infile.hasNextLine()) { System.out.println("Creating model for k-best list num " + index); ArrayList<Double[]> trainexamples = new ArrayList<Double[]>(exsize); int n = 0; // get the next 100 examples while (infile.hasNextLine() && (n < exsize)) { String line = infile.nextLine(); StringTokenizer tok = new StringTokenizer(line); Double[] ex = new Double[numfeatures + 1]; for (int k = 0; k < (numfeatures + 1); k++) ex[k] = Double.parseDouble(tok.nextToken()); trainexamples.add(ex); n++; } // end while // train logistic regression if (trainexamples.size() < exsize) { System.out.println("ERROR: trainexamples has only " + trainexamples.size() + " items!"); System.exit(1); } trainLR(trainexamples); // print weight vector System.out.println("Done, printing weight vector"); for (int k = 0; k < weightvector.length; k++) { outfile.write(weightvector[k] + " "); } outfile.write("\n"); index++; } // end while next k-best list infile.close(); outfile.close(); } // end try catch (IOException e) { System.out.println(e.getMessage()); } } // end main