예제 #1
0
 def __init__(self, lower=-numpy.inf, upper=numpy.inf, mu=0, sigma=1):
     super(TruncNormal, self).__init__(
         trunc_normal(lower=lower, upper=upper, mu=mu, sigma=sigma))
     self._repr_args = chaospy.format_repr_kwargs(lower=(lower, -numpy.inf))
     self._repr_args += chaospy.format_repr_kwargs(upper=(upper, numpy.inf))
     self._repr_args += chaospy.format_repr_kwargs(lower=(mu, 0))
     self._repr_args += chaospy.format_repr_kwargs(lower=(sigma, 1))
예제 #2
0
 def __init__(
     self,
     dist,
     shift=0,
     scale=1,
     rotation=None,
     repr_args=None,
 ):
     assert isinstance(dist,
                       Distribution), "'dist' should be a distribution"
     if repr_args is None:
         repr_args = dist._repr_args[:]
     repr_args += chaospy.format_repr_kwargs(scale=(scale, 1))
     repr_args += chaospy.format_repr_kwargs(shift=(shift, 0))
     length = len(dist) if len(dist) > 1 else None
     dependencies, parameters, rotation = chaospy.declare_dependencies(
         distribution=self,
         parameters=dict(shift=shift, scale=scale),
         rotation=rotation,
         is_operator=True,
         length=length,
         extra_parameters=dict(dist=dist),
     )
     super(ShiftScaleDistribution, self).__init__(
         parameters=parameters,
         rotation=rotation,
         dependencies=dependencies,
         repr_args=repr_args,
     )
     self._dist = dist
     permute = numpy.zeros((len(self._rotation), len(self._rotation)),
                           dtype=int)
     permute[numpy.arange(len(self._rotation), dtype=int),
             self._rotation] = 1
     self._permute = permute
예제 #3
0
 def __init__(self, mu=0, sigma=1):
     super(Laplace, self).__init__(
         dist=laplace(),
         scale=sigma,
         shift=mu,
     )
     self._repr_args = (chaospy.format_repr_kwargs(mu=(mu, 0))+
                        chaospy.format_repr_kwargs(sigma=(sigma, 1)))
예제 #4
0
 def __init__(self, shape=1, mu=0, sigma=1):
     super(PowerNormal, self).__init__(
         dist=power_normal(shape),
         scale=sigma,
         shift=mu,
     )
     self._repr_args = [shape]
     self._repr_args += chaospy.format_repr_kwargs(mu=(mu, 0))
     self._repr_args += chaospy.format_repr_kwargs(sigma=(sigma, 1))
예제 #5
0
 def __init__(self, df=1, mu=0, sigma=1):
     super(StudentT, self).__init__(
         dist=student_t(df),
         scale=sigma,
         shift=mu,
     )
     self._repr_args = [df]
     self._repr_args += chaospy.format_repr_kwargs(mu=(mu, 0))
     self._repr_args += chaospy.format_repr_kwargs(sigma=(sigma, 1))
예제 #6
0
    def __init__(self, dist, lower=None, upper=None):
        """
        Constructor.

        Args:
            dist (Distribution):
                Distribution to be truncated.
            lower (Distribution, numpy.ndarray):
                Lower truncation bound.
            upper (Distribution, numpy.ndarray):
                Upper truncation bound.
        """
        assert isinstance(dist, Distribution)
        repr_args = [dist]
        repr_args += chaospy.format_repr_kwargs(lower=(lower, None))
        repr_args += chaospy.format_repr_kwargs(upper=(upper, None))
        exclusion = set()
        for deps in dist._dependencies:
            exclusion.update(deps)
        if isinstance(lower, Distribution):
            if lower.stochastic_dependent:
                raise chaospy.StochasticallyDependentError(
                    "Joint distribution with dependencies not supported."
                )
            assert len(dist) == len(lower)
            lower_ = lower.lower
        elif lower is None:
            lower = lower_ = dist.lower
        else:
            lower = lower_ = numpy.atleast_1d(lower)
        if isinstance(upper, Distribution):
            if upper.stochastic_dependent:
                raise chaospy.StochasticallyDependentError(
                    "Joint distribution with dependencies not supported."
                )
            assert len(dist) == len(upper)
            upper_ = upper.upper
        elif upper is None:
            upper = upper_ = dist.upper
        else:
            upper = upper_ = numpy.atleast_1d(upper)
        assert numpy.all(
            upper_ > lower_
        ), "condition `upper > lower` not satisfied: %s <= %s" % (upper_, lower_)

        dependencies, parameters, rotation = chaospy.declare_dependencies(
            distribution=self,
            parameters=dict(lower=lower, upper=upper),
            length=len(dist),
        )
        super(Trunc, self).__init__(
            parameters=parameters,
            dependencies=dependencies,
            exclusion=exclusion,
            repr_args=repr_args,
        )
        self._dist = dist
