def test_inference(self): m = 100 y1, (ha1, hb1), y2, (ha2, hb2) = negative_generate_simulate(m, 2) for name_div in AVAILABLE_NAME_DIVER: d1 = calculate_item_in_diversity(name_div, ha1, hb1, y1, m) d2 = calculate_item_in_diversity(name_div, ha2, hb2, y2, m) self.assertEqual(d1, d2) T = 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) for name_div in AVAILABLE_NAME_DIVER: d1 = calculate_overall_diversity(name_div, yt1, y1, m, T) d2 = calculate_overall_diversity(name_div, yt2, y2, m, T) self.assertEqual(d1, d2)
def test_nonpairwise_ensem(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) for name_div in NONPAIRWISE: d1 = nonpairwise_measure_overall_value(name_div, yt1, y1, m, T) d2 = nonpairwise_measure_overall_value(name_div, yt2, y2, m, T) self.assertEqual(d1, d2)
def test_negative_generate_simulated(self): y1, yt1, y2, yt2 = negative_generate_simulate(300, 81) h1 = np.unique(np.concatenate([[y1], yt1])).tolist() h2 = np.unique(np.concatenate([[y2], yt2])).tolist() self.assertEqual((len(h1) == 2) and (len(h2) == 2), True) self.assertEqual((0 in h1) and (1 in h1), True) self.assertEqual((-1 in h2) and (1 in h2), True)
def test_Q_Statistic(self): m = 100 _, yt1, _, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 d1 = Q_Statistic_binary(ha1, hb1) d2 = Q_Statistic_binary(ha2, hb2) self.assertEqual(d1, d2)
def test_Correlation_Coefficient(self): m = 100 _, yt1, _, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 d1 = Correlation_Coefficient_binary(ha1, hb1) d2 = Correlation_Coefficient_binary(ha2, hb2) self.assertEqual(d1, d2)
def test_Interrater_agreement(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Interrater_agreement_multiclass(yt1, y1, m, T) d2 = Interrater_agreement_multiclass(yt2, y2, m, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Interrater_agreement_multiclass(yt3, y3, m, T) self.assertEqual(isinstance(d3, float), True)
def test_Entropy_SK(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Entropy_sk_multiclass(yt1, y1, m, T) d2 = Entropy_sk_multiclass(yt2, y2, m, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Entropy_sk_multiclass(yt3, y3, m, T) self.assertEqual(d3 >= 0, True)
def test_Difficulty(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Difficulty_multiclass(yt1, y1, T) d2 = Difficulty_multiclass(yt2, y2, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Difficulty_multiclass(yt3, y3, T) self.assertEqual(d3 >= 0, True)
def test_Coincident_Failure(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Coincident_Failure_multiclass(yt1, y1, m, T) d2 = Coincident_Failure_multiclass(yt2, y2, m, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Coincident_Failure_multiclass(yt3, y3, m, T) self.assertEqual(d3 >= 0, True)
def test_nonpairwise_item(self): m = 100 y1, yt1, y2, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 for name_div in NONPAIRWISE: d1 = nonpairwise_measure_for_item(name_div, ha1, hb1, y1, m) d2 = nonpairwise_measure_for_item(name_div, ha2, hb2, y2, m) self.assertEqual(d1, d2)
def test_Generalized_Diversity(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Generalized_Diversity_multiclass(yt1, y1, m, T) d2 = Generalized_Diversity_multiclass(yt2, y2, m, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Generalized_Diversity_multiclass(yt3, y3, m, T) self.assertEqual(d3 >= 0, True) self.assertEqual(d3 <= 1, True)
def test_overall_pruning(self): m, L, nb_cls, nb_pru = 20, 2, 11, 5 _, _, y, yt = negative_generate_simulate(m, nb_cls) for name_pru in AVAILABLE_NAME_PRUNE: yo, P, flag = existing_contrastive_pruning_method( name_pru, yt, y, nb_cls, nb_pru) if name_pru in ['OO', 'DREP', 'SEP', 'OEP', 'PEP', 'PEP+', 'LCS']: self.assertEqual(len(P) <= nb_cls, True) else: self.assertEqual(len(P), nb_pru) if name_pru == 'OO': self.assertEqual(0. <= flag <= 180., True) self.assertEqual(all(np.unique(yo) == np.array([-1, 1])), True) del L
def test_KW_Variance(self): m, T = 100, 21 y1, yt1, y2, yt2 = negative_generate_simulate(m, T) d1 = Kohavi_Wolpert_Variance_multiclass(yt1, y1, m, T) d2 = Kohavi_Wolpert_Variance_multiclass(yt2, y2, m, T) self.assertEqual(d1, d2) y3, yt3 = generate_simulated_data(m, 7, T) d3 = Kohavi_Wolpert_Variance_multiclass(yt3, y3, m, T) # self.assertEqual(d3 >= 3./8, True) # only for binary # |-> Nope, all of them belong to [0, 1/2] self.assertEqual(d3 <= 1./2, True) self.assertEqual(d3 >= 0., True) self.assertEqual(0. < d1 <= 1./2, True) self.assertEqual(0. < d2 <= 1./2, True)
def test_Double_Fault_Measure(self): m = 100 y1, yt1, y2, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 d1 = Double_Fault_Measure_binary(ha1, hb1, y1, m) d2 = Double_Fault_Measure_binary(ha2, hb2, y2, m) self.assertEqual(d1, d2) d3 = Double_Fault_Measure_multiclass(ha1, hb1, y1, m) d4 = Double_Fault_Measure_multiclass(ha2, hb2, y2, m) self.assertEqual(d3, d4) self.assertEqual(d1, d3) self.assertEqual(d2, d4) y3, yt3 = generate_simulated_data(m, 7, 2) d3 = Double_Fault_Measure_multiclass(yt3[0], yt3[1], y3, m) self.assertEqual(0 <= d3 <= 1.0, True)
def test_Kappa_Statistic(self): m = 100 y1, yt1, y2, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 d1 = Kappa_Statistic_binary(ha1, hb1, m) d2 = Kappa_Statistic_binary(ha2, hb2, m) self.assertEqual(d1, d2) d3 = Kappa_Statistic_multiclass(ha1, hb1, y1, m) d4 = Kappa_Statistic_multiclass(ha2, hb2, y2, m) self.assertEqual(all(np.array(d3) == np.array(d4)), True) self.assertEqual(d1, d3[0]) self.assertEqual(d2, d4[0]) y3, yt3 = generate_simulated_data(m, 7, 2) d3, t1, t2 = Kappa_Statistic_multiclass(yt3[0], yt3[1], y3, m) self.assertEqual((t1 - t2) / check_zero(1. - t2), d3)
def test_DREP(self): m, nb_cls = 30, 7 h, ht, y, yt = negative_generate_simulate(m, nb_cls) fens = DREP.DREP_fxH(yt) self.assertEqual(all(np.unique(fens) == np.array([-1, 1])), True) tem_h = DREP.DREP_diff(ht[0], ht[1]) tem_y = DREP.DREP_diff(yt[0], yt[1]) self.assertEqual(tem_h == tem_y, True) # yo, P = DREP.DREP_Pruning(yt, y, nb_cls, 0.4) self.assertEqual(len(yo) == sum(P), True) self.assertEqual(sum(P) <= nb_cls, True) h, ht = generate_simulated_data(m, 4, 2) tem_h = DREP.DREP_diff(ht[0], ht[1]) self.assertEqual(-1. <= tem_h <= 1., True) # del h
def test_Disagreement_Measure(self): m = 100 _, yt1, _, yt2 = negative_generate_simulate(m, 2) ha1, hb1 = yt1 ha2, hb2 = yt2 d1 = Disagreement_Measure_binary(ha1, hb1, m) d2 = Disagreement_Measure_binary(ha2, hb2, m) self.assertEqual(d1, d2) d3 = Disagreement_Measure_multiclass(ha1, hb1, m) d4 = Disagreement_Measure_multiclass(ha2, hb2, m) self.assertEqual(d3, d4) self.assertEqual(d1, d3) self.assertEqual(d2, d4) m = 100 _, yt3 = generate_simulated_data(m, 7, 2) d3 = Disagreement_Measure_multiclass(yt3[0], yt3[1], m) self.assertEqual(0 <= d3 <= 1, True)