# Path: mjhmc/search/find_best_params.py
# def write_all():
#     """ Searches through all of output logs in the directories in SEARCHES
#     if suitable output is found, params.json is written in the respective directory
#     it contains the best hyperparameters found in the output logs
# 
#     :returns: None, writes params.json in search directories containing valid output logs
#     :rtype: None
#     """
# 
#     for directory, num_params in SEARCHES:
# 
#         results = find("{}/output/".format(directory), num_params)
#         if results == None:
#             print "No valid output found for {}".format(directory)
#         else:
#             write_best(results, directory)
#             print "Parameters succesfully updated for {}".format(directory)


import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import json
from warnings import warn
from mjhmc.search.find_best_params import write_all
    from mjhmc.samplers.markov_jump_hmc import MarkovJumpHMC, ControlHMC
    from mjhmc.misc.autocor import calculate_autocorrelation, autocorrelation
    from mjhmc.misc.nutshell import sample_nuts_to_df
    from mjhmc.misc.utils import package_path
    from mjhmc.samplers.markov_jump_hmc import MarkovJumpHMC, ControlHMC
    from mjhmc.misc.autocor import calculate_autocorrelation
    except IOError as io_err:
        print("Encountered error: {}".format(io_err))
        mjhmc_params = None



#    with open("../search/LAHMC_{}/{}".format(extension, file_name), 'r') as lahmc:
 #       lahmc_params = json.load(lahmc)
    lahmc_params = None
    return control_params, mjhmc_params, lahmc_params

def plot_best(distribution, num_steps=100000, update_params=False, **kwargs):
    """ Plots the autocorrelation on distribution for all tested samplers using
    the best hyperparameters found so far

    If update_params is set to True then this script will look through the output logs
    in all search directories and update the value of the best found parameters.

    If update_params is set to False then the hyperparameters will be those in the params.json
    of the corresponding search directories

    :param distribution: Distribution object to have autocorrelation plotted of
    :param num_steps: number of sampling steps to run on
    :param update_params: boolean flag specifying whether the parameters should be updated
    or the cached values should be used
    :returns: None, makes a plot
    :rtype: None
    """
    if update_params:
        print 'Searching through output logs to find the best parameters...'

# Path: mjhmc/search/find_best_params.py
# def write_all():
#     """ Searches through all of output logs in the directories in SEARCHES
#     if suitable output is found, params.json is written in the respective directory
#     it contains the best hyperparameters found in the output logs
# 
#     :returns: None, writes params.json in search directories containing valid output logs
#     :rtype: None
#     """
# 
#     for directory, num_params in SEARCHES:
# 
#         results = find("{}/output/".format(directory), num_params)
#         if results == None:
#             print "No valid output found for {}".format(directory)
#         else:
#             write_best(results, directory)
#             print "Parameters succesfully updated for {}".format(directory)


# Path: mjhmc/figures/ac_fig.py
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import json
from warnings import warn
from mjhmc.search.find_best_params import write_all
    from mjhmc.samplers.markov_jump_hmc import MarkovJumpHMC, ControlHMC
    from mjhmc.misc.autocor import calculate_autocorrelation, autocorrelation
    from mjhmc.misc.nutshell import sample_nuts_to_df
    from mjhmc.misc.utils import package_path
    from mjhmc.samplers.markov_jump_hmc import MarkovJumpHMC, ControlHMC
    from mjhmc.misc.autocor import calculate_autocorrelation

    except IOError as io_err:
        print("Encountered error: {}".format(io_err))
        mjhmc_params = None



#    with open("../search/LAHMC_{}/{}".format(extension, file_name), 'r') as lahmc:
 #       lahmc_params = json.load(lahmc)
    lahmc_params = None
    return control_params, mjhmc_params, lahmc_params

def plot_best(distribution, num_steps=100000, update_params=False, **kwargs):
    """ Plots the autocorrelation on distribution for all tested samplers using
    the best hyperparameters found so far

    If update_params is set to True then this script will look through the output logs
    in all search directories and update the value of the best found parameters.

    If update_params is set to False then the hyperparameters will be those in the params.json
    of the corresponding search directories

    :param distribution: Distribution object to have autocorrelation plotted of
    :param num_steps: number of sampling steps to run on
    :param update_params: boolean flag specifying whether the parameters should be updated
    or the cached values should be used
    :returns: None, makes a plot
    :rtype: None
    """
    if update_params:
        print 'Searching through output logs to find the best parameters...'

        write_all()