def plotFunctionApproximatorTrainingFromDirectory(directory,ax,ax2=None):
    """Load data related to function approximator training from a directory and plot it."""
    if ax2 != None:
        plotLocallyWeightedLinesFromDirectory(directory,ax2)
    else:
        plotLocallyWeightedLinesFromDirectory(directory,ax)
        
    plotDataFromDirectory(directory,ax)
def plotFunctionApproximatorTrainingFromDirectory(directory,ax):
    """zzz."""
    plotDataFromDirectory(directory,ax)
    
    data_read_successfully = True
    cur_directory_number=0
    while (data_read_successfully):
      cur_dir = directory+'/perturbation'+str(cur_directory_number)+'/'
      data_read_successfully = plotLocallyWeightedLinesFromDirectory(cur_dir,ax)
      cur_directory_number+=1
def plotFunctionApproximatorTrainingFromDirectory(directory,ax):
    """Load data related to function approximator training from a directory and plot it."""
    plotDataFromDirectory(directory,ax)
    
    data_read_successfully = True
    cur_directory_number=0
    while (data_read_successfully):
      cur_dir = directory+'/perturbation'+str(cur_directory_number)+'/'
      data_read_successfully = plotLocallyWeightedLinesFromDirectory(cur_dir,ax)
      cur_directory_number+=1
def plotFunctionApproximatorTrainingFromDirectory(directory, ax):
    """zzz."""
    plotDataFromDirectory(directory, ax)

    data_read_successfully = True
    cur_directory_number = 0
    while data_read_successfully:
        cur_dir = directory + "/perturbation" + str(cur_directory_number) + "/"
        data_read_successfully = plotLocallyWeightedLinesFromDirectory(cur_dir, ax)
        cur_directory_number += 1
from plotLocallyWeightedLines import plotLocallyWeightedLinesFromDirectory

if __name__=='__main__':
    executable = "../../../bin_test/testBasisFunctionsLWR"
    
    if (not os.path.isfile(executable)):
        print ""
        print "ERROR: Executable '"+executable+"' does not exist."
        print "Please call 'make install' in the build directory first."
        print ""
        sys.exit(-1);
    
    # Call the executable with the directory to which results should be written
    directory = "/tmp/testBasisFunctionsLWR"
    subprocess.call([executable, directory])
    
    # Plot the results in each directory
    fig = plt.figure()
    subplot_number = 1;
    for sym_label in ["symmetric","Asymmetric"]:
        ax = fig.add_subplot(1,2,subplot_number)
        subplot_number += 1;
        directory_fa = directory +"/1D_" + sym_label
        plotDataFromDirectory(directory_fa,ax)
        plotLocallyWeightedLinesFromDirectory(directory_fa,ax)
        #ax.legend(['targets','predictions'])
        ax.set_title(sym_label)
    plt.show()
    

        sys.exit(-1);
    
    # Call the executable with the directory to which results should be written
    directory = "/tmp/demoTrainFunctionApproximators"
    subprocess.call([executable, directory])
    
    # Plot the results in each directory
    function_approximator_names = ["LWR","LWPR","GMR","IRFRLS"]
    fig = plt.figure()
    subplot_number = 1;
    for name in function_approximator_names:
    
    
        ax = fig.add_subplot(1,len(function_approximator_names),subplot_number)
        subplot_number += 1;
    
        directory_fa = directory +"/"+ name
        try:
            plotDataFromDirectory(directory_fa,ax)
            if (name=="LWR" or name=="LWPR"):
                plotLocallyWeightedLinesFromDirectory(directory_fa,ax)
            ax.set_ylim(-1.0,1.5)
        except IOError:
            print "WARNING: Could not find data for function approximator "+name
        ax.set_title(name)
    
    ax.legend(['targets','predictions'])
    plt.show()
    

def plotFunctionApproximatorTrainingFromDirectory(directory, ax):
    """zzz."""
    plotLocallyWeightedLinesFromDirectory(directory, ax)
    plotDataFromDirectory(directory, ax)
def plotFunctionApproximatorTrainingFromDirectory(directory,ax):
    """zzz."""
    plotLocallyWeightedLinesFromDirectory(directory,ax)
    plotDataFromDirectory(directory,ax)