Ejemplo n.º 1
0
    def moment(self, n, mu, sigma):
        r"""

        n-th (non central) moment of the Normal distribution

        .. math::
            E = ... complicated.

        Parameters
        ----------

        n : integer or numpy array of integers
            The ordinal of the moment to calculate
        mu : numpy array or scalar
            The location parameter for the Normal distribution
        sigma : numpy array or scalar
            The scale parameter for the Normal distribution

        Returns
        -------

        moment : scalar or numpy array 
            The moment(s) of the Normal distribution

        Examples
        --------
        >>> from surpyval import Normal
        >>> Normal.moment(2, 3, 4)
        25.0
        """
        return scipy_norm.moment(n, mu, sigma)
Ejemplo n.º 2
0
    def generate_moments(self, max_moment):
        '''
        Calculate & store moments to retrieve more efficiently later
        '''

        self._moments = np.zeros((max_moment, 1))

        #Rely on scipy.stats to return non-central moment
        for i in range(max_moment):
            self._moments[i] = scipynormal.moment(i+1, self._mean, self._std)
Ejemplo n.º 3
0
 def norm_distribution(*args):
     try:
         a, b = float(args[0]), float(args[1])
     except (ValueError, TypeError):
         return {'is_valid': False}
     if not b > 0:
         return {'is_valid': False}
     t = Symbol('t')
     mean, var, mean2 = a, b, norm.moment(2, loc=a, scale=sqrt(b))
     cf = exp(I * a * t - b * t**2 / 2)
     d_cf = diff(cf, t)
     dd_cf = diff(d_cf, t)
     return {
         'a': a,
         'b': b,
         'mean': mean,
         'mean2': mean2,
         'var': var,
         'g': latex(nsimplify(cf, tolerance=0.1)),
         'g1': latex(nsimplify(d_cf, tolerance=0.1)),
         'g2': latex(nsimplify(dd_cf, tolerance=0.1)),
         'type': type,
         'is_valid': True,
     }
Ejemplo n.º 4
0
 def compute_moment(self, order):
     if order not in self._moment_values.keys():
         self._moment_values[order] = norm.moment(order,
                                                  loc=self._mean,
                                                  scale=self._variance**0.5)
     return self._moment_values[order]
Ejemplo n.º 5
0
dir(rv)

dist_continu = [d for d in dir(stats) if isinstance(getattr(stats, d), stats.rv_continuous)]
dist_discrete = [d for d in dir(stats) if isinstance(getattr(stats, d), stats.rv_discrete)]



n = np.empty(1000)

for i in range(1000):
    n[i] = norm.rvs()

plt.hist(n, bins = 50, density = 1)
plt.hist(norm.pdf(n), bins = 50, density = 1)
plt.hist(norm.cdf(n), bins = 50, density = 1)
plt.hist(norm.moment(n.any()), bins = 50, density = 1)
norm.mean()
norm.var()
norm.ppf(0.5) # median of 0-1 normal distribution
norm.rvs(size = 3)

norm.rvs(size = 3, random_state = 1234)
norm.rvs(3) # the first arguement is the loc (mean, in case of normal distrubution) parameter, not size


# Shifting and scaling
x = norm.rvs(size = 5, loc = 3, scale = 4)
norm.stats(x)

norm.stats(loc = 3, scale = 4, moments = "mv")