Example #1
0
    def init(self, n_inputs, n_outputs):
        """Initialize the behavior.

        Parameters
        ----------
        n_inputs : int
            number of inputs

        n_outputs : int
            number of outputs
        """
        if n_inputs != n_outputs:
            raise ValueError("Input and output dimensions must match, got "
                             "%d inputs and %d outputs" %
                             (n_inputs, n_outputs))

        self.n_inputs = n_inputs
        self.n_outputs = n_outputs
        self.n_task_dims = self.n_inputs / 3

        if hasattr(self, "configuration_file"):
            load_dmp_model(self, self.configuration_file)
        else:
            self.name = "Python DMP"
            self.alpha_z = dmp.calculate_alpha(0.01, self.execution_time, 0.0)
            self.widths = np.empty(self.n_features)
            self.centers = np.empty(self.n_features)
            dmp.initialize_rbf(self.widths, self.centers, self.execution_time,
                               0.0, 0.8, self.alpha_z)
            self.alpha_y = 25.0
            self.beta_y = self.alpha_y / 4.0
            self.weights = np.zeros((self.n_features, self.n_task_dims))

        if not hasattr(self, "x0"):
            self.x0 = None
        if not hasattr(self, "x0d"):
            self.x0d = np.zeros(self.n_task_dims)
        if not hasattr(self, "x0dd"):
            self.x0dd = np.zeros(self.n_task_dims)
        if not hasattr(self, "g"):
            self.g = np.zeros(self.n_task_dims)
        if not hasattr(self, "gd"):
            self.gd = np.zeros(self.n_task_dims)
        if not hasattr(self, "gdd"):
            self.gdd = np.zeros(self.n_task_dims)

        self.reset()
Example #2
0
    def init(self, n_inputs, n_outputs):
        """Initialize the behavior.

        Parameters
        ----------
        n_inputs : int
            number of inputs

        n_outputs : int
            number of outputs
        """
        if n_inputs != n_outputs:
            raise ValueError("Input and output dimensions must match, got "
                             "%d inputs and %d outputs" %
                             (n_inputs, n_outputs))

        self.n_task_dims = n_inputs // 3

        if self.execution_times is None:
            self.execution_times = np.ones(self.n_dmps)
        self.execution_times = np.asarray(self.execution_times)
        if self.n_features is None:
            self.n_features = 50 * np.ones(self.n_dmps, dtype=int)
        if self.subgoals is None:
            self.subgoals = [
                np.zeros(self.n_task_dims) for _ in range(self.n_dmps + 1)
            ]
        else:
            self.subgoals = [np.asarray(g) for g in self.subgoals]

        self.n_steps_per_dmp = (self.execution_times / self.dt).astype(int) + 1
        self.n_weights_per_dmp = self.n_task_dims * self.n_features

        self.subgoal_velocities = [
            np.zeros(self.n_task_dims) for _ in range(self.n_dmps + 1)
        ]

        self.n_weights = np.sum(self.n_weights_per_dmp)

        self.split_steps = np.cumsum(self.n_steps_per_dmp - 1)
        self.split_weights = np.cumsum(self.n_weights_per_dmp)

        self.alpha_z = []
        self.widths = []
        self.centers = []
        for i in range(self.n_dmps):
            alpha_z = dmp.calculate_alpha(0.01, self.execution_times[i], 0.0)
            widths = np.empty(self.n_features[i])
            centers = np.empty(self.n_features[i])
            dmp.initialize_rbf(widths, centers, self.execution_times[i], 0.0,
                               0.8, alpha_z)
            self.alpha_z.append(alpha_z)
            self.widths.append(widths)
            self.centers.append(centers)
        self.alpha_y = 25.0
        self.beta_y = self.alpha_y / 4.0
        if self.initial_weights is None:
            self.weights = [
                np.zeros((self.n_weights_per_dmp[i], self.n_task_dims))
                for i in range(self.n_dmps)
            ]
        else:
            self.weights = [
                w.reshape(self.n_weights_per_dmp[i], self.n_task_dims)
                for w in self.initial_weights
            ]

        self.x0 = None
        self.g = None

        self.reset()
Example #3
0
    def init(self, n_inputs, n_outputs):
        """Initialize the behavior.

        Parameters
        ----------
        n_inputs : int
            number of inputs

        n_outputs : int
            number of outputs
        """
        if n_inputs != 7:
            raise ValueError("Number of inputs must be 7")
        if n_outputs != 7:
            raise ValueError("Number of outputs must be 7")

        self.n_inputs = 7
        self.n_outputs = 7
        self.n_task_dims = 6

        if hasattr(self, "configuration_file"):
            load_dmp_model(self, self.configuration_file)
        else:
            self.name = "Python CSDMP"
            self.alpha_z = dmp.calculate_alpha(0.01, self.execution_time, 0.0)
            self.widths = np.empty(self.n_features)
            self.centers = np.empty(self.n_features)
            dmp.initialize_rbf(self.widths, self.centers, self.execution_time,
                               0.0, 0.8, self.alpha_z)
            self.alpha_y = 25.0
            self.beta_y = self.alpha_y / 4.0
            self.position_weights = np.empty((self.n_features, 3))
            self.orientation_weights = np.empty((self.n_features, 3))
            self.weights = np.zeros((self.n_features, self.n_task_dims))

        if not hasattr(self, "x0"):
            self.x0 = np.zeros(3)
        if not hasattr(self, "x0d"):
            self.x0d = np.zeros(3)
        if not hasattr(self, "x0dd"):
            self.x0dd = np.zeros(3)

        if not hasattr(self, "g"):
            self.g = np.zeros(3)
        if not hasattr(self, "gd"):
            self.gd = np.zeros(3)
        if not hasattr(self, "gdd"):
            self.gdd = np.zeros(3)

        if not hasattr(self, "q0"):
            self.q0 = np.array([0.0, 1.0, 0.0, 0.0])
        if not hasattr(self, "q0d"):
            self.q0d = np.zeros(3)
        if not hasattr(self, "q0dd"):
            self.q0dd = np.zeros(3)

        if not hasattr(self, "qg"):
            self.qg = np.array([0.0, 1.0, 0.0, 0.0])
        if not hasattr(self, "qgd"):
            self.qgd = np.zeros(3)
        if not hasattr(self, "qgdd"):
            self.qgdd = np.zeros(3)

        self.reset()
Example #4
0
def test_calculate_alpha():
    alpha = dmp.calculate_alpha(0.01, 0.446, 0.0)
    assert_almost_equal(4.5814764780043, alpha)