Comparing confidence intervals for regularization results

A simple example of uncertainty estimation of results obtained from dipolar signals. This example runs the analysis of a 4-pulse DEER signal and compares the uncertainty of the distance distribution between the moment-based (curvature matrix) and bootstrap methods.

By plotting the results, one can see that the bootstrapped confidence intervals are narrower in comparison to the ones obtained via the curvature matrices. This is because bootstrapping takes the nonnegativity constraint of P(r) into account, whereas the curvature matrix CIs do not.

import numpy as np
import matplotlib.pyplot as plt
import deerlab as dl
# File location
path = '../data/'
file = 'example_4pdeer_1.DTA'

# Experimental parameters
tau1 = 0.3      # First inter-pulse delay, μs
tau2 = 4.0      # Second inter-pulse delay, μs
tmin = 0.1      # Start time, μs

# Load the experimental data
t,Vexp = dl.deerload(path + file)

# Pre-processing
Vexp = dl.correctphase(Vexp) # Phase correction
Vexp = Vexp/np.max(Vexp)     # Rescaling (aesthetic)
t = t - t[0]                 # Account for zerotime
t = t + tmin

# Distance vector
r = np.arange(2,6,0.05) # nm

# Construct dipolar model
Vmodel = dl.dipolarmodel(t,r, experiment=dl.ex_4pdeer(tau1,tau2, pathways=[1]))

# Fit the model to the data using covariane-based uncertainty
results_cm = dl.fit(Vmodel,Vexp)

# Fit the model to the data using bootstrapped uncertainty
results_bs = dl.fit(Vmodel,Vexp,bootstrap=10)

# Compute the covariance-based uncertainty bands of the distance distribution
Pci50_cm = results_cm.PUncert.ci(50)
Pci95_cm = results_cm.PUncert.ci(95)

# Compute the bootstrapped uncertainty bands of the distance distribution
Pci50_bs = results_bs.PUncert.ci(50)
Pci95_bs = results_bs.PUncert.ci(95)
Bootstrap analysis with 1 cores:

  0%|          | 0/10 [00:00<?, ?it/s]
 10%|█         | 1/10 [00:09<01:21,  9.06s/it]
 20%|██        | 2/10 [00:16<01:05,  8.14s/it]
 30%|███       | 3/10 [00:23<00:53,  7.70s/it]
 40%|████      | 4/10 [00:29<00:44,  7.37s/it]
 50%|█████     | 5/10 [00:36<00:36,  7.24s/it]
 60%|██████    | 6/10 [00:43<00:29,  7.27s/it]
 70%|███████   | 7/10 [00:50<00:21,  7.16s/it]
 80%|████████  | 8/10 [00:57<00:14,  7.16s/it]
 90%|█████████ | 9/10 [01:04<00:07,  7.17s/it]
100%|██████████| 10/10 [01:12<00:00,  7.23s/it]
100%|██████████| 10/10 [01:12<00:00,  7.23s/it]
100%|██████████| 10/10 [01:12<00:00,  7.23s/it]
# Plot the results
fig, ax = plt.subplots(1,2,sharey=True)
violet = '#4550e6'

ax[0].plot(r,results_cm.P,'tab:red',linewidth=1)
ax[0].fill_between(r,Pci50_cm[:,0],Pci50_cm[:,1],color='tab:red',linestyle='None',alpha=0.45)
ax[0].fill_between(r,Pci95_cm[:,0],Pci95_cm[:,1],color='tab:red',linestyle='None',alpha=0.25)

ax[1].plot(r,results_bs.P,color=violet,linewidth=1)
ax[1].fill_between(r,Pci50_bs[:,0],Pci50_bs[:,1],color=violet,linestyle='None',alpha=0.45)
ax[1].fill_between(r,Pci95_bs[:,0],Pci95_bs[:,1],color=violet,linestyle='None',alpha=0.25)

ax[0].set_xlabel('Distance $r$ (nm)')
ax[0].set_ylabel('$P(r)$ (nm$^{-1}$)')
ax[0].set_title('Curvature Matrix CI')
ax[0].legend(['Median','50%-CI','95%-CI'],frameon=False,loc='best')

ax[1].set_xlabel('Distance $r$ (nm)')
ax[1].set_title('Bootstrapped CI')
ax[1].legend(['Median','50%-CI','95%-CI'],frameon=False,loc='best')

plt.autoscale(enable=True, axis='both', tight=True)
plt.tight_layout()
plt.show()
Curvature Matrix CI, Bootstrapped CI

Total running time of the script: (1 minutes 53.335 seconds)

Gallery generated by Sphinx-Gallery