Petrophysically guided inversion (PGI): Linear example#

We do a comparison between the classic least-squares inversion and our formulation of a petrophysically constrained inversion. We explore it through the UBC linear example.

Tikhonov Inversion##

import discretize as Mesh
import matplotlib.pyplot as plt
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 = 20
jk = np.linspace(1.0, 60.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)

# True model
mtrue = np.zeros(mesh.nC)
mtrue[mesh.cell_centers_x > 0.2] = 1.0
mtrue[mesh.cell_centers_x > 0.35] = 0.0
t = (mesh.cell_centers_x - 0.65) / 0.25
indx = np.abs(t) < 1
mtrue[indx] = -(((1 - t**2.0) ** 2.0)[indx])

mtrue = np.zeros(mesh.nC)
mtrue[mesh.cell_centers_x > 0.3] = 1.0
mtrue[mesh.cell_centers_x > 0.45] = -0.5
mtrue[mesh.cell_centers_x > 0.6] = 0

# simpeg problem and survey
prob = simulation.LinearSimulation(mesh, G=G, model_map=maps.IdentityMap())
std = 0.01
survey = prob.make_synthetic_data(mtrue, relative_error=std, add_noise=True)

# Setup the inverse problem
reg = regularization.WeightedLeastSquares(mesh, alpha_s=1.0, alpha_x=1.0)
dmis = data_misfit.L2DataMisfit(data=survey, simulation=prob)
opt = optimization.ProjectedGNCG(maxIter=10, maxIterCG=50, tolCG=1e-4)
invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)
directiveslist = [
    directives.BetaEstimate_ByEig(beta0_ratio=1e-5),
    directives.BetaSchedule(coolingFactor=10.0, coolingRate=2),
    directives.TargetMisfit(),
]

inv = inversion.BaseInversion(invProb, directiveList=directiveslist)
m0 = np.zeros_like(mtrue)

mnormal = inv.run(m0)
Running inversion with SimPEG v0.24.0
simpeg.InvProblem will set Regularization.reference_model to m0.
simpeg.InvProblem will set Regularization.reference_model to m0.
simpeg.InvProblem will set Regularization.reference_model to m0.

                    simpeg.InvProblem is setting bfgsH0 to the inverse of the eval2Deriv.
                    ***Done using the default solver Pardiso and no solver_opts.***

model has any nan: 0
=============================== Projected GNCG ===============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment
-----------------------------------------------------------------------------
x0 has any nan: 0
   0  1.81e+01  2.00e+05  0.00e+00  2.00e+05    2.52e+06      0
   1  1.81e+01  4.06e+01  4.52e+01  8.57e+02    8.74e-06      0
------------------------- STOP! -------------------------
0 : |fc-fOld| = 1.9914e+05 <= tolF*(1+|f0|) = 2.0000e+04
0 : |xc-x_last| = 3.9666e+00 <= tolX*(1+|x0|) = 1.0000e-01
1 : |proj(x-g)-x|    = 8.7369e-06 <= tolG          = 1.0000e-01
1 : |proj(x-g)-x|    = 8.7369e-06 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =      10    <= iter          =      1
------------------------- DONE! -------------------------

Petrophysically constrained inversion ##

# fit a Gaussian Mixture Model with n components
# on the true model to simulate the laboratory
# petrophysical measurements
n = 3
clf = utils.WeightedGaussianMixture(
    mesh=mesh,
    n_components=n,
    covariance_type="full",
    max_iter=100,
    n_init=3,
    reg_covar=5e-4,
)
clf.fit(mtrue.reshape(-1, 1))

# Petrophyically constrained regularization
reg = regularization.PGI(
    gmmref=clf,
    mesh=mesh,
    alpha_pgi=1.0,
    alpha_x=1.0,
)

# Optimization
opt = optimization.ProjectedGNCG(maxIter=20, maxIterCG=50, tolCG=1e-4)
opt.remember("xc")

# Setup new inverse problem
invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)

# directives
Alphas = directives.AlphasSmoothEstimate_ByEig(alpha0_ratio=10.0, verbose=True)
beta = directives.BetaEstimate_ByEig(beta0_ratio=1e-8)
betaIt = directives.PGI_BetaAlphaSchedule(
    verbose=True,
    coolingFactor=2.0,
    warmingFactor=1.0,
    tolerance=0.1,
    update_rate=1,
    progress=0.2,
)
targets = directives.MultiTargetMisfits(verbose=True)
petrodir = directives.PGI_UpdateParameters()
addmref = directives.PGI_AddMrefInSmooth(verbose=True)

# Setup Inversion
inv = inversion.BaseInversion(
    invProb, directiveList=[Alphas, beta, petrodir, targets, addmref, betaIt]
)

# Initial model same as for WeightedLeastSquares
mcluster = inv.run(m0)

# Final Plot
fig, axes = plt.subplots(1, 3, figsize=(12 * 1.2, 4 * 1.2))
for i in range(prob.G.shape[0]):
    axes[0].plot(prob.G[i, :])
axes[0].set_title("Columns of matrix G")

axes[1].hist(mtrue, bins=20, linewidth=3.0, density=True, color="k")
axes[1].set_xlabel("Model value")
axes[1].set_xlabel("Occurence")
axes[1].hist(mnormal, bins=20, density=True, color="b")
axes[1].hist(mcluster, bins=20, density=True, color="r")
axes[1].legend(["Mtrue Hist.", "L2 Model Hist.", "PGI Model Hist."])

axes[2].plot(mesh.cell_centers_x, mtrue, color="black", linewidth=3)
axes[2].plot(mesh.cell_centers_x, mnormal, color="blue")
axes[2].plot(mesh.cell_centers_x, mcluster, "r-")
axes[2].plot(mesh.cell_centers_x, invProb.reg.objfcts[0].reference_model, "r--")

axes[2].legend(("True Model", "L2 Model", "PGI Model", "Learned Mref"))
axes[2].set_ylim([-2, 2])

plt.show()
Columns of matrix G
Running inversion with SimPEG v0.24.0
simpeg.InvProblem will set Regularization.reference_model to m0.
simpeg.InvProblem will set Regularization.reference_model to m0.

                    simpeg.InvProblem is setting bfgsH0 to the inverse of the eval2Deriv.
                    ***Done using the default solver Pardiso and no solver_opts.***

Alpha scales: [np.float64(0.5139449615465257), np.float64(0.0)]
<class 'simpeg.regularization.pgi.PGIsmallness'>
model has any nan: 0
=============================== Projected GNCG ===============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment
-----------------------------------------------------------------------------
x0 has any nan: 0
   0  3.21e-02  2.00e+05  0.00e+00  2.00e+05    2.52e+06      0
geophys. misfits: 7.1 (target 20.0 [True]) | smallness misfit: 3827.8 (target: 100.0 [False])
mref changed in  24  places
Beta cooling evaluation: progress: [7.1]; minimum progress targets: [160000.]
Warming alpha_pgi to favor clustering:  2.819336279630197
   1  3.21e-02  7.09e+00  1.37e+02  1.15e+01    6.55e+00      0
geophys. misfits: 7.4 (target 20.0 [True]) | smallness misfit: 1419.3 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [7.4]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  7.615139213979227
   2  3.21e-02  7.40e+00  1.51e+02  1.23e+01    5.24e+00      0   Skip BFGS
geophys. misfits: 7.8 (target 20.0 [True]) | smallness misfit: 708.7 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [7.8]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  19.53960661650075
   3  3.21e-02  7.79e+00  2.02e+02  1.43e+01    9.33e+00      0
geophys. misfits: 8.2 (target 20.0 [True]) | smallness misfit: 391.0 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [8.2]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  47.75167345894014
   4  3.21e-02  8.18e+00  2.75e+02  1.70e+01    1.63e+01      0
