def testPRPaths(self):
        """Use a pr_paths when pull is set."""

        with Stub(bootstrap, 'ci_paths', Bomb):
            with Stub(bootstrap, 'pr_paths', FakePath()) as path:
                bootstrap.bootstrap(JOB, REPO, None, PULL, ROOT)
            self.assertTrue(PULL in path.a or PULL in path.kw)
 def testRoot_NotExists(self):
     with Stub(os, 'chdir', FakeCall()) as fake_chdir:
         with Stub(os.path, 'exists', lambda p: False):
             with Stub(os, 'makedirs', FakeCall()) as fake_makedirs:
                 bootstrap.bootstrap(JOB, REPO, None, PULL, ROOT)
     self.assertTrue(any(ROOT in c[0] for c in fake_chdir.calls), fake_chdir.calls)
     self.assertTrue(any(ROOT in c[0] for c in fake_makedirs.calls), fake_makedirs.calls)
    def testCIPaths(self):
        """Use a ci_paths when branch is set."""

        with Stub(bootstrap, 'pr_paths', Bomb):
            with Stub(bootstrap, 'ci_paths', FakePath()) as path:
                bootstrap.bootstrap(JOB, REPO, BRANCH, None, ROOT)
            self.assertFalse(any(
                PULL in o for o in (path.a, path.kw)))
示例#4
0
 def bootstrap(self, admin_password='******'):
     import bootstrap
     web.ctx.ip = '127.0.0.1'
     
     import cache
     cache.loadhook()
     
     bootstrap.bootstrap(self, admin_password)
示例#5
0
def setup_app(command, conf, vars):
    """Place any commands to setup turbotequila here"""
    print "load environment"
    load_environment(conf.global_conf, conf.local_conf)
    print "setup schema"
    setup_schema(command, conf, vars)
    print "bootstrap"
    bootstrap.bootstrap(command, conf, vars)
示例#6
0
文件: __init__.py 项目: bbcf/biorepo
def setup_app(command, conf, vars):
    """Place any commands to setup biorepo here"""
    print 'load environment'
    load_environment(conf.global_conf, conf.local_conf)
    print 'setup schema'
    setup_schema(command, conf, vars)
    print 'bootstrap'
    bootstrap.bootstrap(command, conf, vars)
 def testFinishWhenBuildFails(self):
     def CallError(*a, **kw):
         raise subprocess.CalledProcessError(1, [], '')
     with Stub(bootstrap, 'finish', FakeFinish()) as fake:
         with Stub(bootstrap, 'call', CallError):
             with self.assertRaises(SystemExit):
                 bootstrap.bootstrap(JOB, REPO, BRANCH, None, ROOT)
     self.assertTrue(fake.called)
     self.assertTrue(fake.result is False)  # Distinguish from None
    def testBranch(self):
        subprocess.check_call(['git', 'checkout', '-b', self.BRANCH])
        subprocess.check_call(['git', 'rm', self.MASTER])
        subprocess.check_call(['touch', self.BRANCH_FILE])
        subprocess.check_call(['git', 'add', self.BRANCH_FILE])
        subprocess.check_call(['git', 'commit', '-m', 'Create %s' % self.BRANCH])

        os.chdir('/tmp')
        bootstrap.bootstrap('fake-branch', self.REPO, self.BRANCH, None, self.root_workspace)
示例#9
0
 def __test__(q):
     try:
         os.setuid(sudo_uid)
         os.environ["JAVA_HOME"] = "/usr/java/latest"
         bootstrap_dir = tempfile.mkdtemp()
         postgres_datadir_path = bootstrap.postgres_datadir_path_default
         bootstrap.bootstrap(bootstrap_dir=bootstrap_dir, skip_build=False, postgres_datadir_path=postgres_datadir_path, force_overwrite_postgres_datadir=None, postgresql_jdbc_url=postgresql_jdbc_url, postgresql_deb_url=postgresql_deb_url, geotools_url=geotools_url, postgis_url=postgis_url, jgrapht_url=jgrapht_url, jfuzzy_url=jfuzzy_url, maven_bin_archive_url=maven_bin_archive_url, commons_src_archive_url=commons_src_archive_url)
     except Exception as ex:
         q.put(ex)
示例#10
0
def main():
    if not os.path.exists(CONSTANTS.DB_NAME):
        bootstrap.bootstrap()

    from paste import httpserver
    logging.basicConfig(level=logging.INFO)
    logging.info("Event manager started")
    webbrowser.open("http://127.0.0.1:8080")
    httpserver.serve(web_app, host='127.0.0.1', port='8080')
    logging.info("Event manager terminated")
示例#11
0
 def testPr(self):
     subprocess.check_call(['git', 'checkout', 'master'])
     subprocess.check_call(['git', 'checkout', '-b', 'unknown-pr-branch'])
     subprocess.check_call(['git', 'rm', self.MASTER])
     subprocess.check_call(['touch', self.PR_FILE])
     subprocess.check_call(['git', 'add', self.PR_FILE])
     subprocess.check_call(['git', 'commit', '-m', 'Create branch for PR %d' % self.PR])
     subprocess.check_call(['git', 'tag', self.PR_TAG])
     os.chdir('/tmp')
     bootstrap.bootstrap('fake-pr', self.REPO, None, self.PR, self.root_workspace)
示例#12
0
    def bootstrap(self):
        logging.debug('Bootstrapping %s begin', self.name())

        with open(self._env.prefix.paths.ssh_id_rsa_pub()) as f:
            pub_key = f.read()

        bootstrap.bootstrap(
            self._spec['disks'][0]['path'],
            [
                bootstrap.add_ssh_key(key=pub_key),
                bootstrap.set_hostname(hostname=self.name()),
                bootstrap.set_selinux(mode='permissive'),
                bootstrap.remove_persistent_nets(),
                bootstrap.set_iscsi_initiator_name(name=self.iscsi_name()),
            ],
        )
        logging.debug('Bootstrapping %s end', self.name())
    def prepare_generic_launch(self, engine_name, context, app_path, app_args):
        """
        Generic engine launcher.

        This method will look for a bootstrap method in the engine's
        python/startup/bootstrap.py file if it exists.  That bootstrap will be
        called if possible.

        :param engine_name: The name of the engine being launched
        :param context: The context that the application is being launched in
        :param app_path: Path to DCC executable or launch script
        :param app_args: External app arguments

        :returns: extra arguments to pass to launch
        """
        # find the path to the engine on disk where the startup script can be found:
        engine_path = tank.platform.get_engine_path(engine_name, self.tank, context)
        if engine_path is None:
            raise TankError(
                "Could not find the path to the '%s' engine. It may not be configured "
                "in the environment for the current context ('%s')." % (engine_name, str(context)))

        # find bootstrap file located in the engine and load that up
        startup_path = os.path.join(engine_path, "python", "startup", "bootstrap.py")

        if not os.path.exists(startup_path):
            raise TankError("Could not find the bootstrap for the '%s' engine at '%s'" % (
                engine_name, startup_path))

        python_path = os.path.dirname(startup_path)

        # add our bootstrap location to the pythonpath
        sys.path.insert(0, python_path)
        try:
            import bootstrap
            extra_args = self.get_setting("extra", {})

            # bootstrap should take kwargs in order to protect from changes in
            # this signature in the future.  For example:
            # def bootstrap(engine, context, app_path, app_args, **kwargs)
            (app_path, new_args) = bootstrap.bootstrap(
                engine_name=engine_name,
                context=context,
                app_path=app_path,
                app_args=app_args,
                extra_args=extra_args,
            )

        except Exception:
            self.log_exception("Error executing engine bootstrap script.")
            raise TankError("Error executing bootstrap script. Please see log for details.")
        finally:
            # remove bootstrap from sys.path
            sys.path.pop(0)

        return (app_path, new_args)
示例#14
0
 def testBatch(self):
     def head_sha():
         # We can't hardcode the SHAs for the test, so we need to determine
         # them after each commit.
         return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
     refs = ['master:%s' % head_sha()]
     for pr in (123, 456):
         subprocess.check_call(['git', 'checkout', '-b', 'refs/pull/%d/head' % pr, 'master'])
         subprocess.check_call(['git', 'rm', self.MASTER])
         subprocess.check_call(['touch', self.PR_FILE])
         subprocess.check_call(['git', 'add', self.PR_FILE])
         open('pr_%d.txt' % pr, 'w').write('some text')
         subprocess.check_call(['git', 'add', 'pr_%d.txt' % pr])
         subprocess.check_call(['git', 'commit', '-m', 'add some stuff (#%d)' % pr])
         refs.append('%d:%s' % (pr, head_sha()))
     os.chdir('/tmp')
     pull = ','.join(refs)
     print '--pull', pull
     bootstrap.bootstrap('fake-pr', self.REPO, None, pull, self.root_workspace)
示例#15
0
 def testEmptyRepo(self):
     repo = None
     with Stub(bootstrap, 'checkout', Bomb):
         bootstrap.bootstrap(JOB, repo, None, None, ROOT)
     with self.assertRaises(ValueError):
         bootstrap.bootstrap(JOB, repo, None, PULL, ROOT)
     with self.assertRaises(ValueError):
         bootstrap.bootstrap(JOB, repo, BRANCH, None, ROOT)
示例#16
0
def main(conf):
    
    pop, toolbox, hof, stats =   bootstrap(conf)
    prog = Progress(conf)
    
            
    pop, logbook = algorithms.eaMuPlusLambda(pop, toolbox, mu=conf.MU, lambda_=conf.LAMBDA, 
            cxpb=conf.CXPB, mutpb=conf.MUTPB, ngen=0, stats=stats, halloffame=hof)
    prog.update(0,pop,hof)
    for gen in range(conf.NGEN/5):
        pop, logbook = algorithms.eaMuPlusLambda(pop, toolbox, mu=conf.MU, lambda_=conf.LAMBDA, 
                cxpb=conf.CXPB, mutpb=conf.MUTPB, ngen=5, stats=stats, halloffame=hof)
        prog.update((gen+1)*5,pop,hof)
    
    #prog.hold()
    
    return pop, stats, hof
def _prepare_flame_flare_launch(engine_name, context, app_path, app_args):
    """
    Flame specific pre-launch environment setup.

    :param engine_name: The name of the engine being launched (tk-flame or tk-flare)
    :param context: The context that the application is being launched in
    :param app_path: Path to DCC executable or launch script
    :param app_args: External app arguments

    :returns: Tuple (app_path, app_args) Potentially modified app_path or
              app_args value, depending on preparation requirements for
              flame.
    """
    # Retrieve the TK Application instance from the current bundle
    tk_app = sgtk.platform.current_bundle()

    # find the path to the engine on disk where the startup script can be found:
    engine_path = sgtk.platform.get_engine_path(engine_name, tk_app.sgtk, context)
    if engine_path is None:
        raise TankError("Path to '%s' engine could not be found." % engine_name)

    # find bootstrap file located in the engine and load that up
    startup_path = os.path.join(engine_path, "python", "startup", "bootstrap.py")
    if not os.path.exists(startup_path):
        raise Exception("Cannot find bootstrap script '%s'" % startup_path)

    python_path = os.path.dirname(startup_path)

    # add our bootstrap location to the pythonpath
    sys.path.insert(0, python_path)
    try:
        import bootstrap
        (app_path, new_args) = bootstrap.bootstrap(engine_name, context, app_path, app_args)

    except Exception, e:
        tk_app.log_exception("Error executing engine bootstrap script.")

        if tk_app.engine.has_ui:
            # got UI support. Launch dialog with nice message
            not_found_dialog = tk_app.import_module("not_found_dialog")
            not_found_dialog.show_generic_error_dialog(tk_app, str(e))

        raise TankError("Error executing bootstrap script. Please see log for details.")
示例#18
0
    def prepare_flame_flare_launch(self, engine_name, context, app_path, app_args):
        """
        Flame specific pre-launch environment setup.

        :param engine_name: The name of the engine being launched (tk-flame or tk-flare)
        :param context: The context that the application is being launched in
        :param app_path: Path to DCC executable or launch script
        :param app_args: External app arguments
        
        :returns: extra arguments to pass to launch
        """
        # find the path to the engine on disk where the startup script can be found:
        engine_path = tank.platform.get_engine_path(engine_name, self.tank, context)
        if engine_path is None:
            raise TankError("Path to '%s' engine could not be found." % engine_name)
        
        # find bootstrap file located in the engine and load that up
        startup_path = os.path.join(engine_path, "python", "startup", "bootstrap.py")
        
        if not os.path.exists(startup_path):
            raise Exception("Cannot find bootstrap script '%s'" % startup_path)        
        
        python_path = os.path.dirname(startup_path)
        
        # add our bootstrap location to the pythonpath
        sys.path.insert(0, python_path)
        try:
            import bootstrap
            (app_path, new_args) = bootstrap.bootstrap(engine_name, context, app_path, app_args)            
            
        except Exception, e:
            self.log_exception("Error executing engine bootstrap script.")
            
            if self.engine.has_ui:
                # got UI support. Launch dialog with nice message
                not_found_dialog = self.import_module("not_found_dialog")                
                not_found_dialog.show_generic_error_dialog(self, str(e))
            
            raise TankError("Error executing bootstrap script. Please see log for details.")
示例#19
0
 def testHappy(self):
     with Stub(bootstrap, 'finish', FakeFinish()) as fake:
         bootstrap.bootstrap(JOB, REPO, BRANCH, None, ROOT)
     self.assertTrue(fake.called)
     self.assertTrue(fake.result)  # Distinguish from None
示例#20
0
def bagging_model(learner, dataset, n_models, sample_size):
    bootstrap_data = bootstrap(dataset, sample_size)
    models = [learner(next(bootstrap_data)) for _ in range(n_models)]
    return voting_ensemble(models)
示例#21
0
 def testPr_Bad(self):
     random_pr = 111
     with Stub(bootstrap, 'start', Bomb):
         with Stub(time, 'sleep', Pass):
             with self.assertRaises(subprocess.CalledProcessError):
                 bootstrap.bootstrap('fake-pr', self.REPO, None, random_pr, self.root_workspace)
示例#22
0
 def test_iter_value(self):
     actual = bootstrap(np.ones(5), np.mean)
     assert_equal(1.0, next(actual))
