示例#1
0
def save_result(n_users, n_items, density, total_fit_time_list):
    # Set up writing folder and file
    results_path = os.path.join(get_project_root_path(), "report",
                                "slim_elastic_net_timing_tests")
    fd, folder_path_with_date = handle_folder_creation(
        result_path=results_path, filename="results.txt")

    fd.write("--- SLIM Elastic Net Experiment ---\n")
    fd.write(" - Number of experiments: {}\n".format(N_EXPERIMENTS))
    fd.write("\n")

    fd.write("DATASET INFO\n")
    fd.write(" - Dataset name: RANDOMLY DISTRIBUTED SYNTHETIC DATASET\n")
    fd.write(" - N_USERS: {}\n".format(n_users))
    fd.write(" - N_ITEMS: {}\n".format(n_items))
    fd.write(" - DENSITY: {}\n".format(density))
    fd.write("\n")

    fd.close()

    # write data and timing info on csv file
    columns = ['n_users', 'n_items', 'density', 'n_exp', 'total_fit_time']
    data_info = pd.DataFrame(
        [[n_users, n_items, density, N_EXPERIMENTS, total_fit_time_list]],
        columns=columns)
    data_info.to_csv(os.path.join(folder_path_with_date,
                                  "experiment_info.csv"),
                     sep=',',
                     header=True,
                     index=False)

    return folder_path_with_date
示例#2
0
    def __init__(self, filename, reload_from_original=False):
        super().__init__(reload_from_original_data=reload_from_original)
        root_path = os.path.join(get_project_root_path(), "data")
        self.URM_path = os.path.join(root_path, filename)
        self.DATASET_SUBFOLDER = "{}/".format(filename.split(".")[0])

        self._LOADED_UCM_DICT = {}
        self._LOADED_UCM_MAPPER_DICT = {}
示例#3
0
DEFAULT_AGGREGATION = "FIRST"
DEFAULT_FILTER_SAMPLE_METHOD = "NONE"

# FIT DEFAULT VALUES
DEFAULT_TOP_K = 5
DEFAULT_ALPHA_MULTIPLIER = 0.0
DEFAULT_NUM_READS = 50
DEFAULT_MULTIPLIER = 1.0
DEFAULT_UNPOPULAR_THRESHOLD = 0
DEFAULT_QUBO_ROUND_PERCENTAGE = 1.0
DEFAULT_FILTER_ITEM_METHOD = "NONE"
DEFAULT_FILTER_ITEM_NUMBERS = 100

# OTHERS
DEFAULT_CUTOFF = 5
DEFAULT_OUTPUT_FOLDER = os.path.join(get_project_root_path(), "report",
                                     "quantum_slim")
DEFAULT_RESPONSES_CSV_FILENAME = "solver_responses.csv"
DEFAULT_MAPPING_MATRIX_FILENAME = "mapping_matrix.npy"


def get_arguments():
    """
    Defining the arguments available for the script

    :return: argument parser
    """
    parser = argparse.ArgumentParser()

    # Data setting
    parser.add_argument(
import os
from datetime import datetime

import pandas as pd

from src.utils.utilities import get_project_root_path

REPORT_ROOT_PATH = os.path.join(get_project_root_path(), "report",
                                "quantum_slim_timing_tests")
FINAL_REPORT_PATH = os.path.join(get_project_root_path(), "report",
                                 "quantum_slim_final_report",
                                 "quantum_slim_timing")

if __name__ == '__main__':
    report_files = []
    for root, dirs, files in os.walk(REPORT_ROOT_PATH):
        for file in files:
            if file.endswith(".csv"):
                report_files.append(os.path.join(root, file))
    report_files = sorted(report_files, key=lambda x: os.path.getmtime(x))
    print(report_files)

    df = pd.DataFrame()

    for path_file in report_files:
        df_file = pd.read_csv(path_file, sep=",")
        df = df.append(df_file, ignore_index=True)
    print(df.head())

    date_string = datetime.now().strftime('%b%d_%H-%M-%S')
    df.to_csv(os.path.join(FINAL_REPORT_PATH, "{}.csv".format(date_string)),
示例#5
0
import os
import pandas as pd
import numpy as np

from src.utils.utilities import get_project_root_path

if __name__ == '__main__':
    data_path = os.path.join(get_project_root_path(), "data", "jester100")
    input_filepath_list = [
        os.path.join(data_path, "jester-data-{}.xls".format(i + 1))
        for i in range(3)
    ]

    df = pd.DataFrame(columns=["user", "item", "rating"])
    last_user_id = 0
    for input_filepath in input_filepath_list:
        dataset = pd.read_excel(input_filepath, header=None)
        dataset = dataset.drop(columns=0)

        mask_df = np.logical_not((dataset == 99) | (dataset <= 0))
        counts = np.sum(mask_df.to_numpy(), axis=1)

        data_matrix = dataset[mask_df].to_numpy()
        index_matrix = np.repeat(np.arange(0, 100).reshape(1, -1),
                                 repeats=dataset.shape[0],
                                 axis=0)

        items = index_matrix[mask_df.to_numpy()]
        data = np.ones(shape=len(data_matrix[mask_df.to_numpy()]), dtype=int)
        users = np.repeat(np.arange(last_user_id,
                                    last_user_id + dataset.shape[0]),
import pandas as pd
import os
import numpy as np

from src.utils.utilities import get_project_root_path

if __name__ == '__main__':
    #np.random.seed(1234)
    data_path = os.path.join(get_project_root_path(), "data", "ml100k")

    input_filepath = os.path.join(data_path, "ml100k.tsv")
    df = pd.read_csv(filepath_or_buffer=input_filepath, sep="\t", header=None)

    #df[2] = 1
    df = df.drop(columns=[3])

    output_filepath = os.path.join(data_path, "ml100k.csv")
    df.to_csv(output_filepath, header=False, index=False)

    """
    item_chosen_filepath = os.path.join(data_path, "{}_item_chosen.txt".format(prefix_name))
    with open(item_chosen_filepath, 'w') as f:
        for item in item_chosen:
            f.write("%s\n" % item)
    """
        qpu_times_dict['qpu_anneal_time_per_sample'],
        qpu_times_dict['qpu_readout_time_per_sample'],
        qpu_times_dict['qpu_programming_time'],
        qpu_times_dict['qpu_delay_time_per_sample']
    ]],
                             columns=columns)
    data_info.to_csv(os.path.join(output_folder, "experiment_info.csv"),
                     sep=',',
                     header=True,
                     index=False)


if __name__ == '__main__':
    arguments = get_arguments()
    dict_args = vars(arguments).copy()
    dict_args["output_folder"] = os.path.join(get_project_root_path(),
                                              "report",
                                              "quantum_slim_timing_tests")

    hyperparameters_combinations = list(
        itertools.product(*HYPERPARAMETERS.values()))

    for i, hyperparameters in enumerate(hyperparameters_combinations):
        print("Experiment n.{}/{}: the hyperparameters are {}:{}".format(
            i + 1, len(hyperparameters_combinations), HYPERPARAMETERS.keys(),
            list(hyperparameters)))
        n_users, n_items, density = hyperparameters[:3]
        for j, key in enumerate(HYPERPARAMETERS.keys()):
            if j <= 2:
                continue
            dict_args[key] = hyperparameters[j]