Exemplo n.º 1
0
def main():
    list_directories = glob.glob(
        path + '*/')  # get a list of all directoies for different step sizes

    # Loop for each lambda and plot it
    for each_lam_directory in list_directories:
        print(each_lam_directory)

        _, lam, _ = get_method_lam_alpha(each_lam_directory)
        result = get_mean_and_SEM_all_stepSizes(each_lam_directory, curve,
                                                performance_measure)
        # Sort the result according to the step size
        result.sort(key=lambda x: x[0])

        alphas = [each_point[0] for each_point in result]
        averages = [each_point[1] for each_point in result]
        errors = [each_point[2] for each_point in result]
        # # Plot the curve for current lambda
        plt.errorbar(alphas,
                     averages,
                     yerr=errors,
                     fmt='-o',
                     label=r'$\lambda$' + '= ' + str(lam))

    plt.title(method + '\n' + curve_verbose, fontsize=15)
    plt.xscale('log')
    plt.xlabel(r'$\alpha$', fontsize=20)
    plt.ylabel('Steps per episode', rotation=0)
    plt.legend(loc='best')
    plt.show()
Exemplo n.º 2
0
from matplotlib import pyplot as plt
import argparse
import numpy as np
from plot_util import get_method_lam_alpha, COMMON_PATH, get_all_files

parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--directory',
                    default='TD/Data/0.0/2-8/',
                    type=str,
                    help='directory that contains files of different runs')

args = parser.parse_args()
directory = COMMON_PATH + args.directory  # Turn directory into an absolute path
method, lam, alpha = get_method_lam_alpha(
    directory)  # Extract method, lambda and step size from the directory path


# Read data from a directory and plot the results
def main():
    # measures is a list of lists, where each element (each list)
    # is the measures of a trial
    measures = get_all_files(directory)

    # Plot the graph
    mean = np.mean(measures, axis=0)
    plt.plot(np.arange(mean.size),
             mean,
             label=r'$\lambda$' + '=' + str(lam) + ', alpha=' + str(alpha))
    plt.xlabel('Episodes')
    plt.ylabel('Step per Episode\nAveraged over ' + str(len(measures)) +