use of org.locationtech.geowave.analytic.AnalyticItemWrapperFactory in project geowave by locationtech.
the class KMeansJumpJobRunner method run.
@Override
@SuppressWarnings("unchecked")
public int run(final Configuration configuration, final PropertyManagement propertyManagement) throws Exception {
propertyManagement.store(CentroidParameters.Centroid.ZOOM_LEVEL, currentZoomLevel);
propertyManagement.storeIfEmpty(GlobalParameters.Global.BATCH_ID, UUID.randomUUID().toString());
propertyManagement.storeIfEmpty(CentroidParameters.Centroid.WRAPPER_FACTORY_CLASS, SimpleFeatureItemWrapperFactory.class);
propertyManagement.storeIfEmpty(CommonParameters.Common.DISTANCE_FUNCTION_CLASS, FeatureCentroidDistanceFn.class);
propertyManagement.storeIfEmpty(CentroidParameters.Centroid.EXTRACTOR_CLASS, SimpleFeatureCentroidExtractor.class);
propertyManagement.storeIfEmpty(CommonParameters.Common.DIMENSION_EXTRACT_CLASS, SimpleFeatureGeometryExtractor.class);
propertyManagement.copy(CentroidParameters.Centroid.DATA_TYPE_ID, SampleParameters.Sample.DATA_TYPE_NAME);
propertyManagement.copy(CentroidParameters.Centroid.INDEX_NAME, SampleParameters.Sample.INDEX_NAME);
ClusteringUtils.createAdapter(propertyManagement);
ClusteringUtils.createIndex(propertyManagement);
final String currentBatchId = propertyManagement.getPropertyAsString(GlobalParameters.Global.BATCH_ID, UUID.randomUUID().toString());
try {
final NumericRange rangeOfIterations = propertyManagement.getPropertyAsRange(JumpParameters.Jump.RANGE_OF_CENTROIDS, new NumericRange(2, 200));
propertyManagement.store(GlobalParameters.Global.PARENT_BATCH_ID, currentBatchId);
final DataStorePluginOptions dataStoreOptions = ((PersistableStore) propertyManagement.getProperty(StoreParam.INPUT_STORE)).getDataStoreOptions();
final DistortionGroupManagement distortionGroupManagement = new DistortionGroupManagement(dataStoreOptions);
for (int k = (int) Math.max(2, Math.round(rangeOfIterations.getMin())); k < Math.round(rangeOfIterations.getMax()); k++) {
// regardless of the algorithm, the sample set is fixed in size
propertyManagement.store(SampleParameters.Sample.MIN_SAMPLE_SIZE, k);
propertyManagement.store(SampleParameters.Sample.MAX_SAMPLE_SIZE, k);
propertyManagement.store(SampleParameters.Sample.SAMPLE_SIZE, k);
jumpRunner.setCentroidsCount(k);
jumpRunner.setDataStoreOptions(dataStoreOptions);
final String iterationBatchId = currentBatchId + "_" + k;
propertyManagement.store(GlobalParameters.Global.BATCH_ID, iterationBatchId);
jumpRunner.setReducerCount(k);
final int status = super.run(configuration, propertyManagement);
if (status != 0) {
return status;
}
}
propertyManagement.store(GlobalParameters.Global.BATCH_ID, currentBatchId);
@SuppressWarnings("rawtypes") final Class<AnalyticItemWrapperFactory> analyticItemWrapperFC = propertyManagement.getPropertyAsClass(CentroidParameters.Centroid.WRAPPER_FACTORY_CLASS, AnalyticItemWrapperFactory.class);
/**
* Associate the batch id with the best set of groups so the caller can find the clusters for
* the given batch
*/
final int result = distortionGroupManagement.retainBestGroups((AnalyticItemWrapperFactory<SimpleFeature>) analyticItemWrapperFC.newInstance(), propertyManagement.getPropertyAsString(CentroidParameters.Centroid.DATA_TYPE_ID), propertyManagement.getPropertyAsString(CentroidParameters.Centroid.INDEX_NAME), currentBatchId, currentZoomLevel);
return result;
} catch (final Exception ex) {
LOGGER.error("Cannot create distortions", ex);
return 1;
}
}
use of org.locationtech.geowave.analytic.AnalyticItemWrapperFactory in project geowave by locationtech.
the class GroupAssigmentJobRunnerTest method init.
@Before
public void init() {
final SimpleFeatureType ftype = AnalyticFeature.createGeometryFeatureAdapter("centroidtest", new String[] { "extra1" }, BasicFeatureTypes.DEFAULT_NAMESPACE, ClusteringUtils.CLUSTERING_CRS).getFeatureType();
runner.setMapReduceIntegrater(new MapReduceIntegration() {
@Override
public int submit(final Configuration configuration, final PropertyManagement runTimeProperties, final GeoWaveAnalyticJobRunner tool) throws Exception {
tool.setConf(configuration);
((ParameterHelper<Object>) StoreParam.INPUT_STORE.getHelper()).setValue(configuration, GroupAssignmentMapReduce.class, StoreParam.INPUT_STORE.getHelper().getValue(runTimeProperties));
return tool.run(new String[] {});
}
@Override
public Counters waitForCompletion(final Job job) throws ClassNotFoundException, IOException, InterruptedException {
Assert.assertEquals(SequenceFileInputFormat.class, job.getInputFormatClass());
Assert.assertEquals(10, job.getNumReduceTasks());
final ScopedJobConfiguration configWrapper = new ScopedJobConfiguration(job.getConfiguration(), GroupAssignmentMapReduce.class);
Assert.assertEquals("file://foo/bin", job.getConfiguration().get("mapred.input.dir"));
Assert.assertEquals(3, configWrapper.getInt(CentroidParameters.Centroid.ZOOM_LEVEL, -1));
Assert.assertEquals("b1234", configWrapper.getString(GlobalParameters.Global.PARENT_BATCH_ID, ""));
Assert.assertEquals("b12345", configWrapper.getString(GlobalParameters.Global.BATCH_ID, ""));
try {
final AnalyticItemWrapperFactory<?> wrapper = configWrapper.getInstance(CentroidParameters.Centroid.WRAPPER_FACTORY_CLASS, AnalyticItemWrapperFactory.class, SimpleFeatureItemWrapperFactory.class);
Assert.assertEquals(SimpleFeatureItemWrapperFactory.class, wrapper.getClass());
final DistanceFn<?> distancFn = configWrapper.getInstance(CommonParameters.Common.DISTANCE_FUNCTION_CLASS, DistanceFn.class, GeometryCentroidDistanceFn.class);
Assert.assertEquals(FeatureCentroidDistanceFn.class, distancFn.getClass());
} catch (final InstantiationException e) {
throw new IOException("Unable to configure system", e);
} catch (final IllegalAccessException e) {
throw new IOException("Unable to configure system", e);
}
return new Counters();
}
@Override
public Job getJob(final Tool tool) throws IOException {
return new Job(tool.getConf());
}
@Override
public Configuration getConfiguration(final PropertyManagement runTimeProperties) throws IOException {
return new Configuration();
}
});
runner.setInputFormatConfiguration(new SequenceFileInputFormatConfiguration(new Path("file://foo/bin")));
runner.setZoomLevel(3);
runner.setReducerCount(10);
runTimeProperties.store(MRConfig.HDFS_BASE_DIR, "/");
runTimeProperties.store(GlobalParameters.Global.BATCH_ID, "b12345");
runTimeProperties.store(GlobalParameters.Global.PARENT_BATCH_ID, "b1234");
runTimeProperties.store(CommonParameters.Common.DISTANCE_FUNCTION_CLASS, FeatureCentroidDistanceFn.class);
final DataStorePluginOptions pluginOptions = new DataStorePluginOptions();
GeoWaveStoreFinder.getRegisteredStoreFactoryFamilies().put("memory", new MemoryStoreFactoryFamily());
pluginOptions.selectPlugin("memory");
final MemoryRequiredOptions opts = (MemoryRequiredOptions) pluginOptions.getFactoryOptions();
final String namespace = "test_" + getClass().getName() + "_" + name.getMethodName();
opts.setGeoWaveNamespace(namespace);
final PersistableStore store = new PersistableStore(pluginOptions);
runTimeProperties.store(StoreParam.INPUT_STORE, store);
final FeatureDataAdapter adapter = new FeatureDataAdapter(ftype);
pluginOptions.createAdapterStore().addAdapter(adapter.asInternalAdapter(pluginOptions.createInternalAdapterStore().addTypeName(adapter.getTypeName())));
}
Aggregations