Skip to content

Commit a4bc1d2

Browse files
committed
Better handling of lb and ub in UQResult
1 parent 8829acb commit a4bc1d2

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

deerlab/classes.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class UQResult:
5454
threshold : function
5555
Treshold function used for the profile method. Only available for ``type='profile'``.
5656
57+
lb : ndarray
58+
Lower bounds of the parameters.
59+
60+
ub : ndarray
61+
Upper bounds of the parameters.
62+
5763
5864
5965
"""
@@ -144,15 +150,19 @@ def __init__(self,uqtype,data=None,covmat=None,lb=None,ub=None,
144150
else:
145151
raise NameError('uqtype not found. Must be: ''moment'', ''bootstrap'' or ''void''.')
146152

153+
# Set default bounds if not provided
147154
if lb is None:
148155
lb = np.full(nParam, -np.inf)
149156

150157
if ub is None:
151158
ub = np.full(nParam, np.inf)
159+
160+
lb = np.array([(-np.inf if v is None else v) for v in lb])
161+
ub = np.array([(np.inf if v is None else v) for v in ub])
152162

153163
# Set private variables
154-
self.__lb = lb
155-
self.__ub = ub
164+
self.lb = lb
165+
self.ub = ub
156166
self.nparam = nParam
157167

158168
# Create confidence intervals structure
@@ -234,8 +244,8 @@ def join(self,*args):
234244
# Original metadata
235245
newargs.append(self.mean)
236246
newargs.append(self.covmat)
237-
newargs.append(self.__lb)
238-
newargs.append(self.__ub)
247+
newargs.append(self.lb)
248+
newargs.append(self.ub)
239249
elif self.type=='bootstrap':
240250
newargs.append(self.samples)
241251

@@ -349,8 +359,8 @@ def pardist(self,n=0):
349359
pdf = fftconvolve(pdf, kernel, mode='same')
350360

351361
# Clip the distributions outside the boundaries
352-
pdf[x < self.__lb[n]] = 0
353-
pdf[x > self.__ub[n]] = 0
362+
pdf[x < self.lb[n]] = 0
363+
pdf[x > self.ub[n]] = 0
354364

355365
# Enforce non-negativity (takes care of negative round-off errors)
356366
pdf = np.maximum(pdf,0)
@@ -469,11 +479,11 @@ def ci(self,coverage):
469479
# Compute moment-based confidence intervals
470480
# Clip at specified box boundaries
471481
standardError = norm.ppf(p)*np.sqrt(np.diag(self.covmat))
472-
confint[:,0] = np.maximum(self.__lb, self.mean.real - standardError)
473-
confint[:,1] = np.minimum(self.__ub, self.mean.real + standardError)
482+
confint[:,0] = np.maximum(self.lb, self.mean.real - standardError)
483+
confint[:,1] = np.minimum(self.ub, self.mean.real + standardError)
474484
if iscomplex:
475-
confint[:,0] = confint[:,0] + 1j*np.maximum(self.__lb, self.mean.imag - standardError)
476-
confint[:,1] = confint[:,1] + 1j*np.minimum(self.__ub, self.mean.imag + standardError)
485+
confint[:,0] = confint[:,0] + 1j*np.maximum(self.lb, self.mean.imag - standardError)
486+
confint[:,1] = confint[:,1] + 1j*np.minimum(self.ub, self.mean.imag + standardError)
477487

478488
elif self.type=='bootstrap':
479489
# Compute bootstrap-based confidence intervals
@@ -573,7 +583,7 @@ def propagate(self,model,lb=None,ub=None,samples=None):
573583
model = lambda p: np.concatenate([model_(p).real,model_(p).imag])
574584

575585
# Get jacobian of model to be propagated with respect to parameters
576-
J = Jacobian(model,parfit,self.__lb,self.__ub)
586+
J = Jacobian(model,parfit,self.lb,self.ub)
577587

578588
# Clip at boundaries
579589
modelfit = np.maximum(modelfit,lb)
@@ -635,8 +645,8 @@ def to_dict(self):
635645
'std': self.std,
636646
'covmat': self.covmat,
637647
'nparam': self.nparam,
638-
'lb': self.__lb,
639-
'ub': self.__ub
648+
'lb': self.lb,
649+
'ub': self.ub
640650
}
641651
elif self.type == 'profile':
642652
if self.__threshold_inputs is None:

0 commit comments

Comments
 (0)