MACS3.Signal.Prob module
Module Description: statistics functions to calculate p-values
This code is free software; you can redistribute it and/or modify it under the terms of the BSD License (see the file LICENSE included with the distribution).
- MACS3.Signal.Prob.binomial_cdf(x, a, b, lower=True)
BINOMIAL_CDF compute the binomial CDF.
CDF(x)(A,B) is the probability of at most X successes in A trials, given that the probability of success on a single trial is B.
- MACS3.Signal.Prob.binomial_cdf_inv(cdf, a, b)
BINOMIAL_CDF_INV inverts the binomial CDF. For lower tail only!
- MACS3.Signal.Prob.binomial_pdf(x, a, b)
binomial PDF by H. Gene Shin
- MACS3.Signal.Prob.binomial_sf(x, a, b, lower=True)
BINOMIAL_SF compute the binomial survival function (1-CDF)
SF(x)(A,B) is the probability of more than X successes in A trials, given that the probability of success on a single trial is B.
- MACS3.Signal.Prob.chisq_logp_e(x, df, log10=False)
Chisq CDF function in log space for upper tail and even degree of freedom Good for p-value calculation and designed for combining pvalues.
Note: we assume df to be an even number larger than 1! Do not violate this assumption and there is no checking.
Return value is -logp. If log10 is set as True, return -log10p instead.
- MACS3.Signal.Prob.chisq_pvalue_e(x, df)
Chisq CDF function for upper tail and even degree of freedom. Good for p-value calculation and designed for combining pvalues.
Note: we assume df to be an even number larger than 1! Do not violate this assumption and there is no checking.
df has to be even number! if df is odd, result will be wrong!
- MACS3.Signal.Prob.factorial(n)
Calculate N!.
- MACS3.Signal.Prob.pduplication(pmf, N_obs)
return the probability of a duplicate fragment given a pmf and a number of observed fragments N_obs
- MACS3.Signal.Prob.pnorm(x, u, v)
The probability of X=x when X=Norm(u,v)
v is int32_t
- MACS3.Signal.Prob.pnorm2(x, u, v)
The probability of X=x when X=Norm(u,v)
v is float32_t
- MACS3.Signal.Prob.poisson_cdf(n, lam, lower=False, log10=False)
Poisson CDF evaluater.
This is a more stable CDF function. It can tolerate large lambda value. While the lambda is larger than 700, the function will be a little slower.
Parameters: n : your observation lam : lambda of poisson distribution lower : if lower is False, calculate the upper tail CDF, otherwise, to
calculate lower tail; Default is False.
- log10if log10 is True, calculation will be in log space. Default is
False.
- MACS3.Signal.Prob.poisson_cdf_Q_inv(cdf, lam, maximum=1000)
inverse poisson distribution.
cdf : the CDF lam : the lambda of poisson distribution
note: maxmimum return value is 1000 and lambda must be smaller than 740.
- MACS3.Signal.Prob.poisson_cdf_Q_log10_many(n, lam, out)
Set out[i] to poisson_cdf(n[i], lam[i], False, True), exactly.
Concurrent calls retain independent immutable table snapshots.
- MACS3.Signal.Prob.poisson_cdf_Q_log10_prepare(max_n)
Cache log tables up to max_n; return False if allocation fails.
Preparation is an optimization, not a concurrency requirement. Readers retain immutable generations even when other calls publish larger ones.
- MACS3.Signal.Prob.poisson_cdf_Q_log10_range(n, lam, out, start, end)
Set out[i] to poisson_cdf(n[i], lam[i], False, True) for start <= i < end without the GIL. Every lam[i] must be > 0.
Concurrent scalar, batch, prepare and range calls are safe without prior preparation. Growth failure uses the existing prefix and ordered uncached sums. Each call retains its table storage until completion.
- MACS3.Signal.Prob.poisson_cdf_inv(cdf, lam, maximum=1000)
inverse poisson distribution.
cdf : the CDF lam : the lambda of poisson distribution
note: maxmimum return value is 1000 and lambda must be smaller than 740.
- MACS3.Signal.Prob.poisson_pdf(k, a)
Poisson PDF.
PDF(K,A) is the probability that the number of events observed in a unit time period will be K, given the expected number of events in a unit time as A.
Concurrent Poisson scoring
poisson_cdf (log10 upper tail), poisson_cdf_Q_log10_many,
poisson_cdf_Q_log10_prepare, and poisson_cdf_Q_log10_range may run
concurrently. Each scoring call retains an immutable snapshot of the
logarithm tables until its native computation finishes. Range and batch
computation release the GIL. Use separate output buffers or disjoint output
ranges, and keep input arrays unchanged while calls are running.
Preparation is optional and can reduce later allocation work. Growth creates
both replacement tables before publishing them under the GIL. If allocation
fails, the previous tables remain valid and scoring uses the ordered uncached
calculation for entries outside that snapshot. Preparation returns False
when its requested table prefix could not be allocated. These paths preserve
the scalar calculation’s operation order and five-decimal rounding.
At the default limit of 2**22 entries, the two float64 tables occupy at most 64 MiB per generation. The current generation remains cached for reuse. Retired generations are released when their last active reader finishes; construction and overlapping readers can temporarily use more than 64 MiB.