Skip to content

Instantly share code, notes, and snippets.

@a2ray
Last active August 17, 2021 07:20
Show Gist options
  • Save a2ray/92a8c14483c21dda6ddf56685b95fbb8 to your computer and use it in GitHub Desktop.
Save a2ray/92a8c14483c21dda6ddf56685b95fbb8 to your computer and use it in GitHub Desktop.

WITHOUT MODIFYING transD_GP: Adding an inverse (and forward) method using the transD_GP API

A 1D example to help you get along

Here we'll add a forward physics module called BarPhysics, which is totally independent of transD_GP. To couple the physics through a misfit function to transD_GP we'll use a helper module BarPhysicsInversion. This helps in code distribution as the authors of BarPhysics will not have to modifytransD_GP at all. Navigate to examples/Bar and have a look at BarPhysics.jl, which willl contain everything you need for forward computation, this file needs to know nothing about transD_GP. To define the get_misfit function such that transD_GP can use it, look at BarPhysicsInversion.jl in the same folder.

Have a close look at these two files as they contain all the essential API elements, including descriptive comments for adding your own forward method for transD_GP inference. Note the .using or ..using as they imply loading a module from the current namespace or in the one outside (just as you would refer to files within a unix/linux directory tree).

Run the 1D example

This BarPhysicsInversion module will basically sample the prior using parallel code, it runs in no time, and does a few plots you need to visualize the sampled posterior (==prior in this case). It will show you how to connect the forward physics, misfit function, data for inference, setting prior options, and plotting the posterior. To run this example, run the NUMBERED scripts in sequence in examples/Bar from within that folder. To ensure that all parallel workers know about BarPhysics and BarPhysicsInversion, pay special attention to the @everywhere begin ... end block in the numbered scripts.

All the inference problems in transD_GP whether 1D, 2D or spatially 3D follow the same recipe -- you don't need to change the downloaded and installed sampler code AT ALL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment