Skip to content
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

Bounds violation error in fitmultimodel #177

Closed
luisfabib opened this issue May 17, 2021 · 1 comment · Fixed by #188
Closed

Bounds violation error in fitmultimodel #177

luisfabib opened this issue May 17, 2021 · 1 comment · Fixed by #188
Assignees
Labels
bug Something isn't working
Milestone

Comments

@luisfabib
Copy link
Collaborator

With the following MWE I get a hard to reproduce error:

import numpy as np 
import matplotlib.pyplot as plt 
import deerlab as dl

data = np.loadtxt('ground_truth_23.dat')
t = data[:,0]/1000 # ns->us
V = data[:,1]

t = dl.correctzerotime(V,t)
rmin = 1.2512846400919055
rmax = 9.59687398219514
r = np.linspace(rmin,rmax,200)

Kmodel = lambda p: dl.dipolarkernel(t,r,mod=p[0],bg=dl.bg_hom3d(t,p[1],p[0]))
fit = dl.fitmultimodel(V,Kmodel,r,dl.dd_gauss,4,lbK=[0,0],ubK=[1,500])
fit.plot()

Here is the dataset required for the example to run:
ground_truth_23.zip

and here is the error callback:

ValueError                                Traceback (most recent call last)
d:\lufa\projects\denoising\test_set_100\test_set_100\analysis_MG_denoising_data.py in 
     106 
     107 Kmodel = lambda p: dl.dipolarkernel(t,r,mod=p[0],bg=dl.bg_hom3d(t,p[1],p[0]))
---> 108 fit = dl.fitmultimodel(V,Kmodel,r,dl.dd_gauss,4,lbK=[0,0],ubK=[1,500])
     109 fit.plot()

d:\lufa\projects\deerlab\deerlab\deerlab\fitmultimodel.py in fitmultimodel(V, Kmodel, r, model, maxModels, method, lb, ub, lbK, ubK, strategy, weights, renormalize, uq, tol, maxiter)
    427         # Separable non-linear least-squares (SNLLS) fit
    428         upscale = 1e2
--> 429         fit = dl.snlls(V*upscale,Knonlin,par0,nlin_lb,nlin_ub,lin_lb,lin_ub, 
    430                         weights=weights, reg=False, nonlin_tol=tol, nonlin_maxiter=maxiter)
    431         pnonlin = fit.nonlin

d:\lufa\projects\deerlab\deerlab\deerlab\snlls.py in snlls(y, Amodel, par0, lb, ub, lbl, ubl, nnlsSolver, reg, weights, regtype, regparam, multistart, regorder, alphareopt, extrapenalty, nonlin_tol, nonlin_maxiter, lin_tol, lin_maxiter, huberparam, uq)
    459         nonlin_subset = np.arange(0,Nnonlin)
    460         lin_subset = np.arange(Nnonlin,Nnonlin+Nlin)
--> 461         paramuq_nonlin = uq_subset(paramuq,nonlin_subset,lb,ub)
    462         paramuq_lin = uq_subset(paramuq,lin_subset,lbl,ubl)
    463 

d:\lufa\projects\deerlab\deerlab\deerlab\snlls.py in uq_subset(uq_full, subset, subset_lb, subset_ub)
    511 
    512     subset_model = lambda x: x[subset]
--> 513     uq_subset = uq_full.propagate(subset_model,lbm=subset_lb, ubm=subset_ub)
    514 
    515     return uq_subset

d:\lufa\projects\deerlab\deerlab\deerlab\classes.py in propagate(self, model, lbm, ubm)
    386 
    387         # Get jacobian of model to be propagated with respect to parameters
--> 388         J = Jacobian(model,parfit,self.__lb,self.__ub)
    389 
    390         # Clip at boundaries

d:\lufa\projects\deerlab\deerlab\deerlab\utils\utils.py in Jacobian(fcn, x0, lb, ub)
    409 
    410     """
--> 411     J = opt._numdiff.approx_derivative(fcn,x0,method='2-point',bounds=(lb,ub))
    412     J = np.atleast_2d(J)
    413     return J

~\AppData\Local\Programs\Python\Python38\lib\site-packages\scipy\optimize\_numdiff.py in approx_derivative(fun, x0, method, rel_step, abs_step, f0, bounds, sparsity, as_linear_operator, args, kwargs)
    449 
    450     if np.any((x0 < lb) | (x0 > ub)):
--> 451         raise ValueError("`x0` violates bound constraints.")
    452 
    453     if as_linear_operator:

ValueError: `x0` violates bound constraints.
@luisfabib luisfabib added the bug Something isn't working label May 17, 2021
@luisfabib luisfabib added this to the 0.14.0 milestone May 17, 2021
@luisfabib luisfabib self-assigned this May 17, 2021
@luisfabib
Copy link
Collaborator Author

This is casused by a round-off error. During the Jacobian evulation for the uncertianty propagation one of the values is evaluated at x=0.9999999999999964 but its bounds are [1.0,inf] leading to x<lb and to the error by scipy.optimize._numdiff.approx_derivative

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant