def clean_exit(reason=None):
    print('Exiting gracefully (reason: {0})'.format(reason), file=sys.stderr)

    # revert all changes to iptables
    helpers.run(
        'iptables-save | grep -v "searchExamServer" | iptables-restore -w')
    helpers.run(
        'iptables-legacy-save | grep -v "searchExamServer" | iptables-legacy-restore -w'
    )

    # if isDeb9OrNewer():
    #     url_whitelist = helpers.run('diff --unchanged-group-format="" <(echo "^{p}://{h}" | sed "s/\./\\\./g") {f}'.format(f = urlWhitelistFile, p = gladosProto, h = gladosHost))
    # else:
    #     url_whitelist = helpers.run('diff --unchanged-group-format="" <(echo "^{p}://{h}") {f}'.format(f = urlWhitelistFile, p = gladosProto, h = gladosHost))

    helpers.run('umount /run/initramfs/newroot 2>/dev/null')
    helpers.run('umount -l /run/initramfs/{base,exam} 2>/dev/null')

    if isDeb9OrNewer(): helpers.run('squid -k reconfigure')  # iptables stays

    exit(0)
def compute(tpl):
    """Takes a combination of gamma and nu value and trains and
    evaluates a OC-SVM using the current feature set"""

    g = tpl[0]
    n = tpl[1]

    ocsvm = svm.OneClassSVM(nu=n, kernel="rbf", gamma=g, cache_size=1000)
    errorRate = func.calcErrorRate(func.run(ocsvm, config["folds"], trS, teS))
    tmpResults[errorRate] = (g, n, lookUp[subsetCnt])
    print str(format(errorRate[0], '.20f')) + " " + str(
        format(errorRate[1], '.20f')) + " : gamma= " + str(g) + " nu= " + str(
            n) + " features= " + str(lookUp[subsetCnt])
Exemple #3
0
    else:
        util.cli = "riff"
    if args.push_secret is None or len(args.push_secret) <= 0:
        util.push_secret = ""
    else:
        if args.image_prefix is None or len(args.image_prefix) <= 0:
            raise Exception("An --image-prefix must be provided when using --push-secret")
        util.push_secret = args.push_secret
        util.image_prefix = args.image_prefix
    if args.pull_secret is None or len(args.pull_secret) <= 0:
        util.pull_secret = ""
    else:
        util.pull_secret = args.pull_secret
    if args.manifest is None or len(args.manifest) <= 0:
        if args.pfs:
            raise Exception("A manifest must be provided for PFS")
        util.manifest = "stable"
    else:
        util.manifest = args.manifest

    import setup, teardown, functions, eventing
    setup.run()
    functions.run()
    eventing.run()
    teardown.run()

    elapsed_time = time.time() - start_time
    elapsed_min = int(elapsed_time / 60)
    elapsed_sec = int(elapsed_time - (elapsed_min * 60))
    print("DONE in {m} min {s} sec".format(m=elapsed_min, s=elapsed_sec))
Exemple #4
0
]
skplt.estimators.plot_feature_importances(extra_clf, max_num_features=5)
selected_x_set = selected_x.transform(X_data)
selected_x_set_new = selected_x.transform(data_new)
selected_x_set_old = selected_x.transform(data_oldies)
# %%

models_old_sig = {}
models_new_sig = {}
models_whole_sig = {}
models_whole = {}
models_old_s = {}
models_new_s = {}
models_whole_s = {}

models_old_sig = func.run(data_oldies_sig, y_old)
models_new_sig = func.run(data_new_sig, y_new)
models_whole_sig = func.run(X_data_sig, y_sig)
models_whole = func.run(X_data, y)
models_old_s = func.run(selected_x_set_old, y_old)
models_new_s = func.run(selected_x_set_new, y_new)
models_whole_s = func.run(selected_x_set, y)

test = func.run_ann(X_data, y)

models_old_sig["ann_basic"] = func.run_ann(data_oldies_sig, y_old)
models_new_sig["ann_basic"] = func.run_ann(data_new_sig, y_new)
models_whole_sig["ann_basic"] = func.run_ann(X_data_sig, y_sig)
models_whole["ann_basic"] = func.run_ann(X_data, y)
models_old_s["ann_basic"] = func.run_ann(selected_x_set_old, y_old)
models_new_s["ann_basic"] = func.run_ann(selected_x_set_new, y_new)
Exemple #5
0
from classes import Pause
from functions import get_driver, run
from sys import exit

