/*
(non-Javadoc)

@see moa.clusterers.Clusterer#getClusteringResult()
554718
@Override
	public Clustering getClusteringResult() {
		List<double[]> microClustering;
		// If the buffer phase is active then the buffer (without duplicates) is
		// equal to the micro clustering
		if (this.bufferPhase) {
			microClustering = new ArrayList<double[]>(this.buffer.size());
			for (double[] pointA : this.buffer) {
				// Searches for a duplicate of the current point
				boolean duplicate = false;
				for (double[] pointB : microClustering) {
					int i;
					for (i = 0; i < pointA.length; i++) {
						if (pointA[i] != pointB[i + 1]) {
							break;
						}
					}
					if (i == pointA.length) {
						duplicate = true;
						pointB[0] += 1;
						break;
					}
				}

				if (!duplicate) {
					// Copies the point to an array with the weight in the first
					// element
					double[] pointWeighted = new double[pointA.length + 1];
					pointWeighted[0] = 1;
					System.arraycopy(pointA, 0, pointWeighted, 1, pointA.length);
					microClustering.add(pointWeighted);
				}
			}
		} else {
			// Collects all nodes as arrays with the weight in the first element
			microClustering = this.root
					.addToClusteringCenters(new ArrayList<double[]>(this.rootCount));
		}
		// Runs the k-means algorithm five times on the micro clustering
		List<double[]> result = null;
		double minValue = Double.POSITIVE_INFINITY;
		for (int i = 0; i < 5; i++) {
			// Creates the starting centroids
			List<double[]> newResult = CoresetKMeans
					.generatekMeansPlusPlusCentroids(this.numClusters,
							microClustering, this.clustererRandom);
			// Runs the k-means algorithm with changing the starting centroids
			double newValue = CoresetKMeans.kMeans(newResult, microClustering);
			// Selects the result with minimum costs
			if (newValue < minValue) {
				result = newResult;
				minValue = newValue;
			}
		}

		// Prepares the points for the clustering result
		AutoExpandVector<Cluster> resultClustering = new AutoExpandVector<Cluster>(
				result.size());
		for (double[] point : result) {
			resultClustering.add(new SphereCluster(point, 0.0));
		}
		return new Clustering(resultClustering);
	}
537894
@Override
  public void processNewResult(ResultHierarchy hier, Result result) {
    // Get all new clusterings
    // TODO: handle clusterings added later, too. Can we update the result?

    List<Clustering<?>> clusterings = Clustering.getClusteringResults(result);
    // Abort if not enough clusterings to compare
    if(clusterings.size() < 2) {
      return;
    }

    // create segments
    Segments segments = new Segments(clusterings);
    hier.add(result, segments);
  }
387428
public List<double[]> addToClusteringCenters(List<double[]> clustering) {
		if (center != null && getClusteringFeature() != null) {
			clustering.add(getClusteringFeature().toClusterCenter());
		}
		for (ClusteringTreeNode child : children) {
			child.addToClusteringCenters(clustering);
		}
		return clustering;
	}
993744
public ResultSet getResults() {
        final SQLListenerContextImpl context = startContext(connection(), queryMixin.getMetadata());
        String queryString = null;
        List<Object> constants = ImmutableList.of();

        try {
            listeners.preRender(context);
            SQLSerializer serializer = serialize(false);
            queryString = serializer.toString();
            logQuery(queryString, serializer.getConstants());
            context.addSQL(getSQL(serializer));
            listeners.rendered(context);

            listeners.notifyQuery(queryMixin.getMetadata());

            constants = serializer.getConstants();

            listeners.prePrepare(context);
            final PreparedStatement stmt = getPreparedStatement(queryString);
            setParameters(stmt, constants, serializer.getConstantPaths(), getMetadata().getParams());
            context.addPreparedStatement(stmt);
            listeners.prepared(context);

            listeners.preExecute(context);
            final ResultSet rs = stmt.executeQuery();
            listeners.executed(context);

            return new ResultSetAdapter(rs) {
                @Override
                public void close() throws SQLException {
                    try {
                        super.close();
                    } finally {
                        stmt.close();
                        reset();
                        endContext(context);
                    }
                }
            };
        } catch (SQLException e) {
            onException(context, e);
            reset();
            endContext(context);
            throw configuration.translate(queryString, constants, e);
        }
    }
530197
public double evaluateClusteringPerformance(Clustering clustering, Clustering trueClustering, ArrayList<DataPoint> points) throws Exception{
        long start = System.nanoTime();
        evaluateClustering(clustering, trueClustering, points);
        long duration = System.nanoTime()-start;
        time+=duration;
        duration/=10e5;
        return duration;
     }
871929
public int getIncrementalMinResultSizeAndReset() {
        int retval = m_workerTask.m_incrMinResultSize;
        m_workerTask.m_incrMinResultSize = Integer.MAX_VALUE;
        if (isCoordinatorStatsUsable(true)) {
            m_coordinatorTask.m_incrMinResultSize = Integer.MAX_VALUE;
        }
        return retval;
    }
373518
protected int currentCluster(List<? extends ModifiableDBIDs> clusters, DBIDRef id) {
    for(int i = 0; i < k; i++) {
      if(clusters.get(i).contains(id)) {
        return i;
      }
    }
    return -1;
  }
958262
public int getHighestClusterCount() {
    int maxClusters = 0;

    for(int i = 0; i < numclusters.length; i++) {
      maxClusters = Math.max(maxClusters, numclusters[i]);
    }
    return maxClusters;
  }
1116288
@Override
    @Synchronized
    public Set<Host> getClusterMembers() {
        if (!cache.isPresent()) {
            initializeCache();
        }
        List<ChildData> data = cache.get().getCurrentData();
        return data.stream()
                .map(d -> Host.fromBytes(d.getData()))
                .collect(Collectors.toSet());
    }
769490
public SearchResultsObjectPool getSearchResultsObjectPool() {
        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled()) {
            SibTr.entry(tc, "getSearchResultsObjectPool");
            SibTr.exit(tc, "getSearchResultsObjectPool", _connectionToMP);
        }
        return _searchResultsPool;
    }
832775
@Override
  public FacetResult[] getFacetResults() {
    if (facets == null || facets.isEmpty()) {
      return new FacetResult[0];
    }
    Collection<FacetResult> facetResults = facets.values();
    return facetResults.toArray(new FacetResult[facetResults.size()]);
  }
1146692
public boolean isSingleMember() {
		final Address localAddress = getLocalAddress();
		if (localAddress != null) {
			final List<Address> clusterMembers = getClusterMembers();
			return clusterMembers.size() == 1;
		}
		else {
			return true;
		}
	}
523678
@Override
	public AverageClusteringCoefficient<K, VV, EV> run(Graph<K, VV, EV> input)
			throws Exception {
		super.run(input);

		DataSet<LocalClusteringCoefficient.Result<K>> localClusteringCoefficient = input
			.run(new LocalClusteringCoefficient<K, VV, EV>()
				.setParallelism(parallelism));

		averageClusteringCoefficientHelper = new AverageClusteringCoefficientHelper<>();

		localClusteringCoefficient
			.output(averageClusteringCoefficientHelper)
				.name("Average clustering coefficient");

		return this;
	}
968633
public Object initResult()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "initResult");

    //theResults = new ArrayList();
    Object theResults = new TopicAclTraversalResults();
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "initResult");
    return theResults;
  }
1203265
int getClusterUserIndex(int cluster, int index) {
		int i = getClusterIndex_(cluster);
		AttributeStreamOfInt32 stream = m_clusterIndices.get(index);
		if (stream.size() <= i)
			return -1;
		return stream.read(i);
	}
41497
public GetClusterResponse getCluster(GetClusterRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getClusterId(), "The parameter clusterId should not be null or empty string.");

        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.GET, CLUSTER, request.getClusterId());

        return this.invokeHttpClient(internalRequest, GetClusterResponse.class);
    }
229806
protected Object getObjectFromResultSet() throws PersistenceBrokerException
    {
        Object[] result = new Object[columnCount];
        for (int i = 0; i < columnCount; i++)
        {
            try
            {
                int jdbcType = rsMetaData.getColumnType(i + 1);
                Object item = JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType), i + 1);
                result[i] = item;
            }
            catch (SQLException e)
            {
                throw new PersistenceBrokerException(e);
            }
        }
        return result;
    }