Note
Go to the end to download the full example code.
Petrophysically guided inversion: Joint linear example with nonlinear relationships#
We do a comparison between the classic least-squares inversion and our formulation of a petrophysically guided inversion. We explore it through coupling two linear problems whose respective physical properties are linked by polynomial relationships that change between rock units.

Running inversion with SimPEG v0.25.1.dev6+gb840df108
Alpha scales: [np.float64(3.48433541929132), np.float64(0.0), np.float64(3.4846653677357706e-06), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers: [0.09521196 0.90478804]
<class 'simpeg.regularization.pgi.PGIsmallness'>
Initial data misfit scales: [0.09521196 0.90478804]
================================================= Projected GNCG =================================================
# beta phi_d phi_m f |proj(x-g)-x| LS iter_CG CG |Ax-b|/|b| CG |Ax-b| Comment
-----------------------------------------------------------------------------------------------------------------
0 1.96e+01 3.00e+05 0.00e+00 3.00e+05 0 inf inf
1 1.96e+01 1.36e+03 1.71e+02 4.70e+03 1.41e+02 0 19 9.10e-04 8.47e+03
geophys. misfits: 7491.9 (target 30.0 [False]); 710.3 (target 30.0 [False]) | smallness misfit: 4087.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [7491.9 710.3]; minimum progress targets: [240000. 240000.]
2 1.96e+01 6.83e+01 4.05e+01 8.63e+02 1.39e+02 0 100 1.32e+00 1.13e+04 Skip BFGS
geophys. misfits: 511.6 (target 30.0 [False]); 21.6 (target 30.0 [True]) | smallness misfit: 1500.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [511.6 21.6]; minimum progress targets: [5993.5 568.3]
Updating scaling for data misfits by 1.3866568750441586
New scales: [0.12733844 0.87266156]
3 1.96e+01 6.22e+01 4.06e+01 8.59e+02 1.02e+02 0 77 7.66e-04 8.32e+00 Skip BFGS
geophys. misfits: 344.4 (target 30.0 [False]); 21.1 (target 30.0 [True]) | smallness misfit: 1286.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [344.4 21.1]; minimum progress targets: [409.3 30. ]
Updating scaling for data misfits by 1.424607962692188
New scales: [0.17210198 0.82789802]
4 1.96e+01 5.69e+01 4.14e+01 8.70e+02 7.20e+01 0 100 2.30e+00 5.19e+02
geophys. misfits: 228.8 (target 30.0 [False]); 21.2 (target 30.0 [True]) | smallness misfit: 1230.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [228.8 21.2]; minimum progress targets: [275.6 30. ]
Updating scaling for data misfits by 1.4168815710411504
New scales: [0.22752415 0.77247585]
5 1.96e+01 5.24e+01 4.22e+01 8.79e+02 8.88e+01 0 100 5.25e-01 2.78e+02 Skip BFGS
geophys. misfits: 157.5 (target 30.0 [False]); 21.4 (target 30.0 [True]) | smallness misfit: 1184.9 (target: 200.0 [False])
Beta cooling evaluation: progress: [157.5 21.4]; minimum progress targets: [183.1 30. ]
Updating scaling for data misfits by 1.4012763938310102
New scales: [0.29215083 0.70784917]
6 1.96e+01 4.88e+01 4.27e+01 8.87e+02 8.50e+01 0 100 1.77e+00 5.73e+02 Skip BFGS
geophys. misfits: 114.0 (target 30.0 [False]); 21.9 (target 30.0 [True]) | smallness misfit: 1147.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [114. 21.9]; minimum progress targets: [126. 30.]
Updating scaling for data misfits by 1.3714000994604227
New scales: [0.36143791 0.63856209]
7 1.96e+01 4.60e+01 4.31e+01 8.92e+02 8.88e+01 0 100 1.83e+00 1.06e+03 Skip BFGS
geophys. misfits: 87.5 (target 30.0 [False]); 22.6 (target 30.0 [True]) | smallness misfit: 1114.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [87.5 22.6]; minimum progress targets: [91.2 30. ]
Updating scaling for data misfits by 1.3292540247503306
New scales: [0.42934825 0.57065175]
8 1.96e+01 4.40e+01 4.34e+01 8.96e+02 8.78e+01 0 100 7.86e-01 7.52e+02 Skip BFGS
geophys. misfits: 71.2 (target 30.0 [False]); 23.5 (target 30.0 [True]) | smallness misfit: 1085.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [71.2 23.5]; minimum progress targets: [70. 30.]
Decreasing beta to counter data misfit decrase plateau.
Updating scaling for data misfits by 1.2787573181615282
New scales: [0.4903457 0.5096543]
9 9.81e+00 2.41e+01 4.49e+01 4.65e+02 1.01e+02 0 100 5.48e-01 4.55e+02
geophys. misfits: 30.0 (target 30.0 [False]); 18.3 (target 30.0 [True]) | smallness misfit: 1149.6 (target: 200.0 [False])
Beta cooling evaluation: progress: [30. 18.3]; minimum progress targets: [56.9 30. ]
Updating scaling for data misfits by 1.6364008313747107
New scales: [0.61156068 0.38843932]
10 9.81e+00 2.30e+01 4.51e+01 4.66e+02 8.01e+01 0 100 1.60e+00 5.79e+02 Skip BFGS
geophys. misfits: 24.9 (target 30.0 [True]); 20.2 (target 30.0 [True]) | smallness misfit: 1087.9 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.9 20.2]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 1.345934077259678
11 9.81e+00 2.37e+01 4.58e+01 4.73e+02 6.29e+01 0 100 7.84e-01 4.55e+02
geophys. misfits: 24.6 (target 30.0 [True]); 22.3 (target 30.0 [True]) | smallness misfit: 1016.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.6 22.3]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 1.7232213529392966
12 9.81e+00 2.46e+01 4.66e+01 4.82e+02 6.27e+01 0 100 5.67e-01 2.59e+02
geophys. misfits: 24.7 (target 30.0 [True]); 24.6 (target 30.0 [True]) | smallness misfit: 956.4 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.7 24.6]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 2.09945258148214
13 9.81e+00 2.54e+01 4.73e+01 4.90e+02 6.68e+01 0 100 1.08e+00 2.82e+02 Skip BFGS
geophys. misfits: 24.4 (target 30.0 [True]); 26.9 (target 30.0 [True]) | smallness misfit: 908.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.4 26.9]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 2.4592219337859724
14 9.81e+00 2.62e+01 4.80e+01 4.97e+02 6.31e+01 0 100 1.76e+00 5.03e+02 Skip BFGS
geophys. misfits: 24.5 (target 30.0 [True]); 28.9 (target 30.0 [True]) | smallness misfit: 867.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.5 28.9]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 2.7841976014605874
15 9.81e+00 2.68e+01 4.85e+01 5.03e+02 6.20e+01 0 100 2.08e+00 1.05e+03 Skip BFGS
geophys. misfits: 24.2 (target 30.0 [True]); 30.7 (target 30.0 [False]) | smallness misfit: 836.3 (target: 200.0 [False])
Beta cooling evaluation: progress: [24.2 30.7]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by 1.2379190718548438
New scales: [0.55982341 0.44017659]
16 4.90e+00 1.82e+01 4.98e+01 2.62e+02 9.86e+01 0 100 3.02e-01 3.60e+02
geophys. misfits: 16.1 (target 30.0 [True]); 20.9 (target 30.0 [True]) | smallness misfit: 945.8 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.1 20.9]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 4.596231625356912
17 4.90e+00 2.00e+01 5.30e+01 2.80e+02 8.26e+01 0 100 5.12e+00 1.93e+03
geophys. misfits: 16.4 (target 30.0 [True]); 24.5 (target 30.0 [True]) | smallness misfit: 796.9 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.4 24.5]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 7.0173486726684695
18 4.90e+00 2.21e+01 5.67e+01 3.00e+02 8.89e+01 0 100 1.71e+00 3.31e+03
geophys. misfits: 16.7 (target 30.0 [True]); 29.1 (target 30.0 [True]) | smallness misfit: 690.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.7 29.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 9.939107727086375
19 4.90e+00 2.47e+01 6.06e+01 3.22e+02 9.38e+01 0 100 1.56e+00 5.18e+03
geophys. misfits: 17.1 (target 30.0 [True]); 34.4 (target 30.0 [False]) | smallness misfit: 601.6 (target: 200.0 [False])
Beta cooling evaluation: progress: [17.1 34.4]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by 1.7502521500037267
New scales: [0.42084283 0.57915717]
20 2.45e+00 1.86e+01 6.28e+01 1.73e+02 9.42e+01 0 100 3.07e-01 2.09e+03
geophys. misfits: 13.8 (target 30.0 [True]); 22.1 (target 30.0 [True]) | smallness misfit: 695.6 (target: 200.0 [False])
Beta cooling evaluation: progress: [13.8 22.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 17.557245613307735
21 2.45e+00 2.16e+01 7.25e+01 1.99e+02 9.99e+01 0 100 1.21e+00 2.55e+03
geophys. misfits: 14.9 (target 30.0 [True]); 26.4 (target 30.0 [True]) | smallness misfit: 544.4 (target: 200.0 [False])
Beta cooling evaluation: progress: [14.9 26.4]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 27.630992544503304
22 2.45e+00 2.03e+01 8.51e+01 2.29e+02 1.05e+02 0 100 2.02e+00 5.18e+03
geophys. misfits: 14.3 (target 30.0 [True]); 24.6 (target 30.0 [True]) | smallness misfit: 484.4 (target: 200.0 [False])
Beta cooling evaluation: progress: [14.3 24.6]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 45.80516129623704
23 2.45e+00 2.79e+01 9.82e+01 2.69e+02 1.13e+02 0 100 3.91e+00 2.04e+04
geophys. misfits: 17.6 (target 30.0 [True]); 35.4 (target 30.0 [False]) | smallness misfit: 316.8 (target: 200.0 [False])
Beta cooling evaluation: progress: [17.6 35.4]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by 1.7044217967712014
New scales: [0.29890023 0.70109977]
24 1.23e+00 2.43e+01 1.00e+02 1.47e+02 1.06e+02 0 100 3.12e-01 7.65e+03
geophys. misfits: 19.1 (target 30.0 [True]); 26.5 (target 30.0 [True]) | smallness misfit: 321.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [19.1 26.5]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 61.83789310137412
25 1.23e+00 2.18e+01 1.14e+02 1.62e+02 9.93e+01 0 100 7.73e-01 5.91e+03
geophys. misfits: 16.4 (target 30.0 [True]); 24.1 (target 30.0 [True]) | smallness misfit: 325.4 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.4 24.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 94.9352036796254
26 1.23e+00 2.25e+01 1.39e+02 1.93e+02 1.11e+02 0 100 7.48e-01 4.43e+03
geophys. misfits: 16.8 (target 30.0 [True]); 25.0 (target 30.0 [True]) | smallness misfit: 298.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.8 25. ]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 141.70488271543303
27 1.23e+00 2.08e+01 1.69e+02 2.28e+02 1.16e+02 0 100 3.40e+00 1.52e+04
geophys. misfits: 22.6 (target 30.0 [True]); 20.1 (target 30.0 [True]) | smallness misfit: 252.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [22.6 20.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 199.7876600197346
28 1.23e+00 2.57e+01 1.98e+02 2.69e+02 1.23e+02 0 100 1.05e+00 1.60e+04
geophys. misfits: 26.4 (target 30.0 [True]); 25.4 (target 30.0 [True]) | smallness misfit: 247.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [26.4 25.4]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 231.3342428512238
29 1.23e+00 2.43e+01 2.14e+02 2.87e+02 1.24e+02 0 100 7.86e-01 1.26e+04
geophys. misfits: 26.8 (target 30.0 [True]); 23.2 (target 30.0 [True]) | smallness misfit: 215.3 (target: 200.0 [False])
Beta cooling evaluation: progress: [26.8 23.2]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 279.15635550631174
30 1.23e+00 2.79e+01 2.24e+02 3.02e+02 1.17e+02 1 100 8.10e-01 1.03e+04
geophys. misfits: 32.0 (target 30.0 [False]); 26.2 (target 30.0 [True]) | smallness misfit: 196.9 (target: 200.0 [True])
Beta cooling evaluation: progress: [32. 26.2]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by 1.1471854534146388
New scales: [0.32844448 0.67155552]
31 6.13e-01 2.14e+01 2.28e+02 1.61e+02 1.07e+02 0 100 5.79e-01 6.33e+03
geophys. misfits: 20.1 (target 30.0 [True]); 22.0 (target 30.0 [True]) | smallness misfit: 193.1 (target: 200.0 [True])
All targets have been reached
Beta cooling evaluation: progress: [20.1 22. ]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 398.95205448257377
------------------------- STOP! -------------------------
1 : |fc-fOld| = 3.9100e+00 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 4.5788e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x| = 1.0700e+02 <= tolG = 1.0000e-01
0 : |proj(x-g)-x| = 1.0700e+02 <= 1e3*eps = 1.0000e-02
0 : maxIter = 50 <= iter = 31
------------------------- DONE! -------------------------
Running inversion with SimPEG v0.25.1.dev6+gb840df108
Alpha scales: [np.float64(0.00034716457657260955), np.float64(0.0), np.float64(3.4713749844477736e-06), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers: [0.09521196 0.90478804]
<class 'simpeg.regularization.pgi.PGIsmallness'>
Initial data misfit scales: [0.09521196 0.90478804]
================================================= Projected GNCG =================================================
# beta phi_d phi_m f |proj(x-g)-x| LS iter_CG CG |Ax-b|/|b| CG |Ax-b| Comment
-----------------------------------------------------------------------------------------------------------------
0 1.96e+03 3.00e+05 0.00e+00 3.00e+05 0 inf inf
1 1.96e+03 6.63e+04 2.23e+01 1.10e+05 1.41e+02 0 15 3.15e-04 2.93e+03
geophys. misfits: 92898.5 (target 30.0 [False]); 63452.8 (target 30.0 [False]) | smallness misfit: 246.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [92898.5 63452.8]; minimum progress targets: [240000. 240000.]
2 1.96e+03 8.00e+01 5.54e-01 1.17e+03 1.33e+02 0 100 8.71e-03 2.37e+02 Skip BFGS
geophys. misfits: 609.3 (target 30.0 [False]); 24.3 (target 30.0 [True]) | smallness misfit: 120.6 (target: 200.0 [True])
Beta cooling evaluation: progress: [609.3 24.3]; minimum progress targets: [74318.8 50762.3]
Updating scaling for data misfits by 1.2345764699500932
New scales: [0.11497846 0.88502154]
3 1.96e+03 3.07e+01 1.33e-01 2.91e+02 1.16e+02 0 100 5.19e-02 1.28e+02 Skip BFGS
geophys. misfits: 101.3 (target 30.0 [False]); 21.6 (target 30.0 [True]) | smallness misfit: 64.4 (target: 200.0 [True])
Beta cooling evaluation: progress: [101.3 21.6]; minimum progress targets: [487.5 30. ]
Updating scaling for data misfits by 1.3902072357314144
New scales: [0.15298036 0.84701964]
4 1.96e+03 2.94e+01 1.29e-01 2.83e+02 9.15e+01 0 100 2.51e-02 3.58e+01
geophys. misfits: 68.9 (target 30.0 [False]); 22.2 (target 30.0 [True]) | smallness misfit: 47.6 (target: 200.0 [True])
Beta cooling evaluation: progress: [68.9 22.2]; minimum progress targets: [81.1 30. ]
Updating scaling for data misfits by 1.3486478589080517
New scales: [0.19586967 0.80413033]
5 1.96e+03 2.82e+01 1.31e-01 2.84e+02 6.97e+01 0 100 1.46e+00 1.82e+02 Skip BFGS
geophys. misfits: 51.0 (target 30.0 [False]); 22.6 (target 30.0 [True]) | smallness misfit: 58.2 (target: 200.0 [True])
Beta cooling evaluation: progress: [51. 22.6]; minimum progress targets: [55.1 30. ]
Updating scaling for data misfits by 1.3259473184816872
New scales: [0.24412702 0.75587298]
6 1.96e+03 2.77e+01 1.31e-01 2.83e+02 7.78e+01 0 100 3.36e-02 2.36e+01
geophys. misfits: 39.9 (target 30.0 [False]); 23.7 (target 30.0 [True]) | smallness misfit: 48.1 (target: 200.0 [True])
Beta cooling evaluation: progress: [39.9 23.7]; minimum progress targets: [40.8 30. ]
Updating scaling for data misfits by 1.2661300605121644
New scales: [0.29023981 0.70976019]
7 1.96e+03 2.71e+01 1.31e-01 2.84e+02 6.04e+01 0 100 6.94e+00 5.71e+02 Skip BFGS
geophys. misfits: 33.9 (target 30.0 [False]); 24.2 (target 30.0 [True]) | smallness misfit: 48.3 (target: 200.0 [True])
Beta cooling evaluation: progress: [33.9 24.2]; minimum progress targets: [31.9 30. ]
Decreasing beta to counter data misfit decrase plateau.
Updating scaling for data misfits by 1.2374201353365846
New scales: [0.33599555 0.66400445]
8 9.79e+02 2.05e+01 1.36e-01 1.53e+02 1.04e+02 0 100 1.03e+00 7.62e+02
geophys. misfits: 20.7 (target 30.0 [True]); 20.4 (target 30.0 [True]) | smallness misfit: 50.4 (target: 200.0 [True])
All targets have been reached
Beta cooling evaluation: progress: [20.7 20.4]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering: 1.4611643692901213
------------------------- STOP! -------------------------
1 : |fc-fOld| = 2.4220e+00 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 1.7437e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x| = 1.0392e+02 <= tolG = 1.0000e-01
0 : |proj(x-g)-x| = 1.0392e+02 <= 1e3*eps = 1.0000e-02
0 : maxIter = 50 <= iter = 8
------------------------- DONE! -------------------------
Running inversion with SimPEG v0.25.1.dev6+gb840df108
Alpha scales: [np.float64(3.08168781323868e-05), np.float64(0.0), np.float64(3.079804254586741e-05), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers: [0.09521196 0.90478804]
/home/vsts/work/1/s/simpeg/directives/_directives.py:334: UserWarning:
There is no PGI regularization. Smallness target is turned off (TriggerSmall flag)
Initial data misfit scales: [0.09521196 0.90478804]
================================================= Projected GNCG =================================================
# beta phi_d phi_m f |proj(x-g)-x| LS iter_CG CG |Ax-b|/|b| CG |Ax-b| Comment
-----------------------------------------------------------------------------------------------------------------
0 1.13e+06 3.00e+05 0.00e+00 3.00e+05 0 inf inf
1 1.13e+06 4.43e+04 3.91e-02 8.87e+04 1.41e+02 0 23 9.20e-04 8.56e+03
geophys. misfits: 62672.0 (target 30.0 [False]); 42403.5 (target 30.0 [False])
2 2.27e+05 4.96e+03 1.04e-01 2.85e+04 1.37e+02 0 100 9.46e-04 1.80e+01 Skip BFGS
geophys. misfits: 9520.3 (target 30.0 [False]); 4475.7 (target 30.0 [False])
3 4.54e+04 3.25e+02 1.40e-01 6.67e+03 1.31e+02 0 100 7.33e-01 4.02e+03 Skip BFGS
geophys. misfits: 659.2 (target 30.0 [False]); 289.4 (target 30.0 [False])
4 9.07e+03 3.16e+01 1.51e-01 1.40e+03 1.04e+02 0 100 1.90e-03 8.04e+00 Skip BFGS
geophys. misfits: 47.1 (target 30.0 [False]); 30.0 (target 30.0 [True])
Updating scaling for data misfits by 1.0003606446010995
New scales: [0.09524303 0.90475697]
5 1.81e+03 1.29e+01 1.55e-01 2.94e+02 7.77e+01 0 100 1.04e-02 2.74e+00 Skip BFGS
geophys. misfits: 12.5 (target 30.0 [True]); 12.9 (target 30.0 [True])
All targets have been reached
------------------------- STOP! -------------------------
1 : |fc-fOld| = 1.2043e+01 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 4.4890e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x| = 7.7742e+01 <= tolG = 1.0000e-01
0 : |proj(x-g)-x| = 7.7742e+01 <= 1e3*eps = 1.0000e-02
0 : maxIter = 50 <= iter = 5
------------------------- DONE! -------------------------
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:302: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "b.-" (-> marker='.'). The keyword argument will take precedence.
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:309: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "r.-" (-> marker='.'). The keyword argument will take precedence.
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:353: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "b.-" (-> marker='.'). The keyword argument will take precedence.
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:360: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "r.-" (-> marker='.'). The keyword argument will take precedence.
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:367: UserWarning:
The following kwargs were not used by contour: 'label'
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:412: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "b.-" (-> marker='.'). The keyword argument will take precedence.
/home/vsts/work/1/s/examples/10-pgi/plot_inv_1_PGI_Linear_1D_joint_WithRelationships.py:419: UserWarning:
marker is redundantly defined by the 'marker' keyword argument and the fmt string "r.-" (-> marker='.'). The keyword argument will take precedence.
import discretize as Mesh
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import numpy as np
from simpeg import (
data_misfit,
directives,
inverse_problem,
inversion,
maps,
optimization,
regularization,
simulation,
utils,
)
# Random seed for reproductibility
np.random.seed(1)
# Mesh
N = 100
mesh = Mesh.TensorMesh([N])
# Survey design parameters
nk = 30
jk = np.linspace(1.0, 59.0, nk)
p = -0.25
q = 0.25
# Physics
def g(k):
return np.exp(p * jk[k] * mesh.cell_centers_x) * np.cos(
np.pi * q * jk[k] * mesh.cell_centers_x
)
G = np.empty((nk, mesh.nC))
for i in range(nk):
G[i, :] = g(i)
m0 = np.zeros(mesh.nC)
m0[20:41] = np.linspace(0.0, 1.0, 21)
m0[41:57] = np.linspace(-1, 0.0, 16)
poly0 = maps.PolynomialPetroClusterMap(coeffyx=np.r_[0.0, -4.0, 4.0])
poly1 = maps.PolynomialPetroClusterMap(coeffyx=np.r_[-0.0, 3.0, 6.0, 6.0])
poly0_inverse = maps.PolynomialPetroClusterMap(coeffyx=-np.r_[0.0, -4.0, 4.0])
poly1_inverse = maps.PolynomialPetroClusterMap(coeffyx=-np.r_[0.0, 3.0, 6.0, 6.0])
cluster_mapping = [maps.IdentityMap(), poly0_inverse, poly1_inverse]
m1 = np.zeros(100)
m1[20:41] = 1.0 + (poly0 * np.vstack([m0[20:41], m1[20:41]]).T)[:, 1]
m1[41:57] = -1.0 + (poly1 * np.vstack([m0[41:57], m1[41:57]]).T)[:, 1]
model2d = np.vstack([m0, m1]).T
m = utils.mkvc(model2d)
clfmapping = utils.GaussianMixtureWithNonlinearRelationships(
mesh=mesh,
n_components=3,
covariance_type="full",
tol=1e-8,
reg_covar=1e-3,
max_iter=1000,
n_init=100,
init_params="kmeans",
random_state=None,
warm_start=False,
means_init=np.array(
[
[0, 0],
[m0[20:41].mean(), m1[20:41].mean()],
[m0[41:57].mean(), m1[41:57].mean()],
]
),
verbose=0,
verbose_interval=10,
cluster_mapping=cluster_mapping,
)
clfmapping = clfmapping.fit(model2d)
clfnomapping = utils.WeightedGaussianMixture(
mesh=mesh,
n_components=3,
covariance_type="full",
tol=1e-8,
reg_covar=1e-3,
max_iter=1000,
n_init=100,
init_params="kmeans",
random_state=None,
warm_start=False,
verbose=0,
verbose_interval=10,
)
clfnomapping = clfnomapping.fit(model2d)
wires = maps.Wires(("m1", mesh.nC), ("m2", mesh.nC))
relatrive_error = 0.01
noise_floor = 0.0
prob1 = simulation.LinearSimulation(mesh, G=G, model_map=wires.m1)
survey1 = prob1.make_synthetic_data(
m, relative_error=relatrive_error, noise_floor=noise_floor, add_noise=True
)
prob2 = simulation.LinearSimulation(mesh, G=G, model_map=wires.m2)
survey2 = prob2.make_synthetic_data(
m, relative_error=relatrive_error, noise_floor=noise_floor, add_noise=True
)
dmis1 = data_misfit.L2DataMisfit(simulation=prob1, data=survey1)
dmis2 = data_misfit.L2DataMisfit(simulation=prob2, data=survey2)
dmis = dmis1 + dmis2
minit = np.zeros_like(m)
# Distance weighting
wr1 = np.sum(prob1.G**2.0, axis=0) ** 0.5 / mesh.cell_volumes
wr1 = wr1 / np.max(wr1)
wr2 = np.sum(prob2.G**2.0, axis=0) ** 0.5 / mesh.cell_volumes
wr2 = wr2 / np.max(wr2)
reg_simple = regularization.PGI(
mesh=mesh,
gmmref=clfmapping,
gmm=clfmapping,
approx_gradient=True,
wiresmap=wires,
non_linear_relationships=True,
weights_list=[wr1, wr2],
)
opt = optimization.ProjectedGNCG(
maxIter=50,
tolX=1e-6,
cg_maxiter=100,
cg_rtol=1e-3,
lower=-10,
upper=10,
)
invProb = inverse_problem.BaseInvProblem(dmis, reg_simple, opt)
# directives
scales = directives.ScalingMultipleDataMisfits_ByEig(
chi0_ratio=np.r_[1.0, 1.0], verbose=True, n_pw_iter=10
)
scaling_schedule = directives.JointScalingSchedule(verbose=True)
alpha0_ratio = np.r_[1e6, 1e4, 1, 1]
alphas = directives.AlphasSmoothEstimate_ByEig(
alpha0_ratio=alpha0_ratio, n_pw_iter=10, verbose=True
)
beta = directives.BetaEstimate_ByEig(beta0_ratio=1e-5, n_pw_iter=10)
betaIt = directives.PGI_BetaAlphaSchedule(
verbose=True,
coolingFactor=2.0,
progress=0.2,
)
targets = directives.MultiTargetMisfits(verbose=True)
petrodir = directives.PGI_UpdateParameters(update_gmm=False)
# Setup Inversion
inv = inversion.BaseInversion(
invProb,
directiveList=[alphas, scales, beta, petrodir, targets, betaIt, scaling_schedule],
)
mcluster_map = inv.run(minit)
# Inversion with no nonlinear mapping
reg_simple_no_map = regularization.PGI(
mesh=mesh,
gmmref=clfnomapping,
gmm=clfnomapping,
approx_gradient=True,
wiresmap=wires,
non_linear_relationships=False,
weights_list=[wr1, wr2],
)
opt = optimization.ProjectedGNCG(
maxIter=50,
tolX=1e-6,
cg_maxiter=100,
cg_rtol=1e-3,
lower=-10,
upper=10,
)
invProb = inverse_problem.BaseInvProblem(dmis, reg_simple_no_map, opt)
# directives
scales = directives.ScalingMultipleDataMisfits_ByEig(
chi0_ratio=np.r_[1.0, 1.0], verbose=True, n_pw_iter=10
)
scaling_schedule = directives.JointScalingSchedule(verbose=True)
alpha0_ratio = np.r_[100.0 * np.ones(2), 1, 1]
alphas = directives.AlphasSmoothEstimate_ByEig(
alpha0_ratio=alpha0_ratio, n_pw_iter=10, verbose=True
)
beta = directives.BetaEstimate_ByEig(beta0_ratio=1e-5, n_pw_iter=10)
betaIt = directives.PGI_BetaAlphaSchedule(
verbose=True,
coolingFactor=2.0,
progress=0.2,
)
targets = directives.MultiTargetMisfits(
chiSmall=1.0, TriggerSmall=True, TriggerTheta=False, verbose=True
)
petrodir = directives.PGI_UpdateParameters(update_gmm=False)
# Setup Inversion
inv = inversion.BaseInversion(
invProb,
directiveList=[alphas, scales, beta, petrodir, targets, betaIt, scaling_schedule],
)
mcluster_no_map = inv.run(minit)
# WeightedLeastSquares Inversion
reg1 = regularization.WeightedLeastSquares(
mesh, alpha_s=1.0, alpha_x=1.0, mapping=wires.m1, weights={"cell_weights": wr1}
)
reg2 = regularization.WeightedLeastSquares(
mesh, alpha_s=1.0, alpha_x=1.0, mapping=wires.m2, weights={"cell_weights": wr2}
)
reg = reg1 + reg2
opt = optimization.ProjectedGNCG(
maxIter=50,
tolX=1e-6,
cg_maxiter=100,
cg_rtol=1e-3,
lower=-10,
upper=10,
)
invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)
# directives
alpha0_ratio = np.r_[1, 1, 1, 1]
alphas = directives.AlphasSmoothEstimate_ByEig(
alpha0_ratio=alpha0_ratio, n_pw_iter=10, verbose=True
)
scales = directives.ScalingMultipleDataMisfits_ByEig(
chi0_ratio=np.r_[1.0, 1.0], verbose=True, n_pw_iter=10
)
scaling_schedule = directives.JointScalingSchedule(verbose=True)
beta = directives.BetaEstimate_ByEig(beta0_ratio=1e-5, n_pw_iter=10)
beta_schedule = directives.BetaSchedule(coolingFactor=5.0, coolingRate=1)
targets = directives.MultiTargetMisfits(
TriggerSmall=False,
verbose=True,
)
# Setup Inversion
inv = inversion.BaseInversion(
invProb,
directiveList=[alphas, scales, beta, targets, beta_schedule, scaling_schedule],
)
mtik = inv.run(minit)
# Final Plot
fig, axes = plt.subplots(3, 4, figsize=(25, 15))
axes = axes.reshape(12)
left, width = 0.25, 0.5
bottom, height = 0.25, 0.5
right = left + width
top = bottom + height
axes[0].set_axis_off()
axes[0].text(
0.5 * (left + right),
0.5 * (bottom + top),
("Using true nonlinear\npetrophysical relationships"),
horizontalalignment="center",
verticalalignment="center",
fontsize=20,
color="black",
transform=axes[0].transAxes,
)
axes[1].plot(mesh.cell_centers_x, wires.m1 * mcluster_map, "b.-", ms=5, marker="v")
axes[1].plot(mesh.cell_centers_x, wires.m1 * m, "k--")
axes[1].set_title("Problem 1")
axes[1].legend(["Recovered Model", "True Model"], loc=1)
axes[1].set_xlabel("X")
axes[1].set_ylabel("Property 1")
axes[2].plot(mesh.cell_centers_x, wires.m2 * mcluster_map, "r.-", ms=5, marker="v")
axes[2].plot(mesh.cell_centers_x, wires.m2 * m, "k--")
axes[2].set_title("Problem 2")
axes[2].legend(["Recovered Model", "True Model"], loc=1)
axes[2].set_xlabel("X")
axes[2].set_ylabel("Property 2")
x, y = np.mgrid[-1:1:0.01, -4:2:0.01]
pos = np.empty(x.shape + (2,))
pos[:, :, 0] = x
pos[:, :, 1] = y
CS = axes[3].contour(
x,
y,
np.exp(clfmapping.score_samples(pos.reshape(-1, 2)).reshape(x.shape)),
100,
alpha=0.25,
cmap="viridis",
)
cs_proxy = mlines.Line2D([], [], label="True Petrophysical Distribution")
ps = axes[3].scatter(
wires.m1 * mcluster_map,
wires.m2 * mcluster_map,
marker="v",
label="Recovered model crossplot",
)
axes[3].set_title("Petrophysical Distribution")
axes[3].legend(handles=[cs_proxy, ps])
axes[3].set_xlabel("Property 1")
axes[3].set_ylabel("Property 2")
axes[4].set_axis_off()
axes[4].text(
0.5 * (left + right),
0.5 * (bottom + top),
("Using a pure\nGaussian distribution"),
horizontalalignment="center",
verticalalignment="center",
fontsize=20,
color="black",
transform=axes[4].transAxes,
)
axes[5].plot(mesh.cell_centers_x, wires.m1 * mcluster_no_map, "b.-", ms=5, marker="v")
axes[5].plot(mesh.cell_centers_x, wires.m1 * m, "k--")
axes[5].set_title("Problem 1")
axes[5].legend(["Recovered Model", "True Model"], loc=1)
axes[5].set_xlabel("X")
axes[5].set_ylabel("Property 1")
axes[6].plot(mesh.cell_centers_x, wires.m2 * mcluster_no_map, "r.-", ms=5, marker="v")
axes[6].plot(mesh.cell_centers_x, wires.m2 * m, "k--")
axes[6].set_title("Problem 2")
axes[6].legend(["Recovered Model", "True Model"], loc=1)
axes[6].set_xlabel("X")
axes[6].set_ylabel("Property 2")
CSF = axes[7].contour(
x,
y,
np.exp(clfmapping.score_samples(pos.reshape(-1, 2)).reshape(x.shape)),
100,
alpha=0.5,
label="True Petro. Distribution",
)
CS = axes[7].contour(
x,
y,
np.exp(clfnomapping.score_samples(pos.reshape(-1, 2)).reshape(x.shape)),
500,
cmap="viridis",
linestyles="--",
)
axes[7].scatter(
wires.m1 * mcluster_no_map,
wires.m2 * mcluster_no_map,
marker="v",
label="Recovered model crossplot",
)
cs_modeled_proxy = mlines.Line2D(
[], [], linestyle="--", label="Modeled Petro. Distribution"
)
axes[7].set_title("Petrophysical Distribution")
axes[7].legend(handles=[cs_proxy, cs_modeled_proxy, ps])
axes[7].set_xlabel("Property 1")
axes[7].set_ylabel("Property 2")
# Tikonov
axes[8].set_axis_off()
axes[8].text(
0.5 * (left + right),
0.5 * (bottom + top),
("Least-Squares\n~Using a single cluster"),
horizontalalignment="center",
verticalalignment="center",
fontsize=20,
color="black",
transform=axes[8].transAxes,
)
axes[9].plot(mesh.cell_centers_x, wires.m1 * mtik, "b.-", ms=5, marker="v")
axes[9].plot(mesh.cell_centers_x, wires.m1 * m, "k--")
axes[9].set_title("Problem 1")
axes[9].legend(["Recovered Model", "True Model"], loc=1)
axes[9].set_xlabel("X")
axes[9].set_ylabel("Property 1")
axes[10].plot(mesh.cell_centers_x, wires.m2 * mtik, "r.-", ms=5, marker="v")
axes[10].plot(mesh.cell_centers_x, wires.m2 * m, "k--")
axes[10].set_title("Problem 2")
axes[10].legend(["Recovered Model", "True Model"], loc=1)
axes[10].set_xlabel("X")
axes[10].set_ylabel("Property 2")
CS = axes[11].contour(
x,
y,
np.exp(clfmapping.score_samples(pos.reshape(-1, 2)).reshape(x.shape)),
100,
alpha=0.25,
cmap="viridis",
)
axes[11].scatter(wires.m1 * mtik, wires.m2 * mtik, marker="v")
axes[11].set_title("Petro Distribution")
axes[11].legend(handles=[cs_proxy, ps])
axes[11].set_xlabel("Property 1")
axes[11].set_ylabel("Property 2")
plt.subplots_adjust(wspace=0.3, hspace=0.3, top=0.85)
plt.show()
Total running time of the script: (0 minutes 34.161 seconds)
Estimated memory usage: 320 MB