当前位置: 首页>>代码示例>>Python>>正文


Python stats.kstest方法代码示例

本文整理汇总了Python中scipy.stats.kstest方法的典型用法代码示例。如果您正苦于以下问题:Python stats.kstest方法的具体用法?Python stats.kstest怎么用?Python stats.kstest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.kstest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: kolsmi

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def kolsmi(dist, fit_result, data):
    """Perform a Kolmogorow-Smirnow-Test for goodness of fit.

    This tests the H0 hypothesis, if data is a sample of dist

    Args:
        dist:         A mle.Distribution instance
        fit_result:   The solution dict, returned by the Distribution.fit method
        data:         The data used in Distribution.fit
    Returns:
        teststat:     the test statistic, e.g. the max distance between the
                      cumulated distributions
        p-value:      the p-value, probability that dist describes the data
    """
    variables = dist.get_vars()
    if len(variables) > 1:
        raise ValueError("Kolmogorov-Smirnov-Test is only valid for 1d distributions")
    var = variables[0]
    teststat, pvalue = stats.kstest(data[var.name], lambda x: dist.cdf(x, **fit_result["x"]))
    return teststat, pvalue 
开发者ID:ibab,项目名称:python-mle,代码行数:22,代码来源:__init__.py

示例2: test_parallel_statistical_significance

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_parallel_statistical_significance(self):
        """...Test that samples generated in parallel are statistically coherent
        """
        n_task = 10
        for thread_type in self.thread_types:
            samples = self._generate_samples_in_parallel(
                parallelization_type=thread_type, n_task=10)

            for sample in samples:
                # compute p-value with Kolmogorov–Smirnov test
                p, _ = stats.kstest(sample, 'uniform')
                self.assertLess(p, 0.05)

            samples.resize((n_task * self.stat_size,))

            # compute p-value with Kolmogorov–Smirnov test
            p, _ = stats.kstest(samples, 'uniform')
            self.assertLess(p, 0.05) 
开发者ID:X-DataInitiative,项目名称:tick,代码行数:20,代码来源:random_test.py

示例3: test_gaussian_random_with_bounds

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_gaussian_random_with_bounds(self):
        """...Test gaussian random numbers simulation with mean and scale
        defined
        """
        mu = -10
        sigma = 0.5

        seeded_sample = \
            [-10.58093465, -10.31294449, -9.98125953, -10.34969085, -9.82447348]

        self._test_dist_with_seed(seeded_sample, test_gaussian, mu, sigma)

        # Statistical tests
        sample = test_gaussian(mu, sigma, self.stat_size, self.test_seed)
        p, _ = stats.kstest(sample, 'norm', (mu, sigma))
        self.assertLess(p, 0.05) 
开发者ID:X-DataInitiative,项目名称:tick,代码行数:18,代码来源:random_test.py

示例4: test_haar

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_haar(self):
        # Test that the eigenvalues, which lie on the unit circle in
        # the complex plane, are uncorrelated.

        # Generate samples
        dim = 5
        samples = 1000  # Not too many, or the test takes too long
        np.random.seed(514)  # Note that the test is sensitive to seed too
        xs = unitary_group.rvs(dim, size=samples)

        # The angles "x" of the eigenvalues should be uniformly distributed
        # Overall this seems to be a necessary but weak test of the distribution.
        eigs = np.vstack(scipy.linalg.eigvals(x) for x in xs)
        x = np.arctan2(eigs.imag, eigs.real)
        res = kstest(x.ravel(), uniform(-np.pi, 2*np.pi).cdf)
        assert_(res.pvalue > 0.05) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_multivariate.py

示例5: testExponentialSample

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def testExponentialSample(self):
    with self.test_session():
      lam = tf.constant([3.0, 4.0])
      lam_v = [3.0, 4.0]
      n = tf.constant(100000)
      exponential = tf.contrib.distributions.Exponential(lam=lam)

      samples = exponential.sample(n, seed=137)
      sample_values = samples.eval()
      self.assertEqual(sample_values.shape, (100000, 2))
      self.assertFalse(np.any(sample_values < 0.0))
      for i in range(2):
        self.assertLess(
            stats.kstest(
                sample_values[:, i], stats.expon(scale=1.0/lam_v[i]).cdf)[0],
            0.01) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:exponential_test.py

