Esempio n. 1
0
 def test_bed_confusion_matrix_datasets(self):
     '''
     Test BED-based confusion matrix upon a dataset.
     '''
     hypothesis = HYPOTHESIS_STARGAZER
     reference = HEARST_1997_STARGAZER
     value = boundary_confusion_matrix(hypothesis, reference)
     hyp_p = precision(value)
     hyp_r = recall(value)
     hyp_f = fmeasure(value)
     # Precision
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,2']), 0.33333333)
     # Recall
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,2']), 0.33333333)
     # FMeasure
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,1']), 0.72727272)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,1']), 0.58333333)
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,2']), 0.6)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,2']), 0.5)
Esempio n. 2
0
 def test_bed_confusion_matrix_datasets(self):
     '''
     Test BED-based confusion matrix upon a dataset.
     '''
     hypothesis = HYPOTHESIS_STARGAZER
     reference = HEARST_1997_STARGAZER
     value = boundary_confusion_matrix(hypothesis, reference)
     hyp_p = precision(value)
     hyp_r = recall(value)
     hyp_f = fmeasure(value)
     # Precision
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,2']), 0.33333333)
     # Recall
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,2']), 0.33333333)
     # FMeasure
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,1']), 0.72727272)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,1']), 0.58333333)
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,2']), 0.6)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,2']), 0.5)
Esempio n. 3
0
 def test_bed_confusion_matrix(self):
     '''
     Test BED-based confusion matrix upon two segmentations.
     '''
     hypothesis = (5,5,5,5,1)
     reference = HEARST_1997_STARGAZER['stargazer']['2']
     value = boundary_confusion_matrix(hypothesis, reference)
     self.assertAlmostEquals(float(precision(value)), 0.23076923)
     self.assertAlmostEquals(float(recall(value)), 0.23076923)
     self.assertAlmostEquals(float(fmeasure(value)), 0.375)
Esempio n. 4
0
 def test_bed_confusion_matrix(self):
     '''
     Test BED-based confusion matrix upon two segmentations.
     '''
     hypothesis = (5, 5, 5, 5, 1)
     reference = HEARST_1997_STARGAZER['stargazer']['2']
     value = boundary_confusion_matrix(hypothesis, reference)
     self.assertAlmostEquals(float(precision(value)), 0.23076923)
     self.assertAlmostEquals(float(recall(value)), 0.23076923)
     self.assertAlmostEquals(float(fmeasure(value)), 0.375)
Esempio n. 5
0
def example_in_paper_test():
    gold = [2, 3, 6]
    h_list = [[5, 6], [2, 2, 7], [2, 3, 3, 3], [1, 1, 3, 1, 5]]
    for n, h in enumerate(h_list):
        cm = boundary_confusion_matrix(h, gold)
        print("第%d次实验" % int(n + 1))
        # The P, R and F values are different from those in the normal method because it will correct the near missing.
        print("P=%.4f, R=%.4f, F=%.4f" %
              (precision(cm), recall(cm), fmeasure(cm)))
        print("1-Pk=%.3f, 1-WD=%.3f, B=%.3f, S=%.3f" %
              (pk(h, gold,
                  one_minus=True), WD(h, gold, one_minus=True,
                                      window_size=2), B(h, gold), S(h, gold)))
Esempio n. 6
0
 def test_fmeasure(self):
     '''
     Test FMeasure.
     '''
     matrix = cm()
     matrix['p']['p'] += 1
     matrix['p']['f'] += 1
     self.assertAlmostEqual(
         __fmeasure__(matrix, 'p'), Decimal('0.66666'), 4)
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.66666'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.33333'), 4)
     self.assertAlmostEqual(fmeasure(matrix, classification='p'),
                            Decimal('0.66666'), 4)
     matrix = cm()
     matrix['p']['p'] += 1
     matrix['p']['f'] += 3
     matrix['f']['p'] += 1
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.33333'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.16666'), 4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'p'),
                            Decimal('0.33333'), 4)
     self.assertAlmostEqual(fmeasure(matrix, classification='p'),
                            Decimal('0.33333'), 4)
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     matrix['p']['p'] += 5
     matrix['p']['f'] += 2
     matrix['f']['p'] += 1
     matrix['f']['f'] += 2
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.68421'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.67032'), 4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'p'),
                            Decimal('0.76923'), 4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'f'),
                            Decimal('0.57142'), 4)
     matrix = cm()
     matrix['p']['f'] += 2
     self.assertEqual(fmeasure(matrix), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     matrix['p']['p'] += 2
     self.assertEqual(fmeasure(matrix), Decimal('1'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('1'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     self.assertEqual(fmeasure(matrix), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
Esempio n. 7
0
 def test_fmeasure(self):
     '''
     Test FMeasure.
     '''
     matrix = cm()
     matrix['p']['p'] += 1
     matrix['p']['f'] += 1
     self.assertAlmostEqual(__fmeasure__(matrix, 'p'), Decimal('0.66666'),
                            4)
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.66666'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.33333'), 4)
     self.assertAlmostEqual(fmeasure(matrix, classification='p'),
                            Decimal('0.66666'), 4)
     matrix = cm()
     matrix['p']['p'] += 1
     matrix['p']['f'] += 3
     matrix['f']['p'] += 1
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.33333'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.16666'), 4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'p'), Decimal('0.33333'),
                            4)
     self.assertAlmostEqual(fmeasure(matrix, classification='p'),
                            Decimal('0.33333'), 4)
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     matrix['p']['p'] += 5
     matrix['p']['f'] += 2
     matrix['f']['p'] += 1
     matrix['f']['f'] += 2
     self.assertAlmostEqual(fmeasure(matrix, version=Average.micro),
                            Decimal('0.68421'), 4)
     self.assertAlmostEqual(fmeasure(matrix, version=Average.macro),
                            Decimal('0.67032'), 4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'p'), Decimal('0.76923'),
                            4)
     self.assertAlmostEqual(__fmeasure__(matrix, 'f'), Decimal('0.57142'),
                            4)
     matrix = cm()
     matrix['p']['f'] += 2
     self.assertEqual(fmeasure(matrix), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     matrix['p']['p'] += 2
     self.assertEqual(fmeasure(matrix), Decimal('1'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('1'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))
     matrix = cm()
     self.assertEqual(fmeasure(matrix), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'p'), Decimal('0'))
     self.assertEqual(__fmeasure__(matrix, 'f'), Decimal('0'))