Skip to content

ValueError: bins must increase monotonically, when an array when propagating uncertainty #323

@andreaegg

Description

@andreaegg

When using the FitResult.propagate() function with a parametric model I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_12144\449243555.py in <module>
     26         Pfcn = lambda V0,sigma: mqr.rbd_gauss(V3,V0=V0,sigma=sigma)
     27         Pfit = resultlocal.evaluate(Pfcn)
---> 28         PfitUncert = resultlocal.propagate(Pfcn)
     29         Vfit = resultlocal.model
     30         VfitUncert = resultlocal.modelUncert

c:\users\andre\documents\doktorat\programs\deerlab\deerlab\model.py in propagate(model, lb, ub, *constants)
   1102         subset = [param_idx[np.where(np.asarray(_paramlist)==param)[0][0]] for param in modelparam]
   1103         # Propagate the uncertainty from that subset to the model
-> 1104         modeluq = fitresults.paramUncert.propagate(lambda param: model(*constants,*[param[s] for s in subset]),lb,ub)
   1105         return modeluq
   1106     # ----------------------------------------------------------------------------

c:\users\andre\documents\doktorat\programs\deerlab\deerlab\classes.py in propagate(self, model, lb, ub, samples)
    532 
    533             # Construct new uncertainty object
--> 534             return  UQResult('bootstrap',data=sampled_model,lb=lb,ub=ub)
    535 
    536     #--------------------------------------------------------------------------------

c:\users\andre\documents\doktorat\programs\deerlab\deerlab\classes.py in __init__(self, uqtype, data, covmat, lb, ub, threshold, profiles, noiselvl)
    170             covmat = np.squeeze(samples).T@np.squeeze(samples)/np.shape(samples)[0] - means*means.T
    171             self.mean = means
--> 172             self.median = self.percentile(50)
    173             self.median = np.array([nth_samples[0] if np.all(nth_samples==nth_samples[0]) else self.median[n] for n,nth_samples in enumerate(samples.T)])
    174             self.std = np.squeeze(np.std(samples,0))

c:\users\andre\documents\doktorat\programs\deerlab\deerlab\classes.py in percentile(self, p)
    350         for n in range(self.nparam):
    351             # Get parameter PDF
--> 352             values,pdf = self.pardist(n)
    353             # Compute corresponding CDF
    354             cdf = np.cumsum(pdf)

c:\users\andre\documents\doktorat\programs\deerlab\deerlab\classes.py in pardist(self, n)
    278                 minbin = np.minimum(np.min(samplen),np.mean(samplen)-3*sigma)
    279                 bins = np.linspace(minbin,maxbin, 2**10 + 1)
--> 280                 count, edges = np.histogram(samplen, bins=bins)
    281 
    282                 # Generate kernel

<__array_function__ internals> in histogram(*args, **kwargs)

c:\Users\andre\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\histograms.py in histogram(a, bins, range, normed, weights, density)
    791     a, weights = _ravel_and_check_weights(a, weights)
    792 
--> 793     bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
    794 
    795     # Histogram is an integer or a float array depending on the weights.

c:\Users\andre\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\histograms.py in _get_bin_edges(a, bins, range, weights)
    430         if np.any(bin_edges[:-1] > bin_edges[1:]):
    431             raise ValueError(
--> 432                 '`bins` must increase monotonically, when an array')
    433 
    434     else:

ValueError: `bins` must increase monotonically, when an array

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions