text stringlengths 0 828 |
|---|
model_cdf = self.cdf(np.arange(l, b + 1), *args) |
unif_rands = np.random.random(size) |
model_rands = np.array([np.where(tx <= model_cdf)[0][0] + l |
for tx in unif_rands]) |
return model_rands" |
3888,"def fit_mle(self, data, b=None): |
""""""%(super)s |
In addition to data, requires ``b``, the upper limit of the |
distribution. |
"""""" |
# Take mean of data as MLE of distribution mean, then calculate p |
mu = np.mean(data) |
if not b: |
b = np.sum(data) |
p = _geom_solve_p_from_mu_vect(mu, b) |
# Just return float, not len 1 array |
if len(np.atleast_1d(p)) == 1: |
return float(p), b |
else: |
return p, b" |
3889,"def fit_mle(self, data, init_vals=(80, 80)): |
""""""%(super)s |
In addition to data, can take init_vals which allows the user to |
specify initial values for (alpha, theta) during the optimization. |
"""""" |
if len(data) > 1: |
mu = np.mean(data) |
var = np.var(data) |
theta0 = var / mu |
alpha0 = mu / theta0 |
else: |
alpha0 = init_vals[0] |
theta0 = init_vals[1] |
def mle(params): |
return -np.sum(np.log(self.pmf(data, params[0], params[1]))) |
# Bounded fmin? |
alpha, theta = optim.fmin(mle, x0=[alpha0, theta0], disp=0) |
return alpha, theta" |
3890,"def fit_mle(self, data, k_array=np.arange(0.1, 100, 0.1)): |
""""""%(super)s |
In addition to data, gives an optional keyword argument k_array |
containing the values to search for k_agg. A brute force search is then |
used to find the parameter k_agg. |
"""""" |
# todo: check and mention in docstring biases of mle for k_agg |
data = np.array(data) |
mu = np.mean(data) |
return mu, _solve_k_from_mu(data, k_array, nbinom_nll, mu)" |
3891,"def translate_args(self, mu, k_agg, return_p=False): |
""""""%(super)s |
The keyword argument return_p computes the p values used to define the |
the truncated negative binomial |
"""""" |
if return_p: |
return nbinom_ztrunc_p(mu, k_agg), k_agg |
else: |
return mu, k_agg" |
3892,"def fit_mle(self, data, k_agg0=0.5): |
""""""%(super)s |
In addition to data, gives an optional keyword argument k_agg0 that |
specifies the initial value of k_agg used in the optimization. |
"""""" |
mu = np.mean(data) |
def mle(k): |
return -np.sum(np.log(self.pmf(data, mu, k))) |
k = optim.fmin(mle, x0=k_agg0, disp=0) |
return mu, k[0]" |
3893,"def fit_mle(self, data, b=None): |
""""""%(super)s |
b : float |
The upper bound of the distribution. If None, fixed at sum(data) |
"""""" |
data = np.array(data) |
length = len(data) |
if not b: |
b = np.sum(data) |
return _trunc_logser_solver(length, b), b" |
3894,"def rank(self, n, mu, sigma, crit=.5, upper=10000, xtol=1): |
""""""%(super)s |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.