Ejemplo n.º 1
0
def predict(input_path, output_path, resources_path):
    """
    This is the skeleton of the prediction function.
    The predict function will build your model, load the weights from the checkpoint and write a new file (output_path)
    with your predictions in the BIES format.
    
    The resources folder should contain everything you need to make the predictions. It is the "resources" folder in your submission.
    
    N.B. DO NOT HARD CODE PATHS IN HERE. Use resource_path instead, otherwise we will not be able to run the code.

    :param input_path: the path of the input file to predict.
    :param output_path: the path of the output file (where you save your predictions)
    :param resources_path: the path of the resources folder containing your model and stuff you might need.
    :return: None
    """

    model = load_model(resources_path + '/model.h5')

    model.summary()

    dictionary = load(resources_path + 'dictionary')
    word2id = dictionary['word2id']
    id2label = dictionary['id2label']

    X_chinese, y, characters, sizes = file2BIES(input_path)

    # Process X
    X_processed = processX(X_chinese, word2id, sentence_size=626)

    y_pred = model.predict(X_processed)

    prediction = []

    arg = np.argmax(y_pred, axis=2)

    for i in range(len(arg)):
        sentence = arg[i]
        labels = []
        num_char = np.count_nonzero(X_processed[i])
        for char in sentence[0:num_char]:
            labels.append(id2label[char])

        prediction.append(labels)

    score(prediction, y, verbose=True)

    # Write prediction file
    filename, extension = os.path.splitext(output_path)
    with open(filename + '_prediction' + extension, "w+") as f:
        for line in prediction:
            f.write(''.join(str(e) for e in line))
            f.write('\n')

    # Write gold file
    with open(output_path, "w+") as f:
        for line in y:
            f.write(''.join(str(e) for e in line))
            f.write('\n')

    pass
Ejemplo n.º 2
0
def main():
    part2xy = load_dataset_fast('FILIMDB')
    train_ids, train_texts, train_labels = part2xy['train']

    print('\nTraining classifier on %d examples from train set ...' %
          len(train_texts))
    st = time()
    params = train(train_texts, train_labels)
    print('Classifier trained in %.2fs' % (time() - st))

    allpreds = []
    for part, (ids, x, y) in part2xy.items():
        print('\nClassifying %s set with %d examples ...' % (part, len(x)))
        st = time()
        preds = classify(x, params)
        print('%s set classified in %.2fs' % (part, time() - st))
        allpreds.extend(zip(ids, preds))

        if y is None:
            print('no labels for %s set' % part)
        else:
            score(preds, y)

    save_preds(allpreds, preds_fname=PREDS_FNAME)
    print('\nChecking saved predictions ...')
    score_preds(preds_fname=PREDS_FNAME)
Ejemplo n.º 3
0
def setup_game():
    global gs
    gs.update()
    gs.snacks.clear()
    gs.snake1 = snake.snake(gs, 1)
    gs.snake1.setGS(gs)

    if gs.obstacles_on:
        for _ in range(5):
            gs.obstacles.append(cube.cube(gs, random_obstacle(), color=gs.color.grey))
    gs.surface = pygame.display.set_mode((gs.width, gs.width + gs.banner_height))
    if gs.mode == "race" or gs.mode == "melee":
        gs.snake2 = snake.snake(gs, 2)
        gs.snake2.setGS(gs)
        gs.scr = score.score(gs, True)
    else:
        gs.scr = score.score(gs, False)
    if gs.mode == "melee":
        gs.snake1.grow = True
        if gs.snake2:
            gs.snake2.grow = True

    if gs.borders_on:
        for x in range(gs.rows):
            for y in range(gs.rows):
                if x == 0 or y == 0 or y == gs.rows-1 or x == gs.rows-1:
                    gs.obstacles.append(cube.cube(gs, (x,y), color=gs.color.grey))

    if gs.mode != "melee":
        for i in range(gs.fruit_count):
            gs.snacks.append(cube.cube(gs, random_snack(), color=gs.color.green))
Ejemplo n.º 4
0
 def test_enro(self):
     os.chdir('models/en-ro/')
     score(['model.npz'], open('../../en-ro/in'),
           open('../../en-ro/references'), open('../../en-ro/out_score',
                                                'w'), normalization_alpha)
     os.chdir('../..')
     self.scoreEqual('en-ro/ref_score', 'en-ro/out_score')
Ejemplo n.º 5
0
def main():
    init(autoreset = True)

    print Fore.GREEN + '============================================'
    print Fore.GREEN + '             Auto-Score by Soxfmr           '
    print Fore.GREEN + '              ver 0.2 20151128              '
    print Fore.GREEN + '============================================'

    try:
        username = require('Sutdent Id: ')
        password = require('Password: '******'Do you want to ignore the marked record')
        settings.IGNORE_ALREADY_SCORED = ignore

        if username == '' or password == '':
            raise Exception('Invalid input value.')

        # Retrieve the user session
        log('Preparing the user session...')
        session = login(username, password)

        # Begin
        log(Fore.GREEN + 'Session established. Getting start to marking...')
        score(session)

        log(Fore.GREEN + 'All done! Now you should login to the education system and confirm all of record!', important = True)

    except Exception as e:
        print Fore.RED + e.message
Ejemplo n.º 6
0
def run():
    from repeats import repeats
    from score import score
    from clean import clean
    from match import match
    from merge import merge
    from id_gen import id_gen
    import pandas as pd
    '''
  This is the new (Summer 2019) implementation of scoring, matching, and merging
  '''
    year = "19"
    season = "Sp"
    mergeName = 'QuaRCSLt2_' + season + year + '_merged.csv'
    PREdata = 'QuaRCSLt2_S19_PRE.csv'
    PSTdata = PREdata[:-7] + "POST.csv"
    stu_DB_name = "Student_ID_Database.csv"
    instr_DB_name = "Instr_ID_Database.csv"

    print("Scoring...")
    # Score PRE and PST
    PREdata = score(PREdata, 'PRE', year, season, 'answ.csv', PREdata[:-4])
    PSTdata = score(PSTdata, 'PST', year, season, 'answ.csv', PSTdata[:-4])

    # Clean PRE and PST
    #PREdata = PREdata[:-4] + "_scored.csv"
    #PSTdata = PSTdata[:-4] + "_scored.csv"
    print("Cleaning...")
    PREdata = clean(PREdata, 'PRE')
    PSTdata = clean(PSTdata, 'PST')

    # Generate IDs for PRE and PST
    # PREdata = PREdata[:-4] + "_cleaned.csv"
    # PSTdata = PSTdata[:-4] + "_cleaned.csv"

    print("Generating student and instructor IDs...")

    PREdata = id_gen(PREdata, 'PRE', year, season, stu_DB_name, instr_DB_name)
    PSTdata = id_gen(PSTdata, 'PST', year, season, stu_DB_name, instr_DB_name)

    # Split Repeats
    print("Splitting...")
    PREdata = repeats(PREdata, 'PRE')
    PSTdata = repeats(PSTdata, 'PST')

    # Match
    # PREdata = PREdata[:-4] + "_id.csv"
    # PSTdata = PSTdata[:-4] + "_id.csv"
    #PREdata = pd.read_csv(PREdata)
    #PSTdata = pd.read_csv(PSTdata)
    print("Matching...")
    PRE_not_matched, PST_not_matched, pairs, instructor_change = match(
        PREdata, PSTdata)

    # Merge
    print("Merging...")
    mergedData = merge(PRE_not_matched, PST_not_matched, PREdata, PSTdata,
                       pairs)
    mergedData.to_csv(mergeName, encoding='utf-8', index=False)
    print("Merged dataset saved to {0}".format(mergeName))
Ejemplo n.º 7
0
def main(rectlist):
    tracing_and_stencil = tracing(rectlist)
    stencil = tracing_and_stencil[0]
    trace = tracing_and_stencil[1]
    stencil_length = len(stencil)  #stencil length
    trace_length = len(trace)  #trace length
    if trace_length >= stencil_length:
        length_diff = trace_length - stencil_length
        temp_lendiff = length_diff
        while temp_lendiff != 0:
            index = random.randint(0, (len(trace) - 1))
            del (trace[index])
            temp_lendiff -= 1
    elif stencil_length > trace_length and trace_length != 0:
        length_diff = stencil_length - trace_length
        temp_lendiff = length_diff
        while temp_lendiff != 0:
            index = random.randint(0, (len(stencil) - 1))
            del (stencil[index])
            temp_lendiff -= 1
    else:
        userScore = 0
        f = open("userscores.txt", "a")
        f.write(str(userScore))
        f.write("\n")
        f.close()
        return str(int(score.score(trace, stencil))) + '%'
    userScore = score.score(trace, stencil)
    f = open("userscores.txt", "a")
    f.write(str(userScore))
    f.write("\n")
    f.close()
    return str(int(score.score(trace, stencil))) + '%'
Ejemplo n.º 8
0
def banner():
    while True:
        print "1. Press 1 for running the tokenizer usually"
        print "2. Press 2 for creating the inverted index"
        print "3. Press 3 for creating the vectors for the documents"
        print "4. Press any other number to search"
        choice =  int(raw_input("$ "))
        if not os.path.exists(TEXT):
            print "No Data at All. No Valid Corpus. Please add something to\n" + str(TEXT)
        if not os.path.exists(DATA_PATH):
            print "No Data Existed, Path Created"
            os.mkdir(DATA)
        if not os.path.exists(TOKENS) or choice == 1:
            print "Creating tokens as they don't exist/You Chose To"
            os.mkdir(TOKENS)
            tokenizer()
        if not os.path.exists(INDICES) or choice == 2:
            print "Creating indices as they don't exist"
            os.mkdir(INDICES)
            counter()
        if not os.path.exists(SCORES) or choice == 3:
            print "Creating Vectors as they don't exist"
            os.mkdir(SCORES)
            score()
            mod()
        if choice > 3 or choice == 0:
            print "Search begins"
            break
Ejemplo n.º 9
0
def main():
    init(autoreset=True)

    print Fore.GREEN + '============================================'
    print Fore.GREEN + '             Auto-Score by Soxfmr           '
    print Fore.GREEN + '              ver 0.2 20151128              '
    print Fore.GREEN + '============================================'

    try:
        username = require('Sutdent Id: ')
        password = require('Password: '******'Do you want to ignore the marked record')
        settings.IGNORE_ALREADY_SCORED = ignore

        if username == '' or password == '':
            raise Exception('Invalid input value.')

        # Retrieve the user session
        log('Preparing the user session...')
        session = login(username, password)

        # Begin
        log(Fore.GREEN + 'Session established. Getting start to marking...')
        score(session)

        log(Fore.GREEN +
            'All done! Now you should login to the education system and confirm all of record!',
            important=True)

    except Exception as e:
        print Fore.RED + e.message
Ejemplo n.º 10
0
 def test_ende(self):
     scorer_settings = self.get_settings()
     os.chdir('models/en-de/')
     score(open('../../en-de/in'), open('../../en-de/references'),
           open('../../en-de/out_score', 'w'), scorer_settings)
     os.chdir('../..')
     self.scoreEqual('en-de/ref_score', 'en-de/out_score')
Ejemplo n.º 11
0
def simann(firstsol, V, E, R, C, X, sizes, latencies, cache_latencies, requests):
    Y = 3
    N = 100
    best_score = score(latencies, cache_latencies, requests, firstsol)

    def cache_size(cache):
        return sum([v for v in sizes if v in cache])

    def find_cache(videoid):
        for i, x in enumerate(caches):
            if videoid in x:
                return i

        return -1

    def remove_from_cache(videoid):
        idx = find_cache(videoid)
        if idx >= 0:
            caches[idx].remove(videoid)
            l_sizes[idx] -= sizes[videoid]

    def move_to_cache(videoid, cacheid):
        size = l_sizes[cacheid]
        
        if sizes[videoid] + size > X:
            return False
        else:
            remove_from_cache(videoid)
            caches[cacheid].add(videoid)
            l_sizes[cacheid] += sizes[videoid]
            return True

    l_sizes = [cache_size(x) for x in firstsol]
    best_sol = [set(x) for x in firstsol]

    for i in range(Y):
        caches = [set(x) for x in firstsol]
        for j in range(N):
            print >> sys.stderr, j
            prevsol = [set(x) for x in caches]

            rv = randint(0, V-1)

            for x in range(10):
                rc = randint(0, C-1)
                if move_to_cache(rv, rc):
                    break

            curr_score = score(latencies, cache_latencies, requests, caches)

            if curr_score > best_score:
                best_sol = [set(x) for x in caches]
                best_score = curr_score
            else:
                if random() < (float(j) / float(N)):
                    caches = prevsol

    return best_sol 
