-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scale invariability of pathway amplitudes and redundancy with V0 #76
Comments
We should take |
I agree with that, of course. However, that is not really the issue. Reformulating my OP in other words: the Here is proof of structural non-identifiability with a working example: import numpy as np
import deerlab as dl
import matplotlib.pyplot as plt
t = np.linspace(-0.5,5,200)
r = np.linspace(2,6,400)
P = dl.dd_gauss(r,[3,0.2])
K = dl.dipolarkernel(t,r)
S = K@P
# Parameters
V0 = 2
Lam0 = 0.6
lam1 = 0.4
# Model
Vexp = V0*(Lam0 + lam1*S)
# Map the objective function
Lam0_vec = np.linspace(0,5,200)
V0_vec = np.linspace(0,5,250)
obj = np.zeros((len(Lam0_vec),len(V0_vec)))
for i,Lam0_ in enumerate(Lam0_vec):
for j,V0_ in enumerate(V0_vec):
V = V0_*(Lam0_ + lam1*S)
obj[i,j] = np.linalg.norm(V - Vexp)**2
# Plot
plt.figure(figsize=[4,3])
cont = plt.contourf(V0_vec,Lam0_vec,np.log10(obj),29,vmin=np.min(obj),vmax=obj.min() + 2.5)
for i in range(9):
cont.collections[-i-1].remove()
plt.xlabel(r'$\Lambda_0$')
plt.ylabel(r'$V_0$')
plt.plot(Lam0,V0,'or')
clb = plt.colorbar()
clb.ax.set_ylabel('log$_{10}$(Obj.Fcn.)') where you can see that the objective function surface for both |
After some discussion and further digging this issue seems to start becoming clearer. There seems to be something fishy going on with all the normalization formalities in DeerLab. Case 1: Background and pathway amplitudes are normalizedThis is the (currently implemented) case where line 209 in B = dipolarbackground(t,pathways,B,renormalize=True,renormpaths=True) This is the case presented in the OP above. As shown above, executing the script leads to the following figure, where the redundancy problems between Case 2: Background and pathway amplitudes are not normalizedThis is the case where line 209 in B = dipolarbackground(t,pathways,B,renormalize=False,renormpaths=False) As seen from the figure obtained executing the same script again, the redundancy seems to lift, thanks to the difference in background induced by different pathway amplitudes. ConclusionThe origin of all this redundancy might indeed be all the (unnecessary) normalization steps in the different functions. In view of this, we should proceed to remove all these normalization segments to ensure this problem does not persist. |
Indeed, the So, I think the |
It looks like #99 solves some aspects of this problem. |
The issues are not closed, however. After the recent changes, when trying to fit a simple 5-pulse DEER signal via the following script import numpy as np
import matplotlib.pyplot as plt
import deerlab as dl
# %%
# Generate data
t = np.linspace(-0.1,6.5,200) # time axis, µs
r = np.linspace(1.5,6,100) # distance axis, nm
param0 = [3, 0.1, 0.2, 3.5, 0.1, 0.65, 3.8, 0.05, 0.15] # parameters for three-Gaussian model
P = dl.dd_gauss3(r,param0) # model distance distribution
B = lambda t,lam: dl.bg_hom3d(t,300,lam) # background decay
exparam = [0.6, 0.3, 0.1, 3.2] # parameters for 5pDEER experiment
pathways = dl.ex_5pdeer(exparam) # pathways information
K = dl.dipolarkernel(t,r,pathways,B)
Vexp = K@P + dl.whitegaussnoise(t,0.005,seed=1)
ex_lb = [ 0, 0, 0, max(t)/2-1] # lower bounds
ex_ub = [1, 1, 1, max(t)/2+1] # upper bounds
ex_par0 = [0.5, 0.5, 0.5, max(t)/2 ] # start values
fit = dl.fitmodel(Vexp,t,r,'P',dl.bg_hom3d,dl.ex_5pdeer,ex_par0=ex_par0,ex_lb=ex_lb,ex_ub=ex_ub,verbose=True)
fit.plot() these are the results we obtain
So this issue requires further inspection to assess the consequences of our recent changes. |
The absolute amplitudes |
In the design of DeerLab seems to be some redundancy and invariability issues related to how the dipolar pathway amplitudes are defined and handled.
Scale invariability of dipolar pathways
In experiment models (except
ex_4pdeer
) where the unmodulated contribution is parametrized (Lam0
), the absolute values of the pathway amplitudes result in a scale-invariant response in DeerLab. For example the simulations forV1
andV2
herewill result in exactly the same signal. The reason behind this is the default behavior of
dipolarkernel
, which normalizes the dipolar kernel after calculations (controlled by the optionrenormalize
). BTW there is an additional option calledrenormpaths
which has no effect on the output and will be deprecated in a future PR).As expected by setting
renormalize=False
the scale-invariability of the dipolar pathways is liftedRedundancy with V0
Setting
renormalize=False
reveals a second issue: the absolute values of the pathway amplitudes and the dipolar signals scale 'V0' become redundant. For example the simulations forV1
andV2
herethe signals are again equal. Only by reinstating the kernel normalization can these be distinguished again.
Summary
K(0,r)=1
) is required forV0
in the separationV(t)=V0*Vintra(t)*Vinter(t)
to be distinguishable.V0*(Lam0 + sum_i lam_i*Vintra_i)
exhibit scale invariability.The question now is: what is the optimal and correct way to treat this?
On one hand, pathway amplitudes are probabilistic quantities so it would make sense to think of them as being confined to a range [0,1]. On the other hand, we could imagine them relative contributions to
V0
, i.e. such that the sum over all dipolar pathways equalsV0
. This second interpretation might be more efficient due to the fact that theex_4pdeer
does not suffer from the issues described here, as the contributions are also define in a relative way.This requires further discussion.
Here is a full working example with a graphical representation of these issues:
The text was updated successfully, but these errors were encountered: