Esempio n. 1
0
 def test_fuzzy_histogram_std_behaviour(self):
     """Test the standard behaviour of fuzzy histogram."""
     values = scipy.random.randint(0, 10, 100)
     
     _, b = fuzzy_histogram(values, bins=12)
     self.assertEqual(len(b), 13, 'violation of requested histogram size.')
     self.assertEqual(b[0], values.min(), 'invalid lower histogram border.')
     self.assertEqual(b[-1], values.max(), 'invalid upper histogram border.')
     
     h, _ = fuzzy_histogram(values, normed=True)
     self.assertAlmostEqual(sum(h), 1.0, msg='histogram not normed.')
     
     _, b = fuzzy_histogram(values, bins=12, guarantee=True)
     self.assertEqual(len(b), 13, 'violation of requested histogram size with guarantee set to True.')
     
     _, b = fuzzy_histogram(values, range=(-5, 5))
     self.assertEqual(b[0], -5.0, 'violation of requested ranges lower bound.')
     self.assertEqual(b[-1], 5.0, 'violation of requested ranges lower bound.')
Esempio n. 2
0
 def test_fuzzy_histogram_contribution(self):
     """Test if all values contribute with nearly one to the created histograms."""
     values = scipy.random.randint(0, 100, 1000)
     
     # test triangular
     h, _ = fuzzy_histogram(values, membership='triangular', normed=False, guarantee=True)
     self.assertAlmostEqual(sum(h), values.size, msg='Triangular contribution does not equal out. {} != {}.'.format(sum(h), values.size))
      
     # test trapezoid
     h, _ = fuzzy_histogram(values, membership='trapezoid', normed=False, guarantee=True)
     self.assertAlmostEqual(sum(h), values.size, msg='Trapezoid contribution does not equal out. {} != {}.'.format(sum(h), values.size))
      
     # test gaussian
     h, _ = fuzzy_histogram(values, membership='gaussian', normed=False, guarantee=True)
     self.assertAlmostEqual(sum(h), values.size, msg='Gaussian contribution does not equal out. {} != {}.'.format(sum(h), values.size), delta=values.size * 0.001) # gaussian maximal error eps
      
     # test sigmoid
     h, _ = fuzzy_histogram(values, membership='sigmoid', normed=False, guarantee=True)
     self.assertAlmostEqual(sum(h), values.size, msg='Sigmoid contribution does not equal out. {} != {}.'.format(sum(h), values.size), delta=values.size * 0.001) # sigmoidal maximal error eps
Esempio n. 3
0
        worst_tp, worst_fp, worst_tn, worst_fn)
    print '{:<30}'.format('worst_mix_against_bnd_term'),
    print '{:>+15.4f}{:>+15.4f}'.format(worst_mix_accuracy - bdr_accuracy,
                                        worst_mix_fscore - bdr_fscore)

    logger.info('Successfully terminated.')


###
# Histogram creations methods
###
__HISTOGRAMS = {
    'standard':
    numpy.histogram,
    'triangular':
    lambda *args, **kwargs: fuzzy_histogram(
        *args, membership='triangular', **kwargs),
    'trapezoid':
    lambda *args, **kwargs: fuzzy_histogram(
        *args, membership='trapezoid', **kwargs),
    'gaussian':
    lambda *args, **kwargs: fuzzy_histogram(
        *args, membership='gaussian', **kwargs),
    'sigmoid':
    lambda *args, **kwargs: fuzzy_histogram(
        *args, membership='sigmoid', **kwargs)
}

###
# Histogram distance measures
###
# available distance measures and their mapping to the respective functions
Esempio n. 4
0
 def test_fuzzy_histogram_parameters(self):
     values = scipy.random.randint(0, 10, 100)
     
     # membership functions
     fuzzy_histogram(values, membership='triangular')
     fuzzy_histogram(values, membership='trapezoid')
     fuzzy_histogram(values, membership='gaussian')
     fuzzy_histogram(values, membership='sigmoid')
     
     # int/float
     fuzzy_histogram(values, range=(0,10)) # int in range
     fuzzy_histogram(values, range=(0.,10.)) # float in range
     fuzzy_histogram(values, bins=10) # int in bins
     fuzzy_histogram(values, membership='sigmoid', smoothness=1) # int in smoothness
     fuzzy_histogram(values, membership='sigmoid', smoothness=1.) # float in smoothness
    
    medium_mix_fscore, medium_mix_accuracy = __calculate_rating(medium_tp, medium_fp, medium_tn, medium_fn)
    print '{:<30}'.format('medium_mix_against_bnd_term'),
    print '{:>+15.4f}{:>+15.4f}'.format(medium_mix_accuracy - bdr_accuracy, medium_mix_fscore - bdr_fscore)
    
    worst_mix_fscore, worst_mix_accuracy = __calculate_rating(worst_tp, worst_fp, worst_tn, worst_fn)
    print '{:<30}'.format('worst_mix_against_bnd_term'),
    print '{:>+15.4f}{:>+15.4f}'.format(worst_mix_accuracy - bdr_accuracy, worst_mix_fscore - bdr_fscore)
    
    logger.info('Successfully terminated.')

###
# Histogram creations methods
###
__HISTOGRAMS = {'standard': numpy.histogram,
                'triangular': lambda *args, **kwargs: fuzzy_histogram(*args, membership='triangular', **kwargs),
                'trapezoid': lambda *args, **kwargs: fuzzy_histogram(*args, membership='trapezoid', **kwargs),
                'gaussian': lambda *args, **kwargs: fuzzy_histogram(*args, membership='gaussian', **kwargs),
                'sigmoid': lambda *args, **kwargs: fuzzy_histogram(*args, membership='sigmoid', **kwargs)}

###
# Histogram distance measures
###
# available distance measures and their mapping to the respective functions
__DISTANCES = {'chebyshev': chebyshev,
               'chebyshev_neg': chebyshev_neg,
               'chi_square': chi_square,               
               'correlate': correlate_1,
               'cosine_1': cosine_1,
               'cosine_2': cosine_2,
               'cosine_alt': cosine_alt,