Ejemplo n.º 12
0
    def __init__(self, data, targets, cv_data, cv_targets, extra, layers, epochs=1, smoothing=1, new=True, filename_in=False):
        
        if len(cv_data) != len(cv_targets): raise Exception("Number of CV data and CV targets must be equal")
        if len(data) != len(targets): raise Exception("Number of data and targets must be equal")

        if new:
            class_tr_targets = [str(int(t[0]) - 1) for t in targets] # for pybrain's classification datset
            print "...training the DNNRegressor"
            if len(layers) > 2: # TODO testing only
                net = DNNRegressor(data, extra, class_tr_targets, layers, hidden_layer="TanhLayer", final_layer="SoftmaxLayer", compression_epochs=epochs, bias=True, autoencoding_only=False)
                print "...running net.fit()"
                net = net.fit()
            elif len(layers) == 2:
                net = buildNetwork(layers[0], layers[-1], outclass=SoftmaxLayer, bias=True)

            ds = ClassificationDataSet(len(data[0]), 1, nb_classes=9)
            bag = 1
            noisy, _ = self.dropout(data, noise=0.0, bag=bag, debug=True)
            bagged_targets = []
            for t in class_tr_targets:
                for b in range(bag):
                    bagged_targets.append(t)
            for i,d in enumerate(noisy):
                t = bagged_targets[i]
                ds.addSample(d, t)
            ds._convertToOneOfMany()

            print "...smoothing for epochs: ", smoothing
            self.model = net
            preds = [self.predict(d) for d in cv_data]
            cv = score(preds, cv_targets, debug=False)
            preds = [self.predict(d) for d in data]
            tr = score(preds, targets, debug=False)
            trainer = BackpropTrainer(net, ds, verbose=True, learningrate=0.0008, momentum=0.04, weightdecay=0.05) # best score 0.398 after 50 compression epochs and 200 epochs with lr=0.0008, weightdecay=0.05, momentum=0.04. Used dropout of 0.2 in compression, 0.5 in softmax pretraining, and no dropout in smoothing.
            print "Train score before training: ", tr
            print "CV score before training: ", cv
            for i in range(smoothing):
                trainer.train()
                self.model = net
                preds = [self.predict(d) for d in cv_data]
                cv = score(preds, cv_targets, debug=False)
                preds = [self.predict(d) for d in data]
                tr = score(preds, targets, debug=False)
                print "Train/CV score at epoch ", (i+1), ': ', tr, '/', cv
                #if i == 1:
                    #print "...saving the model"
                    #save("data/1000_ex_4_hidden/net_epoch_1.txt", net)
                #elif i == 3:
                    #print "...saving the model"
                    #save("data/1000_ex_4_hidden/net_epoch_3.txt", net)
                #elif i == 5:
                    #print "...saving the model"
                    #save("data/1000_ex_4_hidden/net_epoch_5.txt", net)
            print "...saving the model"
            #save("data/1000_ex_4_hidden/net_epoch_10.txt", net)
        else:
            model = load(filename_in)
            self.model = model
Ejemplo n.º 13
0
 def test_enro(self):
     os.chdir('models/en-ro/')
     score(['model.npz'], open('../../en-ro/in'),
           open('../../en-ro/references'), open('../../en-ro/out_score',
                                                'w'))
     os.chdir('../..')
     self.assertEqual(
         open('en-ro/ref_score').read(),
         open('en-ro/out_score').read())
def main():
    load_cluster_countries__file()
    if (mode == "train"):
        train_data = build_sentences(modes[mode]['data'])
        write_feature_file(train_data, modes[mode]['features'])
        train_tagger()
    if (mode == 'dev' or mode == 'test'):
        tag_words(modes[mode]['data'])
        score(modes[mode]['key'], modes[mode]['output'])
Ejemplo n.º 15
0
def decode_hex(inputStr):
    bestStr = ""
    bestScore = 0

    thisStr = xor_repeating_key(inputStr)

    if score(thisStr) > bestScore:
        bestScore = score(thisStr)
        bestStr = thisStr

    return "Plaintext: {}".format(bestStr)
Ejemplo n.º 16
0
 def test_ende(self):
     os.chdir('models/en-de/')
     score(['model.npz'],
           open('../../en-de/in'),
           open('../../en-de/references'),
           open('../../en-de/out_score', 'w'),
           normalize=True)
     os.chdir('../..')
     self.assertEqual(
         open('en-de/ref_score').read(),
         open('en-de/out_score').read())
Ejemplo n.º 17
0
def decode_hex(inputStr):
    bestStr = ""
    bestScore = 0

    # bruteforce all possible values
    for i in range(1, 256):
        thisStr = xor_single_char_key(inputStr.decode("hex"), chr(i))
        if score(thisStr) > bestScore:
            bestScore = score(thisStr)
            bestStr = thisStr

    return "Plaintext: {}".format(bestStr)
 def test_ende(self):
     os.chdir('models/en-de/')
     with open('../../en-de/in', 'r', encoding='utf-8') as in_file, \
          open('../../en-de/references', 'r', encoding='utf-8') as ref_file, \
          open('../../en-de/out_score', 'w', encoding='utf-8') as score_file:
         settings = ScorerSettings()
         settings.models = ['model.npz']
         settings.minibatch_size = 80
         settings.normalization_alpha = 1.0
         score(in_file, ref_file, score_file, settings)
     os.chdir('../..')
     self.scoreEqual('en-de/ref_score', 'en-de/out_score')
Ejemplo n.º 19
0
def decode_hex():
    bestStr = ""
    bestScore = 0

    with (open(sys.argv[1], "r")) as f:
        for i in f:
            for j in range(1, 256):
                thisStr = xor_single_char_key(i.strip().decode("hex"), chr(j))
                if score(thisStr) > bestScore:
                    bestScore = score(thisStr)
                    bestStr = thisStr

    return "Plaintext: {}".format(bestStr)
Ejemplo n.º 20
0
def main(transductive: bool = False):
    try:
        from classifier import pretrain
    except ImportError:
        part2xy = load_dataset_fast('FILIMDB', parts=SCORED_PARTS)
        train_ids, train_texts, train_labels = part2xy['train']
        print('\nTraining classifier on %d examples from train set ...' %
              len(train_texts))
        st = time()
        params = train(train_texts, train_labels)
        print('Classifier trained in %.2fs' % (time() - st))
    else:
        part2xy = load_dataset_fast('FILIMDB',
                                    parts=SCORED_PARTS + ('train_unlabeled', ))
        train_ids, train_texts, train_labels = part2xy['train']
        _, train_unlabeled_texts, _ = part2xy['train_unlabeled']

        st = time()

        if transductive:
            all_texts = list(text for _, text, _ in part2xy.values())
        else:
            all_texts = [train_texts, train_unlabeled_texts]

        total_texts = sum(len(text) for text in all_texts)
        print('\nPretraining classifier on %d examples' % total_texts)
        params = pretrain(all_texts)
        print('Classifier pretrained in %.2fs' % (time() - st))
        print('\nTraining classifier on %d examples from train set ...' %
              len(train_texts))
        st = time()
        params = train(train_texts, train_labels, params)
        print('Classifier trained in %.2fs' % (time() - st))
        del part2xy["train_unlabeled"]

    allpreds = []
    for part, (ids, x, y) in part2xy.items():
        print('\nClassifying %s set with %d examples ...' % (part, len(x)))
        st = time()
        preds = classify(x, params)
        print('%s set classified in %.2fs' % (part, time() - st))
        allpreds.extend(zip(ids, preds))

        if y is None:
            print('no labels for %s set' % part)
        else:
            score(preds, y)

    save_preds(allpreds, preds_fname=PREDS_FNAME)
    print('\nChecking saved predictions ...')
    score_preds(preds_fname=PREDS_FNAME, data_dir='FILIMDB')
