本文整理匯總了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)
示例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)
)
示例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 ####################
示例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)
示例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.))
示例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)
示例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)
示例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)
示例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))
示例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