chrismailer / mailer_gecco_2021

Code for Evolving Gaits for Damage Control in a Hexapod Robot (Mailer et al., GECCO 2021)
4 stars 2 forks source link

How to generate the map_*.dat? #1

Closed wzj-651123 closed 1 year ago

wzj-651123 commented 2 years ago

How to generate the map*.dat? In the process of reproducing your work, we did not find the generated file of the map.dat and log_.dat. We want to know the meaning of each number in the map*.dat and log*.dat. Looking forward to your reply.

chrismailer commented 2 years ago

The map*.dat files are the archive*.dat files generated with pymap_elites, just with a different filename. You can find the meaning of each line in the map/archive files here, and for the log files here.

wzj-651123 commented 2 years ago

How does pymapelites generate archive*.dat? (Is it generated using “multitask.py”?) I did a global search for "archive" and didn't find the path to save this.

chrismailer commented 2 years ago

For our work it is generated using the cvt.py variant of pymap_elites not multitask.py. You cannot specify an archive location, the archive file will simply be saved in the same directory you are running cvt_map_elites.compute(...) from. Maybe have a look at the basic usage section in the pymap_elites readme with the rastrigin function to understand how it works and where the log and archive files are saved.

wzj-651123 commented 2 years ago

Then there are 45 numbers in one line in the map*.dat file. Are these the control signals for the robot? What does each mean? Can it be understood that 45 numbers in a row are a controller, and the number of rows in the map*.dat file is the number of generated controllers?

chrismailer commented 2 years ago

For each line the first value is the fitness of that particular gait (distance walked along x axis), the next 6 values are the centroid (location in the map), the next 6 are the descriptor for that gait (percentage of time each leg spends on the ground), and the final 32 values are the parameters for the gait controller. The number of rows is determined by the map size (number of centroids).

wzj-651123 commented 2 years ago
  1. In Bayesian optimization, enter six centroids (columns 2-7 in the map), and then use the Gaussian distribution to select the location for the next optimization?
  2. In the representation of map, is the meaning of the horizontal and vertical coordinates a descriptor?
  3. What is the difference between centroid and descriptor (columns 8-13 in map)?
chrismailer commented 2 years ago
  1. I don't understand what the question is? Bayesian optimisation fits a gaussian function to the fitness values in the maps, and then updates this expected fitness prior with the real fitness values as gaits in the map are tested on the real/failed hardware. A gait is tested if it has the highest expected performance in the map. This paper provides a better explanation.
  2. Yes, a descriptor with two values can be visualised as a 2D map. Higher dimensional descriptors are harder to visualise.
  3. There isn't a difference with what the descriptor and centroid mean. Both represent the time each foot spends on the ground. However, the descriptor is the precise value from the simulation, whereas the centroids represent a discretisation of the descriptor space. The map size is the number of centroids. After a simulation has determined a gait's descriptor its location in the map is determined by the nearest (euclidian distance) centroid. Only one gait can be associated with one centroid at a time. You can think of the maps descriptor space as being broken up into n evenly spaced bins, where the location of each bin is a particular centroid. Again, this paper probably provides a better explanation
wzj-651123 commented 2 years ago
  1. How do the last 32 parameters in the map_*.dat control the robot? (in the PyBullet simulation environment)
  2. Is it possible to infer the 45 parameters in the map_*.dat based on the footfall diagram?
chrismailer commented 2 years ago
  1. You can find the structure of the 32 gait parameters in the paper here on the bottom left of page 3. That is the same structure used in PyBullet.
  2. It isn't possible to see how the gait parameters correspond to footfalls, and vice versa without forward simulation. There is no constraint on the gait needing to be statically stable which is why we need a simulation with dynamics. The body falls slightly with some gaits which results in legs lifting up. That would be very hard to infer without accurate dynamics. The descriptor also only has the average time the foot spends on the ground and does not have information about when the foot touches down and for how long, so it would not be possible to create a footfall diagram from that. You could however get the descriptor from a footfall diagram.
wzj-651123 commented 2 years ago

The map_.py in the article is a 2000045 list. I used pymap_elites to generate a map_*.py file of the same size, but it cannot be called normally in test_gait.py. The value of fitness in the map I generated is about a few hundred, but your fitness size is all less than 10. When generating a map, can the size of the values in it be controlled?

wzj-651123 commented 2 years ago
  1. Is a dynamic model used in the process of generating the map in this paper?
  2. In the caption of Figure 4 of 《robots that can adapt like animals》 in 2015, it is explained that "the behavior – performance map is created with a simulated robot (bottom left) in the open dynamics engine physics Simulator" is used in generating the map( http://www.ode.org ).”
  3. However, the map generated by "pymap_elites" has only mathematical meaning, not the robot meaning in the simulation.
chrismailer commented 2 years ago

A fitness value of a few hundred doesn't sound correct. The fitness value is the distance travelled along the x axis in 5s which should definitely be below 10m. Maybe make sure you are only running the simulation for 5s. test_gait.py will help to see the gaits and debug any issues. All of the values have physical meaning so their sizes depend on their units.

  1. What do you mean by dynamic model? The physical parameters of the simulation all stay the same between runs, only the controller parameters change. Not sure if that's what you're asking about. 2/3. The physical robot is embedded in the map through the relationship between the fitness and controller parameters. It is not possible to get the fitness of specific controller parameters without simulating full dynamics with contacts, friction, and joint torque limits.
wzj-651123 commented 2 years ago

In the process of generating maps now, I just randomly generate a lot of values, which have nothing to do with the robot model. So, how do you use the robot model to calculate the controller parameters and fitness values in the map?

chrismailer commented 2 years ago

That's good, nice! So the way Map Elites works is it passes 32 parameters to the gait controller which produces a particular gait. This gait is simulated in the pybullet physics simulation and returns a fitness parameter and a behaviour descriptor. This process is iteratively repeated to find gaits with better and better fitness values, whilst also being sufficiency different based on the behaviour descriptor. What you get in the end is a set of diverse gaits which also all have high fitness values, with the map size determining the number of gaits. That is why Map Elites is referred to as a quality diversity (QD) algorithm as it produces both high quality and different/diverse solutions.

Those values being generated have everything to do with the robot model. The robot model is used to simulate a gait. Map Elites passes 32 parameters to the gait controller and simulator and then based on how the robot walks you will get out a fitness value and behaviour descriptor. If you change the robot model and make it heavier or give it shorter legs, it will walk differently and your fitness and behaviour descriptor values will now be different even with the same gait parameters. If I'm not explaining this well enough, please go and have a look through the paper Robots that can adapt like animals. They do a really good job explaining all of the questions you've had.

wzj-651123 commented 2 years ago

When you generated the map, how did you combine the robot model? In the 2015 paper, it seems that the C++ language is used to do this? I'm a little bit confused now what should I do with this generation process?

chrismailer commented 2 years ago

So Map Elites requires a function which given a set of parameters, returns a fitness and descriptor. function(x) -> fitness, descriptor The function evaluate_gait in the file generate_map.py does this. Inside this function I create a controller with the parameters x and pass this to the PyBullet simulator which simulates the gait and returns a fitness. I also determine the descriptor from the foot contact sequence. Both of these then get returned to Map Elites. This is how the robot model is combined with map generation.

chrismailer commented 2 years ago

Hi is everything working? Can I close this issue?