@@ -0,0 +1,1580 @@
+package de.lmu.ifi.dbs.elki.normalization;%0A%0Aimport java.util.BitSet;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport de.lmu.ifi.dbs.elki.data.SparseFloatVector;%0Aimport de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;%0A%0A/**%0A * Perform full TF-IDF Normalization as commonly used in text mining.%0A * %0A * Each record is first normalized using %22term frequencies%22 to sum up to 1. Then%0A * it is globally normalized using the Inverse Document Frequency, so rare terms%0A * are weighted stronger than common terms.%0A * %0A * Restore will only undo the IDF part of the normalization!%0A * %0A * @author Erich Schubert%0A */%0Apublic class TFIDFNormalization extends InverseDocumentFrequencyNormalization %7B%0A  /**%0A   * Constructor, adhering to%0A   * %7B@link de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable%7D%0A   * %0A   * @param config Parameterization%0A   */%0A  public TFIDFNormalization(Parameterization config) %7B%0A    super(config);%0A  %7D%0A%0A  @Override%0A  protected SparseFloatVector normalize(SparseFloatVector featureVector) %7B%0A    BitSet b = featureVector.getNotNullMask();%0A    double sum = 0.0;%0A    for(int i = b.nextSetBit(0); i %3E= 0; i = b.nextSetBit(i + 1)) %7B%0A      sum += featureVector.doubleValue(i);%0A    %7D%0A    if(sum %3C= 0) %7B%0A      sum = 1.0;%0A    %7D%0A    Map%3CInteger, Float%3E vals = new HashMap%3CInteger, Float%3E();%0A    for(int i = b.nextSetBit(0); i %3E= 0; i = b.nextSetBit(i + 1)) %7B%0A      vals.put(i, (float) (featureVector.doubleValue(i) / sum * idf.get(i).doubleValue()));%0A    %7D%0A    return new SparseFloatVector(vals, featureVector.getDimensionality());%0A  %7D%0A%7D

Add TF-IDF Normalization