use of org.locationtech.geowave.analytic.AnalyticItemWrapper in project geowave by locationtech.
the class StripWeakCentroidsRunnerTest method testStable1.
@Test
public void testStable1() throws Exception {
final List<AnalyticItemWrapper<Long>> list = new ArrayList<>();
final int[] cnts = new int[] { 1000, 851, 750, 650, 525, 200, 100, 90, 70 };
for (int i = 0; i < cnts.length; i++) {
list.add(new LongCentroid(i, "", cnts[i]));
}
final StableChangeBreakStrategy<Long> breakS = new StableChangeBreakStrategy<>();
assertEquals(5, breakS.getBreakPoint(list));
}
use of org.locationtech.geowave.analytic.AnalyticItemWrapper in project geowave by locationtech.
the class StripWeakCentroidsRunnerTest method testMaxUniform.
@Test
public void testMaxUniform() throws Exception {
final List<AnalyticItemWrapper<Long>> list = new ArrayList<>();
final int[] cnts = new int[] { 1000, 851, 750, 650, 525, 200, 90, 70 };
for (int i = 0; i < cnts.length; i++) {
list.add(new LongCentroid(i, "", cnts[i]));
}
final TailMaxBreakStrategy<Long> breakS = new TailMaxBreakStrategy<>();
assertEquals(5, breakS.getBreakPoint(list));
}
use of org.locationtech.geowave.analytic.AnalyticItemWrapper in project geowave by locationtech.
the class CentroidManagerGeoWave method toShapeFile.
public void toShapeFile(final String parentDir, final Class<? extends Geometry> shapeClass) throws IOException {
// File shp = new File(parentDir + "/" + this.batchId + ".shp");
// File shx = new File(parentDir + "/" + this.batchId + ".shx");
final ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
final Map<String, Serializable> params = new HashMap<>();
try {
params.put("url", new URL("file://" + parentDir + "/" + this.batchId + ".shp"));
} catch (final MalformedURLException e) {
LOGGER.error("Error creating URL", e);
}
params.put("create spatial index", Boolean.TRUE);
final List<AnalyticItemWrapper<T>> centroids = loadCentroids(batchId, null);
final ToSimpleFeatureConverter<T> converter = getFeatureConverter(centroids, shapeClass);
final ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
newDataStore.createSchema(converter.getFeatureType());
final Transaction transaction = new DefaultTransaction("create");
final String typeName = newDataStore.getTypeNames()[0];
try (final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriterAppend(typeName, transaction)) {
for (final AnalyticItemWrapper<T> item : centroids) {
final SimpleFeature copy = writer.next();
final SimpleFeature newFeature = converter.toSimpleFeature(item);
for (final AttributeDescriptor attrD : newFeature.getFeatureType().getAttributeDescriptors()) {
// the null case should only happen for geometry
if (copy.getFeatureType().getDescriptor(attrD.getName()) != null) {
copy.setAttribute(attrD.getName(), newFeature.getAttribute(attrD.getName()));
}
}
// shape files force geometry name to be 'the_geom'. So isolate
// this change
copy.setDefaultGeometry(newFeature.getDefaultGeometry());
writer.write();
}
} catch (final IOException e) {
LOGGER.warn("Problem with the FeatureWritter", e);
transaction.rollback();
} finally {
transaction.commit();
transaction.close();
}
}
use of org.locationtech.geowave.analytic.AnalyticItemWrapper in project geowave by locationtech.
the class DistortionGroupManagementTest method test.
@Test
public void test() throws IOException {
final DistortionGroupManagement distortionGroupManagement = new DistortionGroupManagement(storePluginOptions);
distortionGroupManagement.retainBestGroups(new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), index.getName(), "b1", 1);
final CentroidManagerGeoWave<SimpleFeature> centroidManager = new CentroidManagerGeoWave<>(storePluginOptions.createDataStore(), storePluginOptions.createIndexStore(), storePluginOptions.createAdapterStore(), new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), storePluginOptions.createInternalAdapterStore().getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1);
final List<String> groups = centroidManager.getAllCentroidGroups();
assertEquals(2, groups.size());
final boolean[] groupFound = new boolean[2];
for (final String grpId : groups) {
final List<AnalyticItemWrapper<SimpleFeature>> items = centroidManager.getCentroidsForGroup(grpId);
assertEquals(2, items.size());
if ("grp1".equals(grpId)) {
groupFound[0] = true;
assertTrue("pearl".equals(items.get(0).getName()) || "roxy".equals(items.get(0).getName()));
} else if ("grp2".equals(grpId)) {
groupFound[1] = true;
assertTrue("chip".equals(items.get(0).getName()) || "bamm-bamm".equals(items.get(0).getName()));
}
}
// each unique group is found?
int c = 0;
for (final boolean gf : groupFound) {
c += (gf ? 1 : 0);
}
assertEquals(2, c);
}
use of org.locationtech.geowave.analytic.AnalyticItemWrapper in project geowave by locationtech.
the class KMeansIterationsJobRunner method checkForConvergence.
private boolean checkForConvergence(final CentroidManager<T> centroidManager, final DistanceFn<T> distanceFunction) throws IOException {
final AtomicInteger grpCount = new AtomicInteger(0);
final AtomicInteger failuresCount = new AtomicInteger(0);
final AtomicInteger centroidCount = new AtomicInteger(0);
final boolean status = centroidManager.processForAllGroups(new CentroidProcessingFn<T>() {
@Override
public int processGroup(final String groupID, final List<AnalyticItemWrapper<T>> centroids) {
grpCount.incrementAndGet();
centroidCount.addAndGet(centroids.size() / 2);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Parent Group: {} ", groupID);
for (final AnalyticItemWrapper<T> troid : centroids) {
LOGGER.warn("Child Group: {} ", troid.getID());
}
}
failuresCount.addAndGet(computeCostAndCleanUp(groupID, centroids, centroidManager, distanceFunction));
return 0;
}
}) == 0 ? true : false;
// update default based on data size
setReducerCount(grpCount.get() * centroidCount.get());
return status && (failuresCount.get() == 0);
}
Aggregations