Beispiel #1
0
def my_read(file):
    num_days, book_scores, libs = read_file(file)
    book_occ = book_occurences(libs, len(book_scores))
    mean_book_occ = sum(book_occ)
    book_occ = [item / mean_book_occ for item in book_occ]
    books = [
        Book(i, score, book_occ[i]) for i, score in enumerate(book_scores)
    ]

    # check = [1 for _ in range(len(books))]
    libraries = []
    for lib in libs:
        num_books_in_lib = lib['num_books_in_lib']
        sign_up_t = lib['sign_up_t']
        ship_per_day = lib['ship_per_day']
        book_ids = lib['book_ids']
        lib_books = [books[id] for id in book_ids]
        # for book_id in book_ids:
        #     check[book_id] = 0
        libraries.append(
            Library(num_books_in_lib, sign_up_t, ship_per_day, lib_books))

    # some books are found in no library
    # checksum = sum(check)
    # assert checksum == 0

    return libraries, books, num_days
def main(_):
    #	tf.reset_default_graph()
    un = False
    max_len = 128
    sents, labels = read_file('./data/train')
    test_sents, test_labels = read_file('./data/test')
    vocab = read_vocab()
    data = sent2vec(sents, vocab, max_len)
    test_data = sent2vec(test_sents, vocab, max_len)
    model = Model(len(vocab), max_len)
    #model = Transformer(len(vocab), max_len)
    epoch = 100
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    sess = tf.Session(config=config)
    init = tf.global_variables_initializer()
    sess.run(init)
    model.train(data, labels, test_data, test_labels, sess, epoch)
Beispiel #3
0
def main(_):
	tf.reset_default_graph()
	un = False
	max_len = 2048
	sents, labels = read_file('./data/train.txt')
	test_sents, test_labels = read_file('./data/test.txt')
	vocab = read_vocab()
	data = sent2vec(sents, vocab, max_len)
	test_data = sent2vec(test_sents, vocab, max_len)
	if un == True:
		un_sents, un_labels = read_file('./data/unsup.txt')
		un_data = sent2vec(un_sents, vocab, max_len)
	#model = single_filter_Model(len(vocab), max_len)
	model = multi_filter_Model(len(vocab), max_len)
	epoch = 100
	config = tf.ConfigProto()
	config.gpu_options.allow_growth = True
	sess = tf.Session(config=config)
	init = tf.global_variables_initializer()
	sess.run(init)
	if un == True:
		model.train(un_data, un_labels, test_data, test_labels, sess, 10)
	model.train(data, labels, test_data, test_labels, sess, epoch)
Beispiel #4
0
def main(id_input):
    B = 100

    scanned_books = np.zeros(B)

    hard_code_path_to_input = "/home/raphael/PycharmProjects/hashcode_2/input/"
    tab_input = ["a_example.txt",
                 "b_read_on.txt",
                 "c_incunabula.txt",
                 "d_tough_choices.txt",
                 "e_so_many_books.txt",
                 "f_libraries_of_the_world.txt",
                 ]

    num_days, book_scores, libs = read_file(hard_code_path_to_input + tab_input[id_input])


    days_left = num_days


    for id_lib, lib in enumerate(libs):
        lib["set_books"] = set(lib["book_ids"])
        lib["id"] = id_lib
        lib["set_books_with_score"] = set()
        lib["taken"]=0


        score_in_lib = 0

        for book in lib["book_ids"]:
            lib["set_books_with_score"].add((book, book_scores[book]))
            score_in_lib += book_scores[book]


        lib["score_in_lib"] = score_in_lib



    global_output = "{}\n".format(number_output_libs) + middle_output
    print("output_text", global_output)

    result_file = hard_code_path_to_input+"result/result_"+tab_input[id_input]

    with open(result_file, 'w') as file:
        file.write(global_output)
Beispiel #5
0
def main():
    statements, interogations, coeficients = read.read_file(sys.argv[1])

    for st in statements:
        print(st, coeficients[atom_utils.convert_to_tuple(st)])
        if coeficients[atom_utils.convert_to_tuple(st)] != 1:
            atom_utils.has_coeficients = True
    print()

    for intr in interogations:
        print("Scopul de demonstrat " +
              atom_utils.print_formula(intr[1], return_result=True))
        statements_aux = copy.deepcopy(statements)
        atom_utils.var_sol_list = check_for_vars(intr[1])
        atom_utils.has_vars = True if atom_utils.var_sol_list != [] else False
        atom_utils.was_proved = False
        atom_utils.all_solutions = []
        atom_utils.visited = []
        atom_utils.initial_theorem = intr[1]
        atom_utils.coeficients = coeficients
        atom_utils.coeficients_sol_list = []
        atom_utils.longest_formula = ""
        atom_utils.backward_chaining(statements_aux, intr[1], [], {}, 1)
        print("Gata")
        if atom_utils.has_vars:
            print(
                print_all_solutions(atom_utils.all_solutions,
                                    atom_utils.var_sol_list))
        else:
            if atom_utils.all_solutions == []:
                print(
                    atom_utils.print_formula(intr[1], return_result=True) +
                    " is false\n")
            else:
                print(
                    atom_utils.print_formula(intr[1], return_result=True) +
                    " is True")
                if atom_utils.has_coeficients:
                    print("Coeficient: " +
                          "%.3f" % atom_utils.coeficients_sol_list[0])
                print()
Beispiel #6
0
import read
import numpy as np
import tensorflow as tf
from tensorflow.python.ops import rnn, rnn_cell
import matplotlib.pyplot as plt
import RNN


#input file
text_path = '/Users/thomastiotto/Documents/USI/1 semester/Deep Learning Lab/clarissa_txt/diocane.txt'

# read input text and create dictionary
data, dict, rev_dict = read.read_file(text_path)
dict_size = len(dict)

# Parameters
learning_rate = 0.001
epochs = 2 #epochs
display_step = 1 #expressed in epochs
n_layers = 1
batch_size = 5

# number of units in RNN cell
n_hidden = 512


def encode(x, y):
    x_enc = [dict[i] for i in x]
    y_enc = [dict[y]]

    #x_enc = np.array(x_enc)
Beispiel #7
0
from config import configer
from Alphabet import Alphabet
from train import train
import collections
from Common import *
import argparse

if __name__ == '__main__':
    parse = argparse.ArgumentParser()
    parse.add_argument('--config',
                       default='./config.cfg',
                       help='input the config path')
    parse.add_argument('--use_cuda',
                       default=False,
                       help='if use cuda or not , default is false')
    args = parse.parse_args()
    config = configer(args.config)
    train_data = read_file(config.train_data_path, split=True)
    train_label = read_file(config.train_label_path, split=True)
    test_data = read_file(config.test_data_path, split=True)
    test_label = read_file(config.test_label_path, split=True)
    dev_data = read_file(config.dev_data_path, split=True)
    dev_label = read_file(config.dev_label_path, split=True)

    word_alpha, label_alpha = createAlphabet(train_data, train_label,
                                             config.word_cut_off)
    alpha_tuple = (word_alpha, label_alpha)
    corpus_tuple = (train_data, train_label, dev_data, dev_label, test_data,
                    test_label)
    train(config, alpha_tuple, corpus_tuple)
Beispiel #8
0
# initialize
print("Starting up Pydoku...")
start = time.clock()
duration = 0
done = False

# parse command-line arguments
args = arg_parse.get_parser().parse_args()                   # get and run parser
no_solve, pretty_print, board, file_ = arg_parse.init(args)  # init args

# read board
# if we were supplied a file, read it
if board:
    print("Reading from file '{}'...".format(board.name))
    board = read.read_file(board)
# else we have to get it from the user
else:
    print("Enter the known numbers (leaving spaces for those you don't know)...")
    now = time.clock()
    board = read.read_stdin()
    duration -= time.clock() - now

# solve board
if not no_solve:
    print("Solving... ", end='')
    board = solve.solve(board)

    # check if we're done
    if solve.done(board):
        done = True
#!/usr/bin/python3 

from read import read_file
from sort import sorting
from write import write_file


# read in the input dataset
file_name = './input/itcont.txt'
list_drug, list_number, list_cost = read_file(file_name)

# sort the list
drug_sorted, number_sorted, cost_sorted = sorting(list_drug, list_number, list_cost)

# write the output dataset
file_write = './output/top_cost_drug.txt'
write_file(file_write, drug_sorted, number_sorted, cost_sorted)
# -*- coding:utf-8 -*-
## SNL编译器前端
import sys
import symbol_list    ## 字符表
import read    ## 读文件
import lexeme    ## 词法分析
import de_comment    ## 去掉注释
import r_d_p    ## 递归下降法

## 读取文件
source = read.read_file(sys.argv[1])

## 添加末尾的EOF
## source = source + " EOF"

## 去掉注释
processed = de_comment.de_comment(source)

## 把词法分析后的结果存入result列表中
result = lexeme.slice(processed)

## 词法分析输出部分
## 创建名为output的文件并把结果输入到文件中
output = open('lexical_analysis.txt', 'w')
for item in result:
    output.write("%s\n" % item)

## 扫描token序列
r_d_p.scan(result)
Beispiel #11
0
import summarize
import process
import evaluate
import pandas as pd
import classifier
import pylab as pl
import numpy as np
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn import cross_validation
import scipy

TARGET_COL = 0

#### read data
df_train = read.read_file('data/cs-training.csv', index_col = 0)
df_test = read.read_file('data/cs-test.csv', index_col = 0)
columns  = df_train.columns


#### seperate x and y variables from training and testing sets
X = df_train.copy()
y = X[columns[TARGET_COL]]
del X[columns[TARGET_COL]]
del df_test[columns[TARGET_COL]]

#### create histograms for each variable in input data
for col in columns:
    summarize.histogram(df_train,col)

### summary tables
Beispiel #12
0
args = parser.parse_args()

tab_input = [
    "a_example.txt",
    "b_read_on.txt",
    "c_incunabula.txt",
    "d_tough_choices.txt",
    "e_so_many_books.txt",
    "f_libraries_of_the_world.txt",
]

hard_code_path_to_input = "/home/toromanoff/workspace/hashcode_2/input"
input_file = os.path.join(hard_code_path_to_input,
                          tab_input[args.input_file_indice])

num_days, book_scores, libs = read_file(input_file)

N_book = len(book_scores)
N_lib = len(libs)
N_days = num_days
list_time_registration_lib = [lib['sign_up_t'] for lib in libs]
tab_score_book = np.array(book_scores)
tab_book_library = [np.array(lib['book_ids']) for lib in libs]

print("N_book = ", N_book)
print("N_lib = ", N_lib)
print("N_days = ", N_days)
# print("list_time_registration_lib = ", list_time_registration_lib)
# print("tab_score_book = ", tab_score_book)
# print("tab_book_library = ", tab_book_library)
Beispiel #13
0
        dict_schedule_solution[inters] = []
        for ind_schedule in range(len(schedule)):
            current_street_name = list_name_street[ind_schedule]
            current_time_schedule = schedule[ind_schedule]
            dict_schedule_solution[inters].append(
                (current_street_name, current_time_schedule))

    return dict_schedule_solution


#tab_file = ["a.txt","b.txt","c.txt","d.txt","e.txt","f.txt"]
tab_file = ["a.txt"]
for file in tab_file:
    input_folder = "input"
    name_file = file
    streets, cars, duration, nb_inters, nb_streets, nb_cars, bonus = read_file(
        os.path.join(input_folder, name_file))
    duration = int(duration)
    list_cars = cars
    print("duration = ", duration)
    start_time = time.time()
    # print("time starting build_dict_inters_car = ", start_time)
    tab_time_cars = compute_length_path_car(list_cars, streets)
    indice_cars_usefull = np.where(tab_time_cars <= duration)[0]
    list_cars_usefull = [
        list_cars[indice_car_usefull]
        for indice_car_usefull in indice_cars_usefull
    ]

    full_dict_inters_car = build_dict_inters_car(list_cars_usefull, streets)
    print("duration build_dict_inters_car = ", time.time() - start_time)
    start_time = time.time()
class_index = 1
correct_predictions = 0

# Hyperparameters, tune as needed
alpha = 0.0001
epochMax = 1
hidden_layer_count = 1
hidden_node_count = 2  # Same number of hidden nodes per layer
output_node_count = 1
total_layer_count = hidden_layer_count + 1  # Add output layer

# User input, read and store input csv files
print("MULTILAYER PERCEPTRON \n")
train_file = input("Enter training csv file name: ")
test_file = input("Enter testing csv file name: ")
train_data = read.read_file(train_file, train_data)
test_data = read.read_file(test_file, test_data)

# Separate class labels from features
train_features = train_data[1:]
train_labels = [element[0] for element in train_data]
test_features = test_data[1:]
test_labels = [element[0] for element in test_data]

# Normalize feature values
train_features = [read.normalize(element) for element in train_features]
test_features = [read.normalize(element) for element in test_features]

# Store features row-wise, convert data to arrays
train_features = np.array(train_features)
train_labels = np.array(train_labels)
Beispiel #15
0
# tab_file = ["a.txt","b.txt","c.txt","d.txt","e.txt","f.txt"]
tab_file = [
    #    "a_an_example.in.txt",
    #    "b_better_start_small.in.txt",
    "c_collaboration.in.txt",
    "d_dense_schedule.in.txt",
    "e_exceptional_skills.in.txt",
    "f_find_great_mentors.in.txt"
]
for file in tab_file:
    start_time = time.time()
    input_folder = "input"
    name_file = file
    projects_done = []
    projects_in_progress = []
    contributors, projects_to_do, list_max_skill_needed, max_iteration = read_file(
        os.path.join(input_folder, name_file))
    projects_sorted = sort_project(projects_to_do, False)

    iteration = 0
    print("ProjectDone " + str(len(projects_done)))
    print("ProjectInProgress " + str(len(projects_in_progress)))
    print("ProjectToDo " + str(len(projects_sorted)))
    print("iteration " + str(iteration))
    print("contributor available " + str(len(contributors)))
    string_progress = str(len(projects_done)) + "-" + str(
        len(projects_in_progress)) + "-" + str(
            len(projects_sorted)) + "-" + str(len(contributors))
    string_progress_end = ""
    while iteration < max_iteration + 5 or len(projects_to_do) == 0:
        if iteration % 1000 == 0:
            print("ProjectDone " + str(len(projects_done)))
Beispiel #16
0
def main(id_input):
    B = 100

    scanned_books = np.zeros(B)

    hard_code_path_to_input = "/home/raphael/PycharmProjects/hashcode_2/input/"
    tab_input = [
        "a_example.txt",
        "b_read_on.txt",
        "c_incunabula.txt",
        "d_tough_choices.txt",
        "e_so_many_books.txt",
        "f_libraries_of_the_world.txt",
    ]

    num_days, book_scores, libs = read_file(hard_code_path_to_input +
                                            tab_input[id_input])

    days_left = num_days

    for id_lib, lib in enumerate(libs):
        lib["set_books"] = set(lib["book_ids"])
        lib["id"] = id_lib
        lib["set_books_with_score"] = set()
        lib["taken"] = 0

        score_in_lib = 0

        for book in lib["book_ids"]:
            lib["set_books_with_score"].add((book, book_scores[book]))
            score_in_lib += book_scores[book]

        lib["score_in_lib"] = score_in_lib

    book_occurence = count_occurence(libs, book_scores)

    STOP = False

    number_output_libs = 0

    global_output = ""
    middle_output = ""
    while not STOP and days_left > 0:
        print(days_left)
        id_best_lib = choose_library(libs,
                                     days_left=days_left,
                                     book_occurence=book_occurence)
        if id_best_lib is None:
            print("no more libs available")
            break

        lib_chosen = libs[id_best_lib]
        book_occurence = update_book_occurence(book_occurence, lib_chosen)
        days_left -= lib_chosen["sign_up_t"]
        output_text, books_taken = choose_books_for_lib(lib_chosen, days_left)

        if len(books_taken) > 0:
            number_output_libs += 1

        #print("before", libs)

        libs = update_libs(libs, books_taken, book_scores)

        middle_output += output_text

    #print("after", libs)

    global_output = "{}\n".format(number_output_libs) + middle_output
    print("output_text", global_output)

    result_file = hard_code_path_to_input + "result/result_" + tab_input[
        id_input]

    with open(result_file, 'w') as file:
        file.write(global_output)
Beispiel #17
0
#module mane: main
import read
import purchase
import write

again = "Y"
while again.upper() == "Y":
    a = read.read_file()
    b = purchase.purchase(a)
    write.over_write(a, b)
    again = input("\nDoes the any new customer waiting to buy product? ")
print("\nThank you for shopping from our store!!")
print(
    "Please check your invoice for your shopping details, \nWhich we created txt file format for you."
)
Beispiel #18
0
import warnings

warnings.warn = warn

import pandas as pd
import numpy as np

from sklearn.externals import joblib
import xgboost as xgb
import time
import pickle
import read as rd

data_file_path = './data/train_lag1_new.csv'
df = rd.read_file(data_file_path)
model_dict = {
    0: 'Linear Regression',
    1: 'SVR',
    2: 'Random Forest',
    3: 'XGBoost'
}

with open('selected_attr_list.txt', 'rb') as f:
    selected_attr_list = f.read().split(',')

with open('selected_model_type.txt', 'rb') as f:
    model_type = int(f.read().split(',')[0])


def train_model():