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


Python distributions.uniform方法代码示例

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


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

示例1: test_with_randomizedsearchcv

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def test_with_randomizedsearchcv(self):
        from sklearn.model_selection import RandomizedSearchCV
        from sklearn.datasets import load_iris
        from sklearn.metrics import accuracy_score, make_scorer
        from scipy.stats.distributions import uniform
        import numpy as np
        lr = LogisticRegression()
        parameters = {'solver':('liblinear', 'lbfgs'), 'penalty':['l2']}
        ranges, cat_idx = lr.get_param_ranges()
        min_C, max_C, default_C = ranges['C']
        # specify parameters and distributions to sample from
        #the loguniform distribution needs to be taken care of properly
        param_dist = {"solver": ranges['solver'],
                      "C": uniform(min_C, np.log(max_C))}
        # run randomized search
        n_iter_search = 5
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            random_search = RandomizedSearchCV(
                lr, param_distributions=param_dist, n_iter=n_iter_search, cv=5,
                scoring=make_scorer(accuracy_score))
            iris = load_iris()
            random_search.fit(iris.data, iris.target) 
开发者ID:IBM,项目名称:lale,代码行数:25,代码来源:test_core_operators.py

示例2: _make_distribution

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def _make_distribution(self) -> _uniform_inclusive:
        """Build a distribution to randomly sample points within the space

        Returns
        -------
        _uniform_inclusive
            Precise parameters based on :attr:`transform_` and :attr:`prior`"""
        if self.transform_ == "normalize":
            # Set upper bound to float after 1 to make the numbers inclusive of upper edge
            return _uniform_inclusive(0.0, 1.0)
        else:
            if self.prior == "uniform":
                return _uniform_inclusive(self.low, self.high - self.low)
            else:
                return _uniform_inclusive(
                    np.log10(self.low), np.log10(self.high) - np.log10(self.low)
                ) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:19,代码来源:dimensions.py

示例3: _make_transformer

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def _make_transformer(self) -> Transformer:
        """Build a `Transformer` to transform and inverse-transform samples in the space

        Returns
        -------
        Transformer
            Precise architecture and parameters based on :attr:`transform_` and :attr:`prior`"""
        if self.transform_ == "normalize":
            if self.prior == "uniform":
                return Pipeline([Identity(), Normalize(self.low, self.high)])
            else:
                return Pipeline([Log10(), Normalize(np.log10(self.low), np.log10(self.high))])
        else:
            if self.prior == "uniform":
                return Identity()
            else:
                return Log10()

    #################### Descriptive Properties #################### 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:21,代码来源:dimensions.py

示例4: transformed_bounds

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def transformed_bounds(self):
        """Dimension bounds in the warped space

        Returns
        -------
        low: Float
            0.0 if :attr:`transform_`="normalize". If :attr:`transform_`="identity" and
            :attr:`prior`="uniform", then :attr:`low`. Else `log10(low)`
        high: Float
            1.0 if :attr:`transform_`="normalize". If :attr:`transform_`="identity" and
            :attr:`prior`="uniform", then :attr:`high`. Else `log10(high)`"""
        if self.transform_ == "normalize":
            return 0.0, 1.0
        else:
            if self.prior == "uniform":
                return self.low, self.high
            else:
                return np.log10(self.low), np.log10(self.high) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:20,代码来源:dimensions.py

示例5: _uniform_inclusive

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def _uniform_inclusive(loc=0.0, scale=1.0):
    # like scipy.stats.distributions but inclusive of `high`
    # XXX scale + 1. might not actually be a float after scale if
    # XXX scale is very large.
    return uniform(loc=loc, scale=np.nextafter(scale, scale + 1.)) 
开发者ID:scikit-optimize,项目名称:scikit-optimize,代码行数:7,代码来源:space.py

示例6: __init__

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def __init__(self, low, high, prior="uniform", base=10, transform=None,
                 name=None, dtype=np.float):
        if high <= low:
            raise ValueError("the lower bound {} has to be less than the"
                             " upper bound {}".format(low, high))
        self.low = low
        self.high = high
        self.prior = prior
        self.base = base
        self.log_base = np.log10(base)
        self.name = name
        self.dtype = dtype
        self._rvs = None
        self.transformer = None
        self.transform_ = transform
        if isinstance(self.dtype, str) and self.dtype\
                not in ['float', 'float16', 'float32', 'float64']:
            raise ValueError("dtype must be 'float', 'float16', 'float32'"
                             "or 'float64'"
                             " got {}".format(self.dtype))
        elif isinstance(self.dtype, type) and self.dtype\
                not in [float, np.float, np.float16, np.float32, np.float64]:
            raise ValueError("dtype must be float, np.float"
                             " got {}".format(self.dtype))

        if transform is None:
            transform = "identity"
        self.set_transformer(transform) 