Ejemplo n.º 21
0
async def load_score(title):
    import asyncio
    from rank.util import purge
    from rank.collect.movie import get_comments
    loop = asyncio.get_event_loop()
    data = get_comments(title.strip())
    lines = ["| {0}".format(purge(comment)) for comment in data]

    logger.debug("Got comments")
    create = asyncio.create_subprocess_exec("vw", "-c", "-k", "-t", "-i", "data/raw.vw", "-p", "/dev/stdout", "--quiet",
                                            stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)

    logger.debug("Creating classifier")
    proc = await create
    proc.stdin.write("\n".join(lines).encode("UTF-8"))
    await proc.stdin.drain()
    proc.stdin.close()
    result = await proc.stdout.read()
    await proc.wait()

    from score import score, parse_num

    logger.debug("Calculating score")
    ratings = [parse_num(line) for line in result.decode("UTF-8").split("\n")]
    for r, c in zip(ratings, data):
        logger.debug("Rating: {0}, Comment: {1}".format(r, c))
    mean = score(ratings[:-1], base=10)
    return True, str(mean)
Ejemplo n.º 22
0
 def initStatScreen(self):
     self.times = []
     self.pointsPerQuestionn = []
     self.scorePerGame = []
     self.timePerGame = []
     self.gameCategories = []
     self.gameDifficulties = []
     self.totalQuestions = 0
     self.totalGames = 0
     self.correct = 0
     self.incorrect = 0
     statScore = score()
     for i in range(len(self.rows)):
         #print(self.rows[i][0])
         if (self.rows[i][0] == '~' or self.rows[i][0] == '~'
             ) and self.rows[i + 12][0] != "DNF":  # coding=utf-8
             self.totalGames = self.totalGames + 1
             for j in range(10):
                 self.times.append(float(self.rows[(i + 2) + j][1]))
                 self.pointsPerQuestionn.append(
                     float(
                         statScore.calculateScore(
                             int(self.rows[(i + 2) + j][0]),
                             float(self.rows[(i + 2) + j][1]))))
                 self.totalQuestions = self.totalQuestions + 1
                 if int(self.rows[(i + 2) + j][0]) == 1:
                     self.correct = self.correct + 1
                 if int(self.rows[(i + 2) + j][0]) == 0:
                     self.incorrect = self.incorrect + 1
             self.scorePerGame.append(int(self.rows[(i + 12)][0]))
             self.timePerGame.append(float(self.rows[(i + 12)][1]))
             self.gameCategories.append(int(self.rows[(i + 1)][0]))
             self.gameDifficulties.append(int(self.rows[(i + 1)][1]))
Ejemplo n.º 23
0
	def __init__(self,width,height):
		pygame.init()
		self.width = 600
		self.height = 600
		self.screen = pygame.display.set_mode((600,600))
		self.background = pygame.Surface(screen.get_size())  	
		self.ground = background.convert()		
		self.mixinit = pygame.mixer.pre_init()
		self.ship = nimbus.ship(100.0,100.0,90)
		self.asteroid aster.asteriod(100,100,90) 
		self.backfill = background.fill((0,0,0))
		self.white = (250, 250,250)
		self.screenblit = screen.blit(background,(0,0))	
		self.laser = laser.bullet
		self.mixload = pygame.mixer.music.load('betsky.ogg')
		self.mixplay = pygame.mixer.music.play(loops = 15, start = 0.0)
		self.player = score.score()
		self.flip = pygame.display.flip()
		self.allsprites = pygame.sprite.Group((aster))
		self.shp = pygame.sprite.Group((nimbus,laser))
		self.clock = pygame.time.Clock() 
		self.keyset = pygame.key.set_repeat(1,10) 
		self.start_screen = True
		self.
		self.
		self.
		self.
		self.
		self.
		self.
		self.
		self.
		self.
Ejemplo n.º 24
0
def main():
    testfarm = Farm((0, 0))
    senone = Sensor((44.790300, -92.931998))
    sentwo = Sensor((44.790300, -92.931998))
    senthree = Sensor((44.790300, -92.931998))

    testfarm.add_sensor(senone)
    testfarm.add_sensor(sentwo)
    testfarm.add_sensor(senthree)

    testfarm.pull_current()
    testfarm.pull_forecast()

    print("\n\n\nRandomized Example Sensor Data")
    print("------------------------------")

    i = 0
    while i < len(testfarm.sensors):
        print("sensor " + str(i + 1))
        print(testfarm.sensors[i].point)
        i += 1

    print("\n\n\nExample Aggregate Scores")
    print("------------------------")

    box = score.score(testfarm, senone.point, senone)

    list = []
    for datapoints in testfarm.future_forecast:
        box = score.aggregateScore(testfarm, datapoints, senone)
        list.append(box)

    print(list)
Ejemplo n.º 25
0
def test_imagenet_model(model_name, val_data, gpus, batch_size):
    """test model on imagenet """
    logging.info('test %s', model_name)
    meta_info = get_model_meta_info(model_name)
    [model_name, mean] = convert_caffe_model(model_name, meta_info)
    sym, arg_params, aux_params = mx.model.load_checkpoint(model_name, 0)
    acc = [mx.metric.create('acc'), mx.metric.create('top_k_accuracy', top_k=5)]
    if isinstance(mean, str):
        mean_args = {'mean_img':mean}
    else:
        mean_args = {'rgb_mean':','.join([str(i) for i in mean])}

    print(val_data)
    (speed,) = score(model=(sym, arg_params, aux_params),
                     data_val=val_data,
                     label_name='prob_label',
                     metrics=acc,
                     gpus=gpus,
                     batch_size=batch_size,
                     max_num_examples=500,
                     **mean_args)
    logging.info('speed : %f image/sec', speed)
    for a in acc:
        logging.info(a.get())
    assert acc[0].get()[1] > meta_info['top-1-acc'] - 0.3
    assert acc[1].get()[1] > meta_info['top-5-acc'] - 0.3
Ejemplo n.º 26
0
def main():
    parser = argparse.ArgumentParser(description="Solves camera placing problem")
    parser.add_argument("input", help="Path to problem input file", type=str)
    args = parser.parse_args()

    radius = []
    cost = []
    points = []

    with open(args.input) as f:
        for i, line in enumerate(f):
            if i == 0:
                radius = list(map(lambda x: int(x) - 0.01, line.split(',')))
            elif i == 1:
                cost = list(map(int, line.split(',')))
            else:
                x, y = list(map(int, line.split(',')))
                points.append((x, y))
    
    start = time()
    solution = solve(radius, cost, points)
    end = time()
    print("solution score:", score(cost, solution), file=sys.stderr)
    print("time:", "{:.2f}s".format(end-start), file=sys.stderr)
    for c, x, y in solution:
        print("{:d},{:.2f},{:.2f}".format(c, x, y))
Ejemplo n.º 27
0
def submittted():
    form_data = request.form
    print 'form submitted, data in form:'
    print form_data

    stochastic = (form_data['stochastic'] == "true")

    scores = score.score()
    simvalues = playgame.playgame(os.getcwd(), stochastic,
                                  float(form_data['param1']),
                                  float(form_data['param2']))
    print 'scores:' + str(scores)
    print 'simvalues:' + str(simvalues)
    try:
        trace2x = score.convert_to_integers(scores[0][0])
        trace2y = score.convert_to_integers(scores[0][1])
    except:
        trace2x = [1]
        trace2y = [1]
    trace1x = score.convert_to_integers(scores[1][0])
    trace1y = score.convert_to_integers(scores[1][1])
    trace3x = score.convert_to_integers(simvalues[0])
    trace3y = score.convert_to_integers(simvalues[1])
    trace4x = score.convert_to_integers(simvalues[0])
    trace4y = score.convert_to_integers(simvalues[2])

    return render_template("hello.html",
                           trace1x=trace1x,
                           trace1y=trace1y,
                           trace2x=trace2x,
                           trace2y=trace2y,
                           trace3x=trace3x,
                           trace3y=trace3y,
                           trace4x=trace4x,
                           trace4y=trace4y)
Ejemplo n.º 28
0
def scores(board=None,
           comp_words=None,
           comp_score=None,
           user_words=None,
           user_score=None):
    board = session['board']
    comp_words = session['comp_words']
    user_words = session['user_words']
    comp_score = score(comp_words, word_score)
    user_score = score(user_words, word_score)
    return render_template('scores.html',
                           board=board,
                           comp_words=comp_words,
                           comp_score=comp_score,
                           user_words=user_words,
                           user_score=user_score)
Ejemplo n.º 29
0
def main():
    try:
        arg1 = sys.argv[1]
    except:
        arg1 = 'help'

    if arg1 == 'help':
        contact_help()
    else:
        try:
            arg2 = sys.argv[2]
        except:
            print "You must provide a valid argument. See help for details"
            return
        if arg2 not in 'print' and \
                arg2 not in 'scores' and \
                arg2 not in 'highest':
            print "You must provide an argument. See help for details"
            return            
        dic = file_to_dict(arg1)
        if arg2 == 'print':
            dic.print_dict()
        elif arg2 == 'score':
            pprint(score(dic))
        elif arg2 == 'highest':
            word = highest_score(dic)
            print "The highest scoring word is..."
            print word['word'], word['score']
        else:
            print "See help for options"
Ejemplo n.º 30
0
 def play_game(self):
     hand_num = 1
     d = Deal()
     d.commit_deal()  # ignoring return for now
     self.p1.new_hand(d.human_hand())
     self.p2.new_hand(d.computer_hand())
     start = d.start_card()
     p1_deals = d.human_is_dealer()
     while max(self.p1_score, self.p2_score) < 121:
         print("Hand # {} Starting new hand p1 score = {} p2 score = {}".format(hand_num, self.p1_score,
                                                                                self.p2_score))
         hand_num += 1
         if p1_deals:
             print("Player 1 deals")
         else:
             print("Player 2 deals")
         crib = self.p1.discard_cards() + self.p2.discard_cards()
         crib_score = score(crib, start, is_crib=True)
         hand1_score = score(self.p1.hand, start)
         hand2_score = score(self.p2.hand, start)
         print("Start {}\nP1 hand {} score {}\nP2 hand {} score {}\ncrib    {} score {}.\n".format(card_names(
             [start]), card_names(self.p1.hand), hand1_score, card_names(self.p2.hand), hand2_score,
             card_names(crib), crib_score))
         if p1_deals:
             self.p2_score += hand2_score
             if self.p2_score > 120:
                 print("P2 wins.  Final score: {}-{}\n".format(self.p1_score, self.p2_score))
                 break
             self.p1_score += hand1_score + crib_score
             if self.p1_score > 120:
                 print("P1 wins.  Final score: {}-{}\n".format(self.p1_score, self.p2_score))
                 break
         else:
             self.p1_score += hand1_score
             if self.p1_score > 120:
                 print("P1 wins.  Final score: {}-{}\n".format(self.p1_score, self.p2_score))
                 break
             self.p2_score += hand2_score + crib_score
             if self.p2_score > 120:
                 print("P2 wins.  Final score: {}-{}\n".format(self.p1_score, self.p2_score))
                 break
         d = Deal()
         d.commit_deal()  # ignoring return for now
         self.p1.new_hand(d.human_hand())
         self.p2.new_hand(d.computer_hand())
         start = d.start_card()
         p1_deals = not p1_deals
Ejemplo n.º 31
0
def xiaoqi(name, merge_file):
    fff = if_has_flag(merge_file)
    if fff == 0:
        json2csv_operate_neo4j_add_time.main(merge_file, name)
        return '文件不需要消歧'
    dictionary = read_file(merge_file)  #把文件读到字典中
    change_flag(dictionary)
    merge_change = copy.deepcopy(dictionary)
    add_delete_flag(dictionary)
    del_value(dictionary)
    #字典最多四层,删除四次
    #for i in range(4):
    #	del_empty_array(dictionary)
    delete_json = copy.deepcopy(dictionary)

    #disambiguate
    xiaoqi_list = find_same_flag(delete_json, name)
    write_keywords_to_file(xiaoqi_list)
    # 判断是否有keywords文件 有就删除
    if os.path.exists('spider1/keywords.txt'):
        os.remove('spider1/keywords.txt')
    shutil.move('keywords.txt', 'spider1')  #把关键字移动到爬虫目录
    os.chdir('/home/chenxl/data_mining_resume/spider1')  # 进入爬虫目录
    # 如果有items.json就删除
    if os.path.exists('items.json'):
        os.remove('items.json')
    os.system(r"scrapy crawl spider1 -o items.json")  #运行爬虫
    # 保存爬虫结果
    with open('items.json', 'r', encoding='utf-8') as f:
        data = json.load(f)
    os.remove('keywords.txt')
    os.remove('items.json')
    os.chdir('../')
    sco, disambiguate = score.score(data)

    #generate_resume1 有分数
    merge_change2 = copy.deepcopy(merge_change)
    add_score(sco, merge_change)
    monitorItems = merge_dict(merge_change)
    loop_dict(monitorItems)
    xiaoqi_json = json.dumps(monitorItems, ensure_ascii=False, indent=4)
    path = 'static/xiaoqi_json/reserve_score/' + name + '.json'
    with open(path, 'w', encoding='utf-8') as file:
        json.dump(monitorItems, file, ensure_ascii=False, indent=4)
        print("success")

    #generate_resume2 没分数
    disambiguate_id_list = record_id(disambiguate)
    find_flag(disambiguate_id_list, merge_change2)
    delete_flag(merge_change2)
    monitorItems = merge_dict(merge_change2)
    loop_dict(monitorItems)
    xiaoqi_json = json.dumps(monitorItems, ensure_ascii=False, indent=4)
    path = 'static/xiaoqi_json/no_score/' + name + '.json'
    with open(path, 'w', encoding='utf-8') as file:
        json.dump(monitorItems, file, ensure_ascii=False, indent=4)
        print("success")
    neo4j_no_batch_import.main(xiaoqi_json, name)
    return xiaoqi_json