def run_logistic_regression(X, y, n_trials=5):
    """
    Runs logistic regression for a dataset
    5 trials of LogReg with 5-fold cross validation and a gridsearch over hyperparameter: C
    and computes mean accuracy over metrics
        accuracy, f1, roc, precision, recall

    parameters
    ----------
    X: feature vector
    y: target vector
    n_trials: number of trials to run

    returns
    --------
    train_metrics: average of each metric on training set across 5 trials
    test_metrics: average of each metric on test set across 5 trials
    hyperp: dataframe of hyperparameters tried during hyperparameter search,
            of metrics (acc, f1, roc) and their mean performance during cross-validation
    """

    # hyperparameters
    C_list = [
        1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4
    ]
    params = {'C': C_list}

    # metric evaluation scores
    scores = ['accuracy', 'f1', 'roc_auc', 'precision', 'recall']

    # to hold calculated metric performances
    train_metrics = []
    test_metrics = []

    for trial in range(n_trials):

        # initialize model for cross validation grid search
        LogReg = LogisticRegression(max_iter=200)
        GS = GridSearchCV(LogReg, params, scoring=scores, refit=False)

        # bootstrap training and testing sets
        X_train, X_test, y_train, y_test = bootstrap(X, y)
        GS.fit(X_train, y_train)

        # collect results and get dataframe to visualize hyperparameter search
        res = GS.cv_results_
        hyperp = pd.DataFrame(res['params'])
        hyperp['acc'] = res['mean_test_accuracy']
        hyperp['f1'] = res['mean_test_f1']
        hyperp['roc'] = res['mean_test_roc_auc']
        hyperp.set_index('C', inplace=True)

        test_per = []  # test set performances
        train_per = []  # train set performances

        # get best hyperparameters for each metric and use on test set
        for s in scores:

            # train logreg with best hyperparameters for metric
            best_C = res['params'][np.argmax(res['mean_test_{}'.format(s)])]
            LR = LogisticRegression(C=best_C['C'])
            LR.fit(X_train, y_train)

            # predictions for train and test sets
            y_pred = LR.predict(X_test)
            y_pred_train = LR.predict(X_train)

            # evaluate metric on test set
            if s == 'accuracy':
                test_per.append(accuracy_score(y_test, y_pred))
                train_per.append(accuracy_score(y_train, y_pred_train))
            elif s == 'f1':
                test_per.append(f1_score(y_test, y_pred))
                train_per.append(f1_score(y_train, y_pred_train))
            elif s == 'roc_auc':
                test_per.append(roc_auc_score(y_test, y_pred))
                train_per.append(roc_auc_score(y_train, y_pred_train))
            elif s == 'precision':
                test_per.append(precision_score(y_test, y_pred))
                train_per.append(precision_score(y_train, y_pred_train))
            elif s == 'recall':
                test_per.append(recall_score(y_test, y_pred))
                train_per.append(recall_score(y_train, y_pred_train))

        train_metrics.append(train_per)
        test_metrics.append(test_per)

        print('Trial {} done'.format(trial + 1))

    # take mean of each metric across 5 trials
    train_metrics = np.mean(np.array(train_metrics), axis=0)
    test_metrics = np.mean(np.array(test_metrics), axis=0)

    return train_metrics, test_metrics, hyperp
示例#24
0
from sqlalchemy.orm import sessionmaker

import bootstrap
import views
from adapters import orm
from config import get_sqlite_engine
from domains import commands
from domains.model import OutOfStock
from services import unit_of_work
from services.handlers import InvalidSku
from services.messagebus import MessageBus

app = Flask(__name__)
#orm.start_mappers()
bus = bootstrap.bootstrap()
#get_session = sessionmaker(bind=create_engine(config.get_postgres_uri()))
#get_session = sessionmaker(bind=get_sqlite_engine())
#app.debug = True

print('chegou ate aqui Flask App - Debian 10')


@app.route("/")
def hello():
    return "Hello World Flask App - Debian 10"


@app.route('/add_batch', methods=['POST'])
def batches():
    #orm.start_mappers()
示例#25
0
					fold = de_utils.log2_ratio(gene_counts_masked[i][j],gene_counts_masked[i][k])
					if np.isfinite(fold):
						fold = abs(fold)
						fold_list[b1].append(fold)
						if b1 != b2:
							fold_list[b2].append(fold)

	# lists are complete. now we can take the 95th percentile
	diff_lim = np.zeros(NUM_BINS)
	fold_lim = np.zeros(NUM_BINS)

	for i in range(NUM_BINS):
		if len(diff_list[i]) > 0:

			if num_samples > 2:
				temp = bs.bootstrap(diff_list[i],quar_stat_low)
				diff_lim[i] = temp.mean
			else:
				temp = bs.bootstrap(diff_list[i],quar_stat_high)
				diff_lim[i] = temp.mean


		if len(fold_list[i]) > 0:

			if num_samples > 2:
				temp = bs.bootstrap(fold_list[i],quar_stat_low)
				fold_lim[i] = temp.mean
			else:
				temp = bs.bootstrap(fold_list[i],quar_stat_high)
				fold_lim[i] = temp.mean
示例#26
0
for i, dataSet in enumerate(sorted(dataSets, key=itemgetter("t", "beta"))):
    ####
    #### get parameters
    ####
    beta = dataSet["beta"]
    L = dataSet["L"]
    t = dataSet["t"]
    J = dataSet["J"]
    N = dataSet["numHoles"]

    ####
    #### sign
    ####
    if N == 1:
        val, err = bootstrap(lambda x: (x), [np.array(dataSet["avgSign"])],
                             np.array(dataSet["avgSign"]) * 0 + 1,
                             dataSet["numData"], maxNumBootstrapIteration)
        sign += [{"beta": beta, "N": N, "val": val, "err": err}]

####
#### plot average sign
####
plt.title(r"$ \langle s \rangle_\mathrm{B} $")
plt.xlabel(r"$ \beta t $")

# extract betas
beta = [f['beta'] for f in sorted(sign, key=itemgetter("beta")) if f["N"] != 0]

