How to use the chaospy.distributions.baseclass.Dist function in chaospy

To help you get started, we’ve selected a few chaospy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonathf / chaospy / chaospy / distributions / cores.py View on Github external
return 1-(1-x**a)**b

    def _ppf(self, q, a, b):
        return (1-(1-q)**(1./b))**(1./a)

    def _mom(self, k, a, b):
        return b*special.gamma(1+k*1./a)*special.gamma(b)/\
                special.gamma(1+b+k*1./a)

    def _str(self, a, b):
        return "kum(%s,%s)" % (a,b)

    def _bnd(self, x, a, b):
        return 0,1

class hypgeosec(Dist):

    def __init__(self):
        Dist.__init__(self)

    def _pdf(self, x):
        return .5*numpy.cosh(numpy.pi*x/2.)**-1

    def _cdf(self, x):
        return 2/numpy.pi*numpy.arctan(numpy.e**(numpy.pi*x/2.))

    def _ppf(self, q):
        return 2/numpy.pi*numpy.log(numpy.tan(numpy.pi*q/2.))

    def _mom(self, k):
        return numpy.abs(special.euler(k))[-1]
github jonathf / chaospy / chaospy / distributions / operators / arccosh.py View on Github external
"""Arc-Cosines Hyperbolic."""
import numpy

from ..baseclass import Dist
from .. import evaluation, approximation


class Arccosh(Dist):
    """
    Arc-Cosine Hyperbolic.

    Args:
        dist (Dist): Distribution to perform transformation on.

    Example:
        >>> distribution = chaospy.Arccosh(chaospy.Uniform(1, 2))
        >>> print(distribution)
        Arccosh(Uniform(lower=1, upper=2))
        >>> q = numpy.linspace(0,1,6)[1:-1]
        >>> print(numpy.around(distribution.inv(q), 4))
        [0.6224 0.867  1.047  1.1929]
        >>> print(numpy.around(distribution.fwd(distribution.inv(q)), 4))
        [0.2 0.4 0.6 0.8]
        >>> print(numpy.around(distribution.pdf(distribution.inv(q)), 4))
github jonathf / chaospy / chaospy / distributions / operators / joint.py View on Github external
def __init__(self, *args):
        args = [dist for arg in args
                for dist in (arg if isinstance(arg, J) else [arg])]
        assert all(isinstance(dist, Dist) for dist in args)
        self.indices = [0] + numpy.cumsum([len(dist) for dist in args[:-1]]).tolist()
        self.inverse_map = {dist: idx for idx, dist in zip(self.indices, args)}
        prm = {"_%03d" % idx: dist for idx, dist in zip(self.indices, args)}
        Dist.__init__(self, **prm)
github jonathf / chaospy / chaospy / distributions / operators / logarithm10.py View on Github external
"""Logarithm with base 10."""
import numpy

from ..baseclass import Dist
from .. import evaluation, approximation


class Log10(Dist):
    """
    Logarithm with base 10.

    Args:
        dist (Dist): Distribution to perform transformation on.

    Example:
        >>> distribution = chaospy.Log10(chaospy.Uniform(1, 2))
        >>> print(distribution)
        Log10(Uniform(lower=1, upper=2))
        >>> q = numpy.linspace(0,1,6)[1:-1]
        >>> print(numpy.around(distribution.inv(q), 4))
        [0.0792 0.1461 0.2041 0.2553]
        >>> print(numpy.around(distribution.fwd(distribution.inv(q)), 4))
        [0.2 0.4 0.6 0.8]
        >>> print(numpy.around(distribution.pdf(distribution.inv(q)), 4))
github jonathf / chaospy / chaospy / distributions / cores.py View on Github external
class levy(Dist):

    def __init__(self):
        Dist.__init__(self)
    def _pdf(self, x):
        return 1/numpy.sqrt(2*numpy.pi*x)/x*numpy.exp(-1/(2*x))
    def _cdf(self, x):
        return 2*(1-normal._cdf(1/numpy.sqrt(x)))
    def _ppf(self, q):
        val = normal._ppf(1-q/2.0)
        return 1.0/(val*val)
    def _bnd(self, x):
        return 0.0, self._ppf(1-1e-10)


class loggamma(Dist):

    def __init__(self, c):
        Dist.__init__(self, c=c)
    def _pdf(self, x, c):
        return numpy.exp(c*x-numpy.exp(x)-special.gammaln(c))
    def _cdf(self, x, c):
        return special.gammainc(c, numpy.exp(x))
    def _ppf(self, q, c):
        return numpy.log(special.gammaincinv(c,q))
    def _bnd(self, x, c):
        return self._ppf(1e-10, c), self._ppf(1-1e-10, c)


class loglaplace(Dist):

    def __init__(self, c):
github jonathf / chaospy / chaospy / distributions / cores.py View on Github external
def __init__(self, lo=0, up=1):
        Dist.__init__(self, lo=lo, up=up)
    def _pdf(self, x, lo, up):
        return 1./(x*(up-lo))
    def _cdf(self, x, lo, up):
        return (numpy.log(x)-lo)/(up-lo)
    def _ppf(self, q, lo, up):
        return numpy.e**(q*(up-lo) + lo)
    def _bnd(self, x, lo, up):
        return numpy.e**lo, numpy.e**up
    def _mom(self, k, lo, up):
        return ((numpy.e**(up*k)-numpy.e**(lo*k))/((up-lo)*(k+(k==0))))**(k!=0)
    def _str(self, lo, up):
        return "loguni(%s,%s)" % (lo, up)

class normal(Dist):

    def __init__(self):
        Dist.__init__(self)
    def _pdf(self, x):
        return (2*numpy.pi)**(-.5)*numpy.e**(-x**2/2.)
    def _cdf(self, x):
        return special.ndtr(x)
    def _ppf(self, x):
        return special.ndtri(x)
    def _mom(self, k):
        return .5*sp.misc.factorial2(k-1)*(1+(-1)**k)
    def _ttr(self, n):
        return 0., 1.*n
    def _bnd(self, x):
        return -7.5, 7.5
    def _str(self):
github jonathf / chaospy / chaospy / distributions / collection / log_uniform.py View on Github external
"""Log-uniform distribution."""
import numpy

from ..baseclass import Dist
from ..operators.addition import Add


class log_uniform(Dist):
    """Log-uniform distribution."""

    def __init__(self, lo=0, up=1):
        Dist.__init__(self, lo=lo, up=up)

    def _pdf(self, x, lo, up):
        return 1./(x*(up-lo))

    def _cdf(self, x, lo, up):
        return (numpy.log(x)-lo)/(up-lo)

    def _ppf(self, q, lo, up):
        return numpy.e**(q*(up-lo) + lo)

    def _lower(self, lo, up):
        return numpy.e**lo