class PerformanceRecord:
  
  def __init__(self, possibleRewards):
    self.confusionMatrix = ConfusionMatrix(possibleRewards)
    self.accumulatedReward = 0
    self.noVisitedStates = -1 # to exclude start and end
    self.predictedReward = 0

  def recordMove(self, currentStateReward, nextStatePredictedReward):
    self.noVisitedStates += 1
    self.accumulatedReward += currentStateReward
    self.confusionMatrix.addObservation(currentStateReward, self.predictedReward)
    self.predictedReward = nextStatePredictedReward
Beispiel #2
0
 def print_order_confusion_matrix_for_feature(self, out_file=sys.stdout):
     # build and print a confusion matrix for svo
     print("\nComparing results with gold standard from WALS for " + self.label + ":", file=out_file)
     confusion_matrix = ConfusionMatrix(self.label, self.possibilities)
     num_reported = 0
     for code in self.feature_dictionary:
         our_value = self.feature_dictionary[code]
         num_instances = self.feature_instances_dictionary[code]
         if num_instances >= self.min_num_instances:
             try:
                 wals_value = self.wals_gold_standard.get_value_from_iso_language_id(code)
                 confusion_matrix.add_label(wals_value, our_value)
                 num_reported += 1
             except KeyError:
                 pass
                 #  print("No matching SVO WALS data for language " + code)
     print("Num Languages Compared: " + str(num_reported), file=out_file)
     if num_reported > 0:
         print(confusion_matrix.print_matrix(), file=out_file)
 def __init__(self, possibleRewards):
   self.confusionMatrix = ConfusionMatrix(possibleRewards)
   self.accumulatedReward = 0
   self.noVisitedStates = -1 # to exclude start and end
   self.predictedReward = 0
Beispiel #4
0
                feature_dictionary[language_code]="Mixed type"
            if ratio<=.20:
                feature_dictionary[language_code]="Tense-aspect prefixes"

        if feature_dictionary[language_code]!=wals_value:
            output.write(language_code+"\n")
            output.write("Our value "+feature_dictionary[language_code]+" WALS "+wals_value+"\n")
            for igt in igt_list:
                printIGT(igt,output)
    print(language_code,prefix_count,suffix_count,affix_count,no_affix_count,wals_value)

print(str(lang_count),"languages classified")
#find the accuracy

possibilities = ["Tense-aspect prefixes","Tense-aspect suffixes","Mixed type","No tense-aspect inflection","Tense-aspect tone"]
confusion_matrix = ConfusionMatrix("Generated and WALS", possibilities)
correct=0

for code in feature_dictionary:
    our_value = feature_dictionary[code]
    try:
        wals_code = wals_dictionary.iso_to_wals[code]
        wals_value = wals.feature_dictionary[wals_code]
        confusion_matrix.addLabel(wals_value, our_value)
    except KeyError:
        print("No matching WALS data for language " + code)

print(confusion_matrix.printMatrix())

print("baseline accuracy:"+str(baseline_correct/lang_count))
output.close()