S_val = np.array([f['val'] for f in sorted(sign, key=itemgetter("beta"))])
S_err = np.array([f['err'] for f in sorted(sign, key=itemgetter("beta"))])
plt.errorbar(np.array(beta) * abs(t),
示例#27
0
 def testJobFails(self):
     with self.assertRaises(SystemExit):
         bootstrap.bootstrap('fake-failure', self.REPO, 'master', None, self.root_workspace)
示例#28
0
 def testJobMissing(self):
     with self.assertRaises(OSError):
         bootstrap.bootstrap('this-job-no-exists', self.REPO, 'master', None, self.root_workspace)
示例#29
0
 def testBranch_Bad(self):
     random_branch = 'something'
     with Stub(bootstrap, 'start', Bomb):
         with Stub(time, 'sleep', Pass):
             with self.assertRaises(subprocess.CalledProcessError):
                 bootstrap.bootstrap('fake-branch', self.REPO, random_branch, None, self.root_workspace)
示例#30
0
def setup_app(command, conf, vars):
    """Place any commands to setup saip here"""
    load_environment(conf.global_conf, conf.local_conf)
    setup_schema(command, conf, vars)
    bootstrap.bootstrap(command, conf, vars)
示例#31
0
        "dense": args['--dense'],
        "nz_dense": int(args['--nz_dense']),
        "rk222": args['--rk222'],
        "max_writes": int(float(args['--writes'])),
        "superstep": args['--superstep'],
        "run_time": float(args['--run_time']),
        "run_time_buoyancies": run_time_buoy,
        "run_time_iter": run_time_iter,
        "label": args['--label']
    }

    if args['bootstrap']:
        logger.info("Bootstrapping...")
        if args['--init_file']:
            init_file = args['--init_file']
        else:
            raise ValueError("Must specify a starting file if bootstrapping")
        ra_end = float(args['--ra_end'])

        bsp_step_time = float(args['--bsp_step'])
        bsp_nx = args['--bsp_nx']
        bsp_nz = args['--bsp_nz']
        bootstrap(init_file,
                  ra_end,
                  kwargs,
                  nx=bsp_nx,
                  nz=bsp_nz,
                  step_run_time=bsp_step_time)
    else:
        FC_convection(**kwargs)
示例#32
0
 def testRoot_Exists(self):
     with Stub(os, 'chdir', FakeCall()) as fake_chdir:
         bootstrap.bootstrap(JOB, REPO, None, PULL, ROOT)
     self.assertTrue(any(ROOT in c[0] for c in fake_chdir.calls))
示例#33
0
def exact_solution(x, time):
    u_exact = np.zeros(N)

    for i in (range(N)):
        u_exact[i] = sco.newton(exact_func, 0.5, fprime=exact_func_prime, args=(x[i], time), maxiter=5000)

    return u_exact

def exact_func(u, x, t):
    return 0.5 + np.sin(np.pi * (x - u * t)) - u

def exact_func_prime(u, x, t):
    return -np.pi * t * np.cos(np.pi * (x - u * t)) - 1

bs.bootstrap()

# Number of cells.
N = 160
a = -1.0
b = 1.0
CHAR_SPEED = 1.0
CFL_NUMBER = 0.6
time_breaking = 0.3183
T = 0.55

w = weno2.Weno2(a, b, N, flux, flux_deriv, max_flux_deriv, CHAR_SPEED, CFL_NUMBER)
x_center = w.get_x_center()
u0 = initial_condition(x_center)

solution = u0
示例#34
0
import os
import sys
from glob import glob
import bootstrap
import tempfile
from mpi4py import MPI

my_rank = MPI.COMM_WORLD.Get_rank()
nprocs = MPI.COMM_WORLD.Get_size()

files = glob('../data/fast*.*_TRUE.fas')
tmpfile = os.path.join(tempfile.gettempdir(), '%d.fa' % (my_rank,))

for i, f in enumerate(files):
    if i % nprocs != my_rank:
        continue

    sys.stdout.write('process %d of %d starting task %s\n' % (my_rank, nprocs, f))

    outfile = open(f.replace('.fas', '.bootstrap.nwk'), 'w')
    bootstrap.bootstrap(f, 100, outfile, tmpfile)
    outfile.close()

MPI.COMM_WORLD.Barrier()
MPI.Finalize()
import advection as advec
import advection_util as au
import bootstrap as bs
import numpy as np

bs.bootstrap()

N = 320
T = 1.0
WENO_ORDER = 3

w = au.createWeno3Solver(N)
x_center = w.get_x_center()
x_boundary = w.get_x_boundary()
u0 = advec.initial_condition_sine(x_center, x_boundary)

solution = w.integrate(u0, T)
exact_solution = advec.exact_solution_sine(x_center - advec.CHAR_SPEED * T, T, N, x_boundary - advec.CHAR_SPEED * T)
error = np.abs(solution - exact_solution)
print(np.argmax(error))
au.plot_advection_solution(x_center, solution, exact_solution, T, N, WENO_ORDER)


示例#36
0
 def test_list_comprehension(self):
     b = bootstrap(np.ones(5), np.mean, reps=5)
     actual = [x for x in b]
     assert_equal([1] * 5, actual)
示例#37
0
cv_avg, cv_err   = mean_stderr(cvke)
pk_avg, pk_err   = mean_stderr(pke)

