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.

Problem 1, Problem 2, Petrophysical Distribution, Problem 1, Problem 2, Petrophysical Distribution, Problem 1, Problem 2, Petro Distribution
Running inversion with SimPEG v0.26.1.dev2+g3562108fd
Alpha scales: [np.float64(3.327161705501232), np.float64(0.0), np.float64(3.3335439594155046e-06), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers:  [0.09431717 0.90568283]
<class 'simpeg.regularization.pgi.PGIsmallness'>
Initial data misfit scales:  [0.09431717 0.90568283]
================================================= Projected GNCG =================================================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS   iter_CG   CG |Ax-b|/|b|  CG |Ax-b|   Comment
-----------------------------------------------------------------------------------------------------------------
   0  2.05e+01  3.00e+05  0.00e+00  3.00e+05                         0           inf          inf
   1  2.05e+01  1.29e+03  1.69e+02  4.76e+03    1.41e+02      0      20       6.66e-04     6.20e+03
geophys. misfits: 7466.3 (target 30.0 [False]); 652.0 (target 30.0 [False]) | smallness misfit: 3968.9 (target: 200.0 [False])
Beta cooling evaluation: progress: [7466.3  652. ]; minimum progress targets: [240000. 240000.]
   2  2.05e+01  6.43e+01  3.85e+01  8.56e+02    1.39e+02      0     100       4.24e-01     2.64e+03   Skip BFGS
geophys. misfits: 499.9 (target 30.0 [False]); 19.0 (target 30.0 [True]) | smallness misfit: 1356.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [499.9  19. ]; minimum progress targets: [5973.   521.6]
Updating scaling for data misfits by  1.5803559774710303
New scales: [0.14131924 0.85868076]
   3  2.05e+01  5.63e+01  3.88e+01  8.54e+02    8.16e+01      0     100       2.45e-03     9.73e+00   Skip BFGS
geophys. misfits: 285.5 (target 30.0 [False]); 18.5 (target 30.0 [True]) | smallness misfit: 1118.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [285.5  18.5]; minimum progress targets: [399.9  30. ]
Updating scaling for data misfits by  1.6178931040854063
New scales: [0.21027791 0.78972209]
   4  2.05e+01  4.87e+01  3.99e+01  8.67e+02    7.58e+01      0     100       7.23e-03     2.29e+00
geophys. misfits: 162.0 (target 30.0 [False]); 18.5 (target 30.0 [True]) | smallness misfit: 1065.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [162.   18.5]; minimum progress targets: [228.4  30. ]
Updating scaling for data misfits by  1.6177153885132058
New scales: [0.30106403 0.69893597]
   5  2.05e+01  4.28e+01  4.06e+01  8.77e+02    7.66e+01      0     100       5.14e-01     1.53e+02   Skip BFGS
geophys. misfits: 98.0 (target 30.0 [False]); 19.0 (target 30.0 [True]) | smallness misfit: 1021.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [98. 19.]; minimum progress targets: [129.6  30. ]
Updating scaling for data misfits by  1.5806076027388878
New scales: [0.40505965 0.59494035]
   6  2.05e+01  3.85e+01  4.11e+01  8.83e+02    7.60e+01      0     100       8.04e-01     2.55e+02   Skip BFGS
geophys. misfits: 65.9 (target 30.0 [False]); 19.8 (target 30.0 [True]) | smallness misfit: 986.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [65.9 19.8]; minimum progress targets: [78.4 30. ]
Updating scaling for data misfits by  1.5123713659880702
New scales: [0.50731249 0.49268751]
   7  2.05e+01  3.57e+01  4.15e+01  8.87e+02    7.38e+01      0     100       1.09e+00     4.00e+02   Skip BFGS
geophys. misfits: 49.7 (target 30.0 [False]); 21.2 (target 30.0 [True]) | smallness misfit: 955.9 (target: 200.0 [False])
Beta cooling evaluation: progress: [49.7 21.2]; minimum progress targets: [52.7 30. ]
Updating scaling for data misfits by  1.4155081477227704
New scales: [0.59308674 0.40691326]
   8  2.05e+01  3.39e+01  4.16e+01  8.89e+02    7.09e+01      0     100       7.94e-01     3.80e+02   Skip BFGS
geophys. misfits: 41.4 (target 30.0 [False]); 22.9 (target 30.0 [True]) | smallness misfit: 929.6 (target: 200.0 [False])
Beta cooling evaluation: progress: [41.4 22.9]; minimum progress targets: [39.8 30. ]
Decreasing beta to counter data misfit decrase plateau.
Updating scaling for data misfits by  1.307450240521018
New scales: [0.6558421 0.3441579]
   9  1.03e+01  1.89e+01  4.27e+01  4.57e+02    8.62e+01      0     100       3.24e-01     1.99e+02
geophys. misfits: 19.4 (target 30.0 [True]); 17.9 (target 30.0 [True]) | smallness misfit: 962.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [19.4 17.9]; minimum progress targets: [33.1 30. ]
Warming alpha_pgi to favor clustering:  1.6105451614958417
  10  1.03e+01  1.97e+01  4.38e+01  4.70e+02    5.96e+01      0     100       5.90e-01     1.23e+02
geophys. misfits: 19.0 (target 30.0 [True]); 21.1 (target 30.0 [True]) | smallness misfit: 864.3 (target: 200.0 [False])
Beta cooling evaluation: progress: [19.  21.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  2.415798204397411
  11  1.03e+01  2.11e+01  4.52e+01  4.85e+02    6.24e+01      0     100       1.37e+00     2.03e+02
geophys. misfits: 19.0 (target 30.0 [True]); 25.3 (target 30.0 [True]) | smallness misfit: 781.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [19.  25.3]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  3.344577537809849
  12  1.03e+01  2.30e+01  4.66e+01  5.02e+02    7.67e+01      0     100       2.67e+00     5.98e+02
geophys. misfits: 19.0 (target 30.0 [True]); 30.6 (target 30.0 [False]) | smallness misfit: 709.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [19.  30.6]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by  1.5809190549653167
New scales: [0.54656793 0.45343207]
  13  5.13e+00  1.56e+01  4.77e+01  2.61e+02    9.21e+01      0     100       9.29e-01     5.06e+02
geophys. misfits: 13.7 (target 30.0 [True]); 17.8 (target 30.0 [True]) | smallness misfit: 776.6 (target: 200.0 [False])
Beta cooling evaluation: progress: [13.7 17.8]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  6.478243729691913
  14  5.13e+00  1.77e+01  5.25e+01  2.87e+02    8.60e+01      0     100       2.18e+00     1.16e+03
geophys. misfits: 14.0 (target 30.0 [True]); 22.2 (target 30.0 [True]) | smallness misfit: 641.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [14.  22.2]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  11.321943668887103
  15  5.13e+00  2.03e+01  5.87e+01  3.22e+02    9.51e+01      0     100       1.62e+00     1.92e+03
geophys. misfits: 14.9 (target 30.0 [True]); 26.8 (target 30.0 [True]) | smallness misfit: 531.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [14.9 26.8]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  17.739840284747885
  16  5.13e+00  2.65e+01  6.43e+01  3.56e+02    1.08e+02      0     100       1.40e+00     2.72e+03
geophys. misfits: 16.2 (target 30.0 [True]); 38.9 (target 30.0 [False]) | smallness misfit: 408.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [16.2 38.9]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by  1.8487554778635598
New scales: [0.39467579 0.60532421]
  17  2.57e+00  1.69e+01  6.72e+01  1.89e+02    1.01e+02      0     100       7.30e-01     1.49e+03
geophys. misfits: 13.6 (target 30.0 [True]); 19.1 (target 30.0 [True]) | smallness misfit: 432.0 (target: 200.0 [False])
Beta cooling evaluation: progress: [13.6 19.1]; minimum progress targets: [30.  31.1]
Warming alpha_pgi to favor clustering:  33.54997887770393
  18  2.57e+00  2.01e+01  8.07e+01  2.27e+02    1.00e+02      0     100       1.71e+00     2.59e+03
geophys. misfits: 15.7 (target 30.0 [True]); 23.0 (target 30.0 [True]) | smallness misfit: 331.1 (target: 200.0 [False])
Beta cooling evaluation: progress: [15.7 23. ]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  53.98493428933941
  19  2.57e+00  1.80e+01  9.64e+01  2.65e+02    1.06e+02      0     100       3.04e-01     8.00e+02
geophys. misfits: 18.0 (target 30.0 [True]); 18.0 (target 30.0 [True]) | smallness misfit: 287.5 (target: 200.0 [False])
Beta cooling evaluation: progress: [18. 18.]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  90.12784111527974
  20  2.57e+00  1.77e+01  1.21e+02  3.28e+02    1.22e+02      0     100       2.42e+00     2.64e+03
geophys. misfits: 22.2 (target 30.0 [True]); 14.7 (target 30.0 [True]) | smallness misfit: 239.2 (target: 200.0 [False])
Beta cooling evaluation: progress: [22.2 14.7]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  152.94264364227837
  21  2.57e+00  2.29e+01  1.48e+02  4.03e+02    1.30e+02      1     100       1.25e+00     3.71e+03
geophys. misfits: 25.3 (target 30.0 [True]); 21.3 (target 30.0 [True]) | smallness misfit: 220.8 (target: 200.0 [False])
Beta cooling evaluation: progress: [25.3 21.3]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  198.10652976054138
  22  2.57e+00  2.73e+01  1.68e+02  4.58e+02    1.34e+02      0     100       1.84e+00     4.47e+03
geophys. misfits: 31.9 (target 30.0 [False]); 24.2 (target 30.0 [True]) | smallness misfit: 188.1 (target: 200.0 [True])
Beta cooling evaluation: progress: [31.9 24.2]; minimum progress targets: [30. 30.]
Decreasing beta to counter data misfit increase.
Updating scaling for data misfits by  1.2382691279389555
New scales: [0.44670694 0.55329306]
  23  1.28e+00  2.79e+01  1.60e+02  2.34e+02    1.23e+02      1     100       1.05e+00     5.12e+03
geophys. misfits: 27.4 (target 30.0 [True]); 28.2 (target 30.0 [True]) | smallness misfit: 185.0 (target: 200.0 [True])
All targets have been reached
Beta cooling evaluation: progress: [27.4 28.2]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  213.58960522840803
------------------------- STOP! -------------------------
1 : |fc-fOld| = 9.3134e+00 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 5.4337e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x|    = 1.2323e+02 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 1.2323e+02 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =      50    <= iter          =     23
------------------------- DONE! -------------------------

Running inversion with SimPEG v0.26.1.dev2+g3562108fd
Alpha scales: [np.float64(0.00034666573599637736), np.float64(0.0), np.float64(3.470135979546567e-06), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers:  [0.09431717 0.90568283]
<class 'simpeg.regularization.pgi.PGIsmallness'>
Initial data misfit scales:  [0.09431717 0.90568283]
================================================= 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.98e+03  3.00e+05  0.00e+00  3.00e+05                         0           inf          inf
   1  1.98e+03  6.84e+04  2.14e+01  1.11e+05    1.41e+02      0      12       9.92e-04     9.24e+03
geophys. misfits: 96763.8 (target 30.0 [False]); 65448.5 (target 30.0 [False]) | smallness misfit: 284.7 (target: 200.0 [False])
Beta cooling evaluation: progress: [96763.8 65448.5]; minimum progress targets: [240000. 240000.]
   2  1.98e+03  7.91e+01  5.55e-01  1.18e+03    1.37e+02      0     100       1.16e-01     3.30e+03   Skip BFGS
geophys. misfits: 670.6 (target 30.0 [False]); 17.5 (target 30.0 [True]) | smallness misfit: 117.0 (target: 200.0 [True])
Beta cooling evaluation: progress: [670.6  17.5]; minimum progress targets: [77411.  52358.8]
Updating scaling for data misfits by  1.711480526709208
New scales: [0.15127098 0.84872902]
   3  1.98e+03  2.37e+01  1.39e-01  2.99e+02    1.12e+02      0     100       1.13e-02     4.85e+01   Skip BFGS
geophys. misfits: 73.6 (target 30.0 [False]); 14.8 (target 30.0 [True]) | smallness misfit: 52.9 (target: 200.0 [True])
Beta cooling evaluation: progress: [73.6 14.8]; minimum progress targets: [536.5  30. ]
Updating scaling for data misfits by  2.0269236096564427
New scales: [0.26538832 0.73461168]
   4  1.98e+03  2.03e+01  1.42e-01  3.02e+02    1.02e+02      0     100       4.55e-02     1.63e+01   Skip BFGS
geophys. misfits: 34.4 (target 30.0 [False]); 15.2 (target 30.0 [True]) | smallness misfit: 54.6 (target: 200.0 [True])
Beta cooling evaluation: progress: [34.4 15.2]; minimum progress targets: [58.9 30. ]
Updating scaling for data misfits by  1.9739268313414065
New scales: [0.41626548 0.58373452]
   5  1.98e+03  1.99e+01  1.42e-01  3.01e+02    8.80e+01      0     100       4.99e-02     1.62e+01
geophys. misfits: 22.3 (target 30.0 [True]); 18.1 (target 30.0 [True]) | smallness misfit: 54.1 (target: 200.0 [True])
All targets have been reached
Beta cooling evaluation: progress: [22.3 18.1]; minimum progress targets: [30. 30.]
Warming alpha_pgi to favor clustering:  1.500871103073776
------------------------- STOP! -------------------------
1 : |fc-fOld| = 4.6311e+00 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 1.2609e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x|    = 8.7996e+01 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 8.7996e+01 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =      50    <= iter          =      5
------------------------- DONE! -------------------------

Running inversion with SimPEG v0.26.1.dev2+g3562108fd
Alpha scales: [np.float64(3.5075776029559405e-05), np.float64(0.0), np.float64(3.5003924873987546e-05), np.float64(0.0)]
Calculating the scaling parameter.
Scale Multipliers:  [0.09431717 0.90568283]
/home/vsts/work/1/s/simpeg/directives/_directives.py:334: UserWarning: There is no PGI regularization. Smallness target is turned off (TriggerSmall flag)
  getattr(r, ruleType)()
Initial data misfit scales:  [0.09431717 0.90568283]
================================================= 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.09e+06  3.00e+05  0.00e+00  3.00e+05                         0           inf          inf
   1  1.09e+06  4.26e+04  4.07e-02  8.68e+04    1.41e+02      0      24       9.17e-04     8.54e+03
geophys. misfits: 61402.0 (target 30.0 [False]); 40588.2 (target 30.0 [False])
   2  2.17e+05  4.60e+03  1.05e-01  2.75e+04    1.37e+02      0     100       5.47e-02     1.02e+03   Skip BFGS
geophys. misfits: 9044.4 (target 30.0 [False]); 4140.2 (target 30.0 [False])
   3  4.34e+04  2.93e+02  1.40e-01  6.39e+03    1.31e+02      0     100       1.62e-02     8.71e+01   Skip BFGS
geophys. misfits: 606.9 (target 30.0 [False]); 260.0 (target 30.0 [False])
   4  8.69e+03  2.85e+01  1.51e-01  1.34e+03    1.04e+02      0     100       9.21e-01     1.12e+03   Skip BFGS
geophys. misfits: 38.5 (target 30.0 [False]); 27.4 (target 30.0 [True])
Updating scaling for data misfits by  1.0931644431262788
New scales: [0.10220609 0.89779391]
   5  1.74e+03  1.17e+01  1.54e-01  2.80e+02    9.26e+01      0     100       9.54e-01     1.08e+03   Skip BFGS
geophys. misfits: 12.0 (target 30.0 [True]); 11.6 (target 30.0 [True])
All targets have been reached
------------------------- STOP! -------------------------
1 : |fc-fOld| = 1.0953e+01 <= tolF*(1+|f0|) = 3.0000e+04
0 : |xc-x_last| = 4.2870e-01 <= tolX*(1+|x0|) = 1.0000e-06
0 : |proj(x-g)-x|    = 9.2572e+01 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 9.2572e+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.
  axes[1].plot(mesh.cell_centers_x, wires.m1 * mcluster_map, "b.-", ms=5, marker="v")
/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.
  axes[2].plot(mesh.cell_centers_x, wires.m2 * mcluster_map, "r.-", ms=5, marker="v")
/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.
  axes[5].plot(mesh.cell_centers_x, wires.m1 * mcluster_no_map, "b.-", ms=5, marker="v")
/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.
  axes[6].plot(mesh.cell_centers_x, wires.m2 * mcluster_no_map, "r.-", ms=5, marker="v")
/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.
  axes[9].plot(mesh.cell_centers_x, wires.m1 * mtik, "b.-", ms=5, marker="v")
/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.
  axes[10].plot(mesh.cell_centers_x, wires.m2 * mtik, "r.-", ms=5, marker="v")

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 24.900 seconds)

Estimated memory usage: 343 MB

Gallery generated by Sphinx-Gallery