Пример #1
0
#  profile = False
profile = True
if len(sys.argv) < 2:
    print("Please specifiy the name of the .py file to execute.")
    sys.exit()


file_name = sys.argv[1]
if file_name[-3:] == '.py':
    file_name = file_name[:-3]

print(f'submit_to_slurm.py will submit the file {file_name}.py')

if file_name == 'main_qlearning':
    parameters.update(parameters_vanilla)
    output_folder_name = 'q_learning'
    job_name = 'QLearning'
elif file_name == 'main_DQL':
    parameters.update(parameters_deep)
    output_folder_name = 'deep_q_learning'
    job_name = 'DQL'
else:
    raise ValueError('Wrong file name.')


if len(sys.argv) < 3:
    n_arrays = 1
else:
    n_arrays = int(sys.argv[2])
    print(gini_score)

y_pred = np.zeros(len(y_test))
print("gini normalized score: ")
gini_score = gini_normalized(y_test, y_pred)
print(gini_score)

y_pred = np.ones(len(y_test))
print("gini normalized score: ")
gini_score = gini_normalized(y_test, y_pred)
print(gini_score)

print("mean de y pred")
print(np.mean(y_pred))
y_pred = (y_pred > 0.5)

# Making the Confusion Matrix
cm = confusion_matrix(y_test, y_pred)
print("confusion matrix")
print(cm)

parameters.update({
    "result": {
        "tp": int(cm[0, 0]),
        "tn": int(cm[1, 1]),
        "fp": int(cm[1, 0]),
        "fn": int(cm[0, 1]),
        "gini_score": gini_score
}})

import numpy as np
import sys
import deep_q_learning as dql
import json
from pathlib import Path

import time
start_time = time.time()

if Path('info.json').is_file():
    with open('info.json') as f:
        info = json.load(f)
    parameters = info['parameters']
else:
    from parameters import parameters, parameters_deep
    parameters.update(parameters_deep)

if len(sys.argv) < 2:
    array_index = 1
    create_output_files = False
    print("Output files won't be created.")
else:
    array_index = int(sys.argv[1])
    create_output_files = True
    print("Output files will be created.")

# The seed here is for the exploration randomness
# The initial state of the system use a different seed (if random)
print(f"Array n. {array_index}")
seed_qlearning = array_index
print(f'The seed used for the q_learning algorithm = {seed_qlearning}.')