示例6: testExponentialSampleMultiDimensional

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def testExponentialSampleMultiDimensional(self):
    with self.test_session():
      batch_size = 2
      lam_v = [3.0, 22.0]
      lam = tf.constant([lam_v] * batch_size)

      exponential = tf.contrib.distributions.Exponential(lam=lam)

      n = 100000
      samples = exponential.sample(n, seed=138)
      self.assertEqual(samples.get_shape(), (n, batch_size, 2))

      sample_values = samples.eval()

      self.assertFalse(np.any(sample_values < 0.0))
      for i in range(2):
        self.assertLess(
            stats.kstest(
                sample_values[:, 0, i], stats.expon(scale=1.0/lam_v[i]).cdf)[0],
            0.01)
        self.assertLess(
            stats.kstest(
                sample_values[:, 1, i], stats.expon(scale=1.0/lam_v[i]).cdf)[0],
            0.01) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:exponential_test.py

示例7: test_evidence

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_evidence(self):
        # 2 sigma tolerance
        tolerance = 2.0*np.sqrt(self.work.NS.state.info/self.work.NS.Nlive)
        print('2-sigma statistic error in logZ: {0:0.3f}'.format(tolerance))
        print('Analytic logZ {0}'.format(self.model.analytic_log_Z))
        print('Estimated logZ {0}'.format(self.work.NS.logZ))
        pos=self.work.posterior_samples['x']
        #t,pval=stats.kstest(pos,self.model.distr.cdf)
        stat,pval = stats.normaltest(pos.T)
        print('Normal test p-value {0}'.format(str(pval)))
        plt.figure()
        plt.hist(pos.ravel(),density=True)
        x=np.linspace(self.model.bounds[0][0],self.model.bounds[0][1],100)
        plt.plot(x,self.model.distr.pdf(x))
        plt.title('NormalTest pval = {0}'.format(pval))
        plt.savefig('posterior.png')
        plt.figure()
        plt.plot(pos.ravel(),',')
        plt.title('chain')
        plt.savefig('chain.png')
        self.assertTrue(np.abs(self.work.NS.logZ - GaussianModel.analytic_log_Z)<tolerance, 'Incorrect evidence for normalised distribution: {0:.3f} instead of {1:.3f}'.format(self.work.NS.logZ,GaussianModel.analytic_log_Z ))
        self.assertTrue(pval>0.01,'Normaltest test failed: KS stat = {0}'.format(pval)) 
开发者ID:johnveitch,项目名称:cpnest,代码行数:24,代码来源:test_1d.py

示例8: test_evidence

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_evidence(self):
        # 2 sigma tolerance
        tolerance = 2.0*np.sqrt(self.work.NS.state.info/self.work.NS.Nlive)
        print('2-sigma statistic error in logZ: {0:0.3f}'.format(tolerance))
        print('Analytic logZ {0}'.format(self.model.analytic_log_Z))
        print('Estimated logZ {0}'.format(self.work.NS.logZ))
        pos=self.work.posterior_samples['x']
        #t,pval=stats.kstest(pos,self.model.distr.cdf)
        pos=self.work.posterior_samples['x']
        #t,pval=stats.kstest(pos,self.model.distr.cdf)
        plt.figure()
        plt.hist(pos.ravel(),density=True)
        x=np.linspace(self.model.bounds[0][0],self.model.bounds[0][1],100)
        plt.plot(x,2*self.model.distr.pdf(x))
        plt.savefig('posterior.png')
        plt.figure()
        plt.plot(pos.ravel(),',')
        plt.title('chain')
        plt.savefig('chain.png')
        self.assertTrue(np.abs(self.work.NS.logZ - self.model.analytic_log_Z)<tolerance, 'Incorrect evidence for normalised distribution: {0:.3f} instead of {1:.3f}'.format(self.work.NS.logZ,self.model.analytic_log_Z )) 
开发者ID:johnveitch,项目名称:cpnest,代码行数:22,代码来源:test_half_gaussian.py

示例9: kolmogorov_smirnov_normality_test

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def kolmogorov_smirnov_normality_test(X,y):
	"""
	Performs the one sample Kolmogorov-Smirnov test, testing wheter the feature values of each class are drawn from a normal distribution

	Keyword arguments:
	X -- The feature vectors
	y -- The target vector
	"""

	kolmogorov_smirnov={}
	# print kolmogorov_smirnov
	for feature_col in xrange(len(X[0])):
		kolmogorov_smirnov[feature_col]=values=[]
		for class_index in xrange(2):
			values.append(stats.kstest(X[y==class_index,feature_col], 'norm'))

		
	#debug
	for f in xrange(23):
			print kolmogorov_smirnov[f]

	return kolmogorov_smirnov 
