neuraxle.hyperparams.scipy_distributions

Module-level documentation for neuraxle.hyperparams.scipy_distributions. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:

Inheritance diagram of neuraxle.hyperparams.scipy_distributions

Functions

get_index_in_list_with_bool(choice_list, value)

scipy_method(func)

Classes

BaseCustomContinuousScipyDistribution(name, …)

BaseCustomDiscreteScipyDistribution(name, …)

Boolean(proba_is_true[, null_default_value])

Get a random boolean hyperparameter.

Choice(choice_list, probas[, null_default_value])

Get a random value from a choice list of possible value for this hyperparameter.

Distribution([momtype, a, b, xtol, …])

FixedHyperparameter(value[, null_default_value])

This is an hyperparameter that won’t change again, but that is still expressed as a distribution.

Gaussian(min_included, max_included, …)

Gaussian distribution that inherits from scipy.stats.rv_continuous

Histogram(histogram, null_default_value, …)

Histogram distribution that inherits from scipy.stats.rv_histogram

LogNormal(log2_space_mean, log2_space_std, …)

Get a normal distribution.

LogUniform(min_included, max_included[, …])

Get a LogUniform distribution.

Normal(mean, std, hard_clip_min, …)

LogNormal distribution that wraps a continuous scipy distribution

Poisson(min_included, max_included, …[, mu])

Poisson distribution that inherits from scipy.stats.rv_discrete

Quantized(hd, hds[, null_default_value])

A quantized wrapper for another distribution: will round() the rvs number.

RandInt(min_included, max_included, **kwargs)

Rand int scipy distribution.

ScipyContinuousDistributionWrapper(…[, …])

ScipyDiscreteDistributionWrapper(…[, …])

ScipyDistributionWrapper(scipy_distribution, …)

Base class for a distribution that wraps a scipy distribution.

Uniform(min_included, max_included[, …])

Get a uniform distribution.


neuraxle.hyperparams.scipy_distributions.scipy_method(func)[source]
class neuraxle.hyperparams.scipy_distributions.ScipyDistributionWrapper(scipy_distribution, **scipy_distribution_arguments)[source]

Bases: abc.ABC

Base class for a distribution that wraps a scipy distribution.

Usage example:

distribution = ScipyDistributionWrapper(
    scipy_distribution=rv_histogram(histogram=histogram),
    null_default_value=null_default_value
)

See also

HyperparameterDistribution

__init__(scipy_distribution, **scipy_distribution_arguments)[source]

Initialize self. See help(type(self)) for accurate signature.

