SoftmaxClassifier implements ProbabilisticClassifier<F,L>, Serializable { public Accuracy train(List<LabeledDatum<F,L>> Data) { trainScores = getTrainingResults(Data); int[] GTLabels = makeLabelVector(Data); int[] Predictions = trainScores.columnArgmaxs(); TrainAccuracy = new Accuracy(Predictions, GTLabels, CatSize); return TrainAccuracy; } SoftmaxClassifier( );  SoftmaxClassifier(ClassifierTheta ClassifierParams, Set<L> labelSet); DoubleMatrix getTrainingResults(List<LabeledDatum<F,L>> Data); Accuracy train(List<LabeledDatum<F,L>> Data); Accuracy test(List<LabeledDatum<F,L>> Data); DoubleMatrix getTrainScores(); DoubleMatrix getTestScores(); @Override L getLabel(Datum<F> datum); @Override Counter<L> getProbabilities(Datum<F> datum); @Override Counter<L> getLogProbabilities(Datum<F> datum); void Dump(String fileName);  }
@Test public void dummyBinaryTest() { String dir = "data/parsed"; DataSet<LabeledDatum<Double, Integer>,Double> Dataset = new DataSet<LabeledDatum<Double, Integer>,Double>(100); int l; double[] x = new double[2]; try { FileInputStream fstream = new FileInputStream(dir + "/binary_test.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); for (int i = 0; i < 100; i++) { String[] parts = br.readLine().split(" "); x[0] = Double.parseDouble(parts[0]); x[1] = Double.parseDouble(parts[1]); l = Integer.parseInt(parts[2]); Dataset.add(new ReviewFeatures(l + " ", l, i, x)); } fstream.close(); in.close(); br.close(); } catch (Exception e) { System.err.println(e.getMessage()); } SoftmaxClassifier<Double, Integer> c = new SoftmaxClassifier<Double, Integer>( ); for(int i=0; i<10; i++) { Accuracy a = c.train(Dataset.Data); System.out.println(a); assertTrue(a.Accuracy == 1.0); } }
@Test public void dummyMultiClassTest (){ int numItems = 400; String dir = "data/parsed"; DataSet<LabeledDatum<Double, Integer>,Double> Dataset = new DataSet<LabeledDatum<Double, Integer>,Double>(numItems); int l = 0; double[] x = new double[2]; try { FileInputStream fstream = new FileInputStream(dir + "/fournary_test.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); for (int i = 0; i < numItems; i++) { String[] parts = br.readLine().split(" "); x[0] = Double.parseDouble(parts[0]); x[1] = Double.parseDouble(parts[1]); l = Integer.parseInt(parts[2]); Dataset.add(new ReviewFeatures(l + " ", l, i, x)); } fstream.close(); in.close(); br.close(); } catch (Exception e) { System.err.println(e.getMessage()); } SoftmaxClassifier<Double, Integer> c = new SoftmaxClassifier<Double, Integer>( ); for(int i=0; i<10; i++) { Accuracy a = c.train(Dataset.Data); System.out.println(a); assertTrue( a.Accuracy == 1.0 ); } }