开发者ID:alexpnt,项目名称:default-credit-card-prediction,代码行数:24,代码来源:feature_selection.py

示例10: _test_null_distribution_lrt

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def _test_null_distribution_lrt(self):
        """
        Test if de.test.continuous() generates a uniform p-value distribution in lrt
        if it is given data simulated based on the null model. Returns the p-value
        of the two-side Kolmgorov-Smirnov test for equality of the observed
        p-value distriubution and a uniform distribution.

        :param n_cells: Number of cells to simulate (number of observations per test).
        :param n_genes: Number of genes to simulate (number of tests).
        """
        logging.getLogger("tensorflow").setLevel(logging.INFO)
        logging.getLogger("batchglm").setLevel(logging.INFO)
        logging.getLogger("diffxpy").setLevel(logging.WARNING)

        self.noise_model = "nb"
        np.random.seed(1)
        test = self._test_null_model(nobs=2000, ngenes=100, test="lrt", constrained=False)

        # Compare p-value distribution under null model against uniform distribution.
        pval_h0 = stats.kstest(test.pval, 'uniform').pvalue

        logging.getLogger("diffxpy").info('KS-test pvalue for null model match of wald(): %f' % pval_h0)
        return True 
开发者ID:theislab,项目名称:diffxpy,代码行数:25,代码来源:test_continuous_null.py

示例11: ks_refine

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def ks_refine(varr, seeds, sig=0.05):
    print("selecting seeds")
    varr_sub = varr.sel(
        spatial=[tuple(hw) for hw in seeds[['height', 'width']].values])
    print("performing KS test")
    ks = xr.apply_ufunc(
        lambda x: kstest(zscore(x), 'norm')[1],
        varr_sub.chunk(dict(frame=-1, spatial='auto')),
        input_core_dims=[['frame']],
        vectorize=True,
        dask='parallelized',
        output_dtypes=[float])
    mask = ks < sig
    mask_df = mask.to_pandas().rename('mask_ks').reset_index()
    seeds = pd.merge(seeds, mask_df, on=['height', 'width'], how='left')
    return seeds 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:18,代码来源:initialization.py

示例12: checkNormalFit

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def checkNormalFit(x_train, y_train, x_control_train):
	train = []
	for i in range(0, len(y_train)):
		temp1 = np.append(x_train[i], y_train[i])
		temp2 = np.append(temp1, x_control_train[i])
		train.append(temp2)

	mean = np.mean(train, axis=0)
	cov = np.cov(train, rowvar=0)
	l = len(mean) - 2
	for i in range(0, l):
		for j in range(0, l):
			if i != j:
				cov[i][j] = 0

	for i in range(0, len(train[0])):
		data = []
		for elem in train:
			data.append(elem[i])

		def cdf(x):
			return st.norm.cdf(x, mean[i], math.sqrt(cov[i][i]))

		print(st.kstest(data, cdf)) 
开发者ID:IBM,项目名称:AIF360,代码行数:26,代码来源:utils.py

示例13: check_distribution_rvs

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def check_distribution_rvs(distfn, args, alpha, rvs):
    ## signature changed to avoid calling a distribution by name
    # test from scipy.stats.tests
    # this version reuses existing random variables
    D,pval = stats.kstest(rvs, distfn.cdf, args=args, N=1000)
    if (pval < alpha):
        D,pval = stats.kstest(distfn.rvs, distfn.cdf, args=args, N=1000)
        npt.assert_(pval > alpha, "D = " + str(D) + "; pval = " + str(pval) +
               "; alpha = " + str(alpha) + "\nargs = " + str(args)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_edgeworth.py

示例14: subtest_normal_distrib

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def subtest_normal_distrib(self, xs, mean, std):
        _, pvalue = stats.kstest(xs, 'norm', (mean, std))
        self.assertGreater(pvalue, 3e-3) 
开发者ID:chainer,项目名称:chainerrl,代码行数:5,代码来源:test_random.py

示例15: test_ks

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import kstest [as 别名]
def test_ks(self):
        # cdf is slow
        # Kolmogorov-Smirnov test against generating sample
        stat, pvalue = stats.kstest(self.rvs, self.dist2.cdf)
        assert_array_less(0.25, pvalue) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_norm_expan.py


注:本文中的scipy.stats.kstest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。