def plotDynamicalSystemComparison(data1, data2, name1, name2, axs, axs_diff):

    lines1 = plotDynamicalSystem(data1, axs)
    lines2 = plotDynamicalSystem(data2, axs)
    plt.setp(lines1,
             linestyle='-',
             linewidth=4,
             color=(0.8, 0.8, 0.8),
             label=name1)
    plt.setp(lines2,
             linestyle='--',
             linewidth=2,
             color=(0.0, 0.0, 0.5),
             label=name2)
    plt.legend()

    data_diff = data1 - data2
    data_diff[:, -1] = data1[:, -1]  # Don't subtract time...
    lines_diff = plotDynamicalSystem(data_diff, axs_diff)
    plt.setp(lines_diff,
             linestyle='-',
             linewidth=2,
             color=(0.50, 0.00, 0.00),
             label='diff')
    plt.legend()
def plotDynamicalSystemComparison(data1,data2,name1,name2,axs,axs_diff):

    lines1     = plotDynamicalSystem(data1,axs)
    lines2     = plotDynamicalSystem(data2,axs)
    plt.setp(lines1,linestyle='-',  linewidth=4, color=(0.8,0.8,0.8), label=name1)
    plt.setp(lines2,linestyle='--', linewidth=2, color=(0.0,0.0,0.5), label=name2)
    plt.legend()
    
    data_diff = data1-data2;
    data_diff[:,-1] = data1[:,-1] # Don't subtract time...
    lines_diff = plotDynamicalSystem(data_diff,axs_diff)
    plt.setp(lines_diff,linestyle= '-', linewidth=2, color=(0.50,0.00,0.00), label='diff')
    plt.legend()
示例#3
0
def plotDmp(data, fig, forcing_terms_data=0, fa_output_data=0):

    # Number of columns in the data
    n_cols = data.shape[1]
    # Dimensionality of dynamical system. -1 because of time, /2 because both x and xd are stored.
    n_state_length = (n_cols - 1) / 2
    # Dimensionality of the DMP. -2 because of phase and gating (which are 1D) and /3 because of spring system (which has dimensionality 2*n_dims_dmp) and goal system (which has dimensionality n_dims_dmp)
    n_dims_dmp = (n_state_length - 2) / 3
    D = n_dims_dmp
    # Abbreviation for convencience

    # We will loop over each of the subsystems of the DMP: prepare some variables here
    # Names of each of the subsystems
    system_names = ['phase', 'gating', 'goal', 'spring']
    system_varname = ['x', 'v', '\mathbf{y}^{g_d}', '\mathbf{y}']
    # The indices they have in the data
    system_indices = [
        range(3 * D, 3 * D + 1),
        range(3 * D + 1, 3 * D + 2),
        range(2 * D, 3 * D),
        range(0 * D, 2 * D)
    ]
    system_order = [1, 1, 1, 2]
    # The subplot in which they are plotted (x is plotted here, xd in the subplot+1)
    subplot_offsets = [1, 6, 3, 8]

    # Loop over each of the subsystems of the DMP
    n_systems = len(system_names)
    for i_system in range(n_systems):

        # Plot 'x' for this subsystem (analytical solution and step-by-step integration)
        #fig.suptitle(filename)
        axs = []
        axs.append(fig.add_subplot(3, 5, subplot_offsets[i_system]))
        axs.append(fig.add_subplot(3, 5, subplot_offsets[i_system] + 1))
        if (system_order[i_system] == 2):
            axs.append(fig.add_subplot(3, 5, subplot_offsets[i_system] + 2))

        indices = system_indices[i_system]
        indices_xd = [i + n_state_length for i in indices
                      ]  # +n_state_length because xd is in second half
        indices.extend(indices_xd)  # For derivative
        indices.append(-1)  # For time

        lines = plotDynamicalSystem(data[:, indices], axs)
        if (system_names[i_system] == 'gating'):
            plt.setp(lines, color='m')
            axs[0].set_ylim([0, 1.1])
        if (system_names[i_system] == 'phase'):
            axs[0].set_ylim([0, 1.1])
            plt.setp(lines, color='c')

        for ii in range(len(axs)):
            x = numpy.mean(axs[ii].get_xlim())
            y = numpy.mean(axs[ii].get_ylim())
            axs[ii].text(x,
                         y,
                         system_names[i_system],
                         horizontalalignment='center')
            if (ii == 0):
                axs[ii].set_ylabel(r'$' + system_varname[i_system] + '$')
            if (ii == 1):
                axs[ii].set_ylabel(r'$\dot{' + system_varname[i_system] + '}$')
            if (ii == 2):
                axs[ii].set_ylabel(r'$\ddot{' + system_varname[i_system] +
                                   '}$')

    ts = data[:, -1]

    # nnn Fix this
    if (len(fa_output_data) > 1):
        ax = fig.add_subplot(3, 5, 11)
        ax.plot(ts, fa_output_data)
        x = numpy.mean(ax.get_xlim())
        y = numpy.mean(ax.get_ylim())
        ax.text(x, y, 'func. approx.', horizontalalignment='center')
        ax.set_xlabel(r'time ($s$)')
        ax.set_ylabel(r'$f_\mathbf{\theta}(' + system_varname[0] + ')$')

    if (len(forcing_terms_data) > 1):
        ax = fig.add_subplot(3, 5, 12)
        ax.plot(ts, forcing_terms_data)
        x = numpy.mean(ax.get_xlim())
        y = numpy.mean(ax.get_ylim())
        ax.text(x, y, 'forcing term', horizontalalignment='center')
        ax.set_xlabel(r'time ($s$)')
        ax.set_ylabel(r'$v\cdot f_{\mathbf{\theta}}(' + system_varname[0] +
                      ')$')
示例#4
0
    executable = "../../../bin/demoExponentialSystem"
    
    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/demoExponentialSystem"
    subprocess.call([executable, directory])
    
    fig = plt.figure(1)
    data_ana = numpy.loadtxt(directory+"/analytical.txt")
    plotDynamicalSystem(data_ana,[fig.add_subplot(1,2,1), fig.add_subplot(1,2,2)])
    plt.title('analytical')

    fig = plt.figure(2)
    data_num = numpy.loadtxt(directory+"/numerical.txt")
    plotDynamicalSystem(data_num,[fig.add_subplot(1,2,1), fig.add_subplot(1,2,2)])
    plt.title('numerical')

    fig = plt.figure(3)
    axs      =  [fig.add_subplot(2,2,1), fig.add_subplot(2,2,2)]
    axs_diff =  [fig.add_subplot(2,2,3), fig.add_subplot(2,2,4)]
    plotDynamicalSystemComparison(data_ana,data_num,'analytical','numerical',axs,axs_diff)

    plt.show()
    
示例#5
0
def plotDmp(data,fig,forcing_terms_data=0,fa_output_data=0):

    # Number of columns in the data
    n_cols = data.shape[1]             
    # Dimensionality of dynamical system. -1 because of time, /2 because both x and xd are stored.
    n_state_length = (n_cols-1)/2      
    # Dimensionality of the DMP. -2 because of phase and gating (which are 1D) and /3 because of spring system (which has dimensionality 2*n_dims_dmp) and goal system (which has dimensionality n_dims_dmp)
    n_dims_dmp = (n_state_length-2)/3
    D = n_dims_dmp;  # Abbreviation for convencience
    
    # We will loop over each of the subsystems of the DMP: prepare some variables here
    # Names of each of the subsystems
    system_names   = ['phase','gating','goal','spring'];
    system_varname = [    'x',     'v',  '\mathbf{y}^{g_d}',  '\mathbf{y}' ];
    # The indices they have in the data 
    system_indices = [ range(3*D,3*D+1), range(3*D+1,3*D+2), range(2*D,3*D), range(0*D,2*D) ];
    system_order   = [       1,          1,           1,         2 ];
    # The subplot in which they are plotted (x is plotted here, xd in the subplot+1)
    subplot_offsets = [      1,          6,           3,         8  ];
    
    # Loop over each of the subsystems of the DMP
    n_systems = len(system_names)
    for i_system in range(n_systems):
      
        # Plot 'x' for this subsystem (analytical solution and step-by-step integration)
        #fig.suptitle(filename)
        axs = [];
        axs.append(fig.add_subplot(3,5,subplot_offsets[i_system]))
        axs.append(fig.add_subplot(3,5,subplot_offsets[i_system]+1))
        if (system_order[i_system]==2):
          axs.append(fig.add_subplot(3,5,subplot_offsets[i_system]+2))
          
        
        indices = system_indices[i_system];
        indices_xd =[i+n_state_length for i in indices] # +n_state_length because xd is in second half
        indices.extend(indices_xd) # For derivative
        indices.append(-1) # For time
      
        lines = plotDynamicalSystem(data[:,indices],axs);
        if (system_names[i_system]=='gating'):
          plt.setp(lines,color='m')
          axs[0].set_ylim([0, 1.1])
        if (system_names[i_system]=='phase'):
          axs[0].set_ylim([0, 1.1])
          plt.setp(lines,color='c')
          
        for ii in range(len(axs)):
          x = numpy.mean(axs[ii].get_xlim())
          y = numpy.mean(axs[ii].get_ylim())
          axs[ii].text(x,y,system_names[i_system], horizontalalignment='center');
          if (ii==0):
              axs[ii].set_ylabel(r'$'+system_varname[i_system]+'$')
          if (ii==1):
              axs[ii].set_ylabel(r'$\dot{'+system_varname[i_system]+'}$')
          if (ii==2):
              axs[ii].set_ylabel(r'$\ddot{'+system_varname[i_system]+'}$')
        
    ts = data[:,-1];

    # todo Fix this
    if (len(fa_output_data)>1):
        ax = fig.add_subplot(3,5,11)
        ax.plot(ts,fa_output_data)
        x = numpy.mean(ax.get_xlim())
        y = numpy.mean(ax.get_ylim())
        ax.text(x,y,'func. approx.', horizontalalignment='center');                                        
        ax.set_xlabel(r'time ($s$)');
        ax.set_ylabel(r'$f_\mathbf{\theta}('+system_varname[0]+')$');
    
    if (len(forcing_terms_data)>1):
        ax = fig.add_subplot(3,5,12)
        ax.plot(ts,forcing_terms_data)
        x = numpy.mean(ax.get_xlim())
        y = numpy.mean(ax.get_ylim())
        ax.text(x,y,'forcing term', horizontalalignment='center');                                        
        ax.set_xlabel(r'time ($s$)');
        ax.set_ylabel(r'$v\cdot f_{\mathbf{\theta}}('+system_varname[0]+')$');