def get_generalized_distribution(self, params, scale=1, exog=None, exposure=None, offset=None): """ Returns a random number generator for the predictive distribution. Parameters ---------- params : array-like The model parameters. scale : scalar The scale parameter. exog : array-like The predictor variable matrix. Returns a frozen random number generator object. Use the ``rvs`` method to generate random values. Notes ----- Due to the behavior of ``scipy.stats.distributions objects``, the returned random number generator must be called with ``gen.rvs(n)`` where ``n`` is the number of observations in the data set used to fit the model. If any other value is used for ``n``, misleading results will be produced. """ fit = self.predict(params, exog, exposure, offset, linear=False) import scipy.stats.distributions as dist if isinstance(self.family, families.Gaussian): return dist.norm(loc=fit, scale=np.sqrt(scale)) elif isinstance(self.family, families.Binomial): return dist.binom(n=1, p=fit) elif isinstance(self.family, families.Poisson): return dist.poisson(mu=fit) elif isinstance(self.family, families.Gamma): alpha = fit / float(scale) return dist.gamma(alpha, scale=scale) else: raise ValueError( "get_generalized_distribution not implemented for %s" % self.family.name)
def pbinom(q, size, prob): '''Binomial probabilites - measured from the left.''' dist = distributions.binom(size, prob) return dist.cdf(q)
def hits_prob_fun(num_hits, num_abs, hit_prob): return binom(n=num_abs, p=hit_prob).pmf(num_hits)
def binomial(p,h,N): dist=D.binom(N,p) return dist.pmf(h)
def pbinom(q,size,prob): '''Binomial probabilites - measured from the left.''' dist = distributions.binom(size,prob) return dist.cdf(q)
def binomial(p, h, N): dist = D.binom(N, p) return dist.pmf(h)
"lr": { "type": float }, "momentum": { "type": float }, "nesterov": { "type": bool }, } # Define the distributions to sample from distributions = { "lr": log_uniform(-5, 2), "momentum": uniform(0.5, 0.5), "nesterov": binom(1, 0.5), } # Allow 36 random evaluations. tuner = RandomSearch( optimizer_class, hyperparams, distributions, runner=StandardRunner, ressources=36, ) # Tune (i.e. evaluate 36 different random samples) and rerun the best setting with 10 different seeds. tuner.tune( "quadratic_deep", rerun_best_setting=True,
'nesterov': [False, True] } # Make sure to set the amount of resources to the grid size. For grid search, this is just a sanity check. tuner = GridSearch(optimizer_class, hyperparams, grid, runner=StandardRunner, ressources=6 * 3 * 2) ### Random Search ### # Define the distributions to sample from distributions = { 'lr': log_uniform(-5, 2), 'momentum': uniform(0.5, 0.5), 'nesterov': binom(1, 0.5) } # Allow 36 random evaluations. tuner = RandomSearch(optimizer_class, hyperparams, distributions, runner=StandardRunner, ressources=36) ### Bayesian Optimization ### # The bounds for the suggestions bounds = {'lr': (-5, 2), 'momentum': (0.5, 1), 'nesterov': (0, 1)} # Corresponds to rescaling the kernel in log space.
def prob(height, left): return 1 - binom(left, .5).cdf(height - 1)