Ejemplo n.º 32
0
def test_imagenet1k_inception_bn(**kwargs):
    acc = mx.metric.create("acc")
    m = "imagenet1k-inception-bn"
    g = 0.72
    (speed,) = score(model=m, data_val="data/val-5k-256.rec", rgb_mean="123.68,116.779,103.939", metrics=acc, **kwargs)
    r = acc.get()[1]
    print("Tested %s acc = %f, speed = %f img/sec" % (m, r, speed))
    assert r > g and r < g + 0.1
Ejemplo n.º 33
0
def main():
    try:
        from classifier import pretrain
    except ImportError:
        part2xy = load_dataset_fast('FILIMDB')
        train_ids, train_texts, train_labels = part2xy['train']
        print('\nTraining classifier on %d examples from train set ...' %
              len(train_texts))
        st = time()
        params = train(train_texts, train_labels)
        print('Classifier trained in %.2fs' % (time() - st))
    else:
        part2xy = load_dataset_fast('FILIMDB',
                                    parts=('train', 'dev', 'test',
                                           'train_unlabeled'))
        train_ids, train_texts, train_labels = part2xy['train']
        _, train_unlabeled_texts, _ = part2xy['train_unlabeled']
        all_texts = train_texts + train_unlabeled_texts

        print('\nPretraining classifier on %d examples' % len(all_texts))
        st = time()
        params = pretrain(all_texts)
        print('Classifier pretrained in %.2fs' % (time() - st))
        print('\nTraining classifier on %d examples from train set ...' %
              len(train_texts))
        st = time()
        params = train(train_texts, train_labels, params)
        print('Classifier trained in %.2fs' % (time() - st))
        del part2xy["train_unlabeled"]

    allpreds = []
    for part, (ids, x, y) in part2xy.items():
        print('\nClassifying %s set with %d examples ...' % (part, len(x)))
        st = time()
        preds = classify(x, params)
        print('%s set classified in %.2fs' % (part, time() - st))
        allpreds.extend(zip(ids, preds))

        if y is None:
            print('no labels for %s set' % part)
        else:
            score(preds, y)

    save_preds(allpreds, preds_fname=PREDS_FNAME)
    print('\nChecking saved predictions ...')
    score_preds(preds_fname=PREDS_FNAME, data_dir='FILIMDB')
Ejemplo n.º 34
0
def all_matches(s, template):
    s = s.upper()
    results = list()
    for partition in partitions(list(s)):
        results.extend(template.match([''.join(part) for part in partition]))
    results = list(set(results))
    results.sort(key=lambda x: -score(x))
    return results
Ejemplo n.º 35
0
def score_cards(h: str, s: str, crib: bool = False) -> int:
    """score_cards adds up the points for a four-card hand represented as a comma-separated string
    and a single start card.  The crib Boolean value only affects if flushes of four cards, i.e.,
    the hand has all one suit and the started card is another, counts for 4 points (yes for hand,
    no for crib)
    """
    return score.score([_card_number(c) for c in h.split(',')],
                       _card_number(s), crib)
Ejemplo n.º 36
0
 def update_score(self, roll):
     dice_count = {}
     for dice in self.dices:
         if dice.strip("D") in roll:
             dice_count[self.dices[dice].get_dice()] = dice_count.get(
                 self.dices[dice].get_dice(), 0) + 1
     self.hand_score += score.score(dice_count, True)
     return self.hand_score
Ejemplo n.º 37
0
def test_imagenet1k_resnet(**kwargs):
    models = ["imagenet1k-resnet-34", "imagenet1k-resnet-50", "imagenet1k-resnet-101", "imagenet1k-resnet-152"]
    accs = [0.72, 0.75, 0.765, 0.76]
    for (m, g) in zip(models, accs):
        acc = mx.metric.create("acc")
        (speed,) = score(model=m, data_val="data/val-5k-256.rec", rgb_mean="0,0,0", metrics=acc, **kwargs)
        r = acc.get()[1]
        print("testing %s, acc = %f, speed = %f img/sec" % (m, r, speed))
        assert r > g and r < g + 0.1
Ejemplo n.º 38
0
 def open_sub_section(self):
     if  self.position_fire==245:
         self.root.destroy()
         jeu.jeu(self.email)
     elif  self.position_fire==310:
         self.root.destroy()
         import rules as ru
         ru.rules(self.email)
     elif self.position_fire==375:
         self.root.destroy()
         import score as sc
         sc.score(self.email)
     elif self.position_fire==440:
         self.root.destroy()
         import credit as cd
         cd.credit(self.email)
     elif self.position_fire==505:
         self.root.destroy()
Ejemplo n.º 39
0
def test_imagenet1k_inception_bn(**kwargs):
    acc = mx.metric.create('acc')
    m = 'imagenet1k-inception-bn'
    g = 0.75
    (speed,) = score(model=m,
                     data_val=VAL_DATA,
                     rgb_mean='123.68,116.779,103.939', metrics=acc, **kwargs)
    r = acc.get()[1]
    print('Tested %s acc = %f, speed = %f img/sec' % (m, r, speed))
    assert r > g and r < g + .1
Ejemplo n.º 40
0
def test_imagenet1k_inception_bn(args):
    acc = mx.metric.create('acc')
    m = 'imagenet1k-inception-bn'
    g = 0.72
    (speed,) = score(model=m,
                     data_val='data/val-5k-256.rec',
                     rgb_mean='123.68,116.779,103.939', metrics=acc, **vars(args))
    r = acc.get()[1]
    print 'Tested %s acc = %f, speed = %f img/sec' % (m, r, speed)
    assert r > g and r < g + .1