print("----------------------------")
print("| Block averaging function |")
print("----------------------------")
print(" v: % .6f  +/-  % .6f" % (pot_avg, pot_err))
print("cv: % .6f  +/-  % .6f" % (cv_avg, cv_err))
print("pk: % .6f  +/-  % .6f" % (pk_avg, pk_err)) 
print("")

# Bootstrapping the error to compare error bars
boots = 2500

pot_avg = np.mean(pot)
pot_lo, pot_high = boot.bootstrap(pot, boots, np.mean, 0.01)

cv_avg = np.mean(cvke)
cv_lo, cv_high = boot.bootstrap(cvke, boots, np.mean, 0.01)

pk_avg = np.mean(pke)
pk_lo, pk_high = boot.bootstrap(pke, boots, np.mean, 0.01)

print("-----------------")
print("| Bootstrapping |")
print("-----------------")
print(" v: % .6f  -/+  (% .6f, % .6f)" % (pot_avg, abs(pot_avg - pot_lo), abs(pot_avg - pot_high)))
print("cv: % .6f  -/+  (% .6f, % .6f)" % (cv_avg, abs(cv_avg - cv_lo), abs(cv_avg - cv_high)))
print("pk: % .6f  -/+  (% .6f, % .6f)" % (pk_avg, abs(pk_avg - pk_lo), abs(pk_avg - pk_high)))
print("")
示例#38
0
 def test_default_init(self):
     bootstrap(np.ones(5))
示例#39
0
 def test_iter_decrements_reps(self):
     actual = bootstrap(np.ones(5), np.mean, reps=50)
     next(actual)
     assert_equal(49, actual.reps)
示例#40
0
 def testNoFinishWhenStartFails(self):
     with Stub(bootstrap, 'finish', FakeFinish()) as fake:
         with Stub(bootstrap, 'start', Bomb):
             with self.assertRaises(AssertionError):
                 bootstrap.bootstrap(JOB, REPO, BRANCH, None, ROOT)
     self.assertFalse(fake.called)
示例#41
0
 def test_len(self):
     actual = bootstrap(np.ones(5), np.mean, reps=50)
     assert_equal(50, len(actual))
print('Pm =', Pm, ', Pmn =', Pmn, ', Pn =', Pn)

Pm_L = 0
Pm_R = Pm
Pmn_L = Pm_R
Pmn_R = Pm + Pmn
Pn_L = Pmn_R
Pn_R = 1

theta_list = []
for i in range(10):
    Pm_cnt = 0
    Pmn_cnt = 0
    Pn_cnt = 0
    
    for j in range(1029):
        rnd = random.random()
        if ((rnd >= Pm_L) and (rnd < Pm_R)): 
             Pm_cnt += 1
        if ((rnd >= Pmn_L) and (rnd < Pmn_R)): 
             Pmn_cnt += 1
        if ((rnd >= Pn_L) and (rnd <= Pn_R)): 
             Pn_cnt += 1
    theta_list.append(estimate_theta(Pm_cnt, Pmn_cnt, Pn_cnt))


bs = BS.bootstrap(theta_list)
lb, ub = bs.confidence_interval(0.05, 0.95, theta_list)
print('lower bound =', lb)
print('upper bound =', ub)
示例#43
0
# coding: utf-8
'''
Created on Aug 28, 2012

@author: yeti
'''

import os

from bootstrap import bootstrap

bootstrap("/yetiweb/scoutfile/scoutfile3/")

from album.models import Eveniment, SetPoze, Imagine

root_linked_path = "/media/rojam_photos/alba/"
media_path_prefix = "ccl2012"
photo_import_paths = ["andreibregar/", "andra/", "yeti/", "irina/", "iuli/", "stefana/", "ioana/", "paul/", "popi/"]
e = Eveniment.objects.get(slug = "ccl2012") 

def process_directory(args, dirname, filenames):
    if not os.path.exists("%s/authors.txt" % dirname):
        return

    with open("%s/authors.txt" % dirname, "rt") as f:
        author = f.read()

    set_poze, created = SetPoze.objects.get_or_create(eveniment = e, autor = author)
    if created:
        set_poze.save()
    
示例#44
0
cov12 = (sigma1**(1 / 2)) * (sigma2**(1 / 2)) * rho
covshocks = [[sigma1, cov12], [cov12, sigma2]]
T = (24 - 8) * 20  #monthly waking hours
Lc = 8 * 20  #monthly cc hours
alpha = -0.1
gamma = 0.4
w_matrix = np.identity(10)
times = 20

#------------ CALL CLASSES, ESTIMATION SIM & BOOTSTRAP ------------#
param0 = parameters.Parameters(betas, betasw, betastd, betasn, sigma2w_estr,
                               sigma2w_reg, meanshocks, covshocks, T, Lc,
                               alpha, gamma, times)
model = util.Utility(param0, N, data)
model_sim = simdata.SimData(N, model)
model_boot = bstr.bootstrap(N, data)

moments_boot = model_boot.boostr(times)
model_est = est.estimate(N, data, param0, moments_boot, w_matrix)

results_estimate = model_est.simulation(model_sim)

#------------ DATA SIMULATION ------------#

