def train_sim_definition(): Parameters.reset_params_zero() (ch_1_n_f_score, ch_1_n_paramas) = choice_1_COL_MIN_FIRST() (ch_n_n_f_score, ch_n_n_paramas) = choice_N_N_MIN_FIRST() Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_1_MIN = 0 Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_MIN_FIRST = ch_1_n_paramas[1] Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST = ch_1_n_paramas[2] Parameters.PARAMETERS_CHOICE_0_1.CHOICE_N_N_MIN_FIRST = ch_n_n_paramas[3] Parameters.PARAMETERS_CHOICE_0_1.CHOICE_N_N_RANGE_FIRST = ch_n_n_paramas[4] # # Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_1_MIN = 0 # Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_MIN_FIRST = 0.0 # Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST = 1.0 # Parameters.PARAMETERS_CHOICE_0_1.CHOICE_N_N_MIN_FIRST = 1 # Parameters.PARAMETERS_CHOICE_0_1.CHOICE_N_N_RANGE_FIRST = 1.25 # sim_ox_wn_via_svm()
def sim_ox_wn_via_svm(): total_tp = 0.00001 total_tn = 0.00001 total_fn = 0.00001 total_fp = 0.00001 total_pair = 0 dict_ox = OxfordParser.get_dict_nouns() flag_can_go = False for word in dict_ox: # if word == "brook": # flag_can_go = True # # if flag_can_go == False: # continue word_syns_ox = dict_ox[word] wn_synsets = WordnetHandler.get_synsets_for_word(word, "n") m2d_sim = [[0 for x in range(len(word_syns_ox))] for x in range(len(wn_synsets))] if len(word_syns_ox) == 1 and len(wn_synsets) == 1: m2d_sim[0][0] = 1 else: m2d_sim = get_m2d_sim_for_word_from_svm_result(word) if m2d_sim == None: continue # DebugHandler.print_2d_matrix(m2d_sim) m2d_sim = choose_pair_0_1(m2d_sim, len(m2d_sim), len(m2d_sim[0])) # DebugHandler.print_2d_matrix(m2d_sim) pair = count_pair(m2d_sim) total_pair += pair (tp, tn, fn, fp) = CompareWithGold.compareGoldWithResult_without_cal_result(m2d_sim,word) if tp != -1: total_tp += tp total_tn += tn total_fn += fn total_fp += fp precision = total_tp / (total_tp + total_fp) recall = total_tp / (total_tp + total_fn) accuracy = (total_tp + total_tn) / (total_tp + total_tn + total_fp + total_fn) f_score = 0 if precision != 0 or recall != 0: f_score = 2*(precision*recall)/(precision + recall) print "total:" print total_pair print total_tp print total_tn print total_fn print total_fp print precision print recall print f_score print accuracy Parameters.append_result_to_file( precision, recall, f_score, accuracy) current_params = Parameters.get_current_params() current_params = copy.deepcopy(current_params) return f_score, current_params