예제 #1
0
    def update(self, current_time):
        if current_time >= self.next_time and self.num_train > self.min_train:
            self.next_time = self.next_time + self.train_duration

            if self.type == 'start':
                self.trains.append(Train(1, Depot.end))
            else:
                self.trains.append(Train(0, Depot.start))

            self.num_train = self.num_train - 1
예제 #2
0
def total_journey_time():
    t = Train("Express One", 50, 100)
    c1 = City("City 1", 0, 3, 300)
    j = Journey(t, [c1], 200)
    print(j.total_journey_time())  #,300)

    t = Train("Express One", 50, 10)
    c1 = City("City 1", 0, 3, 300)
    c2 = City("City 2", 0, 3003, 300)
    j = Journey(t, [c1, c2], 200)
    print(j.total_journey_time())  #,900)
예제 #3
0
 def test_train_arrive_travellers_board_new_arrival(self):
     train = Train()
     train.embark(30)
     self.station.add_travellers(60)
     self.station.travellers_board_new_arrival(20, train)
     self.assertEqual(40, self.station.traveller_count)
     self.assertEqual(50, train.passenger_count)
예제 #4
0
def init(trained,
         data,
         epoch,
         batch,
         Model,
         h1,
         h2,
         h3,
         lr,
         optim,
         NAME,
         skip_done,
         DIR=None,
         STD=False):
    if DIR is None:
        DIR = f'{NAME}/{epoch}/{batch}/{Model.__name__}_{optim.__name__}/{h1}/{h2}/{h3}/{lr}/'
    else:
        DIR = f"{DIR}{batch}/"
    print(
        '=====================================New Model============================================'
    )
    print(
        f'epoch: {epoch}, batch: {batch}, Model: {Model.__name__}, h1: {h1}, h2: {h2}, h3: {h3}, lr: {lr}, optim: {optim.__name__}'
    )
    print(
        '=========================================================================================='
    )
    """
         data_file, epochs=20000, batch_size=10, Model=Model1, H1=128, H2=None, H3=None, learning_rate=1e-4, optim=torch.optim.Adam
    """
    train = Train(
        data,
        epoch,
        batch,
        Model,
        h1,
        h2,
        h3,
        lr,
        optim,
        # DIR=f'Outputs/{NAME}/{epoch}/{batch}/{Model.__name__}_{optim.__name__}/{h1}/{h2}/{h3}/{lr}/',
        DIR=DIR,
        NAME=NAME,
        STD=STD)
    print(f'Training : {train.filename}')
    if not os.path.exists(
            f'{train.filename}.pth') or not skip_done:  # or epoch > 9000:
        train.run()
        # train.run_test()
    trained.append(train)

    print(
        '\n====================================Model Complete==========================================='
    )
    print(
        f'epoch: {epoch}, batch: {batch}, Model: {Model.__name__}, h1: {h1}, h2: {h2}, h3: {h3}, lr: {lr}, optim: {optim.__name__}'
    )
    print(
        '============================================================================================='
    )
예제 #5
0
 def Update_Trains_List(self):
     self.cursor.execute("SELECT * FROM Trains")
     Trains_List_Temp = []
     for row in self.cursor.fetchall():
         T1 = Train(row[2], row[3], row[0], row[4], row[5])
         Trains_List_Temp.append(T1)
     self.Trains_List = Trains_List_Temp
예제 #6
0
def city_arrival_time():
    #t = Train("Express One", 50, 100)
    #c1 = City("City 1",0,3,300)
    #j = Journey(t,[c1],200)
    #print(j.city_arrival_time(c1)) # 200

    #t = Train("Express One", 50, 10)
    #c1 = City("City 1",0,3,300)
    #c2 = City("City 2",0,3003,300)
    #j = Journey(t,[c1,c2],200)
    #print(j.city_arrival_time(c2)) # 800

    #t = Train("Express One", 50, 10)
    #c1 = City("City 1",100,3,120)
    #c2 = City("City 2",78,300,300)
    #j = Journey(t,[c1,c2],1000)
    #print(j.city_arrival_time(c1)) #,1000
    ##print(j.city_arrival_time(c2)) # 1149

    t = Train("Express One", 50, 10)
    c1 = City("City 1", 100, 3, 120)
    c2 = City("City 2", 78, 300, 300)
    c3 = City("City 3", 50, 100, 240)
    j = Journey(t, [c1, c2, c3], 1000)
    print(j.city_arrival_time(c3))  # 1469