Ejemplo n.º 41
0
def solve_single_key(string):
    min_score = float('+inf')
    plaintext = ""
    for i in range(0,255):
        p = bytes(map(lambda c: i ^ c, string))
        s = score.score(p)
        if s < min_score:
            min_score = s
            plaintext = p
    return plaintext
Ejemplo n.º 42
0
def try_decrypt(string):
    min_score = float('+inf')
    plaintext = b''
    for i in range(0,255):
        p = bytes(map(lambda c: i ^ c, string))
        s = score.score(p)
        if s < min_score:
            min_score = s
            plaintext = p
    return (min_score, plaintext)
Ejemplo n.º 43
0
 def __init__(self, scrn):
     Level.new_game()
     self.levels = [
               #width  #mines          #mobs
                   #height #coins          #view
         Level(  2,  2,  0,{1: 1}),
         Level(  5,  5,  4,{1: 4}),
         Level(  4,  4,  4,{1: 1}),
         Level(  5,  5,  4,{1: 4}),
         Level(  6,  6,  6,{1: 4}, life = 1),
         Level(  5, 15, 10,{1: 5},       0, [ 0, 8]),
         Level(  5,  5,  7,{1: 5},       1),
         Level(  7,  7, 20,{1: 2},       2),
         Level(  8,  8,  5,{1:10}, portals = 1),
         Level( 11, 11, 30,{1:12,5: 2},  1, portals = 1),
         Level(  5, 15, 20,{1: 5,5: 3},  3, [ 0, 8], life = 1),
         Level( 12, 12, 40,{1: 5,5: 3},  2, [ 8, 8], 1),
         Level( 15, 15, 40,{1: 4,5: 6},  1, [10, 6]),
         Level( 15, 15, 80,{1: 5,5: 3},  5, [10,10], 4),
         Level( 15, 15,150,{10: 1},      1),
         Level( 20, 20,350,{20: 1},       0, [ 4, 4], life = 2),
         Level( 15, 15,100,{1:40,2:5,20:1},17)
     ]
     global screen
     screen = scrn
     screen.clear()
     screen.refresh()
     self.bank = 0
     self.lives = 1
     
     try:
         while True:
             self.next_level()
     
     except (KeyboardInterrupt):
         self.message("Game quit")
     except (SystemExit):
         score(self.bank, screen,self.message,self.level.height+4)
         sleep(0.5)
     except:
         raise
     finally:
         screen.clear()
Ejemplo n.º 44
0
def test_imagenet1k_resnet(**kwargs):
    models = ['imagenet1k-resnet-50', 'imagenet1k-resnet-152']
    accs = [.77, .78]
    for (m, g) in zip(models, accs):
        acc = mx.metric.create('acc')
        (speed,) = score(model=m, data_val=VAL_DATA,
                         rgb_mean='0,0,0', metrics=acc, **kwargs)
        r = acc.get()[1]
        print('Tested %s, acc = %f, speed = %f img/sec' % (m, r, speed))
        assert r > g and r < g + .1
Ejemplo n.º 45
0
  def search(self, img):
    start = datetime.now()

    index = self.get_index()
    matches = self.match_img(img, index)
    matches = score.score(matches)

    fin = datetime.now()
    print "Search time: ", (fin - start).seconds, " seconds"
    return matches
Ejemplo n.º 46
0
	def __init__(self):
		settings = {
			"static_path": os.path.join(os.path.dirname(__file__), "static"),
			"debug": True
		}
		handlers=[
			(r"/api/login",UserHandler.LoginHandler),
			(r"/api/register",UserHandler.RegisterHandler),
			(r"/api/perfect",UserHandler.PerfectHandler),
			(r"/api/userauthentication",UserHandler.AuthenHandler),
			(r"/api/logout",UserHandler.LogoutHandler),
			(r"/api/cancel",UserHandler.CancelHandler),
			(r"/api/updatecid",UserHandler.UpdateCid),
			(r"/api/search",UserHandler.SearchHandler),
			(r"/api/getavatar",UserHandler.GetAvatarHandler),
			
			(r"/api/checkrelatives",RelativesHandler.CheckrelativesHandler),
			(r"/api/deleterelatives",RelativesHandler.DeleterelativesHandler),
			(r"/api/addrelatives",RelativesHandler.AddrelativesHandler),
			(r"/api/agreerelatives",RelativesHandler.AgreerelativesHandler),
			(r"/api/getvalidation",RelativesHandler.ValidationHandler),

			(r"/api/history",HistoryHandler.HistoryHandler),

			(r"/api/helpmessage",EventHandler.HelpmessageHandler),
			(r"/api/supportmessage",EventHandler.SupportmessageHandler),
			(r"/api/finish",EventHandler.FinishHandler),
			(r"/api/givecredit",EventHandler.GivecreditHandler),
			(r"/api/addaid",EventHandler.AddaidHandler),
			(r"/api/sendsupport",EventHandler.SendsupportHandler),
			(r"/api/quitaid",EventHandler.QuitaidHandler),
			(r"/api/event",EventHandler.EventHandler),

			(r"/api/getuserinfo",UserInfoHandler.GetUserInfoHandler),
			(r"/api/updateuserinfo",UserInfoHandler.UpdateUserInfoHandler),

			(r"/api/getAround",GetArroundEvent.GetArroundEvent),

			(r"/api/startfollow",FollowHandler.startFollowHandler),
			(r"/api/cancelfollow",FollowHandler.cancelFollowHandler),
			
			(r"/api/thirdpartylogin",ThirdPartHandlers.ThirdPartyLoginHandler),
			(r"/api/thirdpartyremoveaccount",ThirdPartHandlers.ThirdPartyRemoveAccountHandler),
			(r"/api/thirdpartyfilluserinfo",ThirdPartHandlers.ThirdPartyFillUserInfoHandler),

			(r"/api/authstate", Authorize.AuthStateHandler),
			(r"/api/requestemailauth", Authorize.RequestEmailAuthHandler),
			(r"/api/authemail", Authorize.AuthEmailHandler),
			(r"/api/requestphoneauth", Authorize.RequestPhoneAuthHandler),
			(r"/api/authphone", Authorize.AuthPhoneHandler)]
		tornado.web.Application.__init__(self,handlers,**settings)
		self.dbapi=dbapi.dbapi()
		self.util=util.util()
		self.push = Push()
		self.score=score.score()
Ejemplo n.º 47
0
  def search(self, img):
    start = datetime.now()

    matches = self.match_img(img)
    matches = score.score(matches)

    for m in matches:
      print m.location, m.score

    fin = datetime.now()
    print "Search time: ", (fin - start).seconds, " seconds"
    return matches