开发者ID:scikit-optimize,项目名称:scikit-optimize,代码行数:30,代码来源:space.py

示例7: set_transformer

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def set_transformer(self, transform="identitiy"):
        """Define rvs and transformer spaces.

        Parameters
        ----------
        transform : str
           Can be 'normalize' or 'identity'

        """
        self.transform_ = transform

        if self.transform_ not in ["normalize", "identity"]:
            raise ValueError("transform should be 'normalize' or 'identity'"
                             " got {}".format(self.transform_))

        # XXX: The _rvs is for sampling in the transformed space.
        # The rvs on Dimension calls inverse_transform on the points sampled
        # using _rvs
        if self.transform_ == "normalize":
            # set upper bound to next float after 1. to make the numbers
            # inclusive of upper edge
            self._rvs = _uniform_inclusive(0., 1.)
            if self.prior == "uniform":
                self.transformer = Pipeline(
                    [Identity(), Normalize(self.low, self.high)])
            else:
                self.transformer = Pipeline(
                    [LogN(self.base),
                     Normalize(np.log10(self.low) / self.log_base,
                               np.log10(self.high) / self.log_base)]
                )
        else:
            if self.prior == "uniform":
                self._rvs = _uniform_inclusive(self.low, self.high - self.low)
                self.transformer = Identity()
            else:
                self._rvs = _uniform_inclusive(
                    np.log10(self.low) / self.log_base,
                    np.log10(self.high) / self.log_base -
                    np.log10(self.low) / self.log_base)
                self.transformer = LogN(self.base) 
开发者ID:scikit-optimize,项目名称:scikit-optimize,代码行数:43,代码来源:space.py

示例8: transformed_bounds

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def transformed_bounds(self):
        if self.transform_ == "normalize":
            return 0.0, 1.0
        else:
            if self.prior == "uniform":
                return self.low, self.high
            else:
                return np.log10(self.low), np.log10(self.high) 
开发者ID:scikit-optimize,项目名称:scikit-optimize,代码行数:10,代码来源:space.py

示例9: _uniform_inclusive

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def _uniform_inclusive(loc=0.0, scale=1.0):
    # TODO: Add docstring
    # Like scipy.stats.distributions but inclusive of `high`
    # XXX scale + 1. might not actually be a float after scale if scale is very large
    return uniform(loc=loc, scale=np.nextafter(scale, scale + 1.0)) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:7,代码来源:dimensions.py

示例10: __init__

# 需要导入模块: from scipy.stats import distributions [as 别名]
# 或者: from scipy.stats.distributions import uniform [as 别名]
def __init__(self, low, high, prior="uniform", transform="identity", name=None):
        """Search space dimension that can assume any real value in a given range

        Parameters
        ----------
        low: Float
            Lower bound (inclusive)
        high: Float
            Upper bound (inclusive)
        prior: {"uniform", "log-uniform"}, default="uniform"
            Distribution to use when sampling random points for this dimension. If "uniform", points
            are sampled uniformly between the lower and upper bounds. If "log-uniform", points are
            sampled uniformly between `log10(lower)` and `log10(upper)`
        transform: {"identity", "normalize"}, default="identity"
            Transformation to apply to the original space. If "identity", the transformed space is
            the same as the original space. If "normalize", the transformed space is scaled
            between 0 and 1
        name: String, tuple, or None, default=None
            A name associated with the dimension

        Attributes
        ----------
        distribution: rv_generic
            See documentation of :meth:`_make_distribution` or :meth:`distribution`
        transform_: String
            Original value passed through the `transform` kwarg - Because :meth:`transform` exists
        transformer: Transformer
            See documentation of :meth:`_make_transformer` or :meth:`transformer`"""
        super().__init__(low, high)

        self.prior = prior
        self.transform_ = transform
        self.name = name

        if self.transform_ not in ["normalize", "identity"]:
            raise ValueError(
                "`transform` must be in ['normalize', 'identity']. Got {}".format(self.transform_)
            )

        # Define distribution and transformer spaces. `distribution` is for sampling in transformed
        #   space. `Dimension.rvs` calls inverse_transform on the points sampled using distribution
        self.distribution = None  # TODO: Add as kwarg?
        self.transformer = None 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:45,代码来源:dimensions.py


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