예제 #7
0
 def run(self):
     TrainImages, TrainAnswers, TestImages, TestAnswers = self.getImageSets(
     )
     #build defulat perceptron
     Percep = Perceptron(self.imageSize**2, self.numBiasNodes,
                         self.numOuputNodes, self.learningRate)
     Percep.init()
     Tester = Test(TestImages, TestAnswers, Percep)
     trainTester = Test(TrainImages, TrainAnswers, Percep)
     dimension = (self.imageSize * self.imageSize +
                  self.numBiasNodes) * self.numOuputNodes
     trainer = Train(TrainImages, TrainAnswers, self.learningRate,
                     self.numPSOIterations, self.PSOSeedRadius,
                     self.psoSeedVelocity)
     self.testResults = []
     self.runTimes = []
     startTime = time.process_time()
     i = 0
     while i < self.epochs:
         Percep, TestResults = self.epoch(Percep, dimension, trainTester,
                                          trainer, Tester)
         self.testResults += [TestResults]
         currentTime = time.process_time() - startTime
         self.runTimes += [currentTime]
         i += 1
     return self.testResults, self.runTimes
예제 #8
0
 def test_train_arrive_overflow_from_embark(self):
     train = Train()
     train.embark(30)
     self.station.add_travellers(100)
     self.station.travellers_board_new_arrival(80, train)
     self.assertEqual(55, self.station.traveller_count)
     self.assertEqual(75, train.passenger_count)
예제 #9
0
def NewTrain():
    MyTrain = Train("Chuggington", 100, 22)  #(name, max passengers, fps)
    print(MyTrain.name)
    print(MyTrain.max_passengers)
    print(MyTrain.speed_fps)
    print(MyTrain.num_passengers)
    MyTrain.num_passengers = 33
    print(MyTrain.num_passengers)
    def __init__(self, trainfile, testfile, outfile):
        self.testfile = testfile
        self.trainfile = trainfile
        self.outfile = outfile

        self.model = Train(trainfile)
        logging.info("Training complete...")
        self.save_results()
예제 #11
0
def CityInJourney():
    t = Train("Express One", 50, 100)
    c1 = City("City 1", 5, 10, 600)
    cities = [c1, City("City 2", 2, 3, 900), City("City 3", 0, 0, 300)]
    j = Journey(t, cities, 200)
    r = j.city_in_journey(c1)
    print(r)
    print(j.city_in_journey("City 1"))
예제 #12
0
def UnloadPassException():
    train = Train("train 1", 10, 22)
    train.load_passengers(10)
    try:
        train.unload_passengers(16)
    except TrainCapacityException as e:
        #print(e.__str__())
        print(e.number)
예제 #13
0
def smtp_pipeline(config):
    path_to_moses = config.get("Environment Settings", "path_to_moses_decoder")
    mem_limit = config.getint("Environment Settings", "mem_limit")
    max_len = config.getint("Iteration Settings", "max_sentence_len")
    min_len = config.getint("Iteration Settings", "min_sentence_len")

    srcf = utilities.safe_string(config.get("Iteration Settings", "src_lang_data"))
    piv1f = utilities.safe_string(config.get("Iteration Settings", "src_piv_lang_data"))
    piv2f = utilities.safe_string(config.get("Iteration Settings", "piv_tar_lang_data"))
    tarf = utilities.safe_string(config.get("Iteration Settings", "tar_lang_data"))
    train = config.getfloat("Iteration Settings", "train_split")
    test = config.getfloat("Iteration Settings", "test_split")
    ncpus = config.getint("Environment Settings", "ncpus")
    ngram = config.getint("Environment Settings", "ngram")
    work_dir1 = utilities.safe_string(config.get("Iteration Settings", "working_dir_first_leg"))
    work_dir2 = utilities.safe_string(config.get("Iteration Settings", "working_dir_second_leg"))

    pair1, pair2 = FileDataPair(srcf, piv1f), FileDataPair(piv2f, tarf)
    raw_files = pair1.get_raw_filenames() + pair2.get_raw_filenames()
    pair1_tokenized_src, pair1_tokenized_tar = pair1.get_tokenized_filenames()
    pair2_tokenized_src, pair2_tokenized_tar = pair2.get_tokenized_filenames()
    pair1_cleansed_src, pair1_cleansed_tar = pair1.get_cleansed_filenames()
    pair2_cleansed_src, pair2_cleansed_tar = pair2.get_cleansed_filenames()

    parser = Parser(path_to_moses, mem_limit, max_len, min_len, False)
    parser.tokenize_files(raw_files)
    parser.cleanse(pair1_tokenized_src, pair1_tokenized_tar)
    parser.cleanse(pair2_tokenized_src, pair2_tokenized_tar)
    parser.split_train_tune_test(pair1_cleansed_src, pair1_cleansed_tar, \
        pair2_cleansed_src, pair2_cleansed_tar, train, test)
    parser.match(pair1_test_src, pair2_test_tar, pair2_test_src, pair2_test_tar)

    pair1_target_train_filename = pair1.get_target_train_filename()
    pair2_target_train_filename = pair2.get_target_train_filename()
    pair1_train_src, pair1_train_tar = pair1.get_train_filenames()
    pair2_train_src, pair2_train_tar = pair2.get_train_filenames()

    trainer = Train(path_to_moses, ncpus, ngram, False)
    trainer.build_language_models(pair1_target_train_filename)
    trainer.build_language_models(pair2_target_train_filename)
    trainer.train(pair1_train_src, pair1_train_tar, work_dir1)
    trainer.train(pair2_train_src, pair2_train_tar, work_dir2)

    pair1_tune_src, pair1_tune_tar = pair1.get_tune_filenames()
    pair2_tune_src, pair2_tune_tar = pair2.get_tune_filenames()

    tuner = Tune(path_to_moses, ncpus, False)
    tuner.tune(pair1_tune_src, pair1_tune_tar, work_dir1)
    tuner.tune(pair2_tune_src, pair2_tune_tar, work_dir2)

    pair1_test_src, pair1_test_tar = pair1.get_test_filenames()
    pair2_test_src, pair2_test_tar = pair2.get_test_filenames()
    pair1_test_tar = pair1.get_eval_filename()
    pair2_test_tar = pair2.get_eval_filename()

    test = Test(path_to_moses, False)
    test.test_pivoting_quality(pair1_test_tar, work_dir1,
        pair2_test_tar, work_dir2)
예제 #14
0
def AddDest():
    t = Train("Express One", 50, 100)
    c1 = City("City 1", 5, 10, 600)
    c2 = City("City 2", 2, 3, 900)
    j = Journey(t, [c1, c2], 200)
    print(j)
    ct = City("City 3", 8, 4, 440)
    j.add_destination(ct)
    print(j)
예제 #15
0
def UnloadPassengers(n):
    #MyTrain = Train("Chuggington", 100, 22) #(name, max passengers, fps)
    #print(MyTrain.max_passengers)
    #Result = MyTrain.unload_passengers(n)
    #print(Result)
    train = Train("train 1", 50, 22)
    train.num_passengers = 40
    train.unload_passengers(25)
    train.unload_passengers(5)
    train.unload_passengers(10)
 def __init__(self, position, total):
     self.position = position
     self.total = total
     self.train = Train(position, self, random.randint(1, self.total),
                        random.randint(1, self.total))
     #adjust the time
     self.occupiedByTrain = False
     self.timer = 0
     self.deltaTime = 0
     self.fails = 0
예제 #17
0
def TotalJourneyDistance():
    #t = Train("Express One", 50, 100)
    #c1 = City("City 1",0,3,300)
    #j = Journey(t,[c1],200)
    #print(j.total_journey_distance()) # 0

    t = Train("Express One", 50, 100)
    c1 = City("City 1", 0, 3, 300)
    c2 = City("City 2", 0, 8, 300)
    j = Journey(t, [c1, c2], 200)
    print(j.total_journey_distance())  # 5
예제 #18
0
 def Add_Train(self, Train_Name, Source, Destination, SeatsSleeper,
               SeatsNormal):
     T1 = Train(SeatsSleeper, SeatsNormal, Train_Name, Source, Destination)
     sql = "INSERT INTO Trains (TrainName, TrainID, SeatsSleeper, SeatsNormal, Source, Destination) VALUES (%s, %s, %s, %s, %s, %s)"
     index = len(self.Trains_List) + 1
     val = (Train_Name, str(index), str(SeatsSleeper), str(SeatsNormal),
            str(Source), str(Destination))
     self.cursor.execute(sql, val)
     self.DB.db.commit()
     print("Record inserted successfully into table")
     self.Trains_List.append(T1)
예제 #19
0
def JourneyTestSTR():
    t = Train("Express One", 50, 100)
    c1 = City("City 1", 5, 10, 600)
    c2 = City("City 2", 2, 3, 900)
    c3 = City("City 3", 0, 0, 300)
    c4 = City("City 4", 12, 4, 1000)
    j = Journey(t, [c1, c2, c3, c4], 200)

    #MyTrain = Train("Norman", 324, 65) #(name, max passengers, fps)
    #Journey1 = Journey(MyTrain, ["aaa", "bbb", "ccc", "ddd", "eee", "fff"], 4060)
    print(j)
예제 #20
0
def main(vargs = None):
    c = Cifar10(True, batchSize=32)
    train = Train()
    images_train, labels_train = c.getInputs(False, True, True)
    images_val, labels_val = c.getInputs(True)
    is_training = tf.placeholder('bool', [], name='is_training')

    images, labels = tf.cond(is_training,
        lambda: (images_train, labels_train),
        lambda: (images_val, labels_val))
    logits = c.getModel(images)
    train.train(is_training, logits, images, labels)
예제 #21
0
def readFile(file):
    """
    Takes a file following a certain model where === separates the paragraphs, reads the lines in each paragraph and
    returns them with the proper object types for createStations()

    If any value is outside of the specifications it raises a ValueError

    :param file: Specifies the file name or file path from which to import data.
    :return: inputStations: A list of lists containing station name and distance from the start station in km
             train: A train object to specify train acceleration
             waitTime: int > 1 [minutes]
                       The time the train waits on each station, up to. for example = 1 gives times between 0-60 seconds
                       according to assignment specification
             waitTimeEnd: datetime.timedelta > 60 seconds
                          The time the train waits on the end stations.
             startTime: A datetime.timedelta object to specify the departure time for the first train
             endTime: A datetime.timedelta object to specify the departure time for the last train from the last station
             trainAm: int >= 0 The amount of trains that travels the line on weekdays
             trainAmWkd: int >= 0 The amount of trains that travels the line on weekdays
    """

    fileStations = []
    fil = open(file, "r", encoding='utf-8', errors='ignore')
    paragraph = 0
    for line in fil:
        if "===" in line:
            paragraph += 1
            continue
        if paragraph == 1:

            trainAcc, trainRet, trainMax = float(line.split()[0]), float(line.split()[1]), float(line.split()[2])
            train = Train(trainAcc, trainRet, trainMax)
        elif paragraph == 3:
            startHour, startMinute, endHour, endMinute = int(line.split()[0].split(":")[0]), \
                                                    int(line.split()[0].split(":")[1]), \
                                                    int(line.split()[1].split(":")[0]), \
                                                    int(line.split()[1].split(":")[1])
            if endHour == 0 and endMinute == 0:
                endHour = 24

        elif paragraph == 5:
            trainAm, trainAmWkd = int(line.split()[0]),\
                                int(line.split()[1])
        elif paragraph == 7:
            waitTime, waitTimeEnd = int(line.split()[0]), int(line.split()[1])

        elif paragraph == 9:
            name = line.split()[0]
            distance = float(line.split()[1])
            fileStations.append([name, distance])

    fil.close()
    return fileStations, train, waitTime, waitTimeEnd, startHour, startMinute, endHour, endMinute, trainAm, trainAmWkd
예제 #22
0
def NewJourney():
    #MyTrain = Train("Norman", 100, 22) #(name, max passengers, fps)
    #Journey1 = Journey(MyTrain, ["xxx", "yyy"], 4000)
    #print(Journey1)

    #MyTrain1 = ""
    #Journey2 = Journey(MyTrain1, ["aaa", "bbb"], 4000)
    #print(Journey2)

    t = Train("Express One", 50, 100)
    j = Journey(t, [], 0)
    print(j.__str__())
예제 #23
0
def LoadPassengers(n):
    #MyTrain = Train("Wally", 100, 22) #(name, max passengers, fps)
    #MyTrain.num_passengers = 40
    #print(MyTrain.name)
    #MyTrain.load_passengers(n)
    #print(MyTrain.num_passengers)
    #MyTrain.load_passengers(45)
    #print(MyTrain.num_passengers)

    train = Train("train 1", 50, 22)
    train.load_passengers(20)
    train.load_passengers(30)
    print(train.num_passengers)
예제 #24
0
def CheckJourney():
    #t = Train("Express One", 50, 100)
    #c1 = City("City 1",5,10,600)
    #c2 = City("City 2",2,3,900)
    #c3 = City("City 3", 0,0,300)
    #c4 = City("City 4", 12,4,1000)
    #c5 = City("City 5", 12,4,1000)
    #j = Journey(t,[c1,c2,c3,c4],200)
    #print(j.check_journey_includes(c5,c2))

    t = Train("Express One", 50, 100)
    c1 = City("City 1", 5, 10, 600)
    c2 = City("City 2", 2, 3, 900)
    c3 = City("City 3", 0, 0, 300)
    c4 = City("City 4", 12, 4, 1000)
    j = Journey(t, [c1, c2, c3, c4], 200)
    print(j.check_journey_includes(c3, c2))
예제 #25
0
 def run(self):
     TrainImages,TrainAnswers,TestImages,TestAnswers = self.getImageSets()
     self.Trainer = Train(TrainImages,TrainAnswers,self.learningRate)
     self.Tester = Test(TestImages,TestAnswers)
     #build defulat perceptron
     Percep = Perceptron(self.imageSize**2, self.numBiasNodes,self.numOuputNodes,self.learningRate)
     Percep.init()
     i = 0
     self.testResults = []
     self.runTimes = []
     startTime = time.process_time()
     while i < self.epochs:
         Percep,TestResults = self.epoch(Percep)
         self.testResults += [TestResults]
         currentTime = time.process_time() - startTime
         self.runTimes += [currentTime]
         i += 1
     return  self.testResults,self.runTimes
예제 #26
0
def main():
    """Main interface"""
    train = Train()
    training = True
    while training:
        train.get_current_direction()
        train.speed_sensor.set_pulse(0)
        if train.current_direction == 'forward':
            train.speed_sensor.forward(train.current_distance)
        elif train.current_direction == 'reverse':
            train.speed_sensor.reverse(train.current_distance)
        elif train.current_direction == 'left':
            train.speed_sensor.left()
        elif train.current_direction == 'right':
            train.speed_sensor.right()
        elif train.current_direction == 'quit':
            train.speed_sensor.cleanup()
            training = False
    train.save_path_to_json()
예제 #27
0
def train_all():
    connect(config_train.database['db_name'],
            host=config_train.database['host'],
            port=config_train.database['port'])

    # print(f'Cantidad de articlus en db: {len(Article.objects())}')

    train = Train(config_train.spacy_model, config_train.publication_name,
                  config_train.chunk_size, config_train.models_folder,
                  config_train.faiss_folder, config_train.word2vect_model)

    if config_train.enabled_processes['tokenize_articles']:
        print('tokenizing articles ...')
        error = train.save_training_tokens()
        if error < 0:
            return

    if config_train.enabled_processes['vectorizers']:
        print('Training vectorizers ...')

        train.train_vectorizers(
            min_df=config_train.vectorizeers_hyperparams['min_df'],
            max_df=config_train.vectorizeers_hyperparams['max_df'])

    if config_train.enabled_processes[
            'w2v'] and config_train.word2vect_model is None:
        print('Training w2vect ...')

        train.Word2Vec(
            size=config_train.w2v_hyperparams['size'],
            epochs=config_train.w2v_hyperparams['epochs'],
            min_count=config_train.w2v_hyperparams['min_count'],
            workers=config_train.w2v_hyperparams['workers'],
        )

    if config_train.enabled_processes['faiss']:
        print('Training faiss ...')
        total_vectors, added_to_faiss, already_got_faiss_in_db = train.add_faiss_vectors_db(
            config_train.word2vect_model)
        print(
            f'Faiss tenía {total_vectors} vectores, se agregaron {added_to_faiss} y se intentaron agregar {already_got_faiss_in_db} que ya estaban'
        )
예제 #28
0
def create_modul(train_ratio=0.66, e=3):
    # load data
    easy_ham, spam = load_dataset(data_preprocessed=True)

    # chuan bi du lieu va nhan
    samples = easy_ham + spam
    labels = [SpamClassification.HAM
              ] * (len(easy_ham)) + [SpamClassification.SPAM] * len(spam)

    # Tron du lieu va chia tap du lieu thanh cac tap train, val, test
    x_train, x_val, x_test, y_train, y_val, y_test = datas_split(
        samples, labels, train_ratio)

    # Train
    train = Train(x_train, y_train)

    # Classify
    classifier = SpamClassification(train.P, train.P_ti, train.T, e)

    return classifier
예제 #29
0
def AllPassengersAccommodated():
    #t = Train("Express One", 50, 100)
    #c1 = City("City 1",0,3,300)
    #j = Journey(t,[c1],200)
    #print(j.all_passengers_accommodated([5],[5])) # False #no passenger to be unloaded

    #t = Train("Express One", 50, 100)
    #c1 = City("City 1",0,3,300)
    #j = Journey(t,[c1],200)
    #print(j.all_passengers_accommodated([0],[100])) # False) #too many to load

    #t = Train("Express One", 50, 10)
    #c1 = City("City 1",0,3,300)
    #j = Journey(t,[c1],200)
    #print(j.all_passengers_accommodated([0],[30])) # ,True)

    t = Train("Express One", 50, 10)
    c1 = City("City 1", 0, 3, 300)
    c2 = City("City 2", 78, 300, 300)
    j = Journey(t, [c1, c2], 200)
    print(j.all_passengers_accommodated([0, 40], [30, 10]))  #,False)
예제 #30
0
def main():

    # Create Train instance, set verbose to True to see whats happening
    trainer = Train(True)

    # Build target language models for only the target languages. In this
    # scenario, the desired target languages are the pivot language in the
    # source to pivot leg of the translation and the target language in the
    # pivot to target leg of the scenario. Language models are saved in the
    # lm directory
    trainer.build_language_models("data/train/europarl-v7.es-en.en.tok.cleansed.train")
    trainer.build_language_models("data/train/europarl-v7.fr-en.fr.tok.cleansed.train")

    # Train each leg of the translation system seperately. The first
    # parameter must be the path to the source training data, the second
    # will be the path to the pivot training data, and the third is the
    # name for the directory which will store the system's results.
    trainer.train("data/train/europarl-v7.es-en.es.tok.cleansed.train",
        "data/train/europarl-v7.es-en.en.tok.cleansed.train", "es-en.working")
    trainer.train("data/train/europarl-v7.fr-en.en.tok.cleansed.train",
        "data/train/europarl-v7.fr-en.fr.tok.cleansed.train", "en-fr.working")