moremath
index


 
Various bits of useful math not in the standard python library.
 
Constants :
 
- euler_gamma  = 0.577215...
- catalan      = 0.915965...
- golden_ratio = 1.618033...
- bits_per_nat = log2(e) = 1/log(2) 
- sqrt_2pi     = 2.50662...
    
Special Functions :
 
- gamma()                       -- Gamma function.
- lngamma()                     -- Logarithm of the gamma function
- factorial()                   -- The factorial function.
- digamma()                     -- Digamma function (logarithmic derivative of gamma).
- trigamma()                    -- Trigamma function (derivative of digamma).
- entropy()                     -- The entropy of a probability vector
- incomplete_gamma()            -- The 'upper' incomplete gamma function.
- normalized_incomplete_gamma() -- 
- lg()                          -- Base 2 logarithms.
 
 
Vector Operations :
 
- rmsd()            -- Root mean squared deviation of two point vectors
- minimize_rmsd()   -- Find the rigid transformation that minimized the 
                            RMSD between two vectors of points. 
    
Minimization :
 
- find_root()          -- 1d root finding
 
Probability Distributions :
- Gamma
- Dirichlet
- Multinomial
- Gaussian

 
Functions
       
argmax(alist)
Return the index of the last occurance of the maximum value in the list.
argmin(alist)
Return the index of the first occurance of the minimum value in the list.
digamma(z)
The digamma function, the logarithmic derivative of the gamma function.
        digamma(z) = d/dz ln( gamma(z) )
 
See: Eric W. Weisstein. "Digamma Function." From MathWorld--
A Wolfram Web Resource. http://mathworld.wolfram.com/DigammaFunction.html
entropy(pvec, base=2.718281828459045)
The entropy S = -Sum_i p_i ln p_i
pvec is a frequency vector, not necessarily normalized.
factorial(z)
The factorial function. 
factorial(z) == gamma(z+1)
gamma(z)
The gamma function. Returns exact results for small integers. Will
overflow for modest sized arguments. Use lngamma(z) instead.
 
See: Eric W. Weisstein. "Gamma Function." From MathWorld, A Wolfram Web Resource.
     http://mathworld.wolfram.com/GammaFunction.html
incomplete_gamma(a, x)
The 'upper' incomplete gamma function:
 
                        oo
                         -
                        |    -t  a-1
incomplete_gamma(a,x) = |   e   t   dt.
                        |
                       -                         
                        x
 
In Mathematica, Gamma[a,x].
 
Note that, very confusingly, the phrase 'incomplete gamma fucntion'
can also refer to the same integral between 0 and x, (the 'lower'
incomplete gamma function) or to the normalized versions,
normalized_incomplete_gamma() )
 
 
See: Eric W. Weisstein. "Gamma Function." From MathWorld, A Wolfram Web Resource.
     http://mathworld.wolfram.com/IncompleteGammaFunction.html
 
Bugs :
    This implentation is not very accurate for some arguments.
lngamma(z)
The logarithm of the gamma function.
log2(x)
Return the base 2 logarithm of x
normalized_incomplete_gamma(a, x)
The upper, incomplete gamma function normalized so that the limiting
values are zero and one.
 
 Q(a,x) = incomplete_gamma(a,x) / gamma(a) 
 
See: 
    incomplete_gamma()
Bugs :
    This implentation is not very accurate for some arguments.
trigamma(z)
The trigamma function, the derivative of the digamma function.
        trigamma(z) = d/dz digamma(z) = d/dz d/dz ln( gamma(z) )
 
See: Eric W. Weisstein. "Digamma Function." From MathWorld--
A Wolfram Web Resource. http://mathworld.wolfram.com/TrigammaFunction.html

 
Data
        __all__ = ('euler_gamma', 'catalan', 'golden_ratio', 'bits_per_nat', 'sqrt_2pi', 'gamma', 'lngamma', 'factorial', 'digamma', 'trigamma', 'entropy', 'log2', 'incomplete_gamma', 'normalized_incomplete_gamma', 'argmax', 'argmin')
bits_per_nat = 1.4426950408889634
catalan = 0.915965594177219
euler_gamma = 0.5772156649015329
golden_ratio = 1.618033988749895
sqrt_2pi = 2.5066282746310007