if __name__ == '__main__':

    sleep_duration = Pause()
    counter = 0

    omegle = "https://www.omegle.com/"
    print(f"[*] Navigating to {omegle}")

    while True:
        driver = get_driver(omegle)
        driver = run(driver, sleep_duration)
        driver.get_screenshot_as_file(f'./screen_shots/run_{counter}.png')
        
        print(f"[*] Iteration {counter} complete | Image: run_{counter}.png")

        counter += 1
        driver.quit()

        sleep_duration.reset()


        
        


Exemple #6
0
from functions import run

semestre = '2021-1'
ramos = [
    # Pregrado
    # {'nrc': 15218, 'sigla': 'ICS3313', 'sec': 3},
    # {'nrc': 10207, 'sigla': 'IHI2315', 'sec': 1},
    # {'nrc': 10725, 'sigla': 'IIC2133', 'sec': 1},
    {'nrc': 10732, 'sigla': 'IIC2143', 'sec': 1},

    # Práctica II
    # {'nrc': 24183, 'sigla': 'ING2005', 'sec': 1},
    # {'nrc': 11844, 'sigla': 'ING2001', 'sec': 1},

    # Magíster
    {'nrc': 18871, 'sigla': 'IIC3697', 'sec': 1},
    {'nrc': 10930, 'sigla': 'IIC3724', 'sec': 1},
    {'nrc': 11856, 'sigla': 'ING4921', 'sec': 1},
]

if __name__ == '__main__':
    run(semestre, ramos, interval=60)
Exemple #7
0
#! /usr/bin/python3

from functions import run

run()
Exemple #8
0
import argparse
import importlib
import os
import sys

from functions import create_exp_name_and_datetime_path, merge_cfg_with_cli, run

from human_id import generate_id

if __name__ == "__main__":
    # parser = argparse.ArgumentParser()
    exp = sys.argv[1].split("/")[-1].split(".")[0]

    module = importlib.import_module("." + exp, package="experiments")
    Experiment = getattr(module, "Experiment")
    cfg = getattr(module, "Config")
    parser = merge_cfg_with_cli(cfg)
    parser.add_argument("exp")
    args = parser.parse_args()
    path = create_exp_name_and_datetime_path(Experiment)
    path = os.path.join("results", path)
    args.run_id = generate_id()
    run(Experiment, args, path)
Exemple #9
0
import functions as hard

hard.run()
def compute(tpl):
    global counter
    global threshold

    g = tpl[0]
    n = tpl[1]
    counter = counter + 1

    ocsvm = svm.OneClassSVM(nu=n, kernel="rbf", gamma=g, cache_size=1000)
    errorRate = func.calcErrorRate(func.run(ocsvm, config["folds"], trS, teS))
    tmpResults[errorRate] = (g, n, lookUp[subsetCnt])
    print str(format(errorRate[0], '.20f')) + " " + str(format(errorRate[1], '.20f')) + " : gamma= " + str(g) + " nu= " + str(n) + " features= " + str(lookUp[subsetCnt])


    if counter == rejected:
        threshold = findBestErrorRate(results)
        t = open('data/results/stopping-rule/result-' + str(config["folds"]) + '.txt', 'a+')
        sys.stdout = t
        print "Results for feature subset / model parameters for " + str(config["folds"]) + "-folded CV with " + str(
            len(gammaVal)) + \
              " gamma values and " + str(len(nuVal)) + " nu values:\n"
        print "Stopping rule threshold:"
        print "gamma                    :" + str(threshold[1][0])
        print "nu                       :" + str(threshold[1][1])
        print "feature subset           :" + str(threshold[1][2])
        print "threshold      : %s%% false alarm rate, %s%% miss rate" % (
            str(threshold[0][0] * 100), str(threshold[0][1] * 100)) + "\n"
        sys.stdout = temp
        t.close()

    elif counter > rejected:
        t = open('data/results/stopping-rule/result-' + str(config["folds"]) + '.txt', 'a+')
        sys.stdout = t
        if (threshold[0][0] > errorRate[0]) or (threshold[0][0] == errorRate[0] and threshold[0][1] > errorRate[1]):

            print "Best result found:"
            print "gamma                    :" + str(g)
            print "nu                       :" + str(n)
            print "feature subset           :" + str(lookUp[subsetCnt])
            print "grid search results      : %s%% false alarm rate, %s%% miss rate" % (
                str(errorRate[0] * 100), str(errorRate[1] * 100))
            print "\n"
            print "Started on " + started.strftime("%Y-%m-%d %H:%M")
            print "Finished on " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
            print "Execution time " + str(datetime.datetime.now() - started)
            print "------------------------------------------------------------"
            temp.write("\n" + "Started on " + started.strftime("%Y-%m-%d %H:%M") + "\n")
            temp.write("Finished on " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + "\n")
            temp.write("------------------------------------------------------------\n")
            sys.exit("Stopping rule")
        elif counter == candidates:
            print "Best result found (not better than the threshold):"
            print "gamma                    :" + str(g)
            print "nu                       :" + str(n)
            print "feature subset           :" + str(lookUp[subsetCnt])
            print "grid search results      : %s%% false alarm rate, %s%% miss rate" % (
                str(errorRate[0] * 100), str(errorRate[1] * 100))
            print "\n"
            print "Started on " + started.strftime("%Y-%m-%d %H:%M")
            print "Finished on " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
            print "Execution time " + str(datetime.datetime.now() - started)
            print "------------------------------------------------------------"
        sys.stdout = temp
        t.close()
Exemple #11
0
        pool.apply_async(run.run,
                         args=(days, horizon, SoC, NL, b, num_samples, taus,
                               inpEndo, inpExo, tar, lambdas, perfectFC))
        for b in bo
    ]
    my_res = [p.get() for p in my_res]
    pool.close()
    print("--- %s seconds ---" % (time.time() - start_time))

# Run just one process during testing
#taus = np.arange(0.1,0.91,0.1)
#fn.run(days,horizon,SoC,NL,False,num_samples,taus,inpEndo,inpExo,tar,lambdas,perfectFC)

# Run the uncontrolled charging
#fn.uncontrolledCharging(perfectFC,SoC,lambdas)
'''
# RUNNING DETERMINISTIC WITH PERFECT FORECASTS
# NOTE THAT THE FUNCTION RUN SHOULD BE MANUALLY ADJUSTED FOR THIS SPECIAL CASE
#num_samples = 1
taus = np.arange(0.1,0.91,0.1)
fn.run(days,horizon,SoC,NL,False,num_samples,taus,inpEndo,inpExo,tar,lambdas,perfectFC)
'''
'''
# Train the GBRT models
# Use the same hyperparameters for all forecast horizons.
all_files = glob.glob(os.path.join("CrossValidation", "*.txt"))
params = pd.concat((pd.read_csv(f, sep="\t") for f in all_files), ignore_index=True).sort_values(by=['CRPS']).iloc[0,0:6]
if __name__ == '__main__':
    pool = mp.Pool(processes=64)
    horizon = np.arange(1,97,1)
    my_res = [pool.apply_async(fc_fn.gbrt_training, args=(h,inpEndo,inpExo,tar,params)) for h in horizon]
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.bind(('localhost', 18493))
    except OSError:
        print('Program is already running, exitting.', file=sys.stderr)
        sys.exit(1)

    signal.signal(signal.SIGINT, trap)
    signal.signal(signal.SIGTERM, trap)

    # import time
    # time.sleep(10)

    # allow bonjour/zeroconf
    helpers.run(
        'iptables -I INPUT -p udp --dport 5353 -d 224.0.0.251 -m comment --comment "searchExamServer" -j ACCEPT'
    )
    helpers.run(
        'iptables -I OUTPUT -p udp --dport 5353 -d 224.0.0.251 -m comment --comment "searchExamServer" -j ACCEPT'
    )

    display = helpers.get_env("DISPLAY")
    xauthority = helpers.get_env("XAUTHORITY")
    env = {
        'DISPLAY': display,
        'XAUTHORITY': xauthority,
        'LANG': helpers.get_env('LANG')
    }

    # create the directory structure and cleanup
    for path in [