geophys. misfits: 8.6 (target 20.0 [True]) | smallness misfit: 279.2 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [8.6]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  111.28011678159343
   5  3.21e-02  8.58e+00  4.19e+02  2.20e+01    3.06e+01      0
geophys. misfits: 9.1 (target 20.0 [True]) | smallness misfit: 239.3 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [9.1]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  243.80382871775754
   6  3.21e-02  9.13e+00  7.03e+02  3.17e+01    5.88e+01      0
geophys. misfits: 10.1 (target 20.0 [True]) | smallness misfit: 217.1 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [10.1]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  480.9066605977599
   7  3.21e-02  1.01e+01  1.17e+03  4.76e+01    1.00e+02      0
geophys. misfits: 11.9 (target 20.0 [True]) | smallness misfit: 200.2 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [11.9]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  805.0776898981907
   8  3.21e-02  1.19e+01  1.74e+03  6.77e+01    1.32e+02      0
geophys. misfits: 14.7 (target 20.0 [True]) | smallness misfit: 186.7 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [14.7]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1098.4620936837164
   9  3.21e-02  1.47e+01  2.18e+03  8.45e+01    1.15e+02      0
geophys. misfits: 17.4 (target 20.0 [True]) | smallness misfit: 177.6 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [17.4]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1261.5291004729493
  10  3.21e-02  1.74e+01  2.37e+03  9.34e+01    6.23e+01      0   Skip BFGS
geophys. misfits: 19.1 (target 20.0 [True]) | smallness misfit: 173.2 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [19.1]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1323.5699856695837
  11  3.21e-02  1.91e+01  2.42e+03  9.67e+01    2.34e+01      0   Skip BFGS
geophys. misfits: 19.7 (target 20.0 [True]) | smallness misfit: 171.6 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [19.7]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1343.1059933221966
  12  3.21e-02  1.97e+01  2.43e+03  9.78e+01    7.34e+00      0   Skip BFGS
geophys. misfits: 19.9 (target 20.0 [True]) | smallness misfit: 171.2 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [19.9]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1348.8511301999242
  13  3.21e-02  1.99e+01  2.44e+03  9.81e+01    2.15e+00      0   Skip BFGS
geophys. misfits: 20.0 (target 20.0 [True]) | smallness misfit: 171.0 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [20.]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1350.505547764556
  14  3.21e-02  2.00e+01  2.44e+03  9.82e+01    6.20e-01      0   Skip BFGS
geophys. misfits: 20.0 (target 20.0 [True]) | smallness misfit: 171.0 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [20.]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1350.979032278791
  15  3.21e-02  2.00e+01  2.44e+03  9.82e+01    1.77e-01      0   Skip BFGS
geophys. misfits: 20.0 (target 20.0 [True]) | smallness misfit: 171.0 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [20.]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1351.1143046333757
  16  3.21e-02  2.00e+01  2.44e+03  9.82e+01    1.43e-01      0   Skip BFGS
geophys. misfits: 20.0 (target 20.0 [True]) | smallness misfit: 171.0 (target: 100.0 [False])
mref changed in  0  places
Add mref to Smoothness. Changes in mref happened in 0.0 % of the cells
Beta cooling evaluation: progress: [20.]; minimum progress targets: [22.]
Warming alpha_pgi to favor clustering:  1351.1529310428593
  17  3.21e-02  2.00e+01  2.44e+03  9.82e+01    1.45e-02      0   Skip BFGS
------------------------- STOP! -------------------------
1 : |fc-fOld| = 2.1173e-03 <= tolF*(1+|f0|) = 2.0000e+04
1 : |xc-x_last| = 4.3065e-06 <= tolX*(1+|x0|) = 1.0000e-01
1 : |proj(x-g)-x|    = 1.4486e-02 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 1.4486e-02 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =      20    <= iter          =     17
------------------------- DONE! -------------------------

Total running time of the script: (0 minutes 11.307 seconds)

Estimated memory usage: 289 MB

Gallery generated by Sphinx-Gallery