# Running the PGI Joint Inversion Code for simulated data

**URL:** <https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416>\
**Category:** Potential Fields\
**Created:** [February 20, 2023, 6:14am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416 "2023-02-20T06:14:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![akamath](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/akamath/32/211_2.png) [@akamath](https://simpeg.discourse.group/u/akamath)\
**Post date:** [February 20, 2023, 6:14am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/1 "2023-02-20T06:14:19Z")

</div>

Greetings! I have been testing and using the PGI formulation in SimPEG as the basis for my master’s thesis and I have some questions I was hoping to get answers to.

1. The `Solver` problem:

I was using an earlier version of SimPEG which when used to run the inverse problem gave me the expected results. The output for the inversion code said ` **Done using same solver and solver_opts as the Simulation3DIntegral problem.** ` But now, for some reason, the `Simulation3DIntegral` class has its solver and solver opts set to None, which results in the default `Pardiso` solver being used for my problem. This in turn changes the outputs to my inversion for the exact same data. How may I go about rectifying this issue?

1. The problem of misfits

This is related to the previous question in a way. The geophysical data misfits at each iteration seem to be converging well for the gravity data, but plateau after a certain point for the magnetic data. This happens for an inversion I had successfully run before, with the exact same p.f. data, uncertainties, petrophysical data and their statistical distributions. I don’t know why this is happening, but I have the results from each of my tests documented and the difference is clear- the magnetic model is not being recovered. Do you see any reason that might be happening?

1. The problem of cell-by-cell lithological information prior

I have been trying to incorporate geological information as a prior in the `WeightedGaussianMixture` class, but so far I have been unsuccessful. Do I have to use a different function to make the model or is there something I am missing?

Any help on these fronts is highly appreciated.

Regards,  
Akshay

---

<div class="post-metadata">

**Author:** ![thibaut.astic](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/thibaut.astic/32/109_2.png) [@thibaut.astic](https://simpeg.discourse.group/u/thibaut.astic)\
**Post date:** [February 20, 2023, 11:23pm UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/2 "2023-02-20T23:23:26Z")

</div>

Hi,

Before anything, just in case you are not aware of it; those are the four scripts most up to date with simpeg PGI present in the documentation:

- [PF examples](http://docs.simpeg.xyz/content/tutorials/14-pgi/index.html)
- [PGI: Petrophysically and Geologically guided Inversion — SimPEG 0.18.1 documentation](http://docs.simpeg.xyz/content/examples/10-pgi/index.html)

1. Solver: You should not have to set a solver for potential fields. Those [PF examples](http://docs.simpeg.xyz/content/tutorials/14-pgi/index.html) in the documentation should show you everything you need with regards to that.

2. If you have issues balancing your various data misfits, as in the PF examples above, consider using the data misfit reweighting strategy. It is an heuristic strategy to iteratively balance the dataset at each iteration

```auto
# iteratively balance the scaling of the data misfits
# initialize values
scaling_init = directives.ScalingMultipleDataMisfits_ByEig(chi0_ratio=[1.0, 100.0])
# iterative reweighting
scale_schedule = directives.JointScalingSchedule(verbose=True)

```

1. To include geology through different GMM proportions (`gmm.weights_`) at various locations (i.e. a geology model), you can pass a numpy array of size (“number of active cells”, “numbers of units”) to `gmm.weights_` (like `gmm.weights_ = your_array`). As they are probabilities of each presence of each rock at each location, each row of your array needs to some to 1, with purely positive values (if you want to set a probability of zero, use something like `1e-128` instead; computations are done in log-space and a zero would trip the computation)

---

<div class="post-metadata">

**Author:** ![akamath](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/akamath/32/211_2.png) [@akamath](https://simpeg.discourse.group/u/akamath)\
**Post date:** [February 21, 2023, 12:51am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/3 "2023-02-21T00:51:23Z")

</div>

Dear Dr. Astic,

Thank you for the quick reply. I have been using the PF scripts you have linked. I have modelled my scripts on them. The reweighting of data misfits through the chi factor line is also set in my script. It gave results earlier, but for some reason is not working right now. It might be an issue from my side, I will check again. Thank you for the help on the geological information, just to confirm; will the row indices of the array correspond to the spatial indices in the block model?

Kindest regards,  
Akshay

---

<div class="post-metadata">

**Author:** ![thibaut.astic](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/thibaut.astic/32/109_2.png) [@thibaut.astic](https://simpeg.discourse.group/u/thibaut.astic)\
**Post date:** [February 21, 2023, 12:59am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/4 "2023-02-21T00:59:26Z")

</div>

> will the row indices of the array correspond to the spatial indices in the block model?

Yes, it will be ordered the same as the model (active cells)

---

<div class="post-metadata">

**Author:** ![akamath](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/akamath/32/211_2.png) [@akamath](https://simpeg.discourse.group/u/akamath)\
**Post date:** [February 21, 2023, 1:29am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/5 "2023-02-21T01:29:46Z")

</div>

Understood. Thank you very much for your assistance.

---

<div class="post-metadata">

**Author:** ![akamath](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/akamath/32/211_2.png) [@akamath](https://simpeg.discourse.group/u/akamath)\
**Post date:** [February 21, 2023, 6:21am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/6 "2023-02-21T06:21:50Z")

</div>

Dear Dr Astic,

Sorry to trouble you again, but the problem persists. The misfits are being rescaled at every iteration to give more weight to the magnetic data misfit, but the plateau is not going away, resulting in the model not converging. I’m using the same data and alpha parameters as I used earlier. Following are a few iterations of the previous inversion (before the update);

```auto
=============================== Projected GNCG ===============================
  # beta phi_d phi_m f |proj(x-g)-x| LS Comment   
-----------------------------------------------------------------------------
x0 has any nan: 0
   0 1.47e-07 1.65e+05 0.00e+00 1.65e+05 8.97e+01 0              
geophys. misfits: 10673.1 (target 200.0 [False]); 33388.5 (target 200.0 [False]) | smallness misfit: 73869.0 (target: 8000.0 [False])
Beta cooling evaluation: progress: [10673.1 33388.5] ; minimum progress targets: [129818. 347727.3]
mref changed in 538 places
   1 1.47e-07 1.09e+04 7.61e+10 2.21e+04 2.55e+01 0              
geophys. misfits: 10002.7 (target 200.0 [False]); 3544.5 (target 200.0 [False]) | smallness misfit: 66356.3 (target: 8000.0 [False])
Beta cooling evaluation: progress: [10002.7 3544.5] ; minimum progress targets: [8538.5 26710.8]
mref changed in 130 places
   2 1.47e-07 9.94e+03 7.99e+10 2.17e+04 1.13e+01 0 Skip BFGS  
geophys. misfits: 9989.9 (target 200.0 [False]); 2565.3 (target 200.0 [False]) | smallness misfit: 59534.1 (target: 8000.0 [False])
Beta cooling evaluation: progress: [9989.9 2565.3] ; minimum progress targets: [8002.2 2835.6]
mref changed in 38 places
   3 1.47e-07 9.91e+03 7.99e+10 2.17e+04 8.67e+00 0 Skip BFGS  
geophys. misfits: 9988.9 (target 200.0 [False]); 1558.4 (target 200.0 [False]) | smallness misfit: 59155.2 (target: 8000.0 [False])
Beta cooling evaluation: progress: [9988.9 1558.4] ; minimum progress targets: [7991.9 2052.2]
mref changed in 106 places
   4 1.47e-07 9.90e+03 7.97e+10 2.16e+04 9.40e+00 0 Skip BFGS  
geophys. misfits: 9984.6 (target 200.0 [False]); 1444.3 (target 200.0 [False]) | smallness misfit: 55748.4 (target: 8000.0 [False])
Beta cooling evaluation: progress: [9984.6 1444.3] ; minimum progress targets: [7991.1 1246.7]
Decreasing beta to counter data misfit decrase plateau.
mref changed in 81 places
   5 7.35e-08 9.90e+03 7.96e+10 1.57e+04 6.29e+01 0 Skip BFGS  
geophys. misfits: 5777.5 (target 200.0 [False]); 857.0 (target 200.0 [False]) | smallness misfit: 49248.6 (target: 8000.0 [False])
Beta cooling evaluation: progress: [5777.5 857.] ; minimum progress targets: [7987.7 1155.5]
mref changed in 119 places
   6 7.35e-08 5.73e+03 1.20e+11 1.45e+04 1.02e+01 0              
geophys. misfits: 5763.1 (target 200.0 [False]); 661.2 (target 200.0 [False]) | smallness misfit: 47824.1 (target: 8000.0 [False])
Beta cooling evaluation: progress: [5763.1 661.2] ; minimum progress targets: [4622. 685.6]
mref changed in 85 places
   7 7.35e-08 5.71e+03 1.20e+11 1.45e+04 8.90e+00 0 Skip BFGS  
geophys. misfits: 5759.1 (target 200.0 [False]); 601.4 (target 200.0 [False]) | smallness misfit: 47981.8 (target: 8000.0 [False])
Beta cooling evaluation: progress: [5759.1 601.4] ; minimum progress targets: [4610.5 528.9]
Decreasing beta to counter data misfit decrase plateau.
mref changed in 65 places
   8 3.67e-08 5.71e+03 1.20e+11 1.01e+04 5.63e+01 0              
geophys. misfits: 3117.6 (target 200.0 [False]); 437.4 (target 200.0 [False]) | smallness misfit: 41670.5 (target: 8000.0 [False])
Beta cooling evaluation: progress: [3117.6 437.4] ; minimum progress targets: [4607.3 481.1]
mref changed in 101 places
   9 3.67e-08 3.09e+03 1.70e+11 9.32e+03 6.85e+00 0              
geophys. misfits: 3115.5 (target 200.0 [False]); 414.7 (target 200.0 [False]) | smallness misfit: 39614.8 (target: 8000.0 [False])
Beta cooling evaluation: progress: [3115.5 414.7] ; minimum progress targets: [2494.1 349.9]
Decreasing beta to counter data misfit decrase plateau.
mref changed in 38 places

```

And the following are some iterations (after the gravity misfit reaches its target) from the inversion I am carrying out now. The data, alpha values and all parameters (bounds, tolerances, etc) are equal in both cases.

```auto
=============================== Projected GNCG ===============================
  # beta phi_d phi_m f |proj(x-g)-x| LS Comment   
-----------------------------------------------------------------------------
  19 6.92e-11 2.32e+05 6.90e+11 2.32e+05 1.88e+01 9              
geophys. misfits: 78.6 (target 200.0 [True]); 325405.5 (target 200.0 [False]) | smallness misfit: 175366.1 (target: 8000.0 [False])
Updating scaling for data misfits by 2.5461134441969566
New scales: [0.13712651 0.86287349]
Beta cooling evaluation: progress: [7.860000e+01 3.254055e+05] ; minimum progress targets: [2.400000e+02 2.603292e+05]
mref changed in 3 places
  20 6.92e-11 2.81e+05 6.95e+11 2.81e+05 1.19e+01 10              
geophys. misfits: 78.0 (target 200.0 [True]); 325297.0 (target 200.0 [False]) | smallness misfit: 179324.8 (target: 8000.0 [False])
Updating scaling for data misfits by 2.5632076475415975
New scales: [0.05838026 0.94161974]
Beta cooling evaluation: progress: [7.80000e+01 3.25297e+05] ; minimum progress targets: [2.400000e+02 2.603244e+05]
mref changed in 26 places
  21 6.92e-11 3.06e+05 7.25e+11 3.06e+05 9.19e+00 8              
geophys. misfits: 77.5 (target 200.0 [True]); 325167.4 (target 200.0 [False]) | smallness misfit: 184381.0 (target: 8000.0 [False])
Updating scaling for data misfits by 2.5818441739138516
New scales: [0.02345064 0.97654936]
Beta cooling evaluation: progress: [7.750000e+01 3.251674e+05] ; minimum progress targets: [2.400000e+02 2.602376e+05]
mref changed in 23 places
  22 6.92e-11 3.18e+05 7.65e+11 3.18e+05 1.26e+01 8 Skip BFGS  
geophys. misfits: 77.2 (target 200.0 [True]); 325142.5 (target 200.0 [False]) | smallness misfit: 186833.8 (target: 8000.0 [False])
Updating scaling for data misfits by 2.589242868227184
New scales: [0.00918921 0.99081079]
Beta cooling evaluation: progress: [7.720000e+01 3.251425e+05] ; minimum progress targets: [2.400000e+02 2.601339e+05]
mref changed in 22 places
  23 6.92e-11 3.22e+05 8.05e+11 3.22e+05 1.37e+01 8              
geophys. misfits: 79.3 (target 200.0 [True]); 325062.5 (target 200.0 [False]) | smallness misfit: 194990.2 (target: 8000.0 [False])
Updating scaling for data misfits by 2.5214254683230912
New scales: [0.00366477 0.99633523]
Beta cooling evaluation: progress: [7.930000e+01 3.250625e+05] ; minimum progress targets: [2.40000e+02 2.60114e+05]
mref changed in 18 places
  24 6.92e-11 3.24e+05 8.40e+11 3.24e+05 1.40e+01 7              
geophys. misfits: 84.3 (target 200.0 [True]); 325007.6 (target 200.0 [False]) | smallness misfit: 201233.6 (target: 8000.0 [False])
Updating scaling for data misfits by 2.3712341933470236
New scales: [0.0015488 0.9984512]
Beta cooling evaluation: progress: [8.430000e+01 3.250076e+05] ; minimum progress targets: [2.4000e+02 2.6005e+05]
mref changed in 17 places
  25 6.92e-11 3.25e+05 8.48e+11 3.25e+05 1.41e+01 7              
geophys. misfits: 87.0 (target 200.0 [True]); 324998.1 (target 200.0 [False]) | smallness misfit: 207635.0 (target: 8000.0 [False])
Updating scaling for data misfits by 2.297707930625463
New scales: [6.74651020e-04 9.99325349e-01]
Beta cooling evaluation: progress: [8.700000e+01 3.249981e+05] ; minimum progress targets: [2.400000e+02 2.600061e+05]
mref changed in 9 places
  26 6.92e-11 3.25e+05 8.61e+11 3.25e+05 1.41e+01 7 Skip BFGS  
geophys. misfits: 104.4 (target 200.0 [True]); 324987.7 (target 200.0 [False]) | smallness misfit: 209433.3 (target: 8000.0 [False])
Updating scaling for data misfits by 1.915625125057218
New scales: [3.52296822e-04 9.99647703e-01]
Beta cooling evaluation: progress: [1.044000e+02 3.249877e+05] ; minimum progress targets: [2.400000e+02 2.599985e+05]
mref changed in 39 places

```

The final value of the magnetic data misfit stays around 320000, and the smallness misfit blows up. Do you have any idea as to what might be causing this? Please let me know. Thank you for being so helpful; I appreciate it.

Regards,  
Akshay

---

<div class="post-metadata">

**Author:** ![akamath](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/akamath/32/211_2.png) [@akamath](https://simpeg.discourse.group/u/akamath)\
**Post date:** [April 3, 2023, 4:36am UTC](https://simpeg.discourse.group/t/running-the-pgi-joint-inversion-code-for-simulated-data/416/7 "2023-04-03T04:36:15Z")

</div>

Hello again,

I have managed to solve the problem I was having earlier; it was caused due to an update of SimPEG I ran, which changed the Magnetic forward modelling equations, resulting in the magnetic data misfit not converging.

I am running some example models with simple fault structures to see how well PGI inverts interfaces. I was getting satisfactory results before, but I seem to have messed up somehow.

Is there any particular way to make the smallness misfit converge quickly without updating the GMM. I have tried changing the Alpha parameters, as well as the covariance matrix of the petrophysical data, which are the only two things that seemingly control the smallness misfit. I would appreciate if anyone could point out any other parameters that I might be overlooking.

Regards  
Akshay