workbook = xlsxwriter.Workbook('data/labor_choice.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('B2', 'parameter')
worksheet.write('B3', 'labor choice')
worksheet.write('B4', 'cc choice')
worksheet.write('B5', 'test score')
示例#45
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings.dev')

# bootstrap for worker
import bootstrap
bootstrap.bootstrap()

from django.conf import settings  # noqa

app = Celery(settings.PROJECT_NAME, broker=settings.BROKER_URL)

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
示例#46
0
 def testJobEnv(self):
     """bootstrap sets JOB_NAME."""
     with Stub(os, 'environ', FakeEnviron()) as env:
         bootstrap.bootstrap(JOB, REPO, BRANCH, None, ROOT)
     self.assertIn(bootstrap.JOB_ENV, env)
示例#47
0
def simple():
    """
    Simple example with synthetic data, 1 real value + 1 categorical value
    :return:
    """

    # User Defined Parameters #
    number_partitions = 10
    categorical_corruption_probability = 0.2
    min_prob_sampling_zero_corruption = 0.2
    number_processes = 50
    nx_boot = 50  # int(np.log(min_prob_sampling_zero_corruption)/np.log(float(n_train - s)/n_train))
    probabilities_artificial_corruption = np.linspace(start=0.02, stop=0.3, num=nx_boot)

    # Synthetic Data #
    distribution = Simple(number_partitions=number_partitions,
                          categorical_corruption_probability=categorical_corruption_probability)
    partitions = distribution.get_partitions()
    train_partitions = np.random.choice(partitions, size=len(partitions)*0.8, replace=False)
    test_partitions = np.array(list(set(partitions).difference(set(train_partitions))))

    # Bootstrapping #
    print 'Bootstrapping with ', nx_boot, ' samples'
    s = 0
    [b, B, A_hat, x_hat] = bootstrap(distribution, train_partitions=train_partitions, test_partitions=test_partitions,
                                     probabilities_artificial_corruption=probabilities_artificial_corruption, nx_boot=nx_boot,
                                     number_processes=number_processes)
    orig, _, _, _ = bootstrap(distribution, train_partitions=train_partitions, test_partitions=test_partitions,
                              probabilities_artificial_corruption=[0.0], nx_boot=nx_boot, number_processes=number_processes)

    # Solve for uncorrupted error #
    probability_natural_corruption = 0.0
    pickle.dump([b, probabilities_artificial_corruption, probability_natural_corruption, orig, nx_boot, A_hat, x_hat], open('bootstrap.p', 'wb'))
    #[b, probabilities_artificial_corruption, probability_natural_corruption, orig, nx_boot, A_hat, x_hat] = pickle.load(open('bootstrap.p', 'rb'))
    x_hat = np.nan_to_num(x_hat)
    print 'Observed mean errors', b
    print 'True mean error', orig
    mean_errors, A = solve_means(b=b, probabilities_artifical_corruption=probabilities_artificial_corruption,
                                 probability_natural_corruption=probability_natural_corruption, nx_boot=nx_boot)
    print "Solved mean errors"
    print mean_errors

    # Make plots
    import matplotlib.pyplot as plt
    percent_corruption = [(1-p)*probability_natural_corruption + p for p in probabilities_artificial_corruption]
    percent_corruption_all = np.linspace(start=0, stop=1, num=250)
    plt.plot(A.T)
    plt.plot(A_hat.T, '--')
    plt.xlabel('Corruption')
    plt.ylabel('Frequency')
    plt.show()

    plt.plot(mean_errors)
    plt.plot(x_hat)
    plt.xlabel('Corruption')
    plt.ylabel('Mean Error')
    plt.legend(['Optimal, solved', 'Observed'])
    plt.show()

    A_all = np.array([binom.pmf(range(0, nx_boot), nx_boot, p) for p in percent_corruption_all])
    plt.plot(percent_corruption, b, 'g')
    plt.plot(percent_corruption_all, A_all*np.matrix(mean_errors), 'b--')
    plt.plot(percent_corruption, np.dot(A_hat, x_hat), 'r--')
    plt.plot(0, orig, 'or')
    plt.plot(0, mean_errors[0], 'ob')
    plt.xlim([-0.1, max(percent_corruption)+0.1])
    plt.ylim([0, max(orig, mean_errors[0])*1.1])
    plt.legend(['Observed b', 'Solved A*x_star', 'Observed A_hat*x_hat', 'True Error', 'Estimated Error'])
    plt.xlabel('Corruption')
    plt.ylabel('Error')
    plt.show()
import bootstrap as BS
import numpy as np

data = [136.3, 136.6, 135.8, 135.4, 134.7, 135.0, 134.1, 143.3, 147.8,\
        148.8, 134.8, 135.2, 134.9, 149.5, 141.2, 135.4, 134.8, 135.8,\
        135.0, 133.7, 134.4, 134.9, 134.8, 134.5, 134.3, 135.2]

bs = BS.bootstrap(data, np.median)
print('bs.theta =', bs.theta)
bs.sampling(len(data), 10000, np.median)

print('bias = ', bs.bias(bs.bootstrap_sample[0], bs.theta))
def setup_app(command, conf, vars):
    """Place any commands to setup turbogears2_sprox_tutorial here"""
    load_environment(conf.global_conf, conf.local_conf)
    setup_schema(command, conf, vars)
    bootstrap.bootstrap(command, conf, vars)
import bootstrap as BS
import numpy as np

data = [9, 8, 10, 12, 11, 12, 7, 9, 11, 8, 9, 7, 7, 8, 9, 7,\
        9, 9, 10, 9, 9, 9, 12, 10, 10, 9, 13, 11, 13, 9]

print('======================Question 1======================')


def mu_sigma(sample, _):
    mu = np.mean(sample)
    sigma = np.var(sample, ddof=1)**0.5
    return mu, sigma


bs = BS.bootstrap(data)
bs.sampling(len(data), 10000, mu_sigma)

mu_list = bs.bootstrap_sample[0]
sigma_list = bs.bootstrap_sample[1]

alpha_left = 0.1 / 2
alpha_right = 1 - 0.1 / 2
left_margin, right_margin = bs.confidence_interval(alpha_left, alpha_right,
                                                   mu_list)
print('confidence interval of mu is [', left_margin, ',', right_margin, ']')

left_margin, right_margin = bs.confidence_interval(alpha_left, alpha_right,
                                                   sigma_list)
print('confidence interval of sigma is [', left_margin, ',', right_margin, ']')
示例#51
0
# coding: utf-8
'''
Created on Aug 28, 2012

@author: yeti
'''


from bootstrap import bootstrap
bootstrap("/yetiweb/scoutfile/scoutfile3/")

from structuri.models import Membru


membri = Membru.objects.all()
count = 0
for membru in membri:
    if membru.afilieri.all().count() == 0:
        print membru
        count += 1
        
        
print "Total %s oameni cu probleme" % count
示例#52
0
def simulation():
    """
    Generates data for C vs T for different values of L along with standard deviation for C using bootstrap.
    The data are written in a txt file and plotted using another file called heat_capacity_plotter.py. This
    function also finds the Tc by taking the T input that gives maximum C and prints a table of L vs Tc
    :return: (void)
    """
    T_val = np.linspace(2, 3, 100)
    T_values = [round(T_val[i], 3) for i in range(len(T_val))]
    L_values = [64]
    print(f'Total samples to calculate: {len(T_values)*len(L_values)}')
    n_bins = 100
    Tc_list = []
    thermalisation_sweeps = 10000
    sample_every = 50

    with open('heat_capacity_data1.txt', 'w') as file:
        for L in L_values:

            C_list, sigma_C_list = [], []
            N = L**2
            s = get_spin_list(hot_start, N)
            neighbours_dictionary = get_neighbours_index(N)

            for T in T_values:

                start = time.process_time()
                avg_mag_list = []
                energy_list = []
                b = 1 / T  # Constant: 1 / temperature
                dE_4 = exp(-4 * b)  # Probability for energy change of +4
                dE_8 = exp(-8 * b)  # Probability for energy change of +8

                for sweep in range(nsweeps):

                    metropolis(dE_4, dE_8, N, s, neighbours_dictionary)

                    if sweep < thermalisation_sweeps:
                        continue
                    else:
                        if sweep % sample_every == 0:
                            avg_mag_list.append(get_average_magnetisation(
                                N, s))
                            energy_list.append(
                                get_energy(N, s, neighbours_dictionary))

                target_tau = get_target_tau(avg_mag_list)
                C, sigma_C = bootstrap(energy_list, n_bins, T, target_tau)
                C_list.append(C)
                sigma_C_list.append(sigma_C)
                time_for_sample = time.process_time() - start

                file.write(f'{L},{T},{C},{sigma_C}\n')
                print(
                    f'[L = {L}, T = {T}, C = {C:.2f}, sigma = {sigma_C:.2f}, tau = {target_tau}]',
                    f'--> Time for sample: {time_for_sample/60:.1f} minutes')

            index_for_Tc = C_list.index(max(C_list))
            Tc_list.append(T_values[index_for_Tc])

        L_df = pd.DataFrame(L_values, columns=['L'])
        Tc_df = pd.DataFrame(Tc_list, columns=['Tc'])
        Tc_data = pd.concat([L_df, Tc_df], axis=1)
        print(Tc_data)
        Tc_data.to_html('Tc_vs_L_table1.html')
示例#53
0
文件: __init__.py 项目: nomed/ebetl
def setup_app(command, conf, vars):
    """Place any commands to setup ebetl here"""
    load_environment(conf.global_conf, conf.local_conf)
    setup_schema(command, conf, vars)
    bootstrap.bootstrap(command, conf, vars)
示例#54
0
                            y1 = pickle.load(fp)
                            y2 = np.concatenate((y2, np.array(y1)), axis=None)
                    except:
                        print(name, year)
                        continue

                y.append(y2)

            y_mean = []
            y_std = []
            dyu = []
            dyd = []
            for i in y:
                y_mean.append(np.mean(i))
                y_std.append(np.std(i))
                boot = bootstrap(i)
                c = boot(.95)
                print(c)
                dyd.append(c[0])
                dyu.append(c[1])

            df = pd.DataFrame({
                "x": x,
                "y": y_mean,
                "dyd": dyd,
                "dyu": dyu,
                "std": y_std
            })
            df.to_csv(
                f"{dst_path}{names[names_list_list.index(names_list)]}{like_name}_{blob}.csv"
            )