def rv(name, cls, *args): args = list(map(sympify, args)) dist = cls(*args) dist.check(*args) pspace = SingleFinitePSpace(name, dist) if any(is_random(arg) for arg in args): from sympy.stats.compound_rv import CompoundPSpace, CompoundDistribution pspace = CompoundPSpace(name, CompoundDistribution(dist)) return pspace.value
def rv(name, cls, *args): args = list(map(sympify, args)) i = 0 while i < len(args): # Converting to Dict since dict is not hashable if isinstance(args[i], dict): args[i] = Dict(args[i]) i += 1 dist = cls(*args) dist.check(*args) return SingleFinitePSpace(name, dist).value
def __new__(cls, s, distribution): s = _symbol_converter(s) if isinstance(distribution, ContinuousDistribution): return SingleContinuousPSpace(s, distribution) if isinstance(distribution, DiscreteDistribution): return SingleDiscretePSpace(s, distribution) if isinstance(distribution, SingleFiniteDistribution): return SingleFinitePSpace(s, distribution) if not isinstance(distribution, CompoundDistribution): raise ValueError("%s should be an isinstance of " "CompoundDistribution"%(distribution)) return Basic.__new__(cls, s, distribution)
def _transform_pspace(self, sym, dist, pdf): """ This function returns the new pspace of the distribution using handmade Distributions and their corresponding pspace. """ pdf = Lambda(sym, pdf(sym)) _set = dist.set if isinstance(dist, ContinuousDistribution): return SingleContinuousPSpace(sym, ContinuousDistributionHandmade(pdf, _set)) elif isinstance(dist, DiscreteDistribution): return SingleDiscretePSpace(sym, DiscreteDistributionHandmade(pdf, _set)) elif isinstance(dist, SingleFiniteDistribution): dens = dict((k, pdf(k)) for k in _set) return SingleFinitePSpace(sym, FiniteDistributionHandmade(dens))
def FiniteRV(name, density): """ Create a Finite Random Variable given a dict representing the density. Returns a RandomSymbol. >>> from sympy.stats import FiniteRV, P, E >>> density = {0: .1, 1: .2, 2: .3, 3: .4} >>> X = FiniteRV('X', density) >>> E(X) 2.00000000000000 >>> P(X>=2) 0.700000000000000 """ return SingleFinitePSpace.fromdict(name, density).value
def FiniteRV(density, symbol=None): """ Create a Finite Random Variable given a dict representing the density. Returns a RandomSymbol. >>> from sympy.stats import FiniteRV, P, E >>> density = {0: .1, 1: .2, 2: .3, 3: .4} >>> X = FiniteRV(density) >>> E(X) 2.00000000000000 >>> P(X>=2) 0.700000000000000 """ return SingleFinitePSpace.fromdict(density, symbol).value
def rv(name, cls, *args): args = list(map(sympify, args)) dist = cls(*args) dist.check(*args) return SingleFinitePSpace(name, dist).value
def rv(name, cls, *args): density = cls(*args) return SingleFinitePSpace(name, density).value