Search in sources :

Example 1 with AnalyticItemWrapper

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));
}
Also used : LongCentroid(org.locationtech.geowave.analytic.clustering.LongCentroid) ArrayList(java.util.ArrayList) StableChangeBreakStrategy(org.locationtech.geowave.analytic.mapreduce.kmeans.runner.StripWeakCentroidsRunner.StableChangeBreakStrategy) TailStableChangeBreakStrategy(org.locationtech.geowave.analytic.mapreduce.kmeans.runner.StripWeakCentroidsRunner.TailStableChangeBreakStrategy) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper) Test(org.junit.Test)

Example 2 with AnalyticItemWrapper

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));
}
Also used : LongCentroid(org.locationtech.geowave.analytic.clustering.LongCentroid) TailMaxBreakStrategy(org.locationtech.geowave.analytic.mapreduce.kmeans.runner.StripWeakCentroidsRunner.TailMaxBreakStrategy) ArrayList(java.util.ArrayList) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper) Test(org.junit.Test)

Example 3 with AnalyticItemWrapper

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();
    }
}
Also used : Serializable(java.io.Serializable) MalformedURLException(java.net.MalformedURLException) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) HashMap(java.util.HashMap) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOException(java.io.IOException) URL(java.net.URL) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper)

Example 4 with AnalyticItemWrapper

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);
}
Also used : SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 5 with AnalyticItemWrapper

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper)

Aggregations

AnalyticItemWrapper (org.locationtech.geowave.analytic.AnalyticItemWrapper)12 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 LongCentroid (org.locationtech.geowave.analytic.clustering.LongCentroid)5 SimpleFeature (org.opengis.feature.simple.SimpleFeature)5 SimpleFeatureItemWrapperFactory (org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CentroidManagerGeoWave (org.locationtech.geowave.analytic.clustering.CentroidManagerGeoWave)2 TailMaxBreakStrategy (org.locationtech.geowave.analytic.mapreduce.kmeans.runner.StripWeakCentroidsRunner.TailMaxBreakStrategy)2 TailStableChangeBreakStrategy (org.locationtech.geowave.analytic.mapreduce.kmeans.runner.StripWeakCentroidsRunner.TailStableChangeBreakStrategy)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 Transaction (org.geotools.data.Transaction)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1