This page was generated from jupyter-notebook/nb_benchmark.ipynb. Interactive online version: Binder badge. Download notebook.

Benchmarking the different inversion methods

:cite:`1960237/TBN6W5IG`

[1]:
import sys
sys.path.append('../src')
import time
import numpy as np
import matplotlib.pyplot as plt
from emagpy import Problem

datadir = '../src/examples/'
timings = {}
[2]:
k = Problem()
k.createSurvey(datadir + 'cover-crop/coverCropTransect.csv')
k.filterRange(vmax=50)
k.show()
k.setInit(depths0=np.linspace(0.1, 2, 10))
2/30 data removed (filterRange).
../_images/gallery_nb_benchmark_2_1.png
[3]:
t0 = time.time()
k.invert(forwardModel='CSgn')
timings['CSgn'] = [time.time() - t0, np.mean(k.misfits[0])]

t0 = time.time()
k.invert(forwardModel='CS', method='L-BFGS-B', regularization='l2')
timings['CS-L-BFGS-B'] = [time.time() - t0, np.mean(k.misfits[0])]

t0 = time.time()
k.invert(forwardModel='CS', method='Gauss-Newton', regularization='l2')
timings['CS-GN'] = [time.time() - t0, np.mean(k.misfits[0])]
Survey 1/1
28/28 inverted
28/28 invertedSurvey 1/1
28/28 inverted
[9]:
k.surveys[0].df = k.surveys[0].df[:4]

t0 = time.time()
k.invert(forwardModel='FSlin', method='L-BFGS-B', regularization='l2', njobs=-1)
timings['FSlin-L-BFGS-B'] = [time.time() - t0, np.mean(k.misfits[0])]

t0 = time.time()
k.invert(forwardModel='FSlin', method='Gauss-Newton', regularization='l1')
timings['FSlin-GN'] = [time.time() - t0, np.mean(k.misfits[0])]
100%|███████████████████████████████████████████| 4/4 [00:00<00:00, 3382.50it/s]
Regularization autommatically set to L2 for Gauss-Newton
4/4 inverted
[10]:
t0 = time.time()
k.invert(forwardModel='FSeq', method='L-BFGS-B', regularization='l1', njobs=-1)
timings['FSeq-L-BFGS-B'] = [time.time() - t0, np.mean(k.misfits[0])]
100%|███████████████████████████████████████████| 4/4 [00:00<00:00, 5551.69it/s]
[11]:
t0 = time.time()
k.invert(forwardModel='FSeq', method='Gauss-Newton', regularization='l1')
timings['FSeq-GN'] = [time.time() - t0, np.mean(k.misfits[0])]
Regularization autommatically set to L2 for Gauss-Newton
4/4 inverted
[12]:
for key in timings:
    print('{:15s}: {:2.3f} s, RRMSE {:2.2f} %'.format(key, *timings[key]))
CSgn           : 0.012 s, RRMSE 9.32 %
CS-L-BFGS-B    : 0.737 s, RRMSE 8.81 %
CS-GN          : 0.006 s, RRMSE 9.32 %
FSlin-L-BFGS-B : 1.912 s, RRMSE 4.05 %
FSlin-GN       : 0.291 s, RRMSE 4.27 %
FSeq-L-BFGS-B  : 6.932 s, RRMSE 29.51 %
FSeq-GN        : 0.531 s, RRMSE 3.88 %

Timing, depends on the type of forward model, the method chosen and the number of parameters of the model (number of layers and depths).

[ ]: