@Override public void consumeKeyMessage(String key, String message, Configuration hadoopConf) throws IOException { switch (key) { case "UP": // do nothing, hearing our own updates break; case "MODEL": case "MODEL-REF": log.info("Loading new model"); PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf); if (pmml == null) { return; } KMeansPMMLUtils.validatePMMLVsSchema(pmml, inputSchema); model = new KMeansSpeedModel(KMeansPMMLUtils.read(pmml)); log.info("New model loaded: {}", model); break; default: throw new IllegalArgumentException("Bad key: " + key); } }
private static List<ClusterInfo> getClusters() { return KMeansPMMLUtils.read(KMeansPMMLUtilsTest.buildDummyClusteringModel()); }
@Override public void consumeKeyMessage(String key, String message, Configuration hadoopConf) throws IOException { switch (key) { case "UP": if (model == null) { return; // No model to interpret with yet, so skip it } List<?> update = TextUtils.readJSON(message, List.class); // Update int id = Integer.parseInt(update.get(0).toString()); double[] center = TextUtils.convertViaJSON(update.get(1), double[].class); long count = Long.parseLong(update.get(2).toString()); model.update(id, center, count); break; case "MODEL": case "MODEL-REF": log.info("Loading new model"); PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf); if (pmml == null) { return; } KMeansPMMLUtils.validatePMMLVsSchema(pmml, inputSchema); List<ClusterInfo> clusters = KMeansPMMLUtils.read(pmml); model = new KMeansServingModel(clusters, inputSchema); log.info("New model: {}", model); break; default: throw new IllegalArgumentException("Bad key: " + key); } }
JavaRDD<Vector> evalData = parsedToVectorRDD(trainData.union(testData).map(MLFunctions.PARSE_FN)); List<ClusterInfo> clusterInfoList = KMeansPMMLUtils.read(model);
@Test public void testPMMLToClusters() { PMML pmml = buildDummyClusteringModel(); List<ClusterInfo> clusterInfoList = KMeansPMMLUtils.read(pmml); assertEquals(NUM_CLUSTERS, clusterInfoList.size()); assertEquals(NUM_DIMENSIONS, clusterInfoList.get(0).getCenter().length); assertEquals(CLUSTER_SIZE, clusterInfoList.get(1).getCount()); }
@Override public void consumeKeyMessage(String key, String message, Configuration hadoopConf) throws IOException { switch (key) { case "UP": // do nothing, hearing our own updates break; case "MODEL": case "MODEL-REF": log.info("Loading new model"); PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf); if (pmml == null) { return; } KMeansPMMLUtils.validatePMMLVsSchema(pmml, inputSchema); model = new KMeansSpeedModel(KMeansPMMLUtils.read(pmml)); log.info("New model loaded: {}", model); break; default: throw new IllegalArgumentException("Bad key: " + key); } }