Esempio n. 1
0
def test_underdefined_distribution():
    """
    Check if under-defined probability distributions raises errors correctly.

    The number of underlying distribution components in a stochastic vector
    must always be at least as large as the length of the vector.
    """
    with pytest.raises(chaospy.StochasticallyDependentError):
        chaospy.Add(2, 2)
    dist = chaospy.Uniform(-1, 1)
    with pytest.raises(chaospy.StochasticallyDependentError):
        chaospy.J(dist, dist)
Esempio n. 2
0
def test_dist_addition_illegals():
    # Too large dim on const:
    with raises(chaospy.UnsupportedFeature):
        _ = MULTIVARIATE+[[1, 1], [0, 1]]
    with raises(chaospy.UnsupportedFeature):
        _ = [[1, 1], [0, 1]]+MULTIVARIATE
    # 2-D object, 1-D var:
    with raises(chaospy.StochasticallyDependentError):
        _ = UNIVARIATE+[1, 1]
    with raises(chaospy.StochasticallyDependentError):
        _ = [1, 1]+UNIVARIATE
    # 0-D object:
    with raises(chaospy.StochasticallyDependentError):
        chaospy.Add(2, 3)
Esempio n. 3
0
def test_dist_addition_wrappers():
    dists = [
        chaospy.J(chaospy.Normal(2), chaospy.Normal(2), chaospy.Normal(3)),  # ShiftScale
        chaospy.J(chaospy.Uniform(1, 3), chaospy.Uniform(1, 3), chaospy.Uniform(1, 5)),  # LowerUpper
        chaospy.MvNormal([2, 2, 3], numpy.eye(3)),  # MeanCovariance
    ]
    for dist in dists:
        joint = chaospy.Add([1, 1, 3], dist)

        assert numpy.allclose(joint.inv([0.5, 0.5, 0.5]), [3, 3, 6])
        assert numpy.allclose(joint.fwd([3, 3, 6]), [0.5, 0.5, 0.5])
        density = joint.pdf([2, 2, 2], decompose=True)
        assert numpy.isclose(density[0], density[1]), (dist, density)
        assert not numpy.isclose(density[0], density[2]), dist
        assert numpy.isclose(joint[0].inv([0.5]), 3)
        assert numpy.isclose(joint[0].fwd([3]), 0.5)
Esempio n. 4
0
 def __rsub__(self, X):
     """Y.__rsub__(X) <==> Y-X"""
     return chaospy.Add(X, -self)
Esempio n. 5
0
 def __sub__(self, X):
     """Y.__sub__(X) <==> X-Y"""
     return chaospy.Add(self, -X)
Esempio n. 6
0
 def __radd__(self, X):
     """Y.__radd__(X) <==> Y+X"""
     return chaospy.Add(self, X)
Esempio n. 7
0
 def __add__(self, X):
     """Y.__add__(X) <==> X+Y"""
     return chaospy.Add(self, X)