_override_scipy_methods()[source]
rvs(**kwargs)[source]
pdf(**kwargs)[source]
cdf(**kwargs)[source]
entropy(**kwargs)[source]
expect(**kwargs)[source]
fit(**kwargs)[source]
fit_loc_scale(**kwargs)[source]
freeze(**kwargs)[source]
interval(**kwargs)[source]
isf(**kwargs)[source]
logcdf(**kwargs)[source]
logpdf(**kwargs)[source]
logsf(**kwargs)[source]
min(**kwargs)[source]
max(**kwargs)[source]
mean(**kwargs)[source]
median(**kwargs)[source]
moment(**kwargs)[source]
nnlf(**kwargs)[source]
ppf(**kwargs)[source]
sf(**kwargs)[source]
stats(**kwargs)[source]
std(**kwargs)[source]
support(**kwargs)[source]
var(**kwargs)[source]
to_sk_learn()[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.ScipyContinuousDistributionWrapper(scipy_distribution, null_default_value=None, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyDistributionWrapper, neuraxle.hyperparams.distributions.HyperparameterDistribution

__init__(scipy_distribution, null_default_value=None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.ScipyDiscreteDistributionWrapper(scipy_distribution, null_default_value=None, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyDistributionWrapper, neuraxle.hyperparams.distributions.DiscreteHyperparameterDistribution

__init__(scipy_distribution, null_default_value=None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.BaseCustomDiscreteScipyDistribution(name, min_included, max_included, null_default_value, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyDiscreteDistributionWrapper

__init__(name, min_included, max_included, null_default_value, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_override_scipy_methods()[source]
_pmf(x, *args)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Distribution(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)[source]

Bases: scipy.stats._distn_infrastructure.rv_continuous

_pdf(x)[source]
class neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution(name, min_included, max_included, null_default_value, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyContinuousDistributionWrapper

__init__(name, min_included, max_included, null_default_value, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_override_scipy_methods()[source]
_pdf(x, *args)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.RandInt(min_included: int, max_included: int, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyDiscreteDistributionWrapper

Rand int scipy distribution. Check out scipy.stats.randint for more info

__init__(min_included: int, max_included: int, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

min()[source]

Abstract method for obtaining minimum value that can sampled in distribution.

Returns

minimal value that can be sampled from distribution.

mean(*args, **kwargs)[source]

Abstract method for calculating distribution mean value.

Returns

distribution mean value.

median(*args, **kwargs)[source]
max()[source]

Abstract method for obtaining maximal value that can sampled in distribution.

Returns

maximal value that can be sampled from distribution.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Uniform(min_included: float, max_included: float, null_default_value=None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

Get a uniform distribution.

See also

UniformScipyDistribution, set_hyperparams_space(), HyperparameterDistribution, ScipyDistributionWrapper, neuraxle.hyperparams.space.HyperparameterSamples, neuraxle.hyperparams.space.HyperparameterSpace, neuraxle.base.BaseStep

__init__(min_included: float, max_included: float, null_default_value=None)[source]

Create a random uniform distribution. A random float between the two values somehow inclusively will be returned.

Parameters
  • min_included (float) – minimum integer, included.

  • max_included (float) – maximum integer, might be included - for more info, see examples

  • null_default_value (int) – null default value for distribution. if None, take the min_included

_pdf(x)[source]

Calculate the Uniform probability distribution value at position x.

Parameters

x – value where the probability distribution function is evaluated.

Returns

value of the probability distribution function.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.LogUniform(min_included: float, max_included: float, null_default_value=None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

Get a LogUniform distribution.

See also

LogUniformScipyDistribution, set_hyperparams_space(), HyperparameterDistribution, ScipyDistributionWrapper, neuraxle.hyperparams.space.HyperparameterSamples, neuraxle.hyperparams.space.HyperparameterSpace, neuraxle.base.BaseStep

__init__(min_included: float, max_included: float, null_default_value=None)[source]

Create a quantized random log uniform distribution. A random float between the two values inclusively will be returned.

Parameters
  • min_included (float) – minimum integer, should be somehow included.

  • max_included (float) – maximum integer, should be somehow included.

  • null_default_value (int) – null default value for distribution. if None, take the min_included

_pdf(x) → float[source]

Calculate the logUniform probability distribution value at position x.

Return type

float

Parameters

x – value where the probability distribution function is evaluated.

Returns

value of the probability distribution function.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Normal(mean: float, std: float, hard_clip_min: float = None, hard_clip_max: float = None, null_default_value: float = None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

LogNormal distribution that wraps a continuous scipy distribution

Example usage :

distribution = LogNormal(
    min_included=0,
    max_included=10,
    null_default_value=0.0
)

assert 0.0 <= distribution.rvs() <= 10.0
assert distribution.pdf(10) < 0.001
assert distribution.pdf(0) < 0.42
assert 0.55 > distribution.cdf(5.0) > 0.45
assert distribution.cdf(0) == 0.0

See also

LogNormalScipyDistribution, set_hyperparams_space(), HyperparameterDistribution, ScipyDistributionWrapper, neuraxle.hyperparams.space.HyperparameterSamples, neuraxle.hyperparams.space.HyperparameterSpace, neuraxle.base.BaseStep

__init__(mean: float, std: float, hard_clip_min: float = None, hard_clip_max: float = None, null_default_value: float = None)[source]

Initialize self. See help(type(self)) for accurate signature.

_pdf(x) → float[source]

Calculate the Normal probability distribution value at position x. :rtype: float :param x: value where the probability distribution function is evaluated. :return: value of the probability distribution function.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.LogNormal(log2_space_mean: float, log2_space_std: float, hard_clip_min: float, hard_clip_max: float, null_default_value: float = None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

Get a normal distribution.

See also

NormalScipyDistribution, set_hyperparams_space(), HyperparameterDistribution, ScipyDistributionWrapper, neuraxle.hyperparams.space.HyperparameterSamples, neuraxle.hyperparams.space.HyperparameterSpace, neuraxle.base.BaseStep

__init__(log2_space_mean: float, log2_space_std: float, hard_clip_min: float, hard_clip_max: float, null_default_value: float = None)[source]

Create a normal distribution from mean and standard deviation.

Parameters
  • log2_space_mean (float) – the most common value to pop

  • log2_space_std (float) – the standard deviation (that is, the sqrt of the variance).

  • hard_clip_min (float) – if not none, rvs will return max(result, hard_clip_min).

  • hard_clip_max (float) – if not none, rvs will return min(result, hard_clip_min).

  • null_default_value (float) – if none, null default value will be set to hard_clip_min.

_pdf(x)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Gaussian(min_included: int, max_included: int, null_default_value: float = None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

Gaussian distribution that inherits from scipy.stats.rv_continuous

Example usage :

gaussian_distribution = Gaussian(
    min_included=0,
    max_included=10,
    null_default_value=0.0
)

assert 0.0 <= gaussian_distribution.rvs() <= 10.0
assert gaussian_distribution.pdf(10) < 0.001
assert gaussian_distribution.pdf(0) < 0.42
assert 0.55 > gaussian_distribution.cdf(5.0) > 0.45
assert gaussian_distribution.cdf(0) == 0.0

See also

GaussianScipyDistribution, ScipyDistributionWrapper, set_hyperparams_space(), HyperparameterDistribution, neuraxle.hyperparams.space.HyperparameterSamples, neuraxle.hyperparams.space.HyperparameterSpace, neuraxle.base.BaseStep

__init__(min_included: int, max_included: int, null_default_value: float = None)[source]

Initialize self. See help(type(self)) for accurate signature.

_pdf(x)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Poisson(min_included: float, max_included: float, null_default_value: float = None, mu=0.6)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomDiscreteScipyDistribution

Poisson distribution that inherits from scipy.stats.rv_discrete

Example usage :

poisson_distribution = Poisson(
    min_included=0.0,
    max_included=10.0,
    null_default_value=0.0,
    mu=5.0
)

rvs = [poisson_distribution.rvs() for i in range(10)]
assert not all(x == rvs[0] for x in rvs)
assert 0.0 <= poisson_distribution.rvs() <= 10.0
assert poisson_distribution.pdf(10) == 0.01813278870782187
assert np.isclose(poisson_distribution.pdf(0), 0.006737946999085467)
assert poisson_distribution.cdf(5.0) == 0.6159606548330632
assert poisson_distribution.cdf(0) == 0.006737946999085467

See also

set_hyperparams_space(), PoissonScipyDistribution, HyperparameterDistribution, ScipyDistributionWrapper, HyperparameterSamples, HyperparameterSpace, BaseStep

__init__(min_included: float, max_included: float, null_default_value: float = None, mu=0.6)[source]

Initialize self. See help(type(self)) for accurate signature.

_pmf(x)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Histogram(histogram: numpy.histogram, null_default_value: float = None, **kwargs)[source]

Bases: neuraxle.hyperparams.scipy_distributions.ScipyDistributionWrapper

Histogram distribution that inherits from scipy.stats.rv_histogram

Example usage :

hist_dist = Histogram(
     histogram=np.histogram(data, bins=100),
     null_default_value=0.0
)

assert min(data) <= hist_dist.rvs() <= max(data)
assert 1.0 > hist_dist.pdf(x=1.0) > 0.0
assert hist_dist.pdf(x=np.max(data)) == 0.0
assert hist_dist.pdf(x=np.min(data)) < 0.001
assert hist_dist.cdf(x=np.max(data)) == 1.0
assert 0.55 > hist_dist.cdf(x=np.median(data)) > 0.45
assert hist_dist.cdf(x=np.min(data)) == 0.0

See also

HyperparameterDistribution, ScipyDistributionWrapper, Poisson, Gaussian, set_hyperparams_space(), HyperparameterSamples, HyperparameterSpace, BaseStep

__init__(histogram: numpy.histogram, null_default_value: float = None, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.FixedHyperparameter(value, null_default_value=None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomDiscreteScipyDistribution

This is an hyperparameter that won’t change again, but that is still expressed as a distribution.

__init__(value, null_default_value=None)[source]

Create a still hyperparameter

Parameters

value – what will be returned by calling .rvs().

_pdf(x)[source]
_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Boolean(proba_is_true: Optional[float] = None, null_default_value=False)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomDiscreteScipyDistribution

Get a random boolean hyperparameter.

__init__(proba_is_true: Optional[float] = None, null_default_value=False)[source]

Create a boolean hyperparameter with given probability.

Boolean distribution is in fact a Bernouilli distribution where given probability set occurance probability of having value 1. (1 - probability) gives occurance probability of having value 0.

Parameters
  • proba (float) – a float corresponding to proportion of 1 over 0.

  • null_default_value (default choice value. if None, default choice value will be the first choice) – default value for distribution

_pmf(x)[source]

Calculate the boolean probability mass function value at position x. :param x: value where the probability mass function is evaluated. :return: value of the probability mass function.

_abc_impl = <_abc_data object>
neuraxle.hyperparams.scipy_distributions.get_index_in_list_with_bool(choice_list: List[Any], value: Any) → int[source]
class neuraxle.hyperparams.scipy_distributions.Choice(choice_list: List[T], probas: Optional[List[float]] = None, null_default_value=None)[source]

Bases: neuraxle.hyperparams.scipy_distributions.BaseCustomDiscreteScipyDistribution

Get a random value from a choice list of possible value for this hyperparameter.

When narrowed, the choice will only collapse to a single element when narrowed enough. For example, if there are 4 items in the list, only at a narrowing value of 0.25 that the first item will be kept alone.

__init__(choice_list: List[T], probas: Optional[List[float]] = None, null_default_value=None)[source]

Create a random choice hyperparameter from the given list.

Parameters
  • choice_list (List) – a list of values to sample from.

  • null_default_value (default choice value. if None, default choice value will be the first choice) – default value for distribution

probabilities()[source]
values()[source]
rvs(*args, **kwargs)[source]

Sample the random variable.

Returns

The randomly sampled value.

pdf(x, *args, **kwargs)[source]

Abstract method for probability distribution function value at x.

Parameters

x – value where the probability distribution function is evaluated.

Returns

The probability distribution function value.

cdf(x, *args, **kwargs)[source]

Abstract method for cumulative distribution function value at x.

Parameters

x – value where the cumulative distribution function is evaluated.

Returns

The cumulative distribution function value.

mean()[source]

Calculate mean value (also called esperance) of the random variable. :return: mean value of the random variable.

var()[source]

Calculate variance value of the random variable. :return: variance value of the random variable.

min()[source]

Abstract method for obtaining minimum value that can sampled in distribution.

Returns

minimal value that can be sampled from distribution.

max()[source]

Abstract method for obtaining maximal value that can sampled in distribution.

Returns

maximal value that can be sampled from distribution.

std()[source]

Base method to calculate distribution std value by taking sqrt of variance value.

Returns

distribution std value.

pmf(x)[source]

Calculate the choice probability mass function value at position x.

Parameters

x – value where the probability mass function is evaluated.

Returns

value of the probability mass function.

_pmf(x)[source]

Calculate the choice probability mass function value at position x.

Parameters

x – value where the probability mass function is evaluated.

Returns

value of the probability mass function.

_abc_impl = <_abc_data object>
class neuraxle.hyperparams.scipy_distributions.Quantized(hd: neuraxle.hyperparams.distributions.HyperparameterDistribution = None, hds: List[neuraxle.hyperparams.distributions.HyperparameterDistribution] = None, null_default_value=None)[source]

Bases: neuraxle.hyperparams.distributions.WrappedHyperparameterDistributions, neuraxle.hyperparams.scipy_distributions.BaseCustomContinuousScipyDistribution

A quantized wrapper for another distribution: will round() the rvs number.

__init__(hd: neuraxle.hyperparams.distributions.HyperparameterDistribution = None, hds: List[neuraxle.hyperparams.distributions.HyperparameterDistribution] = None, null_default_value=None)[source]

Create a wrapper that will surround another HyperparameterDistribution. The wrapper might use one (hd) and/or many (hds) HyperparameterDistribution depending on the argument(s) used.

Parameters
  • hd (HyperparameterDistribution) – the other HyperparameterDistribution to wrap.

  • hds – the others HyperparameterDistribution to wrap.

_pdf(x)[source]

Calculate the Quantized probability mass function value at position x of a continuous distribution. :param x: value where the probability mass function is evaluated. :return: value of the probability mass function.

_abc_impl = <_abc_data object>