def cumulant_from_moments(momt, n):
 if (n < 1):
  raise ValueError(('Expected a positive integer. Got %s instead.' % n))
 if (len(momt) < n):
  raise ValueError(('%s-th cumulant requires %s moments, only got %s.' % (n, n, len(momt))))
 kappa = 0.0
 for p in _faa_di_bruno_partitions(n):
  r = sum((k for (m, k) in p))
  term = (((-1) ** (r - 1)) * factorial((r - 1)))
  for (m, k) in p:
   term *= (np.power((momt[(m - 1)] / factorial(m)), k) / factorial(k))
  kappa += term
 kappa *= factorial(n)
 return kappa

def cumulant_from_moments ( momt , n ) : if ( n < 1 ) : raise ValueError ( ( 'Expected a positive integer. Got %s instead.' % n ) ) if ( len ( momt ) < n ) : raise ValueError ( ( '%s-th cumulant requires %s moments, only got %s.' % ( n , n , len ( momt ) ) ) ) kappa = 0.0 for p in _faa_di_bruno_partitions ( n ) : r = sum ( ( k for ( m , k ) in p ) ) term = ( ( ( - 1 ) ** ( r - 1 ) ) * factorial ( ( r - 1 ) ) ) for ( m , k ) in p : term *= ( np . power ( ( momt [ ( m - 1 ) ] / factorial ( m ) ) , k ) / factorial ( k ) ) kappa += term kappa *= factorial ( n ) return kappa
compute n-th cumulant given moments .