private void transform() { for (int i = 1; i <= 10; i++) { for (int j = 0; j < 10; j++) for (int k = 1; k <= 10; k++) { // strings.put(""+i+Utils.intToDigit(j)+k, levenshtein.Utils.transform(new // RecordParser("records\\"+i+"\\"+Utils.intToDigit(j)+"\\"+Utils.intToDigit(j)+k+".txt").parse())); strings.put( "" + i + Utils.intToDigit(j) + k, algorithm.levenshtein.Utils.transform( new RecordParser( "records/" + i + "/" + Utils.intToDigit(j) + "/" + Utils.intToDigit(j) + k + ".txt") .parse())); } System.out.println(i + " transformed"); } }
public void UI() { for (int normalisation = 0; normalisation <= 3; normalisation++) { tw = new TraceWriter("UI2DigitsStochasticLevenshtein3Norm" + normalisation + ".txt"); tw.println( "-------------------------------------------------- User Dependent -------------------------------------------------"); tw.println(); for (int numberTrainingExamples = 3; numberTrainingExamples <= 3; numberTrainingExamples++) { confusionMatrixes.clear(); for (int knn = 0; knn < numberTrainingExamples; knn++) confusionMatrixes.add(new int[10][10]); tw.println( "------------------------------------------- numberTrainingExamples=" + numberTrainingExamples + " ---------------------------------------"); tw.println(); userRecognitionRates = new double[10][9]; for (int user = 1; user <= 10; user++) { UI(user, numberTrainingExamples, normalisation); } for (int knn = 0; knn < confusionMatrixes.size(); knn++) { tw.println( "normalisation=" + normalisation + " numberTrainingExamples=" + numberTrainingExamples + " knn=" + (knn + 1) + " :"); tw.println(); tw.println(Utils.matrixToString(confusionMatrixes.get(knn))); tw.println(Utils.matrixToStringForLatex(confusionMatrixes.get(knn))); double[] informations = Utils.informations(confusionMatrixes.get(knn)); tw.println(); tw.println( "normalisation=" + normalisation + " numberTrainingExamples=" + numberTrainingExamples + " knn=" + (knn + 1) + " :"); tw.println(); for (int user = 0; user < 10; user++) tw.println( "Recognition rate for user" + (user + 1) + " = " + userRecognitionRates[user][knn]); tw.println(); tw.println("Goodclass examples = " + informations[0]); tw.println("Badclass examples = " + informations[1]); tw.println("total examples = " + informations[2]); tw.println("Recognition rate = " + informations[3]); tw.println( "----------------------------------------------------------------------------------------------------------------"); tw.println(); tw.println(); tw.println(); } tw.println( "================================================================================================================"); tw.println(); } tw.close(); } }
public void UI(int user, int numberTrainingExamples, int normalisation) { List<int[][]> userConfusionMatrixes = new ArrayList<int[][]>(); for (int knn = 0; knn < numberTrainingExamples; knn++) userConfusionMatrixes.add(new int[10][10]); for (int firstUserIndex = 1; firstUserIndex <= 10; firstUserIndex++) { String[] alphabet = {"0", "1", "2", "3", "4", "5", "6", "7"}; ConditionalRecognizer cr = new ConditionalRecognizer(alphabet); for (int digitIndex = 0; digitIndex < 10; digitIndex++) { int mod = 0; int threshold = firstUserIndex + numberTrainingExamples; for (int otherUser = firstUserIndex; mod * 10 + otherUser < threshold; otherUser++) { if (otherUser == user) { if (otherUser == 10) { otherUser = 1; mod = 1; } else otherUser++; threshold++; } cr.addTemplate( Utils.intToDigit(digitIndex) + "", strings.get("" + otherUser + Utils.intToDigit(digitIndex) + "1")); if (otherUser == 10) { otherUser = 0; mod = 1; } } } cr.compile(normalisation); for (int knn = numberTrainingExamples; knn <= numberTrainingExamples; knn++) { for (int digitIndex = 0; digitIndex < 10; digitIndex++) { for (int teIndex = 1; teIndex <= 10; teIndex++) { String[] foundDigits = cr.recognizeForAllKnn( strings.get("" + user + Utils.intToDigit(digitIndex) + teIndex), normalisation, knn); for (int i = 0; i < foundDigits.length; i++) { String foundDigit = foundDigits[i]; confusionMatrixes.get(i)[digitIndex][Utils.digitToInt(foundDigit)]++; userConfusionMatrixes.get(i)[digitIndex][Utils.digitToInt(foundDigit)]++; } System.out.println( "norm=" + normalisation + "|nte=" + numberTrainingExamples + "|user="******"|fui=" + firstUserIndex + "|char=" + Utils.intToDigit(digitIndex) + " recognized"); } } } } for (int knn = 0; knn < numberTrainingExamples; knn++) userRecognitionRates[user - 1][knn] = Utils.recognitionRate(userConfusionMatrixes.get(knn)); }