示例#1
0
def file_write(members, member_elements):
    if not os.path.exists('ttl/common'):
        common.main()
        # os.mkdir('ttl/common')
        # with open('ttl/common.ttl', 'w') as fhandle:
        #     fhandle.write(ttlhead)
        #     fhandle.write('<common> a reg:Register ;\n')
        #     fhandle.write('\trdfs:label "WMO No. 306 Vol I.2 common concepts" ;\n')
#     fhandle.write('\tdc:description "Register of concepts common across WMO No. 306 Vol I.2 formats"@en ;\n')
        #     fhandle.write('\treg:owner <http://codes.wmo.int/system/organization/wmo> ;\n')
        #     fhandle.write('\tdct:publisher <http://codes.wmo.int/system/organization/wmo> ;\n')
        #     fhandle.write('\treg:manager <http://codes.wmo.int/system/organization/www-dm> ;\n')
        #     fhandle.write('\t.\n')

    with open('ttl/common/bulk_c6.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)

        fhandle.write('<unit> a skos:Collection ;\n')
        fhandle.write('\trdfs:label       "Code Table C-6: List of units for TDCFs"@en ;\n')
        fhandle.write('\tdct:description  "WMO No. 306 Vol I.2 Common Code-table C-6 List of units for TDCFs."@en ;\n')
        fhandle.write('\tskos:notation "C-6" ;\n')
        fhandle.write('\treg:manager      <http://codes.wmo.int/system/organization/www-dm> ;\n')
        fhandle.write('\treg:owner        <http://codes.wmo.int/system/organization/wmo> ;\n')
        fhandle.write('\tskos:member ')
        fhandle.write(', '.join(members))
        fhandle.write('\t.\n\n')
        fhandle.write('\n'.join(member_elements))
示例#2
0
def main():
    args = get_arguments()

    if args is None:
        print('No arguments')
        return

    if args.print_memory:
        common.print_memory(args.print_memory)

    if args.initialize:
        common.main()
        xb.get_network_info()

    if args.initialize_gsm_module:
        if retry_count == 0:
            lockscript.get_lock('gateway gsm')
            gsmio.init_gsm()
    if args.get_phonebook:
        dbio.get_phonebook_numbers()
    if args.write_custom_sms:
        custom_sms_routine()
    if args.send_outbox_messages:
        lockscript.get_lock('gateway gsm')
        send_unsent_msg_outbox()
    if args.delete_outbox_messages:
        dbio.delete_smsoutbox()
    if args.delete_all_outbox_messages:
        dbio.delete_all_smsoutbox()
    if args.debug_gsm:
        lockscript.get_lock('gateway gsm')
        gsmio.gsm_debug()
    if args.reset_gsm:
        lockscript.get_lock('gateway gsm')
        gsmio.reset_gsm()

    if args.reset_rain_value:
        rd.reset_rain_value()
    if args.rain_detect:
        rd.check_rain_value()

    if args.send_smsoutbox_memory:
        lockscript.get_lock('gateway gsm')
        send_smsoutbox_memory()
        send_unsent_msg_outbox()
    if args.purge_memory:
        lockscript.get_lock('gateway gsm')
        common.purge_memory(args.purge_memory)

    if args.set_system_time:
        set_system_time()
    if args.create_startup_message:
        create_startup_message()

    if args.sample_routers:
        lockscript.get_lock('xbeegate')
        xb.routine()
示例#3
0
def file_write(members, member_elements):
    if not os.path.exists('ttl/common'):
        common.main()
    with open('ttl/common/bulk_quantitykind.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write('<quantity-kind> a skos:Collection ;\n')
        fhandle.write('\trdfs:label       "Code Table D-2: Physical quantity kinds"@en ;\n')
        fhandle.write('\tskos:notation "D-2" ;\n')
        fhandle.write('\tdct:description  "WMO No. 306 Vol I.3 Common Code-table D-2, Physical quantity kinds."@en ;\n')
        fhandle.write('\treg:manager      <http://codes.wmo.int/system/organization/www-dm> ;\n')
        fhandle.write('\treg:owner        <http://codes.wmo.int/system/organization/wmo> ;\n')
        fhandle.write('\tskos:member ')
        fhandle.write(', '.join(members))
        fhandle.write('\t.\n\n')
        fhandle.write('\n'.join(member_elements))
示例#4
0
def main(
        intensity,  # Whether to include intensity or not
        device='cuda',
        max_epochs=200,
        pos_weight=10,
        *,  # training parameters
        model_name,
        hidden_channels,
        hidden_hidden_channels,
        num_hidden_layers,  # model parameters
        dry_run=False,
        **kwargs):  # kwargs passed on to cdeint

    batch_size = 1024
    lr = 0.0001 * (batch_size / 32)

    static_intensity = intensity
    # these models use the intensity for their evolution. They won't explicitly use it as an input unless we include it
    # via the use_intensity parameter, though.
    time_intensity = intensity or (model_name in ('odernn', 'dt', 'decay'))

    times, train_dataloader, val_dataloader, test_dataloader = datasets.sepsis.get_data(
        static_intensity, time_intensity, batch_size)

    input_channels = 1 + (1 + time_intensity) * 34
    make_model = common.make_model(model_name,
                                   input_channels,
                                   1,
                                   hidden_channels,
                                   hidden_hidden_channels,
                                   num_hidden_layers,
                                   use_intensity=intensity,
                                   initial=False)

    def new_make_model():
        model, regularise = make_model()
        model.linear.weight.register_hook(lambda grad: 100 * grad)
        model.linear.bias.register_hook(lambda grad: 100 * grad)
        return InitialValueNetwork(intensity, hidden_channels,
                                   model), regularise

    if dry_run:
        name = None
    else:
        intensity_str = '_intensity' if intensity else '_nointensity'
        name = 'sepsis' + intensity_str
    num_classes = 2
    return common.main(name,
                       times,
                       train_dataloader,
                       val_dataloader,
                       test_dataloader,
                       device,
                       new_make_model,
                       num_classes,
                       max_epochs,
                       lr,
                       kwargs,
                       pos_weight=torch.tensor(pos_weight),
                       step_mode=True)
def main(
        result_folder=None,  # saving parameters
        result_subfolder=None,  #
        epochs=1000,  # training parameters
        num_shapelets_per_class=4,  # model parameters
        num_shapelet_samples=None,  #
        discrepancy_fn='L2',  #
        max_shapelet_length_proportion=0.3,  #
        num_continuous_samples=None,  #
        initialization_proportion=None,
        ablation_pseudometric=True,  # For ablation studies
        ablation_learntlengths=True,  #
        ablation_similarreg=True,  #
        old_shapelets=False,  # Whether to toggle off all of our innovations and use old-style shapelets
        save_top_logreg_shapelets=False,
        save_on_uniform_grid=True):

    times, train_dataloader, val_dataloader, test_dataloader = get_data()

    input_channels = 40
    num_classes = 10

    return common.main(times, train_dataloader, val_dataloader,
                       test_dataloader, num_classes, input_channels,
                       result_folder, result_subfolder, epochs,
                       num_shapelets_per_class, num_shapelet_samples,
                       discrepancy_fn, max_shapelet_length_proportion,
                       initialization_proportion, num_continuous_samples,
                       ablation_pseudometric, ablation_learntlengths,
                       ablation_similarreg, old_shapelets,
                       save_top_logreg_shapelets, save_on_uniform_grid)
def main(
    dataset_name,  # dataset parameters
    missing_rate=0.,  #
    noise_channels=0,  #
    result_folder=None,  # saving parameters
    result_subfolder='',  #
    dataset_detail='',  #
    epochs=250,  # training parameters
    num_shapelets_per_class=3,  # model parameters
    num_shapelet_samples=None,  #
    discrepancy_fn='L2',  #
    max_shapelet_length_proportion=1.0,  #
    initialization_proportion=None,  # Set to initialise shaplets at a desired fraction of length
    num_continuous_samples=None,  #
    ablation_pseudometric=True,  # For ablation studies
    ablation_learntlengths=True,  #
    ablation_similarreg=True,  #
    old_shapelets=False,  # Whether to toggle off all of our innovations and use old-style shapelets
    save_top_logreg_shapelets=False,  # True will save shapelets of the top logreg coefficients
    save_on_uniform_grid=False
):  # Active if save_top_logreg_shapelets, will first sample onto a uniform grid

    times, train_dataloader, val_dataloader, test_dataloader, num_classes, input_channels = get_data(
        dataset_name, missing_rate, noise_channels)

    return common.main(
        times, train_dataloader, val_dataloader, test_dataloader, num_classes,
        input_channels, result_folder,
        _subfolder(dataset_name, dataset_detail,
                   result_subfolder), epochs, num_shapelets_per_class,
        num_shapelet_samples, discrepancy_fn, max_shapelet_length_proportion,
        initialization_proportion, num_continuous_samples,
        ablation_pseudometric, ablation_learntlengths, ablation_similarreg,
        old_shapelets, save_top_logreg_shapelets, save_on_uniform_grid)
示例#7
0
def make_regs():
    if not os.path.exists('ttl/common'):
        common.main()
    if not os.path.exists('ttl/common/c-15'):
        os.mkdir('ttl/common/c-15')
    if not os.path.exists('ttl/common/c-15/ae'):
        os.mkdir('ttl/common/c-15/ae')
    if not os.path.exists('ttl/common/c-15/me'):
        os.mkdir('ttl/common/c-15/me')
    if not os.path.exists('ttl/common/c-15/oc'):
        os.mkdir('ttl/common/c-15/oc')
        with open('ttl/common/deprec_c-15.ttl', 'w') as fhandle:
            fhandle.write(ttlhead)
            fhandle.write("""<c-15> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
    """)
    with open('ttl/common/c-15/deprec_ae.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<ae> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - aeronautical meteorology discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - aeronautical meteorology discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
    with open('ttl/common/c-15/deprec_me.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<me> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - meteorology discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - meteorology discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
    with open('ttl/common/c-15/deprec_oc.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<oc> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - oceanography discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - oceanography discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
示例#8
0
def make_regs():
    if not os.path.exists('ttl/common'):
        common.main()
    if not os.path.exists('ttl/common/c-15'):
        os.mkdir('ttl/common/c-15')
    if not os.path.exists('ttl/common/c-15/ae'):
        os.mkdir('ttl/common/c-15/ae')
    if not os.path.exists('ttl/common/c-15/me'):
        os.mkdir('ttl/common/c-15/me')
    if not os.path.exists('ttl/common/c-15/oc'):
        os.mkdir('ttl/common/c-15/oc')
        with open('ttl/common/deprec_c-15.ttl', 'w') as fhandle:
            fhandle.write(ttlhead)
            fhandle.write("""<c-15> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
    """)
    with open('ttl/common/c-15/deprec_ae.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<ae> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - aeronautical meteorology discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - aeronautical meteorology discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
    with open('ttl/common/c-15/deprec_me.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<me> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - meteorology discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - meteorology discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
    with open('ttl/common/c-15/deprec_oc.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)
        fhandle.write("""<oc> a reg:Register , ldp:Container ;
    rdfs:label "Physical quantities - oceanography discipline"@en ;
    dct:description "WMO No. 306 Vol I.2 Common Code-table C-15 'Physical quantities - oceanography discipline'."@en ;
    reg:owner <http://codes.wmo.int/system/organization/wmo> ;
    reg:manager <http://codes.wmo.int/system/organization/www-dm> ;
    .
""")
示例#9
0
def main(
        dataset_name,
        missing_rate=0.3,  # dataset parameters
        device='cuda',
        max_epochs=1000,
        *,  # training parameters
        model_name,
        hidden_channels,
        hidden_hidden_channels,
        num_hidden_layers,  # model parameters
        dry_run=False,
        **kwargs):  # kwargs passed on to cdeint

    batch_size = 32
    lr = 0.001 * (batch_size / 32)

    # Need the intensity data to know how long to evolve for in between observations, but the model doesn't otherwise
    # use it because of use_intensity=False below.
    intensity_data = True if model_name in ('odernn', 'dt', 'decay') else False

    (times, train_dataloader, val_dataloader, test_dataloader, num_classes,
     input_channels) = datasets.uea.get_data(dataset_name,
                                             missing_rate,
                                             device,
                                             intensity=intensity_data,
                                             batch_size=batch_size)

    if num_classes == 2:
        output_channels = 1
    else:
        output_channels = num_classes

    make_model = common.make_model(model_name,
                                   input_channels,
                                   output_channels,
                                   hidden_channels,
                                   hidden_hidden_channels,
                                   num_hidden_layers,
                                   use_intensity=False,
                                   initial=True)

    if dry_run:
        name = None
    else:
        name = dataset_name + str(int(missing_rate * 100))
    return common.main(name,
                       times,
                       train_dataloader,
                       val_dataloader,
                       test_dataloader,
                       device,
                       make_model,
                       num_classes,
                       max_epochs,
                       lr,
                       kwargs,
                       step_mode=False)
示例#10
0
文件: dt.py 项目: recdnsfp/classify
def main():
	prs = argparse.ArgumentParser(description='Train/test DNS rec. server model: Decision Tree')
	prs.add_argument('--viz', help='store Graphviz representation in given path')

	args, cls, names = common.main(prs, train, common.load, common.test)

	if args.viz:
		tree.export_graphviz(cls, args.viz,
			feature_names=names, class_names=["ok", "hijack"],
			filled=True, impurity=False)
示例#11
0
def file_write(members, member_elements):
    if not os.path.exists('ttl/common'):
        common.main()
        # os.mkdir('ttl/common')
        # with open('ttl/common.ttl', 'w') as fhandle:
        #     fhandle.write(ttlhead)
        #     fhandle.write('<common> a reg:Register ;\n')
        #     fhandle.write('\trdfs:label "WMO No. 306 Vol I.2 common concepts" ;\n')


#     fhandle.write('\tdc:description "Register of concepts common across WMO No. 306 Vol I.2 formats"@en ;\n')
#     fhandle.write('\treg:owner <http://codes.wmo.int/system/organization/wmo> ;\n')
#     fhandle.write('\tdct:publisher <http://codes.wmo.int/system/organization/wmo> ;\n')
#     fhandle.write('\treg:manager <http://codes.wmo.int/system/organization/www-dm> ;\n')
#     fhandle.write('\t.\n')

    with open('ttl/common/bulk_c6.ttl', 'w') as fhandle:
        fhandle.write(ttlhead)

        fhandle.write('<unit> a skos:Collection ;\n')
        fhandle.write(
            '\trdfs:label       "Code Table C-6: List of units for TDCFs"@en ;\n'
        )
        fhandle.write(
            '\tdct:description  "WMO No. 306 Vol I.2 Common Code-table C-6 List of units for TDCFs."@en ;\n'
        )
        fhandle.write('\tskos:notation "C-6" ;\n')
        fhandle.write(
            '\treg:manager      <http://codes.wmo.int/system/organization/www-dm> ;\n'
        )
        fhandle.write(
            '\treg:owner        <http://codes.wmo.int/system/organization/wmo> ;\n'
        )
        fhandle.write('\tskos:member ')
        fhandle.write(', '.join(members))
        fhandle.write('\t.\n\n')
        fhandle.write('\n'.join(member_elements))
示例#12
0
def main(
        device='cuda',
        max_epochs=200,
        *,  # training parameters
        model_name,
        hidden_channels,
        hidden_hidden_channels,
        num_hidden_layers,  # model parameters
        dry_run=False,
        **kwargs):  # kwargs passed on to cdeint

    batch_size = 1024
    lr = 0.00005 * (batch_size / 32)

    intensity_data = True if model_name in ('odernn', 'dt', 'decay') else False
    times, train_dataloader, val_dataloader, test_dataloader = datasets.speech_commands.get_data(
        intensity_data, batch_size)
    input_channels = 1 + (1 + intensity_data) * 20

    make_model = common.make_model(model_name,
                                   input_channels,
                                   10,
                                   hidden_channels,
                                   hidden_hidden_channels,
                                   num_hidden_layers,
                                   use_intensity=False,
                                   initial=True)

    def new_make_model():
        model, regularise = make_model()
        model.linear.weight.register_hook(lambda grad: 100 * grad)
        model.linear.bias.register_hook(lambda grad: 100 * grad)
        return model, regularise

    name = None if dry_run else 'speech_commands'
    num_classes = 10
    return common.main(name,
                       times,
                       train_dataloader,
                       val_dataloader,
                       test_dataloader,
                       device,
                       new_make_model,
                       num_classes,
                       max_epochs,
                       lr,
                       kwargs,
                       step_mode=True)
示例#13
0
#!/usr/bin/env pypy

import common

if __name__ == "__main__":
    common.main(common.uct, common.SearchTree())
示例#14
0
#!/usr/bin/python

# returns number of songs for each artist

import common
import json
import re

# input: file name
# output: artist_id artist_name
def map(line):
	line_split=re.split("\t",line)
	track_id=line_split[0]
	track_data=json.loads(line_split[1])
	tempo=track_data["tempo"]
	artist_id=track_data["artist_id"]
	artist_name=track_data["artist_name"]
	yield(artist_id,artist_name)

def reduce(word, counts):
	count=0
	for artist in counts:
		count=count+1
	yield(counts[0],str(count))

if __name__ == "__main__":
  common.main(map, reduce)
def main():
    common.main(
        run=run_vm,
        plot=plot_vm,
    )
#!/usr/bin/python
import numpy as np
from common import main

def fft(x):
    N = len(x)
    if N <= 1:
        return x

    even = fft(x[0::2])
    odd =  fft(x[1::2])

    M = N / 2
    rhs = np.exp(-2j*np.pi/N * np.arange(M)) * odd
    l = even + rhs
    r = even - rhs

    return np.concatenate([l, r])


def setup(N):
    return np.arange(N, dtype='complex'),


if __name__ == "__main__":
    main(fft, setup)
    treble_pattern = Staff()
    chords = Staff(context_name='ChordNames')

    for key in sideman.keys_in_order():
        jazz_scale = sideman.JazzScale(key)
        treble_pattern.append( get_pattern_n19(jazz_scale) )
        chords.append( get_pattern_n19_chord_measure(jazz_scale) )

    score = Score([chords, treble_pattern])
    tempo = Tempo(Duration(1, 4), (80, 132))
    attach(tempo, treble_pattern)
    return score

def title():
    return "Jazz Pattern 19"

def composer():
    return "Jerry Greene et al, Thiruvathukal"

def pdf():
    return "jazz019.pdf"

def midi():
    return "jazz019.midi"


if __name__ == '__main__':
    score = get_score()
    common.main( score, title(), composer(), pdf())
    common.main( score, title(), composer(), midi())
def get_score():
    treble_pattern = Staff()
    chords = Staff(context_name='ChordNames')

    for key in sideman.keys_in_order():
        jazz_scale = sideman.JazzScale(key)
        treble_pattern.append( get_pattern3(jazz_scale) )
        chords.append( get_pattern3_chord_measure(jazz_scale) )

    score = Score([chords, treble_pattern])
    tempo = Tempo(Duration(1, 4), (80, 132))
    attach(tempo, treble_pattern)
    return score

def title():
    return "Jazz Pattern 3"

def composer():
    return "Jerry Greene et al, Thiruvathukal"

def pdf():
    return "jazz003.pdf"

def midi():
    return "jazz003.midi"

if __name__ == '__main__':
    score = get_score()
    common.main( score, title(), composer(), pdf())
    common.main( score, title(), composer(), midi())
示例#19
0
    threads = []

    for i in range(common.PARALLEL_COUNT):
        threads.append(
            SearchThread(root_state, iter_max / common.PARALLEL_COUNT,
                         search_tree))

    for t in threads:
        t.start()

    for t in threads:
        t.join()

    root_node = SearchNode(tree_node=search_tree.get_node(root_state))
    selected_node = root_node.uct_select_child(0.0)

    print "Nodes generated:", str(search_tree.size() - node_count)
    print
    print root_node.children2string()

    root_node.clean_sub_tree(selected_node, search_tree)

    print "Nodes remainning:", str(search_tree.size())
    print

    return selected_node.move


if __name__ == "__main__":
    common.main(uct, SearchTree())
示例#20
0
# The browser to use
BROWSER = "Chrome"

# Get list of useragents to use
useragents = getUseragents()


def setUpWebdriver(browser, agent):
    """Set up the webdriver that will be used for the automation."""

    if (browser == "Firefox"):
        profile = webdriver.FirefoxProfile()
        profile.set_preference("general.useragent.override", agent)
        driver = webdriver.Firefox(firefox_profile=profile)
    elif (browser == "Chrome"):
        options = webdriver.ChromeOptions()
        options.add_argument("--user-agent='" + agent + "'")
        driver = webdriver.Chrome(chrome_options=options)
    else:
        print()
        raise TypeError("ERROR - unknown browser:", browser)

    return driver


if __name__ == '__main__':
    for useragent in useragents:
        driver = setUpWebdriver(BROWSER, useragent[0])
        main(driver, BROWSER, useragent)
示例#21
0
import sys
import common

if __name__ == '__main__':
    try:
        backend = common.choose_backend(sys.argv[1])
        filename = sys.argv[2]
    except (KeyError, IndexError) as e:
        print(e)
        print("Usage: python %s <numba|numbapro|numpy> <recorded_file>" % sys.argv[0])
    else:
        print("Click on the screen to plunk the string.")
        print("Y-axis: top -- lighter; bottom -- heavier")
        print("X-axis: position")
        common.main(backend.physics, filename)
示例#22
0
            senttokens = list()
            for tok in sent.split("\n"):
                token, tag = tok.split("\t")
                stts = rftag2stts(tag)
                senttokens.append(
                    Token(word=token,
                          xpos=stts,
                          feats=str(Morph.from_rftag(tag))))
            self.data.append(Sentence(senttokens))


class UDPipe(TestSystem):
    pass  # TODO


if __name__ == "__main__":
    main(
        # "tokens",
        "pos",
        [
            StanfordNLP,
            RFTagger,
            TreeTagger,
            RNNTagger,
            SoMeWeTa,
            CoreNLP,
            Clevertagger,
            Spacy,
        ],
    )
示例#23
0
#!/usr/bin/env pypy

import common

if __name__ == "__main__":
    common.main(common.uct)
示例#24
0
        
    workers = []
    
    for i in range(common.PARALLEL_COUNT):
        w = SearchWorker(root_state, iter_max / common.PARALLEL_COUNT, multiprocessing.Queue());
        workers.append(w);
    
    for w in workers:
        w.start()
        
    for w in workers:
        w.join()
        
    results = [w.get_result() for w in workers]
    
    values = collections.defaultdict(float)    
    for r in results:
        for (move, value) in r[0].items():
            values[move] += value
    
    print "Nodes generated:", sum([r[1] for r in results])
    print
    for (k, v) in values.items():
        print "%s: %.3f" % (str(k), v / common.PARALLEL_COUNT)
    print
    
    return max(values.items(), key=lambda (k, v): v)[0]

if __name__ == "__main__":
    common.main(uct, None)
示例#25
0
import common

if __name__ == '__main__':
    common.main(common.args, model_type='s_ibp_bbvi')
示例#26
0
                (os.path.join(self.build_dir, 'regression.xml')),
                '' if not toolset_to_test else 'toolset=%s' %
                (toolset_to_test),
                '' if not self.address_model else 'address-model=%s' %
                (self.address_model), 'variant=%s' % (self.variant),
                '--test-type=%s' % (self.target), '--verbose-test')

            # Generate a readable test report.
            import build_log
            log_main = build_log.Main([
                '--output=console',
                os.path.join(self.build_dir, 'regression.xml')
            ])
            # And exit with an error if the report contains failures.
            # This lets the CI notice the error and report a failed build.
            # And hence trigger the failure machinery, like sending emails.
            if log_main.failed:
                self.ci.finish(-1)

    def command_before_cache(self):
        script_common.command_before_cache(self)
        os.chdir(self.boost_root)
        utils.check_call("git", "clean", "-dfqx")
        utils.check_call("git", "submodule", "--quiet", "foreach", "git",
                         "clean", "-dfqx")
        utils.check_call("git", "status", "-bs")
        utils.check_call("git", "submodule", "foreach", "git", "status", "-bs")


main(script)
示例#27
0
    def euler(cls, drs):
        """
        Return the result of Euler algorithm for `drs`.

        The arguments `drs` is a list of 2-tuples, each being a divisor and the
        required reminder. The method returns the smallest number that when
        divided by each divisor gives its corresponding reminder.

        The method is based on Euler's article that can be found
        [here](http://eulerarchive.maa.org/docs/translations/E036en.pdf).

        The algorithm can be generalised for more than 2 numbers, but it is
        quite fast this way, so I leave the optimisation to the reader. O:-)

        :param drs: An iterable of 2-tuples, each being a divisor and its
            required reminder.
        :return: The smallest nonnegative integer that divided by each of the
            divisors in `drs` gives their respective reminders.
        """
        while len(drs) > 1:
            drs = drs[:-2] + [cls._euler2(*drs[-1], *drs[-2])]
        return drs[0][1]

    def part2(self):
        return self.euler([(bus, -idx % bus)
                           for idx, bus in enumerate(self.buses) if bus])


if __name__ == "__main__":
    main(Day13)
示例#28
0
		steps, elevator, state = agenda[curmin].pop()
		if all(b == 3 for b in state):
			return steps
		onfloor = [a for a, b in enumerate(state) if b == elevator]
		for comb in itertools.chain(
				((a, ) for a in onfloor),
				itertools.combinations(onfloor, 2)):
			for dir in (1, -1):
				if 0 <= elevator + dir <= 3:
					newstate = [b + dir * (a in comb)
							for a, b in enumerate(state)]
					if legal(newstate) and srepr(
							elevator + dir, newstate) not in seen:
						seen.add(srepr(elevator + dir, newstate))
						est = estimate(elevator, newstate) + steps + 1
						agenda[est].append((
								steps + 1, elevator + dir, newstate))
						if curmin > est:
							curmin = est


def day11b(s):
	lines = s.splitlines()
	lines[0] += ' elerium generator elerium-compatible microchip'
	lines[0] += ' dilithium generator dilithium-compatible microchip'
	return day11a('\n'.join(lines))


if __name__ == '__main__':
	main(globals())
示例#29
0
def construct(args):
    network = NetworkMelody(args)

    with network.session.graph.as_default():
        spectrogram_function, spectrogram_thumb, spectrogram_info = common.spectrograms(args)
        # save spectrogram_thumb to hyperparams
        args.spectrogram_thumb = spectrogram_thumb

        hop_samples = args.frame_width*args.samplerate/44100
        print("hop_samples", hop_samples)
        def preload_fn(aa):
            aa.annotation = datasets.Annotation.from_time_series(*aa.annotation, hop_samples=hop_samples)
            aa.audio.load_resampled_audio(args.samplerate).load_spectrogram(spectrogram_function, spectrogram_thumb, spectrogram_info[2])

        def dataset_transform(tf_dataset, dataset):
            return tf_dataset.map(dataset.prepare_example, num_parallel_calls=args.threads).batch(args.batch_size_evaluation).prefetch(10)

        def dataset_transform_train(tf_dataset, dataset):
            return tf_dataset.shuffle(10**5).map(dataset.prepare_example, num_parallel_calls=args.threads).batch(args.batch_size).prefetch(10)

        valid_hooks = [MetricsHook(), VisualOutputHook(False, False, True, True), SaveBestModelHook(args.logdir), CSVOutputWriterHook(), AdjustVoicingHook()]
        train_dataset, test_datasets, validation_datasets = common.prepare_datasets(args.datasets, args, preload_fn, dataset_transform, dataset_transform_train, valid_hooks=valid_hooks)

        network.construct(args, create_model, train_dataset.dataset.output_types, train_dataset.dataset.output_shapes, spectrogram_info=spectrogram_info)

    return network, train_dataset, validation_datasets, test_datasets


if __name__ == "__main__":
    common.main(sys.argv[1:], construct, parse_args)
示例#30
0
                review_changes.append(change)

        if not review_changes:
            error("No files selected")
            return

        review_changes = merge_changes(review_changes)

        self.start_busy()
        try:
            self.upload_changes(review_changes)
        finally:
            self.end_busy()


    def OnSelectAll(self, evt):
        for i in range(self._files.GetCount()):
            self._files.Check(i, 1)

    def OnUnselectAll(self, evt):
        for i in range(self._files.GetCount()):
            self._files.Check(i, 0)

    def OnInvertSelection(self, evt):
        for i in range(self._files.GetCount()):
            self._files.Check(i, not self._files.IsChecked(i))


if __name__ == "__main__":
    main(UCMCC)
示例#31
0
文件: mruser.py 项目: vasilvv/mrtools
        ('Alternate email', user.alternate_email) if user.alternate_email else None,
        ('Alternate phone', user.alternate_phone) if user.alternate_phone else None,
        ('Created', "%s by %s" % (common.last_modified_date(user.created_date), user.created_by)),
        ('Last modified', "%s by %s using %s" % (common.last_modified_date(user.lastmod_datetime), user.lastmod_by, user.lastmod_with)),
    )

def show_ownerships():
    """Handle 'mruser ownerships'."""

    user = User(client, args.user)
    ownership.show_ownerships(client, args, user)

def setup_subcommands(argparser):
    """Sets up all the subcommands."""

    subparsers = argparser.add_subparsers()

    parser_info = subparsers.add_parser('info', help = 'Provide the information about the user')
    parser_info.add_argument('user', help = 'The user to inspect')

    parser_ownerships = subparsers.add_parser('ownerships', help = 'Show items which this user owns')
    parser_ownerships.add_argument('user', help = 'The name of the user to show information about')
    parser_ownerships.add_argument('-r', '--recursive', action = 'store_true', help = 'Show items which this user own through being in lists')
  
    parser_info.set_defaults(handler = show_info)
    parser_ownerships.set_defaults(handler = show_ownerships)

if __name__ == '__main__':
    client, args = common.init('mruser', 'Inspect Moira users', setup_subcommands)
    common.main()
示例#32
0
def gateway_initialize():
    common.main()
示例#33
0
                     example=1.5),
        'strlen':
        fields.String(required=True,
                      description='length limited str',
                      max_length=4,
                      min_length=2,
                      example="exs"),
        'listlen':
        fields.List(fields.String,
                    required=True,
                    description='length limited list',
                    max_length=4,
                    min_length=2,
                    example=["some", "strings", "here"]),
    })


@example_ns.route('/<int:exint>')
class ExampleResource(Resource):
    @api.expect(ExampleObj)
    @api.response(204, 'App successfully updated.')
    def put(self, exint):
        """Takes in data"""
        log.debug("Got parameter: %r", exint)
        log.debug("Got body: %r", request.data)
        return None, 204


if __name__ == '__main__':
    main(os.path.splitext(os.path.basename(__file__))[0] + '.json')
#!/usr/bin/python
from cmath import exp, pi
from common import main

def fft(x):
    N = len(x)
    if N <= 1:
        return x

    even = fft(x[0::2])
    odd =  fft(x[1::2])

    M = N / 2
    expBase = -2j*pi/N
    l = [even[k] + exp(expBase*k) * odd[k] for k in xrange(M)]
    r = [even[k] - exp(expBase*k) * odd[k] for k in xrange(M)]

    return l + r


if __name__ == "__main__":
    main(fft)
示例#35
0
                    xpos,
                    feats,
                    head,
                    deprel,
                    deps,
                    misc,
                ) = tok.split("\t")
                mytokens.append(
                    Token(
                        id=index,
                        word=word,
                        lemma=lemma,
                        # don't write out gold pos
                        # upos=upos, xpos=xpos,
                        feats=str(Morph.from_parzu(xpos + "|" + feats)),
                        head=head,
                        deprel=deprel,
                        deps=deps,
                        misc=misc,
                    ))
            self.data.append(Sentence(mytokens))


class UDPipe(TestSystem):
    # maybe
    pass


if __name__ == "__main__":
    main("depparse", [CoreNLP, ParZu, Spacy, StanfordNLP])
示例#36
0
            '--dump-tests',
            '--verbose-test',
            '--build-dir=%s'%(self.build_dir),
            '--out-xml=%s'%(os.path.join(self.build_dir,'regression.xml')),
            '' if not toolset_to_test else 'toolset=%s'%(toolset_to_test),
            '' if not self.address_model else 'address-model=%s'%(self.address_model),
            'variant=%s'%(self.variant),
            self.target
            )
        
        # Generate a readable test report.
        import build_log
        log_main = build_log.Main([
            '--output=console',
            os.path.join(self.build_dir,'regression.xml')])
        # And exit with an error if the report contains failures.
        # This lets the CI notice the error and report a failed build.
        # And hence trigger the failure machinery, like sending emails.
        if log_main.failed:
            self.ci.finish(-1)

    def command_before_cache(self):
        script_common.command_before_cache(self)
        os.chdir(self.b2_dir)
        utils.check_call("git","clean","-dfqx")
        utils.check_call("git","status","-bs")
        # utils.check_call("git","submodule","--quiet","foreach","git","clean","-dfqx")
        # utils.check_call("git","submodule","foreach","git","status","-bs")

main(script)
示例#37
0
import common
import os
import cPickle as pickle

class SearchTree(common.SearchTree):
    file_name = "search_tree.pkl"
    
    def __init__(self):
        common.SearchTree.__init__(self) 
               
        if os.path.exists(self.file_name):
            try:
                with open(self.file_name, "r") as f:
                    self.__pool = pickle.load(f)
            except pickle.PickleError:
                self.__pool = {}
        else:
            self.__pool = {}
    
    def dump(self):
        with open(self.file_name, "w") as f:
            pickle.dump(self.__pool, f)
            
    def clean_sub_tree(self, root_node, ignore_node):
        pass

if __name__ == "__main__":
    tree = SearchTree()
    common.main(common.uct, tree)
    tree.dump()
    
        scale = sideman.get_scale(key, 'major')
        pattern_measure = get_pattern_n77(scale)
        chord_measure = get_pattern_n77_chords(scale)
        treble_pattern.append(pattern_measure)
        chords.append(chord_measure)

    tempo = Tempo(Duration(1, 4), (100, 138))
    attach(tempo, treble_pattern)
    score = Score([chords, treble_pattern])
    return score


def title():
    return "Jazz Pattern 77"


def composer():
    return "Jerry Greene et al, Thiruvathukal"


def pdf():
    return "jazz77.pdf"


def midi():
    return "jazz77.midi"


if __name__ == '__main__':
    common.main(get_score(), title(), composer(), pdf())
    common.main(get_score(), title(), composer(), midi())
        if not baseline:
            return
        view = self._view.GetStringSelection()
        baseline = baseline.replace("(", "")
        baseline = baseline.replace(")", "")
        name, owner, date = baseline.split()
        activities = get_baseline_activities_progress(view, name)

        activitires_str = "\t" + "\n\t".join(activities)
        messageDialog(
            self, 
            BASELINE_TEMPLATE  % (name, owner, date, activitires_str),
            "Baseline Information for %s" % name, 
            wx.OK)

    def add_text(self, sizer, caption):
        text = wx.StaticText(self, -1, "%s:" % caption)
        sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL)

    def add_combo(self, sizer, choices=None):
        if choices is None:
            choices = []
        combo = wx.ComboBox(self, -1, choices=choices,
                style=wx.CB_READONLY, size=(500, -1))
        sizer.Add(combo, 0, wx.EXPAND)
        return combo


if __name__ == "__main__":
    main(UCMCCBaseline)
示例#40
0
def main():
    common.main(widget=StatusWidget, window_name='Item/Widget')
示例#41
0
            def myprocessor(myinput):
                mydoc = string2doc(myinput)
                for sent in mydoc:
                    for tok in sent:
                        try:
                            matching_lemmas = self.lemmatizer.lemmatize(
                                tok.word, conv_table.get(tok.xpos))
                            if matching_lemmas is None:
                                tok.lemma = "_"
                                # elif len(matching_lemmas) > 1:
                                #     print("lots o lemmas!", matching_lemmas)
                            else:
                                # unclear how to select best alternative
                                # just use first item in list
                                tok.lemma = matching_lemmas[0]
                        except ValueError:
                            tok.lemma = "_"
                        # don't repeat gold pos in output
                        tok.hide_fields(HIDDEN_FIELDS)
                return mydoc

            self.processor = myprocessor

    def postprocess(self):
        self.data = doc2string(self.output_data)


if __name__ == "__main__":
    main("lemmas", [GermaLemma, CustomLemmatizer, IWNLP])
示例#42
0
def main():
    common.main(widget=StatusView, window_name='Model/View')
    return measure

def get_score():
    treble_pattern = Staff()
    chords = Staff(context_name='ChordNames')

    for key in sideman.keys_in_fifths():
        jazz_scale = sideman.JazzScale(key)
        treble_pattern.append( get_pattern2(jazz_scale) )
        chords.append( get_pattern2_chord_measure(jazz_scale) )

    score = Score([chords, treble_pattern])
    tempo = Tempo(Duration(1, 4), (80, 132))
    attach(tempo, treble_pattern)
    return score

def title():
    return "Jazz Pattern 2"

def composer():
    return "Jerry Greene et al, Thiruvathukal"

def pdf():
    return "jazz002.pdf"

def midi():
    return "jazz002.midi"

if __name__ == '__main__':
    common.main( get_score(), title(), composer(), pdf())
    common.main( get_score(), title(), composer(), midi())
示例#44
0
#!/usr/bin/python

# find song with highest variance in loudness

import common
import json
import re


# input: file name
# output: artist_id artist_name
def map(line):
    line_split = re.split("\t", line)
    track_id = line_split[0]
    track_data = json.loads(line_split[1])
    loudness_variance = track_data["segment_loudness_variance"]
    variance_string = "%010.6f" % loudness_variance
    track_name = track_data["title"]
    artist_name = track_data["artist_name"]
    yield (variance_string, artist_name + " -- " + track_name)


def reduce(word, counts):
    pass


if __name__ == "__main__":
    common.main(map, reduce)
    )

    # Instanciate glanceclient and retrieve the list of images
    glanceclient = client_manager.image

    marker = None
    kwargs = {}
    image_list = []
    while True:
        page = glanceclient.api.image_list(marker=marker, **kwargs)
        if not page:
            break
        image_list.extend(page)
        # Set the marker to the id of the last item we received
        marker = page[-1]['id']

    LOG.info("Found {0} image(s).".format(str(len(image_list))))
    for image in image_list:
        migrate_image(glanceclient, image['id'])

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Glance image backend migration'
    )
    opts = common.base_parser(
        clientmanager.build_plugin_option_parser(parser),
    ).parse_args()

    common.configure_logging(opts)
    sys.exit(common.main(opts, main))
示例#46
0

test = common.Test()
test.show()

box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()

toolbar_box = ToolbarBox()
box.pack_start(toolbar_box, False, False, 0)
toolbar_box.show()

separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)
separator.show()


def color_changed_cb(button, pspec):
    print button.get_color()


color_button = ColorToolButton()
color_button.connect("notify::color", color_changed_cb)
toolbar_box.toolbar.insert(color_button, -1)
color_button.show()


if __name__ == '__main__':
    common.main(test)
示例#47
0
        Assumes 2 alternating players (player 1 starts), with game results in the range [0.0, 1.0]."""

    node_count = search_tree.size()
    threads = []
    
    for i in range(common.PARALLEL_COUNT):
        threads.append(SearchThread(root_state, iter_max / common.PARALLEL_COUNT, search_tree))
    
    for t in threads:
        t.start()
        
    for t in threads:
        t.join()
    
    root_node = SearchNode(tree_node=search_tree.get_node(root_state))
    selected_node = root_node.uct_select_child(0.0)

    print "Nodes generated:", str(search_tree.size() - node_count)
    print
    print root_node.children2string()

    root_node.clean_sub_tree(selected_node, search_tree)

    print "Nodes remainning:", str(search_tree.size())
    print

    return selected_node.move

if __name__ == "__main__":
    common.main(uct, SearchTree())
    # Do useful things with it

    # Look in the object store
    c_list = client_manager.object_store.container_list()
    print("Name\tCount\tBytes")
    for c in c_list:
        print("%s\t%d\t%d" % (c['name'], c['count'], c['bytes']))

    if len(c_list) > 0:
        # See what is in the first container
        o_list = client_manager.object_store.object_list(c_list[0]['name'])
        print("\nObject")
        for o in o_list:
            print("%s" % o)

    # Look at the compute flavors
    flavor_list = client_manager.compute.flavors.list()
    print("\nFlavors:")
    for f in flavor_list:
        print("%s" % f)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='ClientManager Example')
    opts = common.base_parser(
        clientmanager.build_plugin_option_parser(parser),
    ).parse_args()

    common.configure_logging(opts)
    sys.exit(common.main(opts, run))
    score = Score([chords, voicing, bass_pattern])
    return score

def title(key_name):
    return "II-V-I Progression (starting in %s), Piano" % key_name

def composer():
    return "Not Specified"

def pdf(key_name):
    return "progression001-%s.pdf" % key_name.lower()

def midi(key_name):
    return "progression001-%s.midi" % key_name.lower()


if __name__ == '__main__':

    parser = argparse.ArgumentParser(description="compute the II-V-I progression exercise in C or F")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-c", "--key_of_c", action="store_true")
    group.add_argument("-f", "--key_of_f", action="store_true")
    args = parser.parse_args()

    key_name = 'f' if args.key_of_f else 'c'
    key_name = key_name.upper()

    print("Creating II-V-I in key of %s" % key_name)
    score = get_score(key_name)
    common.main( score, title(key_name), composer(), pdf(key_name))
    common.main( score, title(key_name), composer(), midi(key_name))