예제 #7
0
 def __init__(self, shape=1, mu=0, sigma=1, scale=1, shift=0):
     dist = ShiftScaleDistribution(dist=power_log_normal(shape, sigma),
                                   scale=numpy.e**mu)
     super(PowerLogNormal, self).__init__(
         dist=dist,
         scale=scale,
         shift=shift,
         repr_args=[shape] + chaospy.format_repr_kwargs(mu=(mu, 0)) +
         chaospy.format_repr_kwargs(sigma=(sigma, 1)),
     )
예제 #8
0
 def __init__(
         self,
         mu,
         sigma=None,
         rotation=None,
 ):
     super(MvNormal, self).__init__(
         dist=normal(),
         mean=mu,
         covariance=sigma,
         rotation=rotation,
         repr_args=chaospy.format_repr_kwargs(mu=(mu, None))+
                   chaospy.format_repr_kwargs(sigma=(sigma, None)),
     )
예제 #9
0
 def __init__(self, df=1, nc=1, scale=1, shift=0):
     super(ChiSquared, self).__init__(
         dist=chi_squared(df, nc),
         scale=scale,
         shift=shift,
         repr_args=[df] + chaospy.format_repr_kwargs(nc=(nc, 1)),
     )
예제 #10
0
    def __init__(
        self,
        dist,
        lower=0.0,
        upper=1.0,
        rotation=None,
        repr_args=None,
    ):
        assert isinstance(dist,
                          Distribution), "'dist' should be a distribution"
        assert len(dist) == 1
        if repr_args is None:
            repr_args = dist._repr_args[:]
        repr_args += chaospy.format_repr_kwargs(lower=(lower, 0),
                                                upper=(upper, 1))

        dependencies, parameters, rotation, = chaospy.declare_dependencies(
            distribution=self,
            parameters=dict(lower=lower, upper=upper),
            is_operator=True,
            rotation=rotation,
            extra_parameters=dict(dist=dist),
        )
        assert len(dependencies) == 1
        assert len(parameters["lower"]) == 1
        assert len(parameters["upper"]) == 1
        super(LowerUpperDistribution, self).__init__(
            parameters=parameters,
            dependencies=dependencies,
            rotation=rotation,
            repr_args=repr_args,
        )
        self._dist = dist
예제 #11
0
 def __init__(
     self,
     df,
     mu,
     sigma=None,
     rotation=None,
 ):
     super(MvStudentT, self).__init__(
         dist=student_t(df),
         mean=mu,
         covariance=sigma,
         rotation=rotation,
         repr_args=chaospy.format_repr_kwargs(df=(df, None)) +
         chaospy.format_repr_kwargs(mu=(mu, None)) +
         chaospy.format_repr_kwargs(sigma=(sigma, None)),
     )
예제 #12
0
    def __init__(
        self,
        dist,
        lower=0.,
        upper=1.,
        rotation=None,
        repr_args=None,
    ):
        assert isinstance(dist,
                          Distribution), "'dist' should be a distribution"
        if repr_args is None:
            repr_args = dist._repr_args[:]
        repr_args += chaospy.format_repr_kwargs(lower=(lower, 0),
                                                upper=(upper, 1))

        dependencies, parameters, rotation, = chaospy.declare_dependencies(
            distribution=self,
            parameters=dict(lower=lower, upper=upper),
            rotation=rotation,
        )
        super(LowerUpperDistribution, self).__init__(
            parameters=parameters,
            dependencies=dependencies,
            repr_args=repr_args,
        )
        self._dist = dist
예제 #13
0
파일: beta.py 프로젝트: jonathf/chaospy
 def __init__(self, lower, mode, upper, gamma=4):
     mu = (lower + 4 * mode + upper) / 6.0
     alpha = 1 + gamma * (mu - lower) / (upper - lower)
     beta = 1 + gamma * (upper - mu) / (upper - lower)
     LowerUpperDistribution.__init__(
         self,
         dist=beta_(alpha, beta),
         lower=lower,
         upper=upper,
     )
     self._repr_args = [lower, mode, upper]
     self._repr_args += chaospy.format_repr_kwargs(gamma=(gamma, 4))
예제 #14
0
파일: beta.py 프로젝트: jonathf/chaospy
 def __init__(self, radius=1, shift=0):
     super(Wigner, self).__init__(dist=beta_(1.5, 1.5),
                                  scale=2 * radius,
                                  shift=shift - radius)
     self._repr_args = [radius
                        ] + chaospy.format_repr_kwargs(shift=(shift, 0))