private int initialAssignToNearestCluster(Relation<V> relation,double[][] means,double[][] sums,List<ModifiableDBIDs> clusters,WritableIntegerDataStore assignment,WritableDoubleDataStore upper,WritableDataStore<double[]> lower){
  assert (k == means.length);
  final NumberVectorDistanceFunction<? super V> df=getDistanceFunction();
  final boolean issquared=(df instanceof SquaredEuclideanDistanceFunction);
  for (DBIDIter it=relation.iterDBIDs(); it.valid(); it.advance()) {
    V fv=relation.get(it);
    double[] l=lower.get(it);
    double best=Double.POSITIVE_INFINITY;
    int cur=-1;
    for (int j=0; j < k; j++) {
      double dist=df.distance(fv,DoubleVector.wrap(means[j]));
      dist=issquared ? Math.sqrt(dist) : dist;
      l[j]=dist;
      if (dist < best) {
        cur=j;
        best=dist;
      }
    }
    ModifiableDBIDs newc=clusters.get(cur);
    newc.add(it);
    assignment.putInt(it,cur);
    upper.putDouble(it,best);
    double[] newmean=sums[cur];
    for (int d=0; d < fv.getDimensionality(); d++) {
      newmean[d]+=fv.doubleValue(d);
    }
  }
  return relation.size();
}

private int initialAssignToNearestCluster ( Relation < V > relation , double [ ] [ ] means , double [ ] [ ] sums , List < ModifiableDBIDs > clusters , WritableIntegerDataStore assignment , WritableDoubleDataStore upper , WritableDataStore < double [ ] > lower ) { assert ( k == means . length ) ; final NumberVectorDistanceFunction < ? super V > df = getDistanceFunction ( ) ; final boolean issquared = ( df instanceof SquaredEuclideanDistanceFunction ) ; for ( DBIDIter it = relation . iterDBIDs ( ) ; it . valid ( ) ; it . advance ( ) ) { V fv = relation . get ( it ) ; double [ ] l = lower . get ( it ) ; double best = Double . POSITIVE_INFINITY ; int cur = - 1 ; for ( int j = 0 ; j < k ; j ++ ) { double dist = df . distance ( fv , DoubleVector . wrap ( means [ j ] ) ) ; dist = issquared ? Math . sqrt ( dist ) : dist ; l [ j ] = dist ; if ( dist < best ) { cur = j ; best = dist ; } } ModifiableDBIDs newc = clusters . get ( cur ) ; newc . add ( it ) ; assignment . putInt ( it , cur ) ; upper . putDouble ( it , best ) ; double [ ] newmean = sums [ cur ] ; for ( int d = 0 ; d < fv . getDimensionality ( ) ; d ++ ) { newmean [ d ] += fv . doubleValue ( d ) ; } } return relation . size ( ) ; }
reassign objects , but only if their bounds indicate it is necessary to do so .
