本文整理汇总了Java中org.apache.commons.math3.ml.clustering.Cluster.getPoints方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.getPoints方法的具体用法?Java Cluster.getPoints怎么用?Java Cluster.getPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.ml.clustering.Cluster
的用法示例。
在下文中一共展示了Cluster.getPoints方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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()));
}
示例6: 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()));
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: getConvexHull
import org.apache.commons.math3.ml.clustering.Cluster; //导入方法依赖的package包/类
private Polygon getConvexHull(Cluster<ClusterableLocation> cluster) {
List<ClusterableLocation> pointsList = cluster.getPoints();
ClusterableLocation[] pointsArray = pointsList.toArray(new ClusterableLocation[pointsList.size()]);
ClusterableLocation[] pointsConvexHull = ConvexHullGenerator.generateHull(pointsArray);
Polygon convexHull = new Polygon();
convexHull.startPath(pointsConvexHull[0].getPoint()[0], pointsConvexHull[0].getPoint()[1]);
for (int i = 1; i < pointsConvexHull.length; i++) {
ClusterableLocation p = pointsConvexHull[i];
convexHull.lineTo(p.getPoint()[0], p.getPoint()[1]);
}
convexHull.closePathWithLine();
return convexHull;
}
示例11: cluster
import org.apache.commons.math3.ml.clustering.Cluster; //导入方法依赖的package包/类
public MerescoCluster cluster(int docId) {
for (Cluster<MerescoVector> c : this.clusters) {
List<MerescoVector> points = c.getPoints();
for (MerescoVector oc : points) {
if (oc.docId == docId) {
return rankCluster(c.getPoints());
}
}
}
return null;
}
示例12: centroidOf
import org.apache.commons.math3.ml.clustering.Cluster; //导入方法依赖的package包/类
@Override
public MerescoVector centroidOf(Cluster<MerescoVector> arg0) {
MerescoVector centroid = new MerescoVector();
for (MerescoVector v : arg0.getPoints()) {
centroid.combineToSelf(1.0, 1.0/arg0.getPoints().size(), v);
}
return centroid;
}
示例13: print_cluster
import org.apache.commons.math3.ml.clustering.Cluster; //导入方法依赖的package包/类
private void print_cluster(Cluster<MerescoVector> cl) {
for (MerescoVector v : cl.getPoints()) {
v.printVector(this.ords);
}
}