Fork me on GitHub

bolero.representation.DMPBehavior

class bolero.representation.DMPBehavior(execution_time=1.0, dt=0.01, n_features=50, configuration_file=None)[source]

Dynamical Movement Primitive.

Can be used to optimize the weights of a DMP with a black box optimizer. This is a wrapper for the optional DMP module of bolero. Only the weights of the DMP will be optimized. To optimize meta-parameters like the goal or the goal velocity, you have to implement your own wrapper. This can be a subclass of this wrapper that only overrides the methods that provide access to the parameters.

An object can be created either by passing a configuration file or the specification of a DMP. A DMP configuration file describes all parameters of the DMP model and it is not recommended to generate it manually.

Parameters:
execution_time : float, optional (default: 1)

Execution time of the DMP in seconds.

dt : float, optional (default: 0.01)

Time between successive steps in seconds.

n_features : int, optional (default: 50)

Number of RBF features for each dimension of the DMP.

configuration_file : string, optional (default: None)

Name of a configuration file that should be used to initialize the DMP. If it is set all other arguments will be ignored.

__init__(execution_time=1.0, dt=0.01, n_features=50, configuration_file=None)[source]
can_step()[source]

Returns if step() can be called again.

Note that calling step() after this function returns False will not result in an error. The velocity and acceleration will be set to 0 and we hold the last position instead.

Returns:
can_step : bool

Can we call step() again?

get_args()

Get parameters for this estimator.

Returns:
params : mapping of string to any

Parameter names mapped to their values.

get_n_params()[source]

Get number of weights.

Returns:
n_params : int

Number of DMP weights

get_outputs(outputs)[source]

Get outputs of the last step.

Parameters:
outputs : array-like, shape = (3 * n_task_dims,)

Contains positions, velocities and accelerations in that order. Each type is stored contiguously, i.e. for n_task_dims=2 the order would be: xxvvaa (x: position, v: velocity, a: acceleration).

get_params()[source]

Get current weights.

Returns:
params : array-like, shape = (n_params,)

Current weights

imitate(X, Xd=None, Xdd=None, alpha=0.0, allow_final_velocity=True)[source]

Learn weights of the DMP from demonstrations.

Parameters:
X : array, shape (n_task_dims, n_steps, n_demos)

The demonstrated trajectories to be imitated.

Xd : array, shape (n_task_dims, n_steps, n_demos), optional

Velocities of the demonstrated trajectories.

Xdd : array, shape (n_task_dims, n_steps, n_demos), optional

Accelerations of the demonstrated trajectories.

alpha : float >= 0, optional (default: 0)

The ridge parameter of linear regression. Small positive values of alpha improve the conditioning of the problem and reduce the variance of the estimates.

allow_final_velocity : bool, optional (default: True)

Allow the final velocity to be greater than 0

init(n_inputs, n_outputs)[source]

Initialize the behavior.

Parameters:
n_inputs : int

number of inputs

n_outputs : int

number of outputs

load_config(filename)[source]

Load DMP configuration.

Parameters:
filename : string

Name of YAML file

reset()[source]

Reset DMP.

save(dmp, filename)

Save DMP model.

Parameters:
dmp : object

DMP

filename : string

Name of YAML file

save_config(filename)[source]

Save DMP configuration.

Parameters:
filename : string

Name of YAML file

set_inputs(inputs)[source]

Set input for the next step.

In case the start position (x0) has not been set as a meta-parameter we take the first position as x0.

Parameters:
inputs : array-like, shape = (3 * n_task_dims,)

Contains positions, velocities and accelerations in that order. Each type is stored contiguously, i.e. for n_task_dims=2 the order would be: xxvvaa (x: position, v: velocity, a: acceleration).

set_meta_parameters(keys, meta_parameters)[source]

Set DMP meta parameters.

Permitted meta-parameters:

x0 : array
Initial position
g : array
Goal
gd : array
Velocity at the goal
execution_time : float
New execution time
Parameters:
keys : list of string

names of meta-parameters

meta_parameters : list of float

values of meta-parameters

set_params(params)[source]

Set new weights.

Parameters:
params : array-like, shape = (n_params,)

New weights

step()[source]

Compute desired position, velocity and acceleration.

trajectory()[source]

Generate trajectory represented by the DMP in open loop.

The function can be used for debugging purposes.

Returns:
X : array, shape (n_steps, n_task_dims)

Positions

Xd : array, shape (n_steps, n_task_dims)

Velocities

Xdd : array, shape (n_steps, n_task_dims)

Accelerations