Exemplo n.º 1
0
def oneUpdate(directory,plot_results=False):
    
    inputs = np.linspace(-1.5,1.5,21);
    a = 2.0
    c = -1.0
    n_params = 2

    regularization = 0.01
    task = DemoTaskApproximateQuadraticFunction(a,c,inputs,regularization)
  
    mean_init  =  np.full(n_params,0.5)
    covar_init =  0.25*np.eye(n_params)
    initial_distribution = DistributionGaussian(mean_init, covar_init)
  
    eliteness = 10
    weighting_method = 'PI-BB'
    covar_decay_factor = 0.8
    updater = UpdaterCovarDecay(eliteness,weighting_method,covar_decay_factor)
  
    n_samples_per_update = 10
    
    i_update = runOptimizationTaskOneUpdate(directory, task, initial_distribution, updater, n_samples_per_update)

    i_update -= 1
    if plot_results and i_update>1:
        # Plot the optimization results (from the files saved to disk)
        fig = plt.figure(1,figsize=(15, 5))
        plotOptimizationRollouts(directory,fig,task.plotRollout)
        plt.show()
Exemplo n.º 2
0
    """Simple script to plot y of DMP trajectory"""
    n_dofs = (cost_vars.shape[1] - 1) // 4
    y = cost_vars[:, 0:n_dofs]
    if n_dofs == 1:
        line_handles = ax.plot(y, linewidth=0.5)
    else:
        line_handles = ax.plot(y[:, 0], y[:, 1], linewidth=0.5)
    return line_handles


if __name__ == '__main__':
    executable = "../../../bin/demoOptimizationDmp"

    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/demoOptimizationDmp"
    command = executable + " " + directory
    print(command)
    subprocess.call(command, shell=True)

    fig = plt.figure(1, figsize=(12, 4))
    plotOptimizationRollouts(directory, fig, plotRollout)

    plt.show()
    #line_handles = ax.plot(t,cost_vars[:,1:1+n_dofs],linewidth=0.5)
    line_handles = ax.plot(x_endeff,y_endeff,linewidth=0.5)
    ax.plot(0.5, 0.5, 'or')
    ax.axis('equal')
    return line_handles

if __name__=='__main__':
    
    for n_dofs in [3]:
        
        # Initialize a viapoint task and save it to file
        viapoint = 0.5*np.ones(2) # Always 2D!
        task = TaskViapoint(viapoint)
        directory = "/tmp/demoOptimizationDmpArm2D/"+str(n_dofs)+"D/"
        task.saveToFile(directory,"viapoint_task.txt")
        
        # Call the executable with the directory to which results should be written
        print("Call executable to run optimization with "+str(n_dofs)+"D viapoint.")
        executable = "../../bin/demoOptimizationDmpArm2D"
        print(executeBinary(executable, str(n_dofs)+" "+directory))
        
        print("  Plotting")
        fig = plt.figure(n_dofs,figsize=(12, 4))
        plotOptimizationRollouts(directory,fig,plotRollout)
        #plotOptimizationRolloutsTask(directory,fig,task)

    print("Showing")
    plt.show()