<commit_before>import os

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import seaborn


def get_dir_name(ppriors, N, T, sparsity, likelihood_function):
    if len(ppriors) == 1:
        dir_name = 'N_' + str(N) + '_T_' + str(T) + '_ro_' + str(sparsity).replace(".", "") \
                + "_pprior_" + str(ppriors[0]).replace('.', '') + "_" + likelihood_function
    else:
        dir_name = 'N_' + str(N) + '_T_' + str(T) + '_ro_' + \
                   str(sparsity).replace(".", "") + '_' + likelihood_function

    # create a new directory to save the results
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    return dir_name


def save_inference_results_to_file(dir_name, S, J, bias, J_est_EPs, likelihood_function,
                                   ppriors, log_evidences, ros, J_est_lasso=[], i=0):

    # Save simulation data to file
    if list(J_est_lasso):
        file_path = os.path.join(dir_name, 'S_J_J_est_lasso_EP_' + str(i))
        sio.savemat(file_path, {'S': S, 'J': J, 'J_est_lasso': J_est_lasso,
                                'J_est_EPs': J_est_EPs, 'ppriors': ppriors, 'ros': ros,
                                'log_evidences': log_evidences})
    else:
        file_path = os.path.join(dir_name, 'S_J_J_est_EP_' + str(i))
        sio.savemat(file_path, {'S': S, 'J': J, 'J_est_EP': J_est_EPs, 'ppriors': ppriors, 'ros': ros,
                                'log_evidences': log_evidences})

    return dir_name


def plot_and_save(measurements, J, J_est_lasso, J_est_EP, ppriors, log_evidences, ros,
                  plot, show_plot, dir_name):
    if plot:
        inference_fig = plot_J_J_est(J, J_est_EP, J_est_lasso, show_plot)
        inference_fig[0].savefig(os.path.join(dir_name, inference_fig[1] + '.png'))

        if measurements:
            measurements_fig = plot_error_measurements(ppriors, measurements, show_plot)
            measurements_fig[0].savefig(os.path.join(dir_name, measurements_fig[1]))<commit_msg>Fix small mistake<commit_after>import os

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import seaborn


def get_dir_name(ppriors, N, T, sparsity, likelihood_function):
    if len(ppriors) == 1:
        dir_name = 'N_' + str(N) + '_T_' + str(T) + '_ro_' + str(sparsity).replace(".", "") \
                + "_pprior_" + str(ppriors[0]).replace('.', '') + "_" + likelihood_function
    else:
        dir_name = 'N_' + str(N) + '_T_' + str(T) + '_ro_' + \
                   str(sparsity).replace(".", "") + '_' + likelihood_function

    # create a new directory to save the results
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    return dir_name


def save_inference_results_to_file(dir_name, S, J, bias, J_est_EPs, likelihood_function,
                                   ppriors, log_evidences, ros, J_est_lasso=[], i=0):

    # Save simulation data to file
    if list(J_est_lasso):
        file_path = os.path.join(dir_name, 'S_J_J_est_lasso_EP_' + str(i))
        sio.savemat(file_path, {'S': S, 'J': J, 'J_est_lasso': J_est_lasso,
                                'J_est_EPs': J_est_EPs, 'ppriors': ppriors, 'ros': ros,
                                'log_evidences': log_evidences})
    else:
        file_path = os.path.join(dir_name, 'S_J_J_est_EP_' + str(i))
        sio.savemat(file_path, {'S': S, 'J': J, 'J_est_EPs': J_est_EPs, 'ppriors': ppriors, 'ros': ros,
                                'log_evidences': log_evidences})

    return dir_name


def plot_and_save(measurements, J, J_est_lasso, J_est_EP, ppriors, log_evidences, ros,
                  plot, show_plot, dir_name):
    if plot:
        inference_fig = plot_J_J_est(J, J_est_EP, J_est_lasso, show_plot)
        inference_fig[0].savefig(os.path.join(dir_name, inference_fig[1] + '.png'))

        if measurements:
            measurements_fig = plot_error_measurements(ppriors, measurements, show_plot)
            measurements_fig[0].savefig(os.path.join(dir_name, measurements_fig[1]))
{'fraction_non_alphanumeric': 0.13273676360924683, 'fraction_numerical': 0.003479990057171265, 'mean_word_length': 2.688359303391384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2051826', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1457, 'n_words': 291}