ClusterClassifier extends AbstractVectorClassifier implements OnlineLearner, Writable { public List<Cluster> getModels() { return models; } ClusterClassifier(List<Cluster> models);  ClusterClassifier(); @Override Vector classify(Vector instance); @Override double classifyScalar(Vector instance); @Override int numCategories(); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override void train(int actual, Vector instance); void train(int actual, Vector data, double weight); @Override void train(long trackingKey, String groupKey, int actual, Vector instance); @Override void train(long trackingKey, int actual, Vector instance); @Override void close(); List<Cluster> getModels();  }
@Test public void testDMClassifierSerialization() throws Exception { ClusterClassifier classifier = newDMClassifier(); ClusterClassifier classifierOut = writeAndRead(classifier); assertEquals(classifier.getModels().size(), classifierOut.getModels() .size()); assertEquals(classifier.getModels().get(0).getClass().getName(), classifierOut.getModels().get(0).getClass().getName()); }
@Test public void testClusterClassifierSerialization() throws Exception { ClusterClassifier classifier = newClusterClassifier(); ClusterClassifier classifierOut = writeAndRead(classifier); assertEquals(classifier.getModels().size(), classifierOut.getModels() .size()); assertEquals(classifier.getModels().get(0).getClass().getName(), classifierOut.getModels().get(0).getClass().getName()); }
@Test public void testSoftClusterClassifierSerialization() throws Exception { ClusterClassifier classifier = newSoftClusterClassifier(); ClusterClassifier classifierOut = writeAndRead(classifier); assertEquals(classifier.getModels().size(), classifierOut.getModels() .size()); assertEquals(classifier.getModels().get(0).getClass().getName(), classifierOut.getModels().get(0).getClass().getName()); }
@Test public void testGaussianClassifierSerialization() throws Exception { ClusterClassifier classifier = newGaussianClassifier(); ClusterClassifier classifierOut = writeAndRead(classifier); assertEquals(classifier.getModels().size(), classifierOut.getModels() .size()); assertEquals(classifier.getModels().get(0).getClass().getName(), classifierOut.getModels().get(0).getClass().getName()); }
@Test public void testClusterIteratorKMeans() { List<Vector> data = TestKmeansClustering .getPoints(TestKmeansClustering.REFERENCE); ClusteringPolicy policy = new KMeansClusteringPolicy(); ClusterClassifier prior = newClusterClassifier(); ClusterIterator iterator = new ClusterIterator(policy); ClusterClassifier posterior = iterator.iterate(data, prior, 5); assertEquals(3, posterior.getModels().size()); for (Cluster cluster : posterior.getModels()) { System.out .println(cluster.asFormatString(null)); } }
@Test public void testClusterIteratorDirichlet() { List<Vector> data = TestKmeansClustering .getPoints(TestKmeansClustering.REFERENCE); ClusteringPolicy policy = new DirichletClusteringPolicy(3, 1); ClusterClassifier prior = newClusterClassifier(); ClusterIterator iterator = new ClusterIterator(policy); ClusterClassifier posterior = iterator.iterate(data, prior, 5); assertEquals(3, posterior.getModels().size()); for (Cluster cluster : posterior.getModels()) { System.out .println(cluster.asFormatString(null)); } }
@Test public void testClusterIteratorKMeans() { List<Vector> data = TestKmeansClustering .getPoints(TestKmeansClustering.REFERENCE); ClusteringPolicy policy = new KMeansClusteringPolicy(); ClusterClassifier prior = newClusterClassifier(); ClusterIterator iterator = new ClusterIterator(policy); ClusterClassifier posterior = iterator.iterate(data, prior, 5); assertEquals(3, posterior.getModels().size()); for (Cluster cluster : posterior.getModels()) { System.out.println(cluster.asFormatString(null)); } }
@Test public void testClusterIteratorDirichlet() { List<Vector> data = TestKmeansClustering .getPoints(TestKmeansClustering.REFERENCE); ClusteringPolicy policy = new DirichletClusteringPolicy(3, 1); ClusterClassifier prior = newClusterClassifier(); ClusterIterator iterator = new ClusterIterator(policy); ClusterClassifier posterior = iterator.iterate(data, prior, 5); assertEquals(3, posterior.getModels().size()); for (Cluster cluster : posterior.getModels()) { System.out.println(cluster.asFormatString(null)); } }
@Test public void testSeqFileClusterIteratorKMeans() throws IOException { Path pointsPath = getTestTempDirPath("points"); Path priorPath = getTestTempDirPath("prior"); Path outPath = getTestTempDirPath("output"); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); List<VectorWritable> points = TestKmeansClustering .getPointsWritable(TestKmeansClustering.REFERENCE); ClusteringTestUtils.writePointsToFile(points, new Path(pointsPath, "file1"), fs, conf); Path path = new Path(priorPath, "priorClassifier"); ClusterClassifier prior = newClusterClassifier(); writeClassifier(prior, conf, path, fs); assertEquals(3, prior.getModels().size()); System.out.println("Prior"); for (Cluster cluster : prior.getModels()) { System.out.println(cluster.asFormatString(null)); } ClusteringPolicy policy = new KMeansClusteringPolicy(); ClusterIterator iterator = new ClusterIterator(policy); iterator.iterateSeq(pointsPath, path, outPath, 5); for (int i = 1; i <= 5; i++) { System.out.println("Classifier-" + i); ClusterClassifier posterior = readClassifier(conf, new Path(outPath, "classifier-" + i), fs); assertEquals(3, posterior.getModels().size()); for (Cluster cluster : posterior.getModels()) { System.out.println(cluster.asFormatString(null)); } } }