Beispiel #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()
    learning_rate = 0.5
    #updater = UpdaterCovarAdaptation(eliteness, weighting_method)
    updater_adaptation = UpdaterCovarAdaptation(eliteness, weighting_method,
                                                max_level, min_level,
                                                diag_only, learning_rate)

    updater = updater_decay

    n_samples_per_update = 5

    ############################################################

    # Load the initial distribution
    input_mean_file = directory + '/policy_parameters.txt'
    input_covar_file = directory + '/distribution_initial_covar.txt'
    print('Python |     Loading distribution from "' + input_mean_file +
          '" and "' + input_covar_file + '"')
    mean_init = np.loadtxt(input_mean_file)
    covar_init = np.loadtxt(input_covar_file)
    initial_distribution = DistributionGaussian(mean_init, covar_init)

    # Load the task
    task = pickle.load(open(directory + '/task.p', "rb"))

    # Execute one update
    i_update = runOptimizationTaskOneUpdate(directory, task,
                                            initial_distribution, updater,
                                            n_samples_per_update)

    #print("./robotPerformRollouts.bash $DIRECTORY/dmp.xml ${UPDATE_DIR}")