package de.lmu.ifi.dbs.elki.data.model;

import de.lmu.ifi.dbs.elki.data.RealVector;
import de.lmu.ifi.dbs.elki.normalization.NonNumericFeaturesException;
import de.lmu.ifi.dbs.elki.result.textwriter.TextWriteable;
import de.lmu.ifi.dbs.elki.result.textwriter.TextWriterStream;
import de.lmu.ifi.dbs.elki.utilities.Util;
import de.lmu.ifi.dbs.elki.varianceanalysis.PCAFilteredResult;

/**
 * Cluster model using a filtered PCA result and an centroid.
 * 
 * @author Erich Schubert
 *
 * @param <V>
 */
public class CorrelationModel<V extends RealVector<V, ?>> extends BaseModel implements TextWriteable {
  /**
   * The computed PCA result of this cluster.
   */
  private PCAFilteredResult pcaresult;

  /**
   * The centroid of this cluster.
   */
  private V centroid;

  /**
   * Constructor
   * 
   * @param pcaresult
   * @param centroid
   */
  public CorrelationModel(PCAFilteredResult pcaresult, V centroid) {
    super();
    this.pcaresult = pcaresult;
    this.centroid = centroid;
  }

  /**
   * Get assigned PCA result
   * @return PCA result
   */
  public PCAFilteredResult getPCAResult() {
    return pcaresult;
  }

  /**
   * Assign new PCA result
   * @param pcaresult
   */
  public void setPCAResult(PCAFilteredResult pcaresult) {
    this.pcaresult = pcaresult;
  }

  /**
   * Get assigned for Centroid
   * @return centroid
   */
  public V getCentroid() {
    return centroid;
  }

  /**
   * Assign new Centroid
   * @param centroid
   */
  public void setCentroid(V centroid) {
    this.centroid = centroid;
  }

  /**
   * Implementation of {@link TextWriteable} interface
   */
  @Override
  public void writeToText(TextWriterStream out, String label) {
    super.writeToText(out, label);
    try {
      out.commentPrintLn("Centroid: " + out.normalizationRestore(getCentroid()).toString());
      out.commentPrintLn("Strong Eigenvectors:");
      out.commentPrintLn(getPCAResult().getStrongEigenvectors().toString());
      out.commentPrintLn("Weak Eigenvectors:");
      out.commentPrintLn(getPCAResult().getWeakEigenvectors().toString());
      out.commentPrintLn("Eigenvalues: "+Util.format(getPCAResult().getEigenvalues(), " ", 2));
    }
    catch(NonNumericFeaturesException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}

@@ -1687,36 +1687,93 @@
     
-super.writeToText(out, label
+out.commentPrintLn(TextWriterStream.SER_MARKER+%22 %22 + CorrelationModel.class.getName()
 );%0A 
@@ -1930,35 +1930,32 @@
 ;%0A      
-out.commentPrintLn(
+String strong = 
 getPCARe
@@ -1987,32 +1987,168 @@
 ors().toString()
+;%0A      while (strong.endsWith(%22%5Cn%22)) %7B%0A        strong = strong.substring(0, strong.length()-1);%0A      %7D%0A      out.commentPrintLn(strong
 );%0A      out.com
@@ -2188,35 +2188,30 @@
 ;%0A      
-out.commentPrintLn(
+String weak = 
 getPCARe
@@ -2241,32 +2241,158 @@
 ors().toString()
+;%0A      while (weak.endsWith(%22%5Cn%22)) %7B%0A        weak = weak.substring(0, weak.length()-1);%0A      %7D%0A      out.commentPrintLn(weak
 );%0A      out.com

Remove unneeded whitespace.