package yi.iu.imgdb.learn.kmeans;

import yi.util.config.*;
import yi.iu.processor.color.reg.*;
import yi.util.io.input.*;
import yi.iu.imgdb.desc.*;
import java.util.*;
import yi.util.io.*;
import yi.ds.*;
import yi.ds.fold.*;
import yi.ai.classifiers.*;
import org.jmat.gui.*;
import org.jmat.data.*;
import java.io.*;
import yi.iu.imgdb.learn.*;



/**
 * KMeansLearnerApp uses KMeansLearner to learn the feature means of different
 * objects.
 */

public class KMeansLearnerApp {
/*
  public static void main(String[] args) {
    // init configuration
    Configuration.init(args);

    // get the image name
    String imgmanager_name = ReadArgu.getOption('i', args);
    if (imgmanager_name == null) {
      System.err.println("Usage: -i imgmanager_name");
      System.exit(1);
    }

    // get the image scale level
    String scale_str = ReadArgu.getOption('s', args);
    int scale = 0;
    if (scale_str != null) {
      scale = Integer.parseInt(scale_str);
    }

    String reuse_file = ReadArgu.getOption('r', args);

    HashMap analysis = null;
    // reuse the results
    if (reuse_file != null) {
      try {
        analysis = (HashMap)yi.util.io.input.DIU_Ser.input(reuse_file);
      } catch (IOException e) {
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (analysis == null) {

      // new image manager
      ImgDescManager img_manager = new ImgDescManager();
      img_manager.readFromFile(imgmanager_name);

      // learn
//      KMeansLearnerApp learner_app = new KMeansLearnerApp(img_manager, scale);

      ImgDBLearnApp app = new ImgDBLearnApp(
          img_manager,
          scale,
          new DPU_ColorRegion(),
          new KMeansLearner(),
          new ClosestNKMeansClassifier(1)
          );

//      AccumulatorHashMap models = (AccumulatorHashMap)app.getModels();
//      System.out.println(learner.toString(models));

      // fold learn
      HashMap classified = app.foldedLearn(5);
      analysis = app.getResultAnalysis(classified);

      if (reuse_file != null) {
        try {
          yi.util.io.output.DOU_Ser.output(reuse_file, analysis);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }


    Collection performances = analysis.values();
    Matrix matrix = ClassificationPerformance.toHistogramMatrix(performances);
    matrix.toPlot3DFrame("performance", "precision vs recall", Plot3DPanel.BAR);

  }
      */
}