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

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