CMA-ES / pycma

Python implementation of CMA-ES

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CMA-ES in trajectories generation

GiorgioMedico opened this issue · comments

I have a trajectory and each point of the trajectory has 6 degrees of freedom. I want to optimize it according to a score given by my function at each point, but cma.CMAEvolutionStrategy takes a 1-D array as input. How can I do?

Flatten the array. I assume your trajectory is a 2D matrix of N rows (for N points) and 6 columns (for the 6 degrees of freedom) - if so, you can do something like:

import numpy as np

# Example random trajectory
num_points = 42
trajectory = np.random.random((num_points, 6))

# Flatten 2D matrix into 1D vector
trajectory_opt = trajectory.flatten()

# ... run optimisation ...

# Reshape 1D vector back into 2D matrix
reconstructed = trajectory_opt.reshape((num_points, 6))

Thanks for the reply.
This way I treat each degree of freedom as if they were separate variables.
Have you ever optimize a trajectory?

Yes, but I don't know what data you have and what exactly you're optimising - I'm just guessing here:

  • If you have positional data, you can optimise these first, then optimise orientations separately.
  • If you want to enforce constraints, you can think of parameterisations - e.g. to keep orientation a unit vector, parameterise it in spherical coordinates and optimise only the polar and azimuthal angles, then convert them back to what you need (orientation vectors, Euler angles, quaternions, etc.).

I have to optimize the trajectory of a robot based on its interaction forces with the environment. In particular I want to optimize the z and y and the rotation around the y axis.