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


Python mlab.GaussianKDE方法代码示例

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


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

示例1: test_kde_bandwidth_method

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_kde_bandwidth_method(self):

        np.random.seed(8765678)
        n_basesample = 50
        xn = np.random.randn(n_basesample)

        # Default
        gkde = mlab.GaussianKDE(xn)
        # Supply a callable
        gkde2 = mlab.GaussianKDE(xn, 'scott')
        # Supply a scalar
        gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor)

        xs = np.linspace(-7, 7, 51)
        kdepdf = gkde.evaluate(xs)
        kdepdf2 = gkde2.evaluate(xs)
        assert_almost_equal(kdepdf.all(), kdepdf2.all())
        kdepdf3 = gkde3.evaluate(xs)
        assert_almost_equal(kdepdf.all(), kdepdf3.all()) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:21,代码来源:test_mlab.py

示例2: test_kde_bandwidth_method

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_kde_bandwidth_method(self):

        np.random.seed(8765678)
        n_basesample = 50
        xn = np.random.randn(n_basesample)

        # Default
        gkde = mlab.GaussianKDE(xn)
        # Supply a callable
        gkde2 = mlab.GaussianKDE(xn, 'scott')
        # Supply a scalar
        gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor)

        xs = np.linspace(-7, 7, 51)
        kdepdf = gkde.evaluate(xs)
        kdepdf2 = gkde2.evaluate(xs)
        assert kdepdf.all() == kdepdf2.all()
        kdepdf3 = gkde3.evaluate(xs)
        assert kdepdf.all() == kdepdf3.all() 
开发者ID:holzschu,项目名称:python3_ios,代码行数:21,代码来源:test_mlab.py

示例3: test_kde_integer_input

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_kde_integer_input(self):
        """Regression test for #1181."""
        x1 = np.arange(5)
        kde = mlab.GaussianKDE(x1)
        y_expected = [0.13480721, 0.18222869, 0.19514935, 0.18222869,
                      0.13480721]
        np.testing.assert_array_almost_equal(kde(x1), y_expected, decimal=6) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:9,代码来源:test_mlab.py

示例4: test_gaussian_kde_covariance_caching

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_gaussian_kde_covariance_caching(self):
        x1 = np.array([-7, -5, 1, 4, 5], dtype=np.float)
        xs = np.linspace(-10, 10, num=5)
        # These expected values are from scipy 0.10, before some changes to
        # gaussian_kde. They were not compared with any external reference.
        y_expected = [0.02463386, 0.04689208, 0.05395444, 0.05337754,
                      0.01664475]

        # set it to the default bandwidth.
        kde2 = mlab.GaussianKDE(x1, 'scott')
        y2 = kde2(xs)

        np.testing.assert_array_almost_equal(y_expected, y2, decimal=7) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:15,代码来源:test_mlab.py

示例5: test_no_data

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_no_data(self):
        """Pass no data into the GaussianKDE class."""
        assert_raises(ValueError, mlab.GaussianKDE, []) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:5,代码来源:test_mlab.py

示例6: test_single_dataset_element

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_single_dataset_element(self):
        """Pass a single dataset element into the GaussianKDE class."""
        assert_raises(ValueError, mlab.GaussianKDE, [42]) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:5,代码来源:test_mlab.py

示例7: test_silverman_singledim_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_silverman_singledim_dataset(self):
        """Use a single dimension list as the dataset and test silverman's
        output."""
        x1 = np.array([-7, -5, 1, 4, 5])
        mygauss = mlab.GaussianKDE(x1, "silverman")
        y_expected = 0.76770389927475502
        assert_almost_equal(mygauss.covariance_factor(), y_expected, 7) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:9,代码来源:test_mlab.py

示例8: test_scott_multidim_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_scott_multidim_dataset(self):
        """Use a multi-dimensional array as the dataset and test scott's output
        """
        x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        assert_raises(np.linalg.LinAlgError, mlab.GaussianKDE, x1, "scott") 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:7,代码来源:test_mlab.py

示例9: test_scott_singledim_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_scott_singledim_dataset(self):
        """Use a single-dimensional array as the dataset and test scott's
        output"""
        x1 = np.array([-7, -5, 1, 4, 5])
        mygauss = mlab.GaussianKDE(x1, "scott")
        y_expected = 0.72477966367769553
        assert_almost_equal(mygauss.covariance_factor(), y_expected, 7) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:9,代码来源:test_mlab.py

示例10: test_scalar_empty_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_scalar_empty_dataset(self):
        """Use an empty array as the dataset and test the scalar's cov factor
        """
        assert_raises(ValueError, mlab.GaussianKDE, [], bw_method=5) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:6,代码来源:test_mlab.py

示例11: test_scalar_covariance_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_scalar_covariance_dataset(self):
        """Use a dataset and test a scalar's cov factor
        """
        np.random.seed(8765678)
        n_basesample = 50
        multidim_data = [np.random.randn(n_basesample) for i in range(5)]

        kde = mlab.GaussianKDE(multidim_data, bw_method=0.5)
        assert_equal(kde.covariance_factor(), 0.5) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:11,代码来源:test_mlab.py

示例12: test_callable_singledim_dataset

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_callable_singledim_dataset(self):
        """Use a single-dimensional array as the dataset and test the
        callable's cov factor"""
        np.random.seed(8765678)
        n_basesample = 50
        multidim_data = np.random.randn(n_basesample)

        kde = mlab.GaussianKDE(multidim_data, bw_method='silverman')
        y_expected = 0.48438841363348911
        assert_almost_equal(kde.covariance_factor(), y_expected, 7) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:12,代码来源:test_mlab.py

示例13: test_wrong_bw_method

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_wrong_bw_method(self):
        """Test the error message that should be called when bw is invalid."""
        np.random.seed(8765678)
        n_basesample = 50
        data = np.random.randn(n_basesample)
        assert_raises(ValueError, mlab.GaussianKDE, data, bw_method="invalid") 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:8,代码来源:test_mlab.py

示例14: test_evaluate_diff_dim

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_evaluate_diff_dim(self):
        """Test the evaluate method when the dim's of dataset and points are
        different dimensions"""
        x1 = np.arange(3, 10, 2)
        kde = mlab.GaussianKDE(x1)
        x2 = np.arange(3, 12, 2)
        y_expected = [
            0.08797252, 0.11774109, 0.11774109, 0.08797252, 0.0370153
        ]
        y = kde.evaluate(x2)
        np.testing.assert_array_almost_equal(y, y_expected, 7) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:13,代码来源:test_mlab.py

示例15: test_evaluate_inv_dim

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import GaussianKDE [as 别名]
def test_evaluate_inv_dim(self):
        """ Invert the dimensions. i.e., Give the dataset a dimension of
        1 [3,2,4], and the points will have a dimension of 3 [[3],[2],[4]].
        ValueError should be raised"""
        np.random.seed(8765678)
        n_basesample = 50
        multidim_data = np.random.randn(n_basesample)
        kde = mlab.GaussianKDE(multidim_data)
        x2 = [[1], [2], [3]]
        assert_raises(ValueError, kde.evaluate, x2) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:12,代码来源:test_mlab.py


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