Ejemplo n.º 1
0
 @Test
 public void testConstructFromProbability() {
   float[] probability = {0.0f, 0.125f, 0.375f, 0.0f, 0.5f, 0.0f};
   CategoricalPrediction prediction = new CategoricalPrediction(probability);
   assertEquals(FeatureType.CATEGORICAL, prediction.getFeatureType());
   assertEquals(4, prediction.getMostProbableCategoryID());
   assertNull(prediction.getCategoryCounts());
   assertArrayEquals(probability, prediction.getCategoryProbabilities());
 }
Ejemplo n.º 2
0
 @Test
 public void testConstruct() {
   int[] counts = {0, 1, 3, 0, 4, 0};
   CategoricalPrediction prediction = new CategoricalPrediction(counts);
   assertEquals(FeatureType.CATEGORICAL, prediction.getFeatureType());
   assertEquals(4, prediction.getMostProbableCategoryID());
   assertArrayEquals(counts, prediction.getCategoryCounts());
   assertArrayEquals(
       new float[] {0.0f, 0.125f, 0.375f, 0.0f, 0.5f, 0.0f},
       prediction.getCategoryProbabilities());
 }
Ejemplo n.º 3
0
 @Test
 public void testUpdate() {
   int[] counts = {0, 1, 3, 0, 4, 0};
   CategoricalPrediction prediction = new CategoricalPrediction(counts);
   Example example = new Example(CategoricalFeature.forValue(2));
   prediction.update(example);
   prediction.update(example);
   assertEquals(2, prediction.getMostProbableCategoryID());
   counts[2] += 2;
   assertArrayEquals(counts, prediction.getCategoryCounts());
   assertArrayEquals(
       new float[] {0.0f, 0.1f, 0.5f, 0.0f, 0.4f, 0.0f}, prediction.getCategoryProbabilities());
 }