def test_match_distribution(self): """Some really basic testing for match_distribution """ ds = datasets['uni2medium'] # large to get stable stats data = ds.samples[:, ds.a.bogus_features[0]] # choose bogus feature, which # should have close to normal distribution # Lets test ad-hoc rv_semifrozen floc = rv_semifrozen(scipy.stats.norm, loc=0).fit(data) self.failUnless(floc[0] == 0) fscale = rv_semifrozen(scipy.stats.norm, scale=1.0).fit(data) self.failUnless(fscale[1] == 1) flocscale = rv_semifrozen(scipy.stats.norm, loc=0, scale=1.0).fit(data) self.failUnless(flocscale[1] == 1 and flocscale[0] == 0) full = scipy.stats.norm.fit(data) for res in [floc, fscale, flocscale, full]: self.failUnless(len(res) == 2) data_mean = np.mean(data) for loc in [None, data_mean]: for test in ['p-roc', 'kstest']: # some really basic testing matched = match_distribution( data=data, distributions = ['scipy', ('norm', {'name': 'norm_fixed', 'loc': 0.2, 'scale': 0.3})], test=test, loc=loc, p=0.05) # at least norm should be in there names = [m[2] for m in matched] if test == 'p-roc': if cfg.getboolean('tests', 'labile', default='yes'): # we can guarantee that only for norm_fixed self.failUnless('norm' in names) self.failUnless('norm_fixed' in names) inorm = names.index('norm_fixed') # and it should be at least in the first # 30 best matching ;-) self.failUnless(inorm <= 30) # Test plotting only once if loc is None and externals.exists("pylab plottable"): import pylab as pl from mvpa.clfs.stats import plot_distribution_matches fig = pl.figure() plot_distribution_matches(data, matched, legend=1, nbest=5) #pl.show() pl.close(fig)
def test_match_distribution(self): """Some really basic testing for match_distribution """ from mvpa.clfs.stats import match_distribution, rv_semifrozen ds = datasets['uni2medium'] # large to get stable stats data = ds.samples[:, ds.a.bogus_features[0]] # choose bogus feature, which # should have close to normal distribution # Lets test ad-hoc rv_semifrozen floc = rv_semifrozen(scipy.stats.norm, loc=0).fit(data) self.failUnless(floc[0] == 0) fscale = rv_semifrozen(scipy.stats.norm, scale=1.0).fit(data) self.failUnless(fscale[1] == 1) flocscale = rv_semifrozen(scipy.stats.norm, loc=0, scale=1.0).fit(data) self.failUnless(flocscale[1] == 1 and flocscale[0] == 0) full = scipy.stats.norm.fit(data) for res in [floc, fscale, flocscale, full]: self.failUnless(len(res) == 2) data_mean = np.mean(data) for loc in [None, data_mean]: for test in ['p-roc', 'kstest']: # some really basic testing matched = match_distribution( data=data, distributions = ['scipy', ('norm', {'name': 'norm_fixed', 'loc': 0.2, 'scale': 0.3})], test=test, loc=loc, p=0.05) # at least norm should be in there names = [m[2] for m in matched] if test == 'p-roc': if cfg.getboolean('tests', 'labile', default='yes'): # we can guarantee that only for norm_fixed self.failUnless('norm' in names) self.failUnless('norm_fixed' in names) inorm = names.index('norm_fixed') # and it should be at least in the first # 30 best matching ;-) self.failUnless(inorm <= 30)
def test_match_distribution(self): """Some really basic testing for match_distribution """ from mvpa.clfs.stats import match_distribution, rv_semifrozen ds = datasets["uni2medium"] # large to get stable stats data = ds.samples[:, ds.a.bogus_features[0]] # choose bogus feature, which # should have close to normal distribution # Lets test ad-hoc rv_semifrozen floc = rv_semifrozen(scipy.stats.norm, loc=0).fit(data) self.failUnless(floc[0] == 0) fscale = rv_semifrozen(scipy.stats.norm, scale=1.0).fit(data) self.failUnless(fscale[1] == 1) flocscale = rv_semifrozen(scipy.stats.norm, loc=0, scale=1.0).fit(data) self.failUnless(flocscale[1] == 1 and flocscale[0] == 0) full = scipy.stats.norm.fit(data) for res in [floc, fscale, flocscale, full]: self.failUnless(len(res) == 2) data_mean = np.mean(data) for loc in [None, data_mean]: for test in ["p-roc", "kstest"]: # some really basic testing matched = match_distribution( data=data, distributions=["scipy", ("norm", {"name": "norm_fixed", "loc": 0.2, "scale": 0.3})], test=test, loc=loc, p=0.05, ) # at least norm should be in there names = [m[2] for m in matched] if test == "p-roc": if cfg.getboolean("tests", "labile", default="yes"): # we can guarantee that only for norm_fixed self.failUnless("norm" in names) self.failUnless("norm_fixed" in names) inorm = names.index("norm_fixed") # and it should be at least in the first # 30 best matching ;-) self.failUnless(inorm <= 30)
# Prepare few distributions to test #kwargs = {'permutations':10, 'tail':'any'} nulldist_sweep = [ MCNullDist(permutations=30, tail='any'), MCNullDist(permutations=30, tail='right')] if externals.exists('scipy'): from mvpa.support.stats import scipy from scipy.stats import f_oneway from mvpa.clfs.stats import rv_semifrozen nulldist_sweep += [ MCNullDist(scipy.stats.norm, permutations=30, tail='any'), MCNullDist(scipy.stats.norm, permutations=30, tail='right'), MCNullDist(rv_semifrozen(scipy.stats.norm, loc=0), permutations=30, tail='right'), MCNullDist(scipy.stats.expon, permutations=30, tail='right'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='any'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='right'), scipy.stats.norm(0, 0.1) ] class StatsTests(unittest.TestCase): """Unittests for various statistics""" @sweepargs(null=nulldist_sweep[1:]) def test_null_dist_prob(self, null): """Testing null dist probability"""
# Prepare few distributions to test #kwargs = {'permutations':10, 'tail':'any'} permutator = AttributePermutator('targets', count=30) nulldist_sweep = [ MCNullDist(permutator, tail='any'), MCNullDist(permutator, tail='right')] if externals.exists('scipy'): from mvpa.support.stats import scipy from scipy.stats import f_oneway from mvpa.clfs.stats import rv_semifrozen nulldist_sweep += [ MCNullDist(permutator, scipy.stats.norm, tail='any'), MCNullDist(permutator, scipy.stats.norm, tail='right'), MCNullDist(permutator, rv_semifrozen(scipy.stats.norm, loc=0), tail='right'), MCNullDist(permutator, scipy.stats.expon, tail='right'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='any'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='right'), scipy.stats.norm(0, 0.1) ] class StatsTests(unittest.TestCase): """Unittests for various statistics""" @sweepargs(null=nulldist_sweep[1:]) def test_null_dist_prob(self, null): """Testing null dist probability"""
# Prepare few distributions to test #kwargs = {'permutations':10, 'tail':'any'} nulldist_sweep = [ MCNullDist(permutations=30, tail='any'), MCNullDist(permutations=30, tail='right') ] if externals.exists('scipy'): from mvpa.support.stats import scipy from scipy.stats import f_oneway from mvpa.clfs.stats import rv_semifrozen nulldist_sweep += [ MCNullDist(scipy.stats.norm, permutations=30, tail='any'), MCNullDist(scipy.stats.norm, permutations=30, tail='right'), MCNullDist(rv_semifrozen(scipy.stats.norm, loc=0), permutations=30, tail='right'), MCNullDist(scipy.stats.expon, permutations=30, tail='right'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='any'), FixedNullDist(scipy.stats.norm(0, 10.0), tail='right'), scipy.stats.norm(0, 0.1) ] class StatsTests(unittest.TestCase): """Unittests for various statistics""" @sweepargs(null=nulldist_sweep[1:]) def test_null_dist_prob(self, null): """Testing null dist probability""" if not isinstance(null, NullDist):