Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMA-ES implementation and Force example #236

Closed
wants to merge 98 commits into from

Conversation

thurinj
Copy link
Member

@thurinj thurinj commented Nov 6, 2023

Here is a brief list of the main contributions of this pull request:

  1. Implementation of the CMA-ES (wiki) algorithm in MTUQ. This comes with its own set of utils and plotting. It integrates most of the pre-existing MTUQ classes and functions so as not to alter the main part of the code.
  2. Refinement of the matplotlib backend. I added Lune and Force Sphere visualization options based on matplotlib. The only piece missing to be 100% competitive with GMT is the beachball plots (which would be quite challenging to implement). Nevertheless, it is easier to work with to implement new options (plot type, scaling, combining plots, etc.). This is the default backend for most of the CMA-ES plotting functions, although the CMA-ES output is also compatible with the GMT backend. This also includes some default plots for polarity misfits (both on the Lune and Force Sphere).
  3. Added the Barry arm landslide data for the Force source type of MTUQ. This comes with bundled data and two examples for the Gridsearch and CMA-ES mode.
  4. Implemented point force polarity misfit. As it appears that the DPRK nuclear test of 2017-09-03 is very well fitted by a point force, we can also use the data polarity with a point force source. Implemented from R. Madariaga book chapter on Seismic Source Theory. (PDF available here at the time of this PR).

I have made a lot of tests and integrated feedback from @SeismoFelix and @ammcpherson who helped test an earlier version of the CMA-ES implementation.

The CMA-ES solver has been tested with several data groups and polarity misfits. It includes the option to balance the contribution of each waveform group that is given as input (and will otherwise default to normalize each misfit contribution by the data norm).

It is initialized with the following:

parameter_list = initialize_mt(Mw_range=[4,6], src_type=src_type)

# Creating list of important objects to be passed to solving and plotting functions later
DATA = [data_bw, data_sw]
MISFIT = [misfit_bw, misfit_sw]
PROCESS = [process_bw, process_sw]
GREENS = [greens_bw, greens_sw]

popsize = 48 # -- CMA-ES population size - number of mutants
CMA = CMA_ES(parameter_list , origin=origin, lmbda=popsize, event_id=event_id)
iter = 60

which uses most of the default MTUQ objects. The solve method will perform 60 CMA-ES iterations, with a population of 48 samples/mutants to evolve, and plot waveform misfit and misfit map every 10 steps along the way. The misfit map is updated by the new one rather than being kept on disk.

CMA.Solve(DATA, stations, MISFIT, PROCESS, GREENS, iter, plot_interval=10, misfit_weights=[2., 3.])

If you want to be more specific with your result processing, it is possible to return the whole CMA-ES history of samples with the following:

result = CMA.mutants_logger_list

which returns a similar object to the random grid search solutions (mtuq.grid_search.MTUQDataFrame) and is thus compatible with other base functions in the code.

(The fork was open for PR earlier today but an mpi4py error prevented the tests to pass and it was discarded for this updated version. I added a check in code that should help with the tests.)

thurinj and others added 30 commits May 10, 2023 12:18
Added all base method for the CMA-ES component of MTUQ. In the process of streamlining the parallel_cmaes.py implementation.
This will be the default file for development. Non-mpi version will be tested but might not be fully developed.
Corrected a few anomalies in the code. The path and cov update now correspond to purecma python package.
Based on GridSearch.FullMomentTensor.py, should provide a nice overview of the basic MT inversion with CMA-ES. Still work in progress.
Added a new function to automatically create the list of parameters for force inversion.
Work in progress Force CMA-ES application. Currently works with the "greens" mode in CMAES.Force.py
Fixed import error and cleaned up debug plot.
Tested the database mode on a depth-search.
Overhauled the script description and populated with comments and recommendations on uses.
Local paths referring to my machine have been replaced with "generic" path to be changed by users.
Reset boundary handling method back to rand-based, instead of re-initialize.
Slight modification to allow for matplotlib backend plot for _plot_lune_matplotlib and the use of CMA-ES log as input for the main mtuq plot_misfit_lune() function
thurinj and others added 26 commits October 4, 2023 10:04
Implemented polarity misfit for point-force sources. A test function has also been added in order to verify that the USE convention is respected.
Removed unnecessary normalization.
Changed the default behavior for the v and w variable to "reinitialize" as it might helps with sampling close to the boundaries (even if making the convergence a bit slower).
Updated CMA-ES examples with new input syntax (for weighted misfit)
Fixed tri-contour bug encountered with NaN values in force plots.
Fixed colormesh on the sphere by splitting the plot in two to avoid projection artifacts.
Corrected the mis-rotation of DC data
Replaced dataset with Ezgi's example.
Changed default behavior for h to reinitialize for better exploration of both up and down hemispheres.
Defined default example for the Force CMA-ES, based on the Barry Arm glacier Landslide
Modified default weights for CMA.Solve in the database mode.
Changed naming convention for figures, and added event_id field in example CMA object initialization.
Fixed final naming convention.
Added data from the Barry Arm landslide for force inversion examples.
Allowing different naming conventions for long-period data (MXZ, MXR, MXT on top of BXZ, BXR, BXT)
Added the force sphere plot during the plotting phase of the Solve method. Also fixed the mean misfit location as the green circle in the plot (in-lieu of the minimum of the misfit map).
Added scatter plot functionality to force mode. The behavior will now be to return a different plot for each mode (Lune or Force sphere) based on CMA-ES mode (mt, mt_dc, mt_dev or force).
Added rank.0 plotting function (would otherwise cause problems on parallel jobs).
Final version of the CMA-ES force example.
Created the Force Example for MTUQ based on the Barry Arm glacier landslide.
Restored default .gitignore
Updated comment before final commit and PR.
Change the type of import to mimic import of mpi4py in example scripts.
Added a check for mpi environment.
@rmodrak
Copy link
Member

rmodrak commented Nov 7, 2023

Julien, It appears the request includes CMA-ES (very useful) as well as many other changes that I'm just starting to go through. Thanks for your patience as myself and others I work with get into the details. Looking forward to discussing at the next AFRL project meeting. -Ryan

@rmodrak rmodrak self-assigned this Nov 7, 2023
@thurinj
Copy link
Member Author

thurinj commented Nov 8, 2023

Will cancel this PR and restructure.

@thurinj thurinj closed this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants