text stringlengths 0 828 |
|---|
else: |
backend = PlaybackBackend( |
recording_filename=filename |
) |
gui = GUI(backend) |
return wrapped(gui, *args, **kwargs)" |
3877,"def reverse_cyk_transforms(root): |
# type: (Nonterminal) -> Nonterminal |
"""""" |
Reverse transformation made to grammar before CYK. |
Performs following steps: |
- transform from chomsky normal form |
- restore unit rules |
- restore epsilon rules |
:param root: Root node of the parsed tree. |
:return: Restored parsed tree. |
"""""" |
root = InverseContextFree.transform_from_chomsky_normal_form(root) |
root = InverseContextFree.unit_rules_restore(root) |
root = InverseContextFree.epsilon_rules_restore(root) |
return root" |
3878,"def _geom_solve_p_from_mu(mu, b): |
"""""" |
For the geom_uptrunc, given mu and b, return p. |
Ref: Harte 2011, Oxford U Press. Eq. 7.50. |
"""""" |
def p_eq(x, mu, b): |
x, mu, b = Decimal(x), Decimal(mu), Decimal(b) |
return ( (x / (1 - x)) - ((b + 1) / (x**-b - 1)) - mu ) |
# x here is the param raised to the k_agg power, or 1 - p |
return 1 - optim.brentq(p_eq, 1e-16, 100, args=(mu, b), disp=True)" |
3879,"def _nbinom_ztrunc_p(mu, k_agg): |
"""""" Calculates p parameter for truncated negative binomial |
Function given in Sampford 1955, equation 4 |
Note that omega = 1 / 1 + p in Sampford |
"""""" |
p_eq = lambda p, mu, k_agg: (k_agg * p) / (1 - (1 + p)**-k_agg) - mu |
# The upper bound needs to be large. p will increase with increasing mu |
# and decreasing k_agg |
p = optim.brentq(p_eq, 1e-10, 1e10, args=(mu, k_agg)) |
return p" |
3880,"def _ln_choose(n, k_agg): |
''' |
log binomial coefficient with extended gamma factorials. n and k_agg may be |
int or array - if both array, must be the same length. |
''' |
gammaln = special.gammaln |
return gammaln(n + 1) - (gammaln(k_agg + 1) + gammaln(n - k_agg + 1))" |
3881,"def _solve_k_from_mu(data, k_array, nll, *args): |
"""""" |
For given args, return k_agg from searching some k_range. |
Parameters |
---------- |
data : array |
k_range : array |
nll : function |
args : |
Returns |
-------- |
:float |
Minimum k_agg |
"""""" |
# TODO: See if a root finder like fminbound would work with Decimal used in |
# logpmf method (will this work with arrays?) |
nll_array = np.zeros(len(k_array)) |
for i in range(len(k_array)): |
nll_array[i] = nll(data, k_array[i], *args) |
min_nll_idx = np.argmin(nll_array) |
return k_array[min_nll_idx]" |
3882,"def _trunc_logser_solver(bins, b): |
"""""" |
Given bins (S) and b (N) solve for MLE of truncated logseries |
parameter p |
Parameters |
----------- |
bins : float |
Number of bins. Considered S in an ecological context |
b : float |
Upper truncation of distribution. Considered N in an ecological context |
Returns |
------- |
: float |
MLE estimate of p |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.