Example #1
0
File: tune.py Project: kcwu/2048-c
def main():
    global iteration
    run.init()

    bots = []
    b = Bot(Para())
    b.run()
    bots.append(b)
    for s in seeds:
        b = Bot(Para())
        b.p.p = list(s)
        b.run()
        bots.append(b)

    iteration = 0
    while True:
        iteration += 1
        print 'iteration', iteration
        
        crossover_count = 3
        more_bots = []
        for i in range(crossover_count):
            b1 = Bot(None)
            b2 = Bot(None)
            for i in range(num_tournament):
                b = random.choice(bots)
                if sum(b.score) > sum(b1.score):
                    b1 = b
                b = random.choice(bots)
                if sum(b.score) > sum(b2.score):
                    b2 = b

            winner = Bot(b1.p.crossover(b2.p))
            more_bots.append(winner)

        bots = uniq(bots + more_bots)
        for b in bots:
            if b.score == [0]:
                b.run()

        bots.sort(key=lambda p: sum(p.score), reverse=True)
        bots = bots[:population]

        # mutation
        for b in bots[:len(bots)/4]:
            if random.random() < mutation_rate*4:
                b = b.clone()
                b.p.mutate()
                bots.append(b)

        bots = uniq(bots)
        for b in bots:
            if b.score == [0]:
                b.run()

        print '-'*30
        bots.sort(key=lambda p: sum(p.score), reverse=True)
        print [sum(b.score) for b in bots]
Example #2
0
#!/usr/bin/python
import run
run.init()

import sys
import datetime

import inbox
from icalendar import UTC

import ARCADE


def main():
    # Read the descriptions and the table from arcade
    print "Running ARCADE... (cross your fingers now) ",
    sys.stdout.flush()
    
    input = ARCADE.ArcadeClient().getTimetable()
    
    print "OK! (Probably.)"
    
    # Get the parts from the ARCADE output.
    parts = inbox.get_parts(input)

    # Use the current time as the timestamp.
    time_stamp = datetime.datetime.now(UTC)

    # Write the iCal file
    run.run_with_input(parts, time_stamp)
Example #3
0
import argparse
import codecs
from datetime import datetime
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.exc import NoResultFound
from run import db, init
from models import Person, Bankcard, User, PayBook, PayBookItem

init()
Session = sessionmaker(bind=db.engine)


def _normal_from_line(line):
    idcard, remark = map(
        lambda s: s.decode('utf-8'),
        line.split(','))
    remark = remark.rstrip('\r').rstrip('\n')
    if remark != 'normal'.decode('utf-8'):
        return False
    session = Session()
    try:
        person = session.query(Person).filter(
            Person.idcard == idcard).one()
    except NoResultFound:
        return False
    if not person.can_normal:
        return False
    person.normal()
    session.commit()
    session.close()
    return True
        sys.stdout.write("Versions:       \n")
        sys.stdout.write("    CUDA:       %s\n" % torch.version.cuda)
        sys.stdout.write("    cuDNN:      %s\n" %
                         torch.backends.cudnn.version())
        sys.stdout.write("Memory Usage:\n")
        sys.stdout.write(
            "    Max Alloc:  %g GB\n" %
            round(torch.cuda.max_memory_allocated(cur_device) / 1024**3, 1))
        sys.stdout.write(
            "    Allocated:  %g GB\n" %
            round(torch.cuda.memory_allocated(cur_device) / 1024**3, 1))
        sys.stdout.write(
            "    Cached:     %g GB\n" %
            round(torch.cuda.memory_reserved(cur_device) / 1024**3, 1))
        sys.stdout.write("\n")
    else:
        device = 'cpu'
        sys.stdout.write("You are using CPU.\n")

    method = "2"
    data_path = "../data/WA_Fn-UseC_-HR-Employee-Attrition.csv"

    sys.stdout.write("You chose the method %s.\n" % method)
    sys.stdout.write("Data path: %s\n" % data_path)
    sys.stdout.write('\n')

    run.init(device, data_path, "method_" + method)
    run.train()
    accuracy = run.evaluate("valid")
    sys.stdout.write("Accuracy: %.2f%%\n" % (accuracy * 100))
Example #5
0
    open(config.path_data, 'rb'))
train_batches = get_batches(train_df, config.batch_size)
dev_batches = get_batches(dev_df, config.batch_size)
test_batches = get_batches(test_df, config.batch_size)
config = update_config(config, train_batches, dev_batches, word_to_idx,
                       bow_idxs)

os.environ["CUDA_VISIBLE_DEVICES"] = config.gpu
np.random.seed(config.seed)
random.seed(config.seed)

# buiild model
sess, model, saver = load(config)

# initialize log
epoch, log_df, logger = init(config, trash=False)
train_batches_iterator = get_batches_iterator(train_batches, config.log_period)

# run model
epoch_iterator = iter(range(epoch, config.n_epochs))
for epoch in takewhile(lambda epoch: epoch is not None, epoch_iterator):
    for log_batches in takewhile(lambda log_batches: log_batches is not None,
                                 train_batches_iterator):
        sess, model, saver, log_df, nan_flg = train(sess,
                                                    model,
                                                    saver,
                                                    log_batches,
                                                    dev_batches,
                                                    test_batches,
                                                    log_df,
                                                    logger,