SZI2019SmieciarzWmi/VowpalWabbit/generate_dataset.py
2019-06-09 08:25:18 +02:00

38 lines
1.5 KiB
Python

import glob, datetime, os
from VowpalWrapper.wrapper import wrap_ex
def generate_dataset(run_count, clear, model_name, learn):
print("GENERATING DATASET")
if(clear == True):
print("Clearing stored data... ", end = '')
for dfile in glob.glob('./VowpalWabbit/VowpalInputData/input_map*.txt'):
if(os.path.exists(dfile)):
os.remove(dfile)
print("Done")
print("Collecting data from " + str(run_count) + " runs...")
wrap_ex("./VowpalWabbit/vowpal_auto_run.sh "+str(run_count))
print("Collected data")
filename = "./VowpalWabbit/VowpalInputData/input_dataset" + str(datetime.datetime.now().strftime("%m%d%H%M")) + model_name
print("Creating input file " + filename + ".txt... ", end = '')
input_file = open(filename,"a+")
for pfile in glob.glob('./VowpalWabbit/VowpalInputData/input_map*.txt'):
#print(pfile)
partial_input = open(pfile, "r+")
for line in partial_input:
input_file.write(line)
partial_input.close()
input_file.close()
os.rename(filename, filename + ".txt")
print("Done")
if(learn == True):
print("Learning from " + str(filename) + ".txt")
model_file = "./VowpalWabbit/VowpalModels/" + model_name + ".model"
wrap_ex("vw " + filename + ".txt -c --passes 2 -f " + model_file)
print("Learning process complete, model saved to " + model_file)
generate_dataset(200, True, "teraz", True)