Esempio n. 1
0
 public static void main(String[] args) {
   // Create a training set
   List<Datum<String, String>> trainingData = new ArrayList<>();
   trainingData.add(makeStopLights(GREEN, RED));
   trainingData.add(makeStopLights(GREEN, RED));
   trainingData.add(makeStopLights(GREEN, RED));
   trainingData.add(makeStopLights(RED, GREEN));
   trainingData.add(makeStopLights(RED, GREEN));
   trainingData.add(makeStopLights(RED, GREEN));
   trainingData.add(makeStopLights(RED, RED));
   // Create a test set
   Datum<String, String> workingLights = makeStopLights(GREEN, RED);
   Datum<String, String> brokenLights = makeStopLights(RED, RED);
   // Build a classifier factory
   LinearClassifierFactory<String, String> factory = new LinearClassifierFactory<>();
   factory.useConjugateGradientAscent();
   // Turn on per-iteration convergence updates
   factory.setVerbose(true);
   // Small amount of smoothing
   factory.setSigma(10.0);
   // Build a classifier
   LinearClassifier<String, String> classifier = factory.trainClassifier(trainingData);
   // Check out the learned weights
   classifier.dump();
   // Test the classifier
   System.out.println("Working instance got: " + classifier.classOf(workingLights));
   classifier.justificationOf(workingLights);
   System.out.println("Broken instance got: " + classifier.classOf(brokenLights));
   classifier.justificationOf(brokenLights);
 }
 /** Sets the minimizer to {@link CGMinimizer}, with the passed <code>verbose</code> flag. */
 public void useConjugateGradientAscent(boolean verbose) {
   this.verbose = verbose;
   useConjugateGradientAscent();
 }