Ejemplo n.º 48
0
def test_imagenet1k_resnet(args):
    models = ['imagenet1k-resnet-34',
              'imagenet1k-resnet-50',
              'imagenet1k-resnet-101',
              'imagenet1k-resnet-152']
    accs = [.72, .75, .765, .76]
    for (m, g) in zip(models, accs):
        acc = mx.metric.create('acc')
        (speed,) = score(model=m, data_val='data/val-5k-256.rec',
                         rgb_mean='0,0,0', metrics=acc, **vars(args))
        r = acc.get()[1]
        print 'testing %s, acc = %f, speed = %f img/sec' % (m, r, speed)
        assert r > g and r < g + .1
Ejemplo n.º 49
0
def process_files(files, source, regex, max_results):
    out = []
    for filename in filter(isfile, files):
        file_score = score.score(filename, source)
        for result in match.match_lines(filename, regex, int(args.message_size)):
            result.score = file_score
            filename = os.path.relpath(result.filename, os.path.curdir)
            out += ['%s:%d:%d:%s' % (filename, result.linenr, result.index + 1, result.message)]
            if max_results is not None:
                max_results -= 1
                if max_results <= 0:
                    return out

    return out
Ejemplo n.º 50
0
def run_prediction(parser=None,args_in=None,competition=False):
	"""
	Either pick up the arguments from the command line or use the 
	ones pre-packaged for the script.
	"""
	global train
	global leaderboard

	if competition:
		logging.info('Running prepackaged arguments (%r)' % args_in)
		args = parser.parse_args(args_in)
	else:
		logging.info('Using arguments from command line %r' % args_in)
		args = args_in

	train,leaderboard = initialize(args)
	if args.tune:
		folds = tuning(args)
		save_folds(folds)
	else:
		folds = saved_folds()
	predict(folds,args)
	if args.score:
		score.score()
Ejemplo n.º 51
0
  def recommendations( self, method, args = None ):
    data = []
    
    if method == "new":
      data = db.session().query( db.Product )\
                  .order_by( db.Product.date )\
                  .limit( 5 )\
                  .all()
    elif method == "random":
      data = db.session().query( db.Product )\
                  .limit( 10 )\
                  .all()
      random.shuffle( data )
      data = data[:5]
    elif method == "recommended":
      data = score.score( args["user_id"], 5 )

    result = []
    for p in data:
      d = helpers.get( db.Product ).to_dictionary( p )
      result.append( d )
    return result
Ejemplo n.º 52
0
from data import CompressedData
from models.classifier import Classifier
from sklearn.linear_model import LogisticRegression
from score import score
import time
import sys

limit = int(sys.argv[1])
data, targets = CompressedData.data(limit=limit)
tr_data, tr_targets = data[:limit/2], targets[:limit/2]
cv_data, cv_targets = data[limit/2:], targets[limit/2:]

logistic = Classifier(LogisticRegression())
start = time.time()
logistic.train(tr_data, tr_targets) 
print 'duration ', time.time() - start

preds = [logistic.predict(c) for c in cv_data]
print score(preds, cv_targets)
Ejemplo n.º 53
0
objective = Objective.MAXIMIZE

# data
train_data, train_targets = Data.train()
test_data, test_targets = Data.test()

# feature engineering
extra_data = test_data
pipe = Pipeline(Polynomial, LogisticRegressionModel, objective, logging.WARN)
pipe.fit(train_data, train_targets, extra_data)
print pipe.hyperparams

# train model
train_data = pipe.transform(train_data)

voter1 = LogisticRegressionModel(objective, logging.INFO)
models = [m(objective, logging.INFO) for m in [SVCModel, LogisticRegressionModel]]
ensemble = ClassifierEnsemble(models, voter1, objective, logging.INFO)

voter2 = LogisticRegressionModel(objective, logging.INFO)
master = ClassifierEnsemble([ensemble], voter2, objective, logging.INFO)

master.optimize(train_data, train_targets)
master.fit(train_data, train_targets, master.hyperparams)

# submission file
test_data = pipe.transform(test_data)
preds = master.predict(test_data)
print score(preds, test_targets)
Ejemplo n.º 54
0
    if args.ignore_case or (args.smart_case and not re.search('[A-Z]', args.pattern)):
        flags = re.IGNORECASE
    else:
        flags = 0

    pattern_string = args.pattern
    if args.literal:
        pattern_string = re.escape(pattern_string)
    if args.word_regexp:
        pattern_string = "\\b%s\\b" % pattern_string

    regex = re.compile(pattern_string, flags)

    files = found_filenames

    score.exclude_globs = ';'.join(args.exclude_files)
    score.low_priority_globs = ';'.join(args.low_priority_globs)

    # Map files into (score, filename) tuples
    files = map(lambda filename: (score.score(filename, source), filename), files)

    # Filter and sort files
    files = filter(lambda x: x[0] > 0, files)
    files = sorted(files, reverse=True)

    # Get back filenames
    files = list(zip(*files)[1])

    print(os.linesep.join(process_files(files, source, regex, args.max_results)))
Ejemplo n.º 55
0
Archivo: ga.py Proyecto: alpdeniz/GA
   def fitness(self):
      ng = self.nofgenomes
      dna=self.dna
#         
      self.fit = score.score(dna[0],dna[1],dna[2],dna[3])[0]
      return self.fit
Ejemplo n.º 56
0
Archivo: ga.py Proyecto: alpdeniz/GA
   dnas[i].fitness()
generation=0

for i in range(10000):      
  newpop = Generation()
  fittestmum=max(dnas, key=lambda dna: dna.fit)
  dnas.remove(fittestmum)
  fittestdad=max(dnas, key=lambda dna: dna.fit)
  dnas.remove(fittestdad)
  for parents in range(population/20-1):
     mum.append(newpop.choose(dnas))
     dad.append(newpop.choose(dnas))  

  del dnas[:] 
  dnas.append(fittestmum)
  dnas.append(fittestdad)
  newpop.breed(fittestmum.dna,fittestdad.dna)
  for parents in range(population/20-1):
    newpop.breed(mum[parents].dna,dad[parents].dna)
  if i % 10 == 0:
     print max(dnas, key=lambda dna: dna.fit).fit, 'generation :', generation
  generation+=1
a=max(dnas, key=lambda dna: dna.fit)
b=score.score(a.dna[0],a.dna[1],a.dna[2],a.dna[3])
print b,a.dna
#Ain = raw_input("Enter core inlet area: ")
Thrust=1.5*b[3]
print Thrust
#for baby in dnas:
 # print baby.fit
Ejemplo n.º 57
0
#!/usr/bin/python
#!coding=utf-8
import stockmanager
import score

manager = stockmanager.stockmanager()
x = manager.get_stock_index('002204')
x = manager.cal_kline(x)
score = score.score()
x =score.get_level()
for i in x:
	print i