Ejemplo n.º 1
0
def plotLocallyWeightedLinesFromDirectory(directory, ax):
    """Read activations from file, and plot them."""

    try:
        inputs = numpy.loadtxt(directory + '/inputs_grid.txt')
    except IOError:
        return False

    try:
        lines = numpy.loadtxt(directory + '/lines_grid.txt')
    except IOError:
        # If there are no lines, assume this to be a weighted sum of basis functions instead
        return plotBasisFunctionsFromDirectory(directory, ax)

    n_dims = len(numpy.atleast_1d(inputs[0]))
    if (n_dims > 2):
        sys.exit('Cannot plot input data with a dimensionality of ' +
                 str(n_dims) + '.')

    try:
        filename = directory + '/n_samples_per_dim.txt'
        n_samples_per_dim = numpy.loadtxt(filename, dtype=int)
    except IOError:
        # Assume data is 1D
        n_samples_per_dim = len(inputs)

    #try:
    #    predictions  = numpy.loadtxt(directory+'/predictions_grid.txt')
    #    plotDataPredictionsGrid(inputs,predictions,ax,n_samples_per_dim)
    #except IOError:
    #    predictions = [];

    try:
        activations_unnormalized = numpy.loadtxt(
            directory + '/activations_unnormalized_grid.txt')
    except IOError:
        activations_unnormalized = None

    try:
        activations = numpy.loadtxt(directory + '/activations_grid.txt')
    except IOError:
        activations = None

    plotLocallyWeightedLines(inputs, lines, ax, n_samples_per_dim, activations,
                             activations_unnormalized)

    if (n_dims == 1):
        ax.set_xlabel('input')
        ax.set_ylabel('output')
    else:
        ax.set_xlabel('input_1')
        ax.set_ylabel('input_2')
        ax.set_zlabel('output')

    return True
Ejemplo n.º 2
0
def plotLocallyWeightedLinesFromDirectory(directory,ax):
    """Read activations from file, and plot them."""
  
    try:
      inputs = numpy.loadtxt(directory+'/inputs_grid.txt')                             
    except IOError:
      return False;
      
    try:
        lines  = numpy.loadtxt(directory+'/lines_grid.txt')                         
    except IOError:
        # If there are no lines, assume this to be a weighted sum of basis functions instead
        return plotBasisFunctionsFromDirectory(directory,ax)
      
    n_dims = len(numpy.atleast_1d(inputs[0]))
    if (n_dims>2):
        sys.exit('Cannot plot input data with a dimensionality of '+str(n_dims)+'.')
    
    try:
        n_samples_per_dim = numpy.loadtxt(directory+'/n_samples_per_dim.txt')                             
    except IOError:
        # Assume data is 1D
        n_samples_per_dim = len(inputs)
        
    #try:
    #    predictions  = numpy.loadtxt(directory+'/predictions_grid.txt')
    #    plotDataPredictionsGrid(inputs,predictions,ax,n_samples_per_dim)
    #except IOError:
    #    predictions = [];

    try:
        activations_unnormalized = numpy.loadtxt(directory+'/activations_unnormalized_grid.txt')
    except IOError:
        activations_unnormalized = None
        
    try:
        activations = numpy.loadtxt(directory+'/activations_grid.txt')
    except IOError:
        activations = None
      
        
    plotLocallyWeightedLines(inputs,lines,ax,n_samples_per_dim,activations,activations_unnormalized) 

    if (n_dims==1):
      ax.set_xlabel('input');
      ax.set_ylabel('output');
    else:
      ax.set_xlabel('input_1');
      ax.set_ylabel('input_2');
      ax.set_zlabel('output');

    return True;
Ejemplo n.º 3
0
    fig_number = 1
    for name in function_approximator_names:
        fig = plt.figure(fig_number)

        directory_fa = directory + "/" + name
        if (getDataDimFromDirectory(directory_fa) == 1):
            ax = fig.add_subplot(111)
        else:
            ax = fig.add_subplot(111, projection='3d')

        fig_number += 1

        try:
            if (name == "WLS" or name == "LWR" or name == "LWPR"
                    or name == "GMR"):
                plotLocallyWeightedLinesFromDirectory(directory_fa, ax)
            elif (name == "RBFN" or name == "GPR" or name == "IRFRLS"):
                plotBasisFunctionsFromDirectory(directory_fa, ax)
            plotDataFromDirectory(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(['f(x)', '+std', '-std', 'residuals'])

    plt.show()

    #fig.savefig("lwr.svg")
Ejemplo n.º 4
0
        
    fig_number = 1;
    for name in function_approximator_names:
        fig = plt.figure(fig_number)

        directory_fa = directory +"/"+ name
        if (getDataDimFromDirectory(directory_fa)==1):
            ax = fig.add_subplot(111)
        else:
            ax = fig.add_subplot(111, projection='3d')

        fig_number += 1;
    
        try:
            if (name=="WLS" or name=="LWR" or name=="LWPR" or name=="GMR"):
                plotLocallyWeightedLinesFromDirectory(directory_fa,ax)
            elif (name=="RBFN" or name=="GPR" or name=="IRFRLS"):
                plotBasisFunctionsFromDirectory(directory_fa,ax)
            plotDataFromDirectory(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(['f(x)','+std','-std','residuals'])
    
    plt.show()
    
    #fig.savefig("lwr.svg")

        directory_fa = directory + "/" + name
        if (getDataDimFromDirectory(directory_fa) == 1):
            ax = fig.add_subplot(111)
        else:
            ax = fig.add_subplot(111, projection='3d')

        fig_number += 1

        try:
            plotDataFromDirectory(directory_fa, ax)
            if (name == "WLS" or name == "LWR" or name == "LWPR"
                    or name == "GPR"):
                plotLocallyWeightedLinesFromDirectory(directory_fa, ax)
            elif (name == "RBFN"):
                plot_normalized = False
                plotBasisFunctionsFromDirectory(directory_fa, ax,
                                                plot_normalized)
            ax.set_ylim(-1.0, 1.5)
        except IOError:
            print "WARNING: Could not find data for function approximator " + name
        ax.set_title(name + " (" + devel[name] + ")")

    ax.legend(['f(x)', '+std', '-std', 'residuals'])

    print "stable/testing/unstable in the titles refers to the development status of the algorithm"
    print "   * stable    - tested and should work"
    print "   * testing   - seems ok, but still needs testing"
    print "   * unstable  - seems ok, but still needs testing, and is still being modified regularly"
    plt.show()

    #fig.savefig("lwr.svg")
        directory_fa = directory +"/"+ name
        if (getDataDimFromDirectory(directory_fa)==1):
            ax = fig.add_subplot(111)
        else:
            ax = fig.add_subplot(111, projection='3d')

        fig_number += 1;
    
        try:
            plotDataFromDirectory(directory_fa,ax)
            if (name=="WLS" or name=="LWR" or name=="LWPR" or name=="GPR"):
                plotLocallyWeightedLinesFromDirectory(directory_fa,ax)
            elif (name=="RBFN"):
                plot_normalized=False
                plotBasisFunctionsFromDirectory(directory_fa,ax,plot_normalized)
            ax.set_ylim(-1.0,1.5)
        except IOError:
            print "WARNING: Could not find data for function approximator "+name
        ax.set_title(name+" ("+devel[name]+")")
    
    ax.legend(['f(x)','+std','-std','residuals'])
    
    print "stable/testing/unstable in the titles refers to the development status of the algorithm"
    print "   * stable    - tested and should work"
    print "   * testing   - seems ok, but still needs testing"
    print "   * unstable  - seems ok, but still needs testing, and is still being modified regularly"
    plt.show()
    
    #fig.savefig("lwr.svg")