コード例 #1
0
  public void UI(int user, int numberTrainingExamples) {
    int[][] userTrainingConfusionMatrix = new int[26][26];
    List<int[][]> usersConfusionMatrixes = new ArrayList<int[][]>();
    for (int i = 0; i < 5; i++) usersConfusionMatrixes.add(new int[26][26]);

    for (int firstTeIndex = 1; firstTeIndex <= 10; firstTeIndex++) {
      Classifier classifier = new Classifier();
      for (int characterIndex = 0; characterIndex < 26; characterIndex++) {
        GestureClass gc = new GestureClass(Utils.intToChar(characterIndex) + "");
        int mod = 0;
        for (int teIndex = firstTeIndex;
            mod * 10 + teIndex
                < firstTeIndex
                    + numberTrainingExamples /*&& (teIndex != firstTeIndex || firstTeIndexPassage)*/;
            teIndex++) {
          Gesture gest = new Gesture();
          // List<Dot> dotSet = (new
          // RecordParser("records\\"+user+"\\"+Utils.intToChar(characterIndex)+"\\"+Utils.intToChar(characterIndex)+teIndex+".txt")).parse();
          List<Dot> dotSet =
              (new RecordParser(
                      "records/"
                          + user
                          + "/"
                          + Utils.intToChar(characterIndex)
                          + "/"
                          + Utils.intToChar(characterIndex)
                          + teIndex
                          + ".txt"))
                  .parse();
          gest.addGesture(dotSet, false, false, false, false);
          gc.addExample(gest);
          if (teIndex == 10) {
            teIndex = 0;
            mod = 1;
          }
        }
        classifier.addClass(gc);
      }
      classifier.compile();

      for (int characterIndex = 0; characterIndex < 26; characterIndex++) {
        int tmp = (firstTeIndex + numberTrainingExamples) % 10;
        if (tmp == 0) tmp = 10;
        for (int teIndex = tmp; teIndex != firstTeIndex; teIndex = (teIndex % 10) + 1) {
          for (int otherUser = 1; otherUser <= 5; otherUser++)
            if (otherUser != user) {
              Gesture toRecognize = new Gesture();
              // List<Dot> dotSet = (new
              // RecordParser("records\\"+user+"\\"+Utils.intToChar(characterIndex)+"\\"+Utils.intToChar(characterIndex)+teIndex+".txt")).parse();
              List<Dot> dotSet =
                  (new RecordParser(
                          "records/"
                              + otherUser
                              + "/"
                              + Utils.intToChar(characterIndex)
                              + "/"
                              + Utils.intToChar(characterIndex)
                              + teIndex
                              + ".txt"))
                      .parse();
              toRecognize.addGesture(dotSet, false, false, false, false);

              char foundChar = classifier.classify(toRecognize).getName().charAt(0);
              confusionMatrix[characterIndex][Utils.charToInt(foundChar)]++;
              userTrainingConfusionMatrix[characterIndex][Utils.charToInt(foundChar)]++;
              usersConfusionMatrixes
                  .get(otherUser - 1)[characterIndex][Utils.charToInt(foundChar)]++;
            }
        }
      }

      System.out.println(
          "nte="
              + numberTrainingExamples
              + "|user="******"|ftei="
              + firstTeIndex
              + " recognized");
    }

    usersTrainingRecognitionRate[user - 1] = Utils.recognitionRate(userTrainingConfusionMatrix);
    for (int i = 0; i < 5; i++)
      if (i != user - 1)
        usersRecognitionRate[i] += Utils.recognitionRate(usersConfusionMatrixes.get(i)) / 4;
  }
コード例 #2
0
 public void UIRubine() {
   for (int i = 1; i <= 15; i += 3) {
     Classifier classifier = new Classifier();
     for (int j = 0; j < 26; j++) {
       GestureClass gc = new GestureClass(Utils.intToChar(j) + "");
       for (int k = 1; k <= 15; k++) {
         if (!(k >= i && k < i + 3)) {
           for (int l = 1; l <= 1; l++) {
             Gesture gest = new Gesture();
             List<Dot> dotSet =
                 (new RecordParser(
                         "records\\"
                             + k
                             + "\\"
                             + Utils.intToChar(j)
                             + "\\"
                             + Utils.intToChar(j)
                             + l
                             + ".txt"))
                     .parse();
             Iterator<Dot> it = dotSet.iterator();
             while (it.hasNext()) {
               Dot dot = it.next();
               if (dot.valid) gest.addPoint(dot.posX, dot.posY, dot.time_millis);
             }
             gc.addExample(gest);
           }
         }
       }
       classifier.addClass(gc);
       System.out.println(i + gc.getName());
     }
     classifier.compile();
     for (int j = i; j < i + 3; j++) {
       for (int k = 0; k < 26; k++) {
         for (int l = 1; l <= 10; l++) {
           Gesture toRecognize = new Gesture();
           List<Dot> dotSet =
               (new RecordParser(
                       "records\\"
                           + j
                           + "\\"
                           + Utils.intToChar(k)
                           + "\\"
                           + Utils.intToChar(k)
                           + l
                           + ".txt"))
                   .parse();
           Iterator<Dot> it = dotSet.iterator();
           while (it.hasNext()) {
             Dot dot = it.next();
             if (dot.valid) toRecognize.addPoint(dot.posX, dot.posY, dot.time_millis);
           }
           char foundChar = classifier.classify(toRecognize).getName().charAt(0);
           confusionMatrix[k][Utils.charToInt(foundChar)]++;
         }
       }
     }
     System.out.println("check :" + i);
   }
 }