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


Python _util.check_random_state方法代码示例

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


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

示例1: __init__

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def __init__(self, stepsize=0.5, random_state=None):
        self.stepsize = stepsize
        self.random_state = check_random_state(random_state) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:5,代码来源:_basinhopping.py

示例2: __init__

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def __init__(self, seed=None):
        super(multi_rv_generic, self).__init__()
        self._random_state = check_random_state(seed) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:5,代码来源:_multivariate.py

示例3: random_state

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def random_state(self, seed):
        self._random_state = check_random_state(seed) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:_multivariate.py

示例4: _get_random_state

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def _get_random_state(self, random_state):
        if random_state is not None:
            return check_random_state(random_state)
        else:
            return self._random_state 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:_multivariate.py

示例5: random_state

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def random_state(self, seed):
        self.dist._random_state = check_random_state(seed) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:_distn_infrastructure.py

示例6: __init__

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def __init__(self, seed=None):
        super(rv_generic, self).__init__()

        # figure out if _stats signature has 'moments' keyword
        sign = _getargspec(self._stats)
        self._stats_has_moments = ((sign[2] is not None) or
                                   ('moments' in sign[0]))
        self._random_state = check_random_state(seed) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:_distn_infrastructure.py

示例7: cwt_matrix

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def cwt_matrix(n_rows, n_columns, seed=None):
    r""""
    Generate a matrix S for the Clarkson-Woodruff sketch.

    Given the desired size of matrix, the method returns a matrix S of size
    (n_rows, n_columns) where each column has all the entries set to 0 less one
    position which has been randomly set to +1 or -1 with equal probability.

    Parameters
    ----------
    n_rows: int
        Number of rows of S
    n_columns: int
        Number of columns of S
    seed : None or int or `numpy.random.RandomState` instance, optional
        This parameter defines the ``RandomState`` object to use for drawing
        random variates.
        If None (or ``np.random``), the global ``np.random`` state is used.
        If integer, it is used to seed the local ``RandomState`` instance.
        Default is None.

    Returns
    -------
    S : (n_rows, n_columns) array_like

    Notes
    -----
    Given a matrix A, with probability at least 9/10,
    .. math:: ||SA|| == (1 \pm \epsilon)||A||
    Where epsilon is related to the size of S
    """
    S = np.zeros((n_rows, n_columns))
    nz_positions = np.random.randint(0, n_rows, n_columns)
    rng = check_random_state(seed)
    values = rng.choice([1, -1], n_columns)
    for i in range(n_columns):
        S[nz_positions[i]][i] = values[i]

    return S 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:41,代码来源:_sketches.py

示例8: test_check_random_state

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def test_check_random_state():
    # If seed is None, return the RandomState singleton used by np.random.
    # If seed is an int, return a new RandomState instance seeded with seed.
    # If seed is already a RandomState instance, return it.
    # Otherwise raise ValueError.
    rsi = check_random_state(1)
    assert_equal(type(rsi), np.random.RandomState)
    rsi = check_random_state(rsi)
    assert_equal(type(rsi), np.random.RandomState)
    rsi = check_random_state(None)
    assert_equal(type(rsi), np.random.RandomState)
    assert_raises(ValueError, check_random_state, 'a') 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:14,代码来源:test__util.py

示例9: test_random_state

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def test_random_state(self):
        # ensure that the global random state is not modified because
        # the directed Hausdorff algorithm uses randomization
        rs = check_random_state(None)
        old_global_state = rs.get_state()
        directed_hausdorff(self.path_1, self.path_2)
        rs2 = check_random_state(None)
        new_global_state = rs2.get_state()
        assert_equal(new_global_state, old_global_state) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_hausdorff.py

示例10: test_random_state_None_int

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def test_random_state_None_int(self):
        # check that seed values of None or int do not alter global
        # random state
        for seed in [None, 27870671]:
            rs = check_random_state(None)
            old_global_state = rs.get_state()
            directed_hausdorff(self.path_1, self.path_2, seed)
            rs2 = check_random_state(None)
            new_global_state = rs2.get_state()
            assert_equal(new_global_state, old_global_state) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,代码来源:test_hausdorff.py

示例11: _perm_test

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def _perm_test(
    test, sim, n=100, p=1, noise=False, reps=1000, workers=1, random_state=None
):
    r"""
    Helper function that calculates the statistical.

    Parameters
    ----------
    test : callable()
        The independence test class requested.
    sim : callable()
        The simulation used to generate the input data.
    reps : int, optional (default: 1000)
        The number of replications used to estimate the null distribution
        when using the permutation test used to calculate the p-value.
    workers : int, optional (default: -1)
        The number of cores to parallelize the p-value computation over.
        Supply -1 to use all cores available to the Process.

    Returns
    -------
    null_dist : list
        The approximated null distribution.
    """
    # set seeds
    random_state = check_random_state(random_state)
    rngs = [
        np.random.RandomState(random_state.randint(1 << 32, size=4, dtype=np.uint32))
        for _ in range(reps)
    ]

    # use all cores to create function that parallelizes over number of reps
    mapwrapper = MapWrapper(workers)
    parallelp = _ParallelP(test=test, sim=sim, n=n, p=p, noise=noise, rngs=rngs)
    alt_dist, null_dist = map(list, zip(*list(mapwrapper(parallelp, range(reps)))))
    alt_dist = np.array(alt_dist)
    null_dist = np.array(null_dist)

    return alt_dist, null_dist 
开发者ID:neurodata,项目名称:hyppo,代码行数:41,代码来源:power.py

示例12: _perm_test_3samp

# 需要导入模块: from scipy._lib import _util [as 别名]
# 或者: from scipy._lib._util import check_random_state [as 别名]
def _perm_test_3samp(
    test, n=100, epsilon=1, weight=0, case=1, reps=1000, workers=1, random_state=None
):
    r"""
    Helper function that calculates the statistical.

    Parameters
    ----------
    test : callable()
        The independence test class requested.
    sim : callable()
        The simulation used to generate the input data.
    reps : int, optional (default: 1000)
        The number of replications used to estimate the null distribution
        when using the permutation test used to calculate the p-value.
    workers : int, optional (default: -1)
        The number of cores to parallelize the p-value computation over.
        Supply -1 to use all cores available to the Process.

    Returns
    -------
    null_dist : list
        The approximated null distribution.
    """
    # set seeds
    random_state = check_random_state(random_state)
    rngs = [
        np.random.RandomState(random_state.randint(1 << 32, size=4, dtype=np.uint32))
        for _ in range(reps)
    ]

    # use all cores to create function that parallelizes over number of reps
    mapwrapper = MapWrapper(workers)
    parallelp = _ParallelP3Samp(test, n, epsilon, weight, case, rngs)
    alt_dist, null_dist = map(list, zip(*list(mapwrapper(parallelp, range(reps)))))
    alt_dist = np.array(alt_dist)
    null_dist = np.array(null_dist)

    return alt_dist, null_dist 
开发者ID:neurodata,项目名称:hyppo,代码行数:41,代码来源:power_3samp.py


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