Exemplo n.º 1
0
  public static void main(String[] args) throws ClassNotFoundException, IOException {

    int nbPCA = 250;
    // String sourcePath = "/Vrac/3000693/RI_Image/bows_" + nbPCA + ".ser";
    String sourcePath = "/Users/remicadene/Dropbox/_Docs/UPMC/RI/bows_" + nbPCA + ".ser";
    int dimpsi = 0;
    Set<String> classes;

    // Modèle MultiClass
    // --------------------------------------------------------------------------------

    // Hyperparamètres
    double eps = 1e-2;
    double lambda = 1e-6;
    int maxIter = 100;

    // Définition du modèle
    DataSet<double[], String> dataSet = VisualIndexes.load(sourcePath);
    classes = dataSet.outputs();

    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;

    int n = classes.size();
    double[][] distances = new double[n][n];
    double[][] new_distances = new double[n][n];
    ILexicalDatabase db = new NictWordNet();
    RelatednessCalculator calculator = new WuPalmer(db);

    HashMap<String, Integer> hm_classes = new HashMap<String, Integer>();
    int id = 0;
    for (String classe : classes) {
      hm_classes.put(classe, id);
      id++;
    }

    for (String word1 : classes) {
      int i = hm_classes.get(word1);
      for (String word2 : classes) {
        int j = hm_classes.get(word2);
        // this.distances[i][j] = calculator.calcRelatednessOfWords(word1, word2);
        if (i == j) {
          distances[i][j] = 0;
        } else {
          distances[i][j] = 1 - calculator.calcRelatednessOfWords(word1, word2);

          if (distances[i][j] < min) {
            min = distances[i][j];
          }
          if (distances[i][j] > max) {
            max = distances[i][j];
          }
        }
      }
    }

    // [a; b] -> [0.1 ; 2]
    // (1.9 * (x - a) / (b - a)) + .1
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j) {
          new_distances[i][j] = (distances[i][j] - min) * (2 - 0.1) / (max - min) + 0.1;
        }
      }
    }

    System.out.println("--------------");

    for (int i = 0; i < classes.size(); i++) {
      for (int j = i + 1; j < classes.size(); j++) {
        System.out.println("[" + i + "," + j + "]");
        System.out.println("avant: " + distances[i][j]);
        System.out.println("apres: " + new_distances[i][j]);
      }
    }

    System.out.println(max);

    System.out.println(min);

    double a =
        0.1 + (2 - 0.1) * (0.6 - 0.0714285714285714) / (0.15384615384615385 - 0.0714285714285714);
  }
Exemplo n.º 2
0
 public MulticlassClassif(String sourcePath) throws ClassNotFoundException, IOException {
   this(VisualIndexes.load(sourcePath));
 }