Package gmisclib :: Module gpkmisc
[frames] | no frames]

Module gpkmisc

source code

Classes
  threaded_readable_file
  dir_lock
  PrereqError
Functions
 
median(x) source code
 
median_across(xl) source code
 
avg(x) source code
 
median_ad(x)
Median absolute deviation
source code
 
mad(x)
Median absolute deviation
source code
 
mean(x) source code
(float, float) or (float, None)
mean_stdev(x)
Returns: the mean and standard deviation of the input list.
source code
 
mean_ad(x) source code
float
geo_mean(*d)
Returns: Geometric mean of its arguments.
source code
 
entropy(x)
Compute the entropy of a list of probabilities.
source code
 
resample(d)
Bootstrap resampling.
source code
 
jackknife(d)
Jackknife resampling.
source code
 
Student_t_dens(x, n)
From p.337 Statistical Theory by Bernard Lindgren.
source code
 
log_Student_t_dens(x, n)
From p.337 Statistical Theory by Bernard Lindgren.
source code
 
log_factorial(n) source code
 
log_Combinations(n, m) source code
 
ComplexMedian(P)
P is a list of complex numbers.
source code
 
testCM() source code
 
thr_iter_read(fd)
Read the contents of a file as an iterator.
source code
 
makedirs(fname, mode=509)
This makes the specified directory, including all necessary directories above it.
source code
 
shuffle_Nrep(y, n=1, compare=None)
Shuffle a list, y, so that no item occurs more than n times in a row.
source code
 
testSNR() source code
 
open_nowipe(nm1, nm2, mode='w')
Open a file (typically for writing) but make sure that the file doesn't already exist.
source code
 
dropfront(prefix, s)
Drops the prefix from the string and raises an exception if it is not there to be dropped.
source code
 
open_compressed(fn) source code
 
gammaln(x) source code
 
a_factor(n)
Finds the smallest prime factor of a number.
source code
 
primes()
This is a generator that produces an infinite list of primes.
source code
list
factor(n)
Factor a number into a list of prime factors, in increasing order.
source code
 
test_primes() source code
int
gcd(a, b)
Greatest common factor/denominator.
source code
str
find_in_PATH(progname)
Search PATH to find where a program resides.
source code
None or float
get_mtime(fn)
Paired with need_to_recompute().
source code
 
prereq_mtime(*tlist) source code
bool
need_to_recompute(fn, lazytime, size=-1)
Paired with get_mtime().
source code
 
truncate(s, maxlen) source code
 
erf(x)
erf(x)=(2/sqrt(pi))*integral{0 to x of exp(-t**2) dt}
source code
 
asinh(x)
Inverse hyperbolic sine.
source code
whatever is inside x
chooseP(x, p)
Sample from a list with specified probabilities.
source code
 
misc_mode(lx)
Returns: The most common object from a list of arbitrary objects.
source code
str
distrib(key)
Returns: The release name of the linux distribution that you're running.
source code
Variables
  __package__ = 'gmisclib'

Imports: os, sys, math, time, stat, errno, die, N_maximum, N_minimum, N_median, N_mean_ad, variance, stdev, set_diag, make_diag, limit, vec_variance, qform, KolmogorovSmirnov, interp, interpN, Queue, threading


Function Details

median(x)

source code 
Raises:
  • ValueError - if the input list is zero length.

median_across(xl)

source code 
Raises:
  • ValueError - If the input vectors are different lengths.
  • ValueError - see median.

Note: There is a version of this in Numeric_gpk that is more efficient when the input is a list of numpy.ndarray vectors.

mean_stdev(x)

source code 
Parameters:
  • x (list(float), typically.) - A list of data to average.
Returns: (float, float) or (float, None)
the mean and standard deviation of the input list. If there is only one datum, the standard deviation is reported as None.
Raises:
  • ValueError - If there is no data.

geo_mean(*d)

source code 
Returns: float
Geometric mean of its arguments.
Raises:
  • ValueError - if any argument is negative.

resample(d)

source code 

Bootstrap resampling. Call this many times: each one returns a random resampling.

jackknife(d)

source code 

Jackknife resampling. Call this once. It returns a list of deleted lists.

ComplexMedian(P)

source code 

P is a list of complex numbers. This algorithm works by repeatedly stripping off the convex hull of the points.

thr_iter_read(fd)

source code 

Read the contents of a file as an iterator. The read is two-threaded, so that one thread can be waiting on disk I/O while the other thread is processing the results.

makedirs(fname, mode=509)

source code 

This makes the specified directory, including all necessary directories above it. It is like os.makedirs(), except that if the directory already exists it does not raise an exception.

Parameters:
  • fname (str) - Name of the directory to create.
  • mode (int) - Linux file permissions for any directories it needs to create.
Raises:
  • OSError - If it cannot create a part of the directory chain.

Note: If the directory already exists, it does not force it to have the specified mode.

shuffle_Nrep(y, n=1, compare=None)

source code 

Shuffle a list, y, so that no item occurs more than n times in a row. Equality is determined by the comparison function compare returning zero.

open_nowipe(nm1, nm2, mode='w')

source code 

Open a file (typically for writing) but make sure that the file doesn't already exist. The name is constructed from nm1, a sequence number, and nm2. The sequence number gets incremented until a name is found that doesn't exist. This works by creating a directory as a lock file; it should be safe across NFS.

Parameters:
  • nm1 (str) - the part of the name to the left of the sequence number
  • nm2 (str) - the part of the name to the right of the sequence number Typically, nm2 is a suffix like ".wav". This may not contain a slash.
  • mode (str @rtype file) - The way to open the file -- passed to open().
Returns:
The opened file object. (Its name can be gotten from the name attribute.)

Note: The directory containing nm1 must exist and be writeable.

factor(n)

source code 

Factor a number into a list of prime factors, in increasing order.

Parameters:
  • n (int) - input number
Returns: list
prime factors

gcd(a, b)

source code 

Greatest common factor/denominator.

Parameters:
  • a (int)
  • b (int)
Returns: int
the greatest common factor of a and b.

find_in_PATH(progname)

source code 

Search PATH to find where a program resides.

Parameters:
  • progname (str) - the program to look for.
Returns: str
the full path name.

get_mtime(fn)

source code 

Paired with need_to_recompute(). These implement something like make, where we figure out if we need to compute things based on the age of files. This is used to get the age of the pre-requisites.

Parameters:
  • fn (str or file) - a filename or a file
Returns: None or float
None (if the file doesn't exist) or its modification time.

need_to_recompute(fn, lazytime, size=-1)

source code 

Paired with get_mtime(). These implement something like make, where we figure out if we need to compute things.

Parameters:
  • fn (str or file) - a filename or a file
  • lazytime (None or float) - a time (as obtained from ST_MTIME in os.stat()). If the file modification time of fn is older than lazytime, recompute.
  • size (int) - recompute the file if it is smaller than size. Normally, this is used to recompute on empty output files by setting size=0.
Returns: bool
True if fn needs to be recomputed or if it doesn not exist.

chooseP(x, p)

source code 

Sample from a list with specified probabilities.

Parameters:
  • x (list(something)) - a list of things from which to sample
  • p (list(float)) - a list of probabilities for sampling the corresponding item of x.
Returns: whatever is inside x
a sample from x
Raises:
  • AssertionError - Will (sometimes) detect negative probabilities, or probabilities that sum to something other than one.

misc_mode(lx)

source code 
Parameters:
  • lx - a sequence of hashable objects.
Returns:
The most common object from a list of arbitrary objects.

distrib(key)

source code 
Returns: str
The release name of the linux distribution that you're running.