当前位置: 首页>>代码示例>>Java>>正文


Java Cluster类代码示例

本文整理汇总了Java中org.apache.commons.math3.ml.clustering.Cluster的典型用法代码示例。如果您正苦于以下问题:Java Cluster类的具体用法?Java Cluster怎么用?Java Cluster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Cluster类属于org.apache.commons.math3.ml.clustering包,在下文中一共展示了Cluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
private void add(List<Cluster<ClusterableLocation>> clusters) {
  int max = getMax(clusters);
  for (Cluster<ClusterableLocation> cluster : clusters) {
    Geometry geometry = null;
    Symbol symbol = null;
    Color color = cluster.getPoints().size() == max ? Color.RED : Color.GRAY;
    ClusterType thisClusterType = cluster.getPoints().size() < 2 ? ClusterType.POINT : clusterType;
    switch (thisClusterType) {
      default:
      case POINT:
        geometry = getCenter(cluster);
        symbol = createPointSymbol(color, cluster.getPoints().size());
        break;
      case BOUNDING_RECTANGLE:
        geometry = getBoundingRectangle(cluster);
        symbol = createPolygonSymbol(color, cluster.getPoints().size());
        break;
      case CONVEX_HULL:
        geometry = getConvexHull(cluster);
        symbol = createPolygonSymbol(color, cluster.getPoints().size());
        break;
    };
    addGraphic(new Graphic(geometry, symbol));
  }
}
 
开发者ID:Esri,项目名称:arcgis-runtime-demo-java,代码行数:26,代码来源:ClusterLayer.java

示例2: score

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public double score(final List<? extends Cluster<T>> clusters) {
    double varianceSum = 0.0;
    for (final Cluster<T> cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            final Clusterable center = centroidOf(cluster);

            // compute the distance variance of the current cluster
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center));
            }
            varianceSum += stat.getResult();

        }
    }
    return varianceSum;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:SumOfClusterVariances.java

示例3: centroidOf

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Computes the centroid for a cluster.
 *
 * @param cluster the cluster
 * @return the computed centroid for the cluster,
 * or {@code null} if the cluster does not contain any points
 */
protected Clusterable centroidOf(final Cluster<T> cluster) {
    final List<T> points = cluster.getPoints();
    if (points.isEmpty()) {
        return null;
    }

    // in case the cluster is of type CentroidCluster, no need to compute the centroid
    if (cluster instanceof CentroidCluster) {
        return ((CentroidCluster<T>) cluster).getCenter();
    }

    final int dimension = points.get(0).getPoint().length;
    final double[] centroid = new double[dimension];
    for (final T p : points) {
        final double[] point = p.getPoint();
        for (int i = 0; i < centroid.length; i++) {
            centroid[i] += point[i];
        }
    }
    for (int i = 0; i < centroid.length; i++) {
        centroid[i] /= points.size();
    }
    return new DoublePoint(centroid);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:ClusterEvaluator.java

示例4: score

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
@Override
public double score(final List<? extends Cluster<T>> clusters) {
    double varianceSum = 0.0;
    for (final Cluster<T> cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            final Clusterable center = centroidOf(cluster);

            // compute the distance variance of the current cluster
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center));
            }
            varianceSum += stat.getResult();

        }
    }
    return varianceSum;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:SumOfClusterVariances.java

示例5: SimpleOccurrenceClusterer

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
public SimpleOccurrenceClusterer(Iterator<SimpleOccurrence> simpleOccurrences, int minDist) {
    Map<Point2D, SimpleOccurrence> occMap = new HashMap<>();
    out = LinkedListMultimap.create();
    Multimap<Integer, SimpleOccurrence> singletons = LinkedListMultimap.create();
    int counter = 0;

    while(simpleOccurrences.hasNext()) {
        SimpleOccurrence so = simpleOccurrences.next();
        UTMCoordinate utm = so._getUTMCoordinates();
        if(utm != null) {
            if(!so.getPrecision()._isImprecise())
                occMap.put(new Point2DAlwaysDifferent(utm.getX(), utm.getY(), null, null), so);
            else {
                singletons.put(counter, so);
                counter++;
            }
        }
    }
    DBSCANClusterer<Point2D> cls = new DBSCANClusterer<>(minDist, 0);
    List<Cluster<Point2D>> clusters = cls.cluster(occMap.keySet());

    for (int i = 0; i < clusters.size(); i++) {
        for(Point2D p : clusters.get(i).getPoints()) {
            out.put(i + counter, occMap.get(p));
        }
    }
    out.putAll(singletons);
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:29,代码来源:SimpleOccurrenceClusterer.java

示例6: getLocationAreas

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Gets an array of the areas of all locations. Area is computed as the area of the convex hull of each location.
 * @return
 */
public Double[] getLocationAreas() {
    List<Double> areas = new ArrayList<>();
    Stack<Point2D> hull;
    for(Cluster<Point2D> cl : clusters) {
        switch(cl.getPoints().size()) {
            case 1:
                areas.add(10000d);
                break;

            case 2:
                areas.add(20000d);
                break;

            default:
                hull = new GrahamScan(cl.getPoints().toArray(new Point2D[cl.getPoints().size()])).getHull();
                areas.add(new Polygon(hull).area());
                break;
        }
    }
    return areas.toArray(new Double[areas.size()]);
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:26,代码来源:OccurrenceProcessor.java

示例7: getBoundingRectangle

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
private Envelope getBoundingRectangle(Cluster<ClusterableLocation> cluster) {
  double xmin = cluster.getPoints().get(0).getPoint()[0];
  double xmax = xmin;
  double ymin = cluster.getPoints().get(0).getPoint()[1];
  double ymax = ymin;
  for (ClusterableLocation p : cluster.getPoints()) {
    if (p.getPoint()[0] < xmin) {
      xmin = p.getPoint()[0];
    }
    if (p.getPoint()[0] > xmax) {
      xmax = p.getPoint()[0];
    }
    if (p.getPoint()[1] < ymin) {
      ymin = p.getPoint()[1];
    }
    if (p.getPoint()[1] > ymax) {
      ymax = p.getPoint()[1];
    }
  }
  Envelope boundingRectangle = new Envelope(xmin, ymin, xmax, ymax);
  return boundingRectangle;
}
 
开发者ID:Esri,项目名称:arcgis-runtime-demo-java,代码行数:23,代码来源:ClusterLayer.java

示例8: test6

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
@Test
public void test6() throws Exception {
    Clusterer<DoublePoint> clusterer = new KMeansPlusPlusClusterer<DoublePoint>(3);
    List<DoublePoint> list = new ArrayList<>();

    list.add(new DoublePoint(new double[]{1}));
    list.add(new DoublePoint(new double[]{1.5}));
    list.add(new DoublePoint(new double[]{1.8}));
    list.add(new DoublePoint(new double[]{3.5}));
    list.add(new DoublePoint(new double[]{3.6}));
    list.add(new DoublePoint(new double[]{4}));
    list.add(new DoublePoint(new double[]{4.2}));
    System.out.println(list);

    List<? extends Cluster<DoublePoint>> res = clusterer.cluster(list);
    System.out.println("!!!");
    System.out.println(res.size());
    for (Cluster<DoublePoint> re : res) {
        System.out.println(re.getPoints());
    }
}
 
开发者ID:kun368,项目名称:ACManager,代码行数:22,代码来源:MyTest2.java

示例9: expandCluster

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Expands the cluster to include density-reachable items.
 *
 * @param cluster Cluster to expand
 * @param point Point to add to cluster
 * @param neighbors List of neighbors
 * @param points the data set
 * @param visited the set of already visited points
 * @return the expanded cluster
 */
private Cluster<T> expandCluster(final Cluster<T> cluster,
                                 final T point,
                                 final List<T> neighbors,
                                 final Collection<T> points,
                                 final Map<Clusterable, PointStatus> visited) {
    cluster.addPoint(point);
    visited.put(point, PointStatus.PART_OF_CLUSTER);
 
    List<T> seeds = new ArrayList<T>(neighbors);
    int index = 0;
    while (index < seeds.size()) {
        final T current = seeds.get(index);
        PointStatus pStatus = visited.get(current);
        // only check non-visited points
        if (pStatus == null) {
            final List<T> currentNeighbors = getNeighbors(current, points);
            if (currentNeighbors.size() >= minPts) {
                seeds = merge(seeds, currentNeighbors);
            }
        }
 
        if (pStatus != PointStatus.PART_OF_CLUSTER) {
            visited.put(current, PointStatus.PART_OF_CLUSTER);
            cluster.addPoint(current);
        }
 
        index++;
    }
    return cluster;
}
 
开发者ID:yahoo,项目名称:egads,代码行数:41,代码来源:DBSCANClusterer.java

示例10: getPointFromLargestVarianceCluster

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Get a random point from the {@link Cluster} with the largest distance variance.
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 */
private T getPointFromLargestVarianceCluster(final Collection<CentroidCluster<T>> clusters)
        throws ConvergenceException {

    double maxVariance = Double.NEGATIVE_INFINITY;
    Cluster<T> selected = null;
    for (final CentroidCluster<T> cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            // compute the distance variance of the current cluster
            final Clusterable center = cluster.getCenter();
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(point.getWeight() * distance(point, center));
            }
            final double variance = stat.getResult();

            // select the cluster with the largest variance
            if (variance > maxVariance) {
                maxVariance = variance;
                selected = cluster;
            }

        }
    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return selectedPoints.remove(random.nextInt(selectedPoints.size()));

}
 
开发者ID:C0rWin,项目名称:Java-KMeans-Coreset,代码行数:43,代码来源:WeightedKMeansPlusPlusClusterer.java

示例11: getPointFromLargestNumberCluster

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Get a random point from the {@link Cluster} with the largest number of points
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 */
private T getPointFromLargestNumberCluster(final Collection<? extends Cluster<T>> clusters)
        throws ConvergenceException {

    int maxNumber = 0;
    Cluster<T> selected = null;
    for (final Cluster<T> cluster : clusters) {

        // get the number of points of the current cluster
        final int number = cluster.getPoints().size();

        // select the cluster with the largest number of points
        if (number > maxNumber) {
            maxNumber = number;
            selected = cluster;
        }

    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return selectedPoints.remove(random.nextInt(selectedPoints.size()));

}
 
开发者ID:C0rWin,项目名称:Java-KMeans-Coreset,代码行数:36,代码来源:WeightedKMeansPlusPlusClusterer.java

示例12: getFarthestPoint

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Get the point farthest to its cluster center
 *
 * @param clusters the {@link Cluster}s to search
 * @return point farthest to its cluster center
 * @throws ConvergenceException if clusters are all empty
 */
private T getFarthestPoint(final Collection<CentroidCluster<T>> clusters) throws ConvergenceException {

    double maxDistance = Double.NEGATIVE_INFINITY;
    Cluster<T> selectedCluster = null;
    int selectedPoint = -1;
    for (final CentroidCluster<T> cluster : clusters) {

        // get the farthest point
        final Clusterable center = cluster.getCenter();
        final List<T> points = cluster.getPoints();
        for (int i = 0; i < points.size(); ++i) {
            final double distance = points.get(i).getWeight() * distance(points.get(i), center);
            if (distance > maxDistance) {
                maxDistance     = distance;
                selectedCluster = cluster;
                selectedPoint   = i;
            }
        }

    }

    // did we find at least one non-empty cluster ?
    if (selectedCluster == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    return selectedCluster.getPoints().remove(selectedPoint);

}
 
开发者ID:C0rWin,项目名称:Java-KMeans-Coreset,代码行数:37,代码来源:WeightedKMeansPlusPlusClusterer.java

示例13: getNumberOfLocationsInsideProtectedAreas

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
/**
 * Gets the total number of locations which fall inside at least one protected area.
 * If at least one point in the cluster falls inside, then the location is counted.
 * @return
 */
public int getNumberOfLocationsInsideProtectedAreas() {
    int count = 0;
    for(Cluster<Point2D> cl : clusters) {
        for(Point2D p : cl.getPoints()) {
            if(!pointsInPolygons.get(p).iterator().next().isNullPolygon()) {    // exists at least in one protected area
                count++;
                break;
            }
        }
    }
    return count;
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:18,代码来源:OccurrenceProcessor.java

示例14: clusters

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
@operator (
		value = "dbscan",
		can_be_const = false,
		type = IType.LIST,
		category = { IOperatorCategory.STATISTICAL },
		concept = { IConcept.STATISTIC, IConcept.CLUSTERING })
@doc (
		value = "returns the list of clusters (list of instance indices) computed with the dbscan (density-based spatial clustering of applications with noise) algorithm from the first operand data according to the maximum radius of the neighborhood to be considered (eps) and the minimum number of points needed for a cluster (minPts). Usage: dbscan(data,eps,minPoints)",
		special_cases = "if the lengths of two vectors in the right-hand aren't equal, returns 0",
		examples = { @example (value = "dbscan ([[2,4,5], [3,8,2], [1,1,3], [4,3,4]],10,2)", equals = "[]") })
public static IList<GamaList> DBscanApache(final IScope scope, final GamaList data, final Double eps,
		final Integer minPts) throws GamaRuntimeException {

	final DBSCANClusterer<DoublePoint> dbscan = new DBSCANClusterer(eps, minPts);
	final List<DoublePoint> instances = new ArrayList<DoublePoint>();
	for (int i = 0; i < data.size(); i++) {
		final GamaList d = (GamaList) data.get(i);
		final double point[] = new double[d.size()];
		for (int j = 0; j < d.size(); j++) {
			point[j] = Cast.asFloat(scope, d.get(j));
		}
		instances.add(new Instance(i, point));
	}
	final List<Cluster<DoublePoint>> clusters = dbscan.cluster(instances);
	final GamaList results = (GamaList) GamaListFactory.create();
	for (final Cluster<DoublePoint> cl : clusters) {
		final GamaList clG = (GamaList) GamaListFactory.create();
		for (final DoublePoint pt : cl.getPoints()) {
			clG.addValue(scope, ((Instance) pt).getId());
		}
		results.addValue(scope, clG);
	}
	return results;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:35,代码来源:Stats.java

示例15: getCenter

import org.apache.commons.math3.ml.clustering.Cluster; //导入依赖的package包/类
private Point getCenter(Cluster<ClusterableLocation> cluster) {
  double sumx = 0;
  double sumy = 0;
  for (ClusterableLocation p : cluster.getPoints()) {
    sumx += p.getPoint()[0];
    sumy += p.getPoint()[1];
  }
  Point center = new Point(sumx / cluster.getPoints().size(), sumy/ cluster.getPoints().size());
  return center;
}
 
开发者ID:Esri,项目名称:arcgis-runtime-demo-java,代码行数:11,代码来源:ClusterLayer.java


注:本文中的org.apache.commons.math3.ml.clustering.Cluster类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。