def __init__(self, y: float): super().__init__(samplespace=R((0, inf))) assert y > 0, Exception self.y = y
def rvsvar(self, P: float, n: int = None, p: float = None) -> 'Binomial': # Almost one parameter need to be specified assert (n is not None or p is not None) and P in R((0, 1)), Exception # Given Var(X) and n, return Binomial with parameter p if p is None: return Binomial(n, (1 + (1 - (4 * (P / n)))**0.5) / 2) # Given Var(X) and p, return Binomial with parameter n return Binomial(P / (p * (1 - p)), p)
def rvsev(self, P: float, n: int = None, p: float = None) -> 'Binomial': # Almost one parameter need to be defined assert (n is not None or p is not None) and P in R((0, 1)), Exception # Given E(X) and n, return new Binomial with parameter p if p is None: return Binomial(n, P / n) # Given E(X) and p, return new Binomial with parameter n return Binomial(P / p, p)
def rvspmf(self, x: int, n: int, P: float) -> 'Binomial': # Verify integrity of parameters assert x in N([0, ..., inf]) and n in N([0, ..., inf]) and P in R((0, 1)) # The equation to which to apply the zero theorem f = lambda c: (comb(n, x) * c**x * (1 - c)**(n - x)) - P # Given pmf(x) = P, return Binomial with parameter n and p return Binomial(n, R.bfzero(f, (0, 1)))
def __init__(self, p): # Call super class with a list of possible specifications (infinite, numerative specifications) super().__init__(samplespace=N()) assert p in R([0,1]), Exception # Probability parameter p of success of bernoulli event self.p = p
def __init__(self, mu, sigma): super().__init__(samplespace=R((-inf, inf))) # Mean self.mu = mu # teta ∈ R+ assert sigma >= 0, Exception() # Standard deviation self.sigma = sigma
def __init__(self, n: int = 0, p: float = 0): # Call super class with list of specifications super().__init__(samplespace=N([0, ..., n])) # p need to be in (0,1) and n must be natural value assert p in R([0, 1]) and n in N() # Probability parameter p of success of bernoulli event self.p = p # Number of independents events self.n = n
def quantile(data, q): assert data is not None and q in R((0,1)), Exception # Riordino l'array data = sorted(data) s,e = (ceil(len(data)*q), len(data) - floor(len(data)*(1-q))) # Interpolazione return (lambda s,e: (s*q + e*(1-q)))(*data[s-1: e+1])
def __init__(self, a, b): super().__init__(samplespace=R((a, b)))
def rvsdevstd(P: float) -> 'Bernoulli': # Verify integrity of value d passed assert P in R((0, 1)), Exception # p = (1 + (1 - (4*var)**0.5)) / 2)) ** 0.5 return Bernoulli(rvsvar(P**2))
def rvsvar(P): # Variance need to be in (0,1) assert P in R((0, 1)), Exception # p = 1 + (1 - (4*var)**0.5)) / 2) return Bernoulli((1 + (1 - (4 * P))**0.5) / 2)
def rvsev(P): # Excpected value need to be in (0,1) assert P in R((0, 1)), Exception # p = ev return Bernoulli(P)
def rvspmf(x: int, P: float): # Verify integrity of parameters assert x in N([0, ..., inf]) and P in R((0, 1)) # p = return Bernoulli(P if x == 0 else 1 - P)
def rvsdevstd(self, P: float): # Verify integrity of value d passed assert P in R((0, 1)), Exception # Given DevStd(X), return new Binomial with parameter p or n return self.fvar(P**2)