def main(): bootstrap() display_introduction() factory = Router() command = None while not is_command_exit(command): clear_screen() command = get_command() try: factory.execute_command(command) except Exception as e: print(e)
def plot_bar(variations, q=None, show_title=False): index = np.arange(len(variations)) bar_width = 0.8 mu = np.empty(len(variations)) se = np.empty(len(variations)) for i, v in enumerate(variations): scores = v.LOO_scores if q is None: f = np.mean else: def f(vals): return np.percentile(vals, q) mu[i], se[i] = bootstrap(scores, f) fig = plt.figure() ax = fig.add_axes([0.12, 0.12, 0.8, 0.8]) ax.bar( index, mu, yerr=se, width=bar_width, color='b', error_kw={ 'ecolor': '0.3', 'linewidth': 2 }, ) ttl = '' if q is None: ttl = 'Mean $R^2$ dependence on priors' ylabel = 'mean $R^2$' else: ttl = '{} percentile $R^2$ dependence on priors'.format(q) ylabel = '{} percentile $R^2$'.format(q) if show_title: ax.set_title(ttl, fontsize=fontsize) ax.set_xlabel('which priors', fontsize=fontsize) ax.set_ylabel(ylabel, fontsize=fontsize) ax.set_xticks(index + bar_width / 2) ax.set_xticklabels([latex_label(v.theta, v.sigma) for v in variations]) ticks = [0, 0.1, 0.2, 0.3] ax.set_yticks(ticks) ax.set_yticklabels(['{:g}'.format(t) for t in ticks]) ax.tick_params(axis='both', labelsize=fontsize) ax.set_ylim(0, 0.3) return fig
def analyze_variant(theta,sigma): theta_priors = priors_name if theta else None sigma_prior = 'normal' if sigma else None shape = Sigslope(theta_priors) fitter = Fitter(shape,sigma_prior) fits = get_all_fits(data,fitter,allow_new_computation=False) LOO_scores = [f.LOO_score for f in iterate_fits(fits) if f.LOO_score is not None] mu,sem = bootstrap(LOO_scores, np.mean) return Bunch( theta = theta, sigma = sigma, LOO_scores = LOO_scores, mu = mu, sem = sem, )
def analyze_variant(theta, sigma): theta_priors = priors_name if theta else None sigma_prior = 'normal' if sigma else None shape = Sigslope(theta_priors) fitter = Fitter(shape, sigma_prior) fits = get_all_fits(data, fitter, allow_new_computation=False) LOO_scores = [ f.LOO_score for f in iterate_fits(fits) if f.LOO_score is not None ] mu, sem = bootstrap(LOO_scores, np.mean) return Bunch( theta=theta, sigma=sigma, LOO_scores=LOO_scores, mu=mu, sem=sem, )
def plot_bar(variations, q=None, show_title=False): index = np.arange(len(variations)) bar_width = 0.8 mu = np.empty(len(variations)) se = np.empty(len(variations)) for i,v in enumerate(variations): scores = v.LOO_scores if q is None: f = np.mean else: def f(vals): return np.percentile(vals,q) mu[i],se[i] = bootstrap(scores, f) fig = plt.figure() ax = fig.add_axes([0.12,0.12,0.8,0.8]) ax.bar( index, mu, yerr=se, width=bar_width, color='b', error_kw = {'ecolor': '0.3', 'linewidth': 2}, ) ttl = '' if q is None: ttl = 'Mean $R^2$ dependence on priors' ylabel = 'mean $R^2$' else: ttl = '{} percentile $R^2$ dependence on priors'.format(q) ylabel = '{} percentile $R^2$'.format(q) if show_title: ax.set_title(ttl, fontsize=fontsize) ax.set_xlabel('which priors', fontsize=fontsize) ax.set_ylabel(ylabel, fontsize=fontsize) ax.set_xticks(index + bar_width/2) ax.set_xticklabels([latex_label(v.theta,v.sigma) for v in variations]) ticks = [0,0.1,0.2,0.3] ax.set_yticks(ticks) ax.set_yticklabels(['{:g}'.format(t) for t in ticks]) ax.tick_params(axis='both', labelsize=fontsize) ax.set_ylim(0,0.3) return fig
def setUpClass(cls): bootstrap()
from datetime import datetime, timedelta import pytest from app.storage import Storage from utils.bootstrap import bootstrap bootstrap() storage = Storage() class TestToken: @pytest.fixture(scope='class') def new_token(self): return storage.add_token() def test_add_token(self, new_token): token, expires = new_token assert token assert not expires def test_verify_expire_token(self, new_token): token, expires = new_token assert storage.verify_token(token) assert storage.expire_token(token) def test_expired_token(self, new_token): token, expires = new_token assert not storage.verify_token(token) def test_delete_token(self, new_token): token, expires = new_token