Giter VIP home page Giter VIP logo

simetenn / uncertainpy Goto Github PK

View Code? Open in Web Editor NEW
212.0 15.0 49.0 33.66 MB

Uncertainpy: a Python toolbox for uncertainty quantification and sensitivity analysis, tailored towards computational neuroscience.

Home Page: http://uncertainpy.readthedocs.io

License: GNU General Public License v3.0

Python 87.99% Shell 0.07% AMPL 1.30% C 10.65%
uncertainty-quantification sensitivity-analysis neuroscience python computational-modeling

uncertainpy's People

Contributors

coschroeder avatar lepmik avatar schmitts avatar simen-tennoee avatar simetenn avatar volpatto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uncertainpy's Issues

Univariate effects

Hi,

Thank you for developing this interesting project!
I am interested in univariate effects, which is not directly supported by uncertainpy, as far as I have observed, but is closely related to the polynomial chaos expansions.
(Please see Eq. (31) and (32) in the paper below:
https://www.sciencedirect.com/science/article/abs/pii/S0951832015003324)
Do you have an efficient way to implement this using uncertainpy or chaospy?

Thank you very much in advance.

Calculation stalls at 'Calculating Statistics from PCE'

Hello,

I am trying to conduct PCE for uncertainty quantification for a model that produces time series data. The output is 1200 data points. I am doing UQ with 11 uncertain input parameters, and so PCE requires 2732 function calls. I have taken advantage of multiprocessing and I am currently running this job utilizing all the cores of a 48 core machine. This makes the sampling relatively fast (about 5.5 hours for all the function calls) and 'Calculating PC for each feature' requires about 3 minutes.

When it comes to 'Calculating statistics from PCE' the computation appears to stall. I have not dug into the code to see how many and what operations are required during this step, so maybe this just requires a lot of time to compute, but my machine has been sitting idle for over 12 hours with this message. Is this a reasonable amount of time for this calculation?

If this is actually indicative of an error, I would recommend including a timeout and error message into the code.

Thanks.

Matplotlib dependency

Hi!

What is the rationale behind the Matplotlib version dependency (< 3.1.3 if I remember correctly)? The current version of Matplotlib is 3.3.3 and I like to use the latest versions when possible.

Number of collocation points for PCE

Hi,

I have a minor question:
You defined the number of collocation points for PCE such as:

nr_collocation_nodes = 2*len(P) + 2

then draw samples from the corresponding distribution

nodes = distribution.sample(nr_collocation_nodes, "M")

Do you arbitrary choice 2*len(P) + 2 or is it a sort of rule of thumb in the UQ literature?
Do you have some literature in your mind?

Thank you very much in advance.

Display bug

Running for: uniform 0.035
Running for Rm
Running for Epas
Running for gkdr
Running for kdrsh
Running for gahp
Running for gcat
Running for gcal
Error when running simulation:
Maximum number of clients reachedcan't open DISPLAY

UQ.Quantify fails with scipy==1.9.1

Hello, I noticed that the same script failed for two different machines, I compared libraries, found out the scipy version was different. Forced the installation of scipy 1.9.1 on the machine where it worked, and it reproduces the same error.

The part of the code that produces the error is

UQ = un.UncertaintyQuantification(model=un_model,
                                   parameters=parameters,
                                   logger_level=u'critical',
                                   logger_filename=unsaveplace+'uncertainpy.log')

undata = UQ.quantify(seed=10,
                     method='pc',
                     plot=None,
                     pc_method='collocation',
                     logger_level=u'critical',
                     figure_folder=unsaveplace+'figures',
                     data_folder=unsaveplace+'data',
                     single=False)

Displaying

File ~/anaconda3/lib/python3.9/site-packages/uncertainpy/uncertainty.py:415, in UncertaintyQuantification.quantify(self, method, pc_method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, nr_mc_samples, allow_incomplete, seed, single, plot, figure_folder, figureformat, save, data_folder, filename, **custom_kwargs)
    397         data = self.polynomial_chaos_single(uncertain_parameters=uncertain_parameters,
    398                                             method=pc_method,
    399                                             rosenblatt=rosenblatt,
   (...)
    411                                             filename=filename,
    412                                             **custom_kwargs)
    414     else:
--> 415         data = self.polynomial_chaos(uncertain_parameters=uncertain_parameters,
    416                                      method=pc_method,
    417                                      rosenblatt=rosenblatt,
    418                                      polynomial_order=polynomial_order,
    419                                      nr_collocation_nodes=nr_collocation_nodes,
    420                                      quadrature_order=quadrature_order,
    421                                      nr_pc_mc_samples=nr_pc_mc_samples,
    422                                      allow_incomplete=allow_incomplete,
    423                                      seed=seed,
    424                                      plot=plot,
    425                                      figure_folder=figure_folder,
    426                                      figureformat=figureformat,
    427                                      save=save,
    428                                      data_folder=data_folder,
    429                                      filename=filename,
    430                                      **custom_kwargs)
    432 elif method.lower() == "mc":
    433     if single:

File ~/anaconda3/lib/python3.9/site-packages/uncertainpy/uncertainty.py:702, in UncertaintyQuantification.polynomial_chaos(self, method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, allow_incomplete, seed, plot, figure_folder, figureformat, save, data_folder, filename, **custom_kwargs)
    697 if len(uncertain_parameters) > 20:
    698     raise RuntimeWarning("The number of uncertain parameters is high."
    699                          + "The Monte-Carlo method might be faster.")
--> 702 self.data = self.uncertainty_calculations.polynomial_chaos(
    703     method=method,
    704     rosenblatt=rosenblatt,
    705     uncertain_parameters=uncertain_parameters,
    706     polynomial_order=polynomial_order,
    707     nr_collocation_nodes=nr_collocation_nodes,
    708     quadrature_order=quadrature_order,
    709     nr_pc_mc_samples=nr_pc_mc_samples,
    710     allow_incomplete=allow_incomplete,
    711     seed=seed,
    712     **custom_kwargs
    713     )
    715 self.data.backend = self.backend
    717 if filename is None:

File ~/anaconda3/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py:1383, in UncertaintyCalculations.polynomial_chaos(self, method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, allow_incomplete, seed, **custom_kwargs)
   1374 # TODO add support for more methods here by using
   1375 # try:
   1376 #     getattr(self, method)
   (...)
   1379 
   1380 else:
   1381     raise ValueError("No polynomial chaos method with name {}".format(method))
-> 1383 data = self.analyse_PCE(U_hat, distribution, data, nr_samples=nr_pc_mc_samples)
   1385 data.seed = seed
   1387 return data

File ~/anaconda3/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py:1032, in UncertaintyCalculations.analyse_PCE(self, U_hat, distribution, data, nr_samples)
   1030 if feature in U_hat:
   1031     data[feature].mean = cp.E(U_hat[feature], distribution)
-> 1032     data[feature].variance = cp.Var(U_hat[feature], distribution)
   1034     samples = distribution.sample(nr_samples, "M")
   1036     if len(data.uncertain_parameters) > 1:

File ~/anaconda3/lib/python3.9/site-packages/chaospy/descriptives/variance.py:43, in Var(poly, dist, **kws)
     41 poly = poly - E(poly, dist, **kws)
     42 poly = numpoly.square(poly)
---> 43 return E(poly, dist, **kws)

File ~/anaconda3/lib/python3.9/site-packages/chaospy/descriptives/expected.py:42, in E(poly, dist, **kws)
     39 if poly.isconstant():
     40     return poly.tonumpy()
---> 42 moments = dist.mom(poly.exponents.T, **kws)
     43 if len(dist) == 1:
     44     moments = moments[0]

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py:668, in Distribution.mom(self, K, allow_approx, **kwargs)
    666 K = K.reshape(dim, size)
    667 try:
--> 668     out = [self._get_mom(kdata) for kdata in K.T]
    669     logger.debug("%s: moment calculated successfully", str(self))
    670 except chaospy.UnsupportedFeature:

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py:668, in <listcomp>(.0)
    666 K = K.reshape(dim, size)
    667 try:
--> 668     out = [self._get_mom(kdata) for kdata in K.T]
    669     logger.debug("%s: moment calculated successfully", str(self))
    670 except chaospy.UnsupportedFeature:

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py:693, in Distribution._get_mom(self, kdata)
    691     parameters = self.get_parameters(idx=None, cache={}, assert_numerical=False)
    692 assert "idx" not in parameters, (self, parameters)
--> 693 ret_val = float(self._mom(kdata, **parameters))
    694 assert not isinstance(ret_val, Distribution), (self, ret_val)
    695 self._mom_cache[tuple(kdata)] = ret_val

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/operators/joint.py:169, in J._mom(self, kloc, index)
    167 kloc = kloc[self._rotation]
    168 for unique_idx in numpy.unique(index[self._rotation]):
--> 169     output *= self._owners[unique_idx][1]._get_mom(kloc[index == unique_idx])
    170 return output

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py:693, in Distribution._get_mom(self, kdata)
    691     parameters = self.get_parameters(idx=None, cache={}, assert_numerical=False)
    692 assert "idx" not in parameters, (self, parameters)
--> 693 ret_val = float(self._mom(kdata, **parameters))
    694 assert not isinstance(ret_val, Distribution), (self, ret_val)
    695 self._mom_cache[tuple(kdata)] = ret_val

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/shift_scale.py:109, in ShiftScaleDistribution._mom(self, kloc, dist, shift, scale)
    106 poly = numpoly.sum(scale * poly, axis=-1) + shift
    107 poly = numpoly.set_dimensions(numpoly.prod(poly**kloc), len(self))
    108 out = sum(
--> 109     [
    110         dist._get_mom(key) * coeff
    111         for key, coeff in zip(poly.exponents, poly.coefficients)
    112     ]
    113 )
    114 return out

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/shift_scale.py:110, in <listcomp>(.0)
    106 poly = numpoly.sum(scale * poly, axis=-1) + shift
    107 poly = numpoly.set_dimensions(numpoly.prod(poly**kloc), len(self))
    108 out = sum(
    109     [
--> 110         dist._get_mom(key) * coeff
    111         for key, coeff in zip(poly.exponents, poly.coefficients)
    112     ]
    113 )
    114 return out

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py:693, in Distribution._get_mom(self, kdata)
    691     parameters = self.get_parameters(idx=None, cache={}, assert_numerical=False)
    692 assert "idx" not in parameters, (self, parameters)
--> 693 ret_val = float(self._mom(kdata, **parameters))
    694 assert not isinstance(ret_val, Distribution), (self, ret_val)
    695 self._mom_cache[tuple(kdata)] = ret_val

File ~/anaconda3/lib/python3.9/site-packages/chaospy/distributions/collection/trunc_normal.py:50, in trunc_normal._mom(self, n, a, b, mu, sigma)
     49 def _mom(self, n, a, b, mu, sigma):
---> 50     return truncnorm.moment(int(n), a, b, loc=mu, scale=sigma)

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_distn_infrastructure.py:1371, in rv_generic.moment(self, order, *args, **kwds)
   1369     mu, mu2, g1, g2 = self._stats(*shapes, **mdict)
   1370 val = np.empty(loc.shape)  # val needs to be indexed by loc
-> 1371 val[...] = _moment_from_stats(n, mu, mu2, g1, g2, self._munp, shapes)
   1373 # Convert to transformed  X = L + S*Y
   1374 # E[X^n] = E[(L+S*Y)^n] = L^n sum(comb(n, k)*(S/L)^k E[Y^k], k=0...n)
   1375 result = zeros(i0.shape)

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_distn_infrastructure.py:393, in _moment_from_stats(n, mu, mu2, g1, g2, moment_func, args)
    391         val = mu4+4*mu*mu3+6*mu*mu*mu2+mu*mu*mu*mu
    392 else:
--> 393     val = moment_func(n, *args)
    395 return val

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:8141, in truncnorm_gen._munp(self, n, a, b)
   8138         moments.append(mk)
   8139     return moments[-1]
-> 8141 return _lazywhere((n >= 0) & (a == a) & (b == b), (n, a, b),
   8142                   np.vectorize(n_th_moment, otypes=[np.float64]),
   8143                   np.nan)

File ~/anaconda3/lib/python3.9/site-packages/scipy/_lib/_util.py:69, in _lazywhere(cond, arrays, f, fillvalue, f2)
     67 tcode = np.mintypecode([a.dtype.char for a in arrays])
     68 out = np.full(np.shape(arrays[0]), fill_value=fillvalue, dtype=tcode)
---> 69 np.place(out, cond, f(*temp))
     70 if f2 is not None:
     71     temp = tuple(np.extract(~cond, arr) for arr in arrays)

File ~/anaconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2163, in vectorize.__call__(self, *args, **kwargs)
   2160     vargs = [args[_i] for _i in inds]
   2161     vargs.extend([kwargs[_n] for _n in names])
-> 2163 return self._vectorize_call(func=func, args=vargs)

File ~/anaconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2246, in vectorize._vectorize_call(self, func, args)
   2243 # Convert args to object arrays first
   2244 inputs = [asanyarray(a, dtype=object) for a in args]
-> 2246 outputs = ufunc(*inputs)
   2248 if ufunc.nout == 1:
   2249     res = asanyarray(outputs, dtype=otypes[0])

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:8127, in truncnorm_gen._munp.<locals>.n_th_moment(n, a, b)
   8122 def n_th_moment(n, a, b):
   8123     """
   8124     Returns n-th moment. Defined only if n >= 0.
   8125     Function cannot broadcast due to the loop over n
   8126     """
-> 8127     pA, pB = self._pdf([a, b], a, b)
   8128     probs = [pA, -pB]
   8129     moments = [0, 1]

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:8047, in truncnorm_gen._pdf(self, x, a, b)
   8046 def _pdf(self, x, a, b):
-> 8047     return np.exp(self._logpdf(x, a, b))

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:8050, in truncnorm_gen._logpdf(self, x, a, b)
   8049 def _logpdf(self, x, a, b):
-> 8050     return _norm_logpdf(x) - _log_gauss_mass(a, b)

File ~/anaconda3/lib/python3.9/site-packages/scipy/stats/_continuous_distns.py:271, in _norm_logpdf(x)
    270 def _norm_logpdf(x):
--> 271     return -x**2 / 2.0 - _norm_pdf_logC

TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'

Could it be done so it is compatible with newer versions of scipy?

Cheers,
Pablo

Difficult during installation

Hi, i'm trying to install uncertainpy through pip. I think there are some problems with the dependency with matplotlib, I'm now using matplotlib 3.4.2 with python 3.9. During the installation process appears this error message "ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/cv/lqg257bn5l73k6zmpsjcrc8r0000gn/T/pip-install-efp71dav/matplotlib_00e40e036c024ec7813df13681fb71df/setup.py'"'"'; file='"'"'/private/var/folders/cv/lqg257bn5l73k6zmpsjcrc8r0000gn/T/pip-install-efp71dav/matplotlib_00e40e036c024ec7813df13681fb71df/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/cv/lqg257bn5l73k6zmpsjcrc8r0000gn/T/pip-record-6vfmmri0/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/matplotlib
cwd: /private/var/folders/cv/lqg257bn5l73k6zmpsjcrc8r0000gn/T/pip-install-efp71dav/matplotlib_00e40e036c024ec7813df13681fb71df/"

Did someone have this problem too?

Can I use Uncertainpy to interpret results in a cluster analysis?

Hi all,

I read the description of Uncertainpy and made me wonder how this analysis can be applied on the outcome of a cluster analysis.

For input, I have a matrix N x D (where N is the number of observations and D is the number of features) and usually N >> D.

Then, Self-Organizing Maps is used to generate a cluster structure from the input data . The output consists of:

  • Each row of the matrix N x D is assigned to a specific neuron value (1, 2, 33, or any other nominal value)
  • Each neuron is composed of a weight vector, representing the cluster center

I am interested in using Uncertainpy to understand the sensitivity and uncertainty of the classification output with respect to input features.

The input features can not be sampled using a predefined model (e.g., uniform). But rather, I will randomly sample the matrix N X D to extract evaluation data points.

I went to check SALib package, and they suggested me to use the Delta method which fits better my approach.

I noticed that Uncertainty makes use of Sobol analysis from SALib. I would like to know how feasible is to replace Sobol analysis by Delta one? The Delta analysis provides the following outputs: Delta index and its confidence value, and Sobol first index and its confidence value.

Another question is. Can Uncertainty be applied to this type of scenario?

Many thanks for your advice,
Ivan

isnan for empty entries in a spike train

Spike train [[19.700000000000003, 22.0, 24.7, 28.200000000000003, 30.500000000000004, 32.4, 34.2, 36.1, 38.0, 49.9], [12.5, 14.8, 17.5, 21.0, 23.1, 25.7, 27.6, 29.5, 31.400000000000002, 47.300000000000004, 48.9], [15.5, 17.9, 20.6, 24.0, 30.3], [], [], [28.200000000000003, 30.500000000000004, 33.2, 36.7, 42.800000000000004], [8.1, 10.200000000000001, 12.0, 13.7, 15.4, 17.6, 19.5, 21.400000000000002, 23.700000000000003, 26.3, 29.400000000000002, 33.9, 36.2, 38.3, 40.199999999999996, 42.1], [20.3, 22.3, 24.099999999999998, 25.8, 27.6, 29.5, 31.400000000000002, 39.199999999999996, 41.5, 43.4, 45.3, 47.199999999999996, 49.2], [13.5, 15.8, 18.6, 22.1], [8.1, 10.100000000000001, 12.0, 13.7, 15.4, 17.6, 19.5, 21.400000000000002, 23.700000000000003, 26.3, 29.400000000000002, 33.9, 36.2, 38.3, 40.199999999999996, 42.1], [], [25.7, 28.0, 30.7, 34.2, 40.400000000000006], [7.800000000000001, 10.0, 11.9, 13.600000000000001, 19.3, 34.9, 37.1, 39.300000000000004, 41.2, 43.1, 45.00000000000001, 46.8, 48.6], [20.0, 22.1, 24.0, 26.0, 28.200000000000003, 30.0, 31.900000000000006, 33.800000000000004, 35.6, 41.6, 43.9, 46.3, 49.1], [7.5, 9.9, 11.799999999999999, 13.9, 16.400000000000002, 19.200000000000003, 23.0], [28.5, 30.6, 32.5, 34.5, 36.7, 38.5, 40.699999999999996, 42.9, 44.8, 47.199999999999996, 49.800000000000004]]
Running model: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [02:07<00:00, 5.81s/it]
ERROR Brian 2 encountered an unexpected error. If you think this is bug in Brian 2, please report this issue either to the mailing list at http://groups.google.com/group/brian-development/, or to the issue tracker at https://github.com/brian-team/brian2/issues. Please include this file with debug information in your report: /tmp/brian_debug_sRAD4V.log Additionally, you can also include a copy of the script that was run, available at: /tmp/brian_script_LTQpab.py Thanks! [brian2]
Traceback (most recent call last):
File "ntwk_sim_demo_un_NetworkFeatures.py", line 307, in
data = UQ.quantify()
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/uncertainty.py", line 372, in quantify
**custom_kwargs)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/uncertainty.py", line 636, in polynomial_chaos
**custom_kwargs
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/uncertainty_calculations.py", line 1219, in polynomial_chaos
allow_incomplete=allow_incomplete)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/uncertainty_calculations.py", line 518, in create_PCE_collocation
data = self.runmodel.run(nodes, uncertain_parameters)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/run_model.py", line 498, in run
data = self.results_to_data(results)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/run_model.py", line 221, in results_to_data
results = self.regularize_nan_results(results)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/run_model.py", line 590, in regularize_nan_results
results = regularize(results, "values")
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/uncertainpy/core/run_model.py", line 577, in regularize
if not np.all(np.isnan(values)):
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Add option to enable multiple model outputs

Add an option in Model that enables multiple model outputs. Would look something like Model(nr_model_outputs=3), with default option of 1 model output.

Need to figure out how to represent multiple model outputs, as well as add checks in all methods that directly parse the model output.

The current workaround is to use several features, as described in #23.

Chaospy issue

Dear developers,

First of all, thank you for this package which seems very interesting.

I am contacting you because I have an issue during the installation of the package about the dependency with Chaospy.
I used this command line to install the package :

pip install uncertainpy[all]

Normally every dependencies are well installed but this is the raised error when I try to import the package :

ImportError                               Traceback (most recent call last)
<ipython-input-2-dab34869d730> in <module>
----> 1 import uncertainpy as un
      2 import chaospy as cp

~/anaconda3/lib/python3.8/site-packages/uncertainpy/__init__.py in <module>
     24 
     25 from .data import Data, DataFeature
---> 26 from .distribution import uniform, normal
     27 from .parameters import Parameter, Parameters
     28 from .uncertainty import UncertaintyQuantification

~/anaconda3/lib/python3.8/site-packages/uncertainpy/distribution.py in <module>
      1 from __future__ import absolute_import, division, print_function, unicode_literals
      2 
----> 3 import chaospy as cp
      4 
      5 """

~/anaconda3/lib/python3.8/site-packages/chaospy/__init__.py in <module>
     12 
     13 import chaospy.chol
---> 14 import chaospy.descriptives
     15 import chaospy.distributions
     16 import chaospy.orthogonal

~/anaconda3/lib/python3.8/site-packages/chaospy/descriptives/__init__.py in <module>
     36 """
     37 from .expected import E
---> 38 from .conditional import E_cond
     39 from .covariance import Cov
     40 from .kurtosis import Kurt

~/anaconda3/lib/python3.8/site-packages/chaospy/descriptives/conditional.py in <module>
      6 
      7 from .expected import E
----> 8 from .. import distributions
      9 
     10 

~/anaconda3/lib/python3.8/site-packages/chaospy/distributions/__init__.py in <module>
     67 """
     68 from . import baseclass
---> 69 from .baseclass import Dist
     70 
     71 from .sampler import *
ImportError: cannot import name 'Dist' from 'chaospy.distributions.baseclass' (/home/ggirier/anaconda3/lib/python3.8/site-packages/chaospy/distributions/baseclass/__init__.py)

I have check on internet, and I didn't find any solution which works.

Have you already had this issue? If yes, how can I solve it?

Thank you very much,

Respectfully,

GIRIER Guillaume.

error: fit_regression() got an unexpected keyword argument 'rule'

Hi,

After the installation in python (using anaconda in Ubuntu), the running for the "coffee_cup" or other example cases shows the same error: fit_regression() got an unexpected keyword argument 'rule'.

I don't know if it is because of wrong installation or other reasons. Thanks for your help.

Parameters class using 'distribution=' parameter results in an error

Hi, I am trying to run the coffee cup example with dependant variables. I am passing the dependant distribution to the Uncertainpy as Parameters(distribution=joint_mvNorm), which later fails with an error. I am using the following code:

#!/usr/bin/env python
# coding: utf-8

import uncertainpy as un
import chaospy as cp
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def coffee_cup_dependent(T_env, alpha):
    # Initial temperature and time
    time = np.linspace(0, 200, 150)            # Minutes
    T_0 = 95                                   # Celsius

    # The equation describing the model
    def f(T, time, alpha, T_env):
        return -alpha*(T - T_env)

    # Solving the equation by integration.
    temperature = odeint(f, T_0, time, args=(alpha, T_env))[:, 0]

    # Return time and model results
    return time, temperature


model = un.Model(run=coffee_cup_dependent, labels=["Time (min)", "Temperature (C)"])


#alpha, T_env
mean_param = [0.2, 20]
cov_param = [[0.0005, 0.01], [0.01, 1.5]]
joint_mvNorm = cp.MvNormal(mean_param, cov_param)

parameters = un.Parameters(distribution=joint_mvNorm)


# Set up the uncertainty quantification
UQ = un.UncertaintyQuantification(model=model, parameters=parameters)


# Perform the uncertainty quantification using polynomial chaos with point collocation (by default)
data = UQ.quantify(method="pc",
                 pc_method="collocation",
                 rosenblatt=True,
                 uncertain_parameters=None,
                 polynomial_order=4,
                 nr_collocation_nodes=None,
                 quadrature_order=None,
                 nr_pc_mc_samples=10**4,
                 nr_mc_samples=10**4,
                 allow_incomplete=False,
                 seed=None,
                 single=False,
                 plot="condensed_first",
                 figure_folder="figures",
                 figureformat=".png",
                 save=True,
                 data_folder="data",
                 filename=None,)

Running the script above produces an error:

Traceback (most recent call last):
  File "coffee_cup_dep_ucpy.py", line 92, in <module>
    data = UQ.quantify(method="pc",
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/uncertainty.py", line 415, in quantify
    data = self.polynomial_chaos(uncertain_parameters=uncertain_parameters,
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/uncertainty.py", line 702, in polynomial_chaos
    self.data = self.uncertainty_calculations.polynomial_chaos(
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py", line 1345, in polynomial_chaos
    self.create_PCE_collocation_rosenblatt(uncertain_parameters=uncertain_parameters,
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py", line 925, in create_PCE_collocation_rosenblatt
    dist_R = cp.J(*dist_R)
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/chaospy/distributions/operators/joint.py", line 54, in __init__
    super(J, self).__init__(
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/chaospy/distributions/baseclass/distribution.py", line 73, in __init__
    assert min(rotation) == 0
ValueError: min() arg is an empty sequence

My environment:

conda create --name uncertainpy
conda activate uncertainpy
conda install pip
pip install uncertainpy
conda list -n uncertainpy
# packages in environment:
#
# Name                    Version                   Build  Channel
chaospy                   4.3.3                    pypi_0    pypi
numpoly                   1.2.3                    pypi_0    pypi
uncertainpy               1.2.3                    pypi_0    pypi
...

Enable continuing UQ and SA after loading model results

Enable continuing UQ and SA after loading model results from file.
This require the following additional information to be saved:

  • Parameters for each model evaluation
  • Method, with all parameters used (make machine readable unlike the current method string)
  • info dictionary
  • Model information (such as model.ignore)
  • Feature information

The confidence level

Hi,
Is the 'prediction interval' same as 'confidence level' ? If yes, then is there a way to set it to 95% (k~2) ?
Thanks,
Piotr

Uncertainpy model run in hpc clusters

Hi,
The uncertainpy calculation quickly goes out of control with increasing no. of uncertain parameters mainly in terms of memory requirement for any personal machines. I could be wrong but don't think the multiprocessing module is suitable for distributed computing? I was thinking about taking a pass at run_model.py to configure the map function to accept parallelization frameworks such ipyparallel or mpi4py? Are there obvious issues in doing that?

Thanks

Not computed features

Although spike trains are filled, I get the following warnings:

WARNING - Feature: mean_cv only yields results for 0/10 parameter combinations.
WARNING - Uncertainty quantification is not performed for feature: mean_cv due too not all parameter combinations giving a result. Set allow_incomplete=True to calculate the uncertainties anyway.
WARNING - Feature: corrcoef only yields results for 0/10 parameter combinations.
WARNING - Uncertainty quantification is not performed for feature: corrcoef due too not all parameter combinations giving a result. Set allow_incomplete=True to calculate the uncertainties anyway.
WARNING - Feature: cv only yields results for 0/10 parameter combinations.

so, some features are not computed at all

use bayesian calibration and then apply uncertainpy to do a GSA?

Dear Uncertainpy developers,

I am calibrating a glacier model with a Bayesian inference model, i.e. I assume prior distributions for two free parameters and incorporate uncertainties of the observations that are used for calibration. So, after calibration I get posterior distributions of the two parameters and I can use those to estimate uncertainties of the model output. I would like to assess the influence of the individual parameters on the total uncertainty. So, I thought that a Global Sensitivity Analysis after the Bayesian calibration (on the posterior distribution) could give me some quantitative estimates (more detailed infos are here) . Did you try out something similar to that by chance? I was thinking about combining the Bayesian calibration (using the PyMC3 package) with uncertainpy? Would it be a possible way that I use the posterior distributions of the parameters from the Bayesian calibration as input parameters (e.g. just by prescribing mean and std) and then do the sensitivity analysis with uncertainpy?

If you don't know if this can be done / is possible, no problem. I just thought that you might know an answer to that.

Greetings,
Lilian

Models support **kwargs

Models should support using **kwargs to set default values given to the run function.

Example

NeuronModel(.., **kwargs)

Which then call something similar to

NeuronModel.run(**parameters, **kwargs)

load pandas dataframe or csv

Hi,
do you have an advice how to load a pandas dataframe or a csv file?

data = un.Data()
data.load("filename")
variance = data["nr_spikes"].variance

I actually would like to use uncertainpy mainly for post-processing.
Thank you!

AttributeError: 'MultiprocessLoggingHandler'

I have installed with pip the version 1.1.0 of uncertainpy. I use Windows 10 and Python 3.6. When I tried the package I got the following error:

RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\gu\AppData\Local\Continuum\anaconda3\envs\uncertainty\lib\logging\__init__.py", line 1945, in shutdown
    h.close()
  File "C:\Users\gu\AppData\Local\Continuum\anaconda3\envs\uncertainty\lib\site-packages\uncertainpy\utils\logger.py", line 141, in close
    if not self.is_closed:
AttributeError: 'MultiprocessLoggingHandler' object has no attribute 'is_closed'

@simetenn Do you have any idea what's wrong?

AttributeError: module 'numpoly' has no attribute 'variable for the coffe cup example

Hello
I used chaospy in order to perform sensitivity analsises some time ago and want now to continue this work but get the following error. In order to exclude the error in my program I tried the example https://uncertainpy.readthedocs.io/en/latest/examples/coffee_cup.html
On Fedora 33 with chaospy-4.2.5, and Python 3.8.7
And get the same error

Traceback (most recent call last):
File "test_chaospy.py", line 40, in
data = UQ.quantify(seed=10)
File "/usr/local/lib/python3.8/site-packages/uncertainpy/uncertainty.py", line 415, in quantify
data = self.polynomial_chaos(uncertain_parameters=uncertain_parameters,
File "/usr/local/lib/python3.8/site-packages/uncertainpy/uncertainty.py", line 702, in polynomial_chaos
self.data = self.uncertainty_calculations.polynomial_chaos(
File "/usr/local/lib/python3.8/site-packages/uncertainpy/core/uncertainty_calculations.py", line 1351, in polynomial_chaos
self.create_PCE_collocation(uncertain_parameters=uncertain_parameters,
File "/usr/local/lib/python3.8/site-packages/uncertainpy/core/uncertainty_calculations.py", line 621, in create_PCE_collocation
P = cp.orth_ttr(polynomial_order, distribution)
File "/usr/local/lib/python3.8/site-packages/chaospy-4.2.5-py3.8.egg/chaospy/orthogonal/three_terms_recurrence.py", line 111, in orth_ttr
_, polynomials, norms, = chaospy.stieltjes(numpy.max(order), dist)
File "/usr/local/lib/python3.8/site-packages/chaospy-4.2.5-py3.8.egg/chaospy/recurrence/stieltjes.py", line 68, in stieltjes
return analytical_stieltjes(order=order, dist=dist)
File "/usr/local/lib/python3.8/site-packages/chaospy-4.2.5-py3.8.egg/chaospy/recurrence/stieltjes.py", line 165, in analytical_stieltjes
var = numpoly.variable(dimensions)
AttributeError: module 'numpoly' has no attribute 'variable'

I will be very pleased to recieve help since I need chaospy for my research.
Greets Momme

Memory Error

At the stage of "Calculating statistics from PCE:" I get a MemoryError, even though I specially extended swap by 8Gb, thus I suppose some very heavy operations are being performed. The network of spiking neurons and simulation times were relatively low (100 neurons, 1000 time steps).

File "ntwk_sim_demo_un_NetworkFeatures.py", line 314, in
data = UQ.quantify(save=False)
File "/home/maciek/anaconda3/envs/HH_MF/src/uncertainpy-master/src/uncertainpy/uncertainty.py", line 372, in quantify
**custom_kwargs)
File "/home/maciek/anaconda3/envs/HH_MF/src/uncertainpy-master/src/uncertainpy/uncertainty.py", line 636, in polynomial_chaos
**custom_kwargs
File "/home/maciek/anaconda3/envs/HH_MF/src/uncertainpy-master/src/uncertainpy/core/uncertainty_calculations.py", line 1248, in polynomial_chaos
data = self.analyse_PCE(U_hat, distribution, data, nr_samples=nr_pc_mc_samples)
File "/home/maciek/anaconda3/envs/HH_MF/src/uncertainpy-master/src/uncertainpy/core/uncertainty_calculations.py", line 924, in analyse_PCE
U_mc[feature] = U_hatfeature
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/chaospy/poly/base.py", line 160, in call
return chaospy.poly.caller.call(self, args)
File "/home/maciek/anaconda3/envs/HH_MF/lib/python2.7/site-packages/chaospy/poly/caller.py", line 69, in call
val = np.where(val != val, 0, val)
MemoryError

Example code does not work

Hi,

I thought this might be interesting for you.
I haven't spent any time on solving the problem, but
Apparently, fhe following code (from the examples) does not work:

import uncertainpy as un
import chaospy as cp                       # To create distributions
import numpy as np                         # For the time array
from scipy.integrate import odeint         # To integrate our equation


# Create the coffee cup model function
def coffee_cup(kappa, T_env):
    # Initial temperature and time array
    time = np.linspace(0, 200, 150)            # Minutes
    T_0 = 95                                   # Celsius

    # The equation describing the model
    def f(T, time, kappa, T_env):
        return -kappa*(T - T_env)

    # Solving the equation by integration
    temperature = odeint(f, T_0, time, args=(kappa, T_env))[:, 0]

    # Return time and model output
    return time, temperature


# Create a model from the coffee_cup function and add labels
model = un.Model(run=coffee_cup, labels=["Time (min)", "Temperature (C)"])

# Create the distributions
kappa_dist = cp.Uniform(0.025, 0.075)
T_env_dist = cp.Uniform(15, 25)

# Define the parameter dictionary
parameters = {"kappa": kappa_dist, "T_env": T_env_dist}

# Set up the uncertainty quantification
UQ = un.UncertaintyQuantification(model=model, parameters=parameters)

# Perform the uncertainty quantification using
# polynomial chaos with point collocation (by default)
# We set the seed to easier be able to reproduce the result
data = UQ.quantify(seed=10)

I get the following error:

AttributeErrorTraceback (most recent call last)
<ipython-input-2-817cc5caf2a1> in <module>()
     38 # polynomial chaos with point collocation (by default)
     39 # We set the seed to easier be able to reproduce the result
---> 40 data = UQ.quantify(seed=10)

/usr/local/lib/python3.5/dist-packages/uncertainpy/uncertainty.py in quantify(self, method, pc_method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, nr_mc_samples, allow_incomplete, seed, single, plot, figure_folder, figureformat, save, data_folder, filename, **custom_kwargs)
    426                                              data_folder=data_folder,
    427                                              filename=filename,
--> 428                                              **custom_kwargs)
    429 
    430         elif method.lower() == "mc":

/usr/local/lib/python3.5/dist-packages/uncertainpy/uncertainty.py in polynomial_chaos(self, method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, allow_incomplete, seed, plot, figure_folder, figureformat, save, data_folder, filename, **custom_kwargs)
    708             allow_incomplete=allow_incomplete,
    709             seed=seed,
--> 710             **custom_kwargs
    711             )
    712 

/usr/local/lib/python3.5/dist-packages/uncertainpy/core/uncertainty_calculations.py in polynomial_chaos(self, method, rosenblatt, uncertain_parameters, polynomial_order, nr_collocation_nodes, quadrature_order, nr_pc_mc_samples, allow_incomplete, seed, **custom_kwargs)
   1309 
   1310         if rosenblatt == "auto":
-> 1311             if distribution.dependent():
   1312                 rosenblatt = True
   1313             else:

AttributeError: 'J' object has no attribute 'dependent'

Coffe cup example

I have a following setup

conda create --name uncertainpy
conda activate uncertainpy
conda install -c conda-forge uncertainpy

which results in the following environment

$ conda list -n uncertainpy
# Name                    Version                   Build  Channel
chaospy                   3.3.8                      py_0    conda-forge
numpoly                   1.2.3              pyhd8ed1ab_0    conda-forge
numpy                     1.21.2           py39h7eed0ac_0    conda-forge
python                    3.9.6           hd187cdc_1_cpython    conda-forge
uncertainpy               1.2.2              pyh9f0ad1d_0    conda-forge
...

Running the coffe cup example results in an error

Running model: 100%|█████████████████████████████████████████████| 32/32 [00:00<00:00, 120808.04it/s]
Calculating PC for each feature: 100%|█████████████████████████████████| 1/1 [00:00<00:00, 81.68it/s]
Calculating statistics from PCE:   0%|                                         | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/Users/Juraj/Documents/DXT/uncertainpy/examples/coffee_cup/main.py", line 40, in <module>
    data = UQ.quantify(seed=10)
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/uncertainty.py", line 415, in quantify
    data = self.polynomial_chaos(uncertain_parameters=uncertain_parameters,
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/uncertainty.py", line 702, in polynomial_chaos
    self.data = self.uncertainty_calculations.polynomial_chaos(
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py", line 1384, in polynomial_chaos
    data = self.analyse_PCE(U_hat, distribution, data, nr_samples=nr_pc_mc_samples)
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/uncertainpy/core/uncertainty_calculations.py", line 1032, in analyse_PCE
    data[feature].mean = cp.E(U_hat[feature], distribution)
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/chaospy/descriptives/expected.py", line 48, in E
    out += poly[key]*moments[idx]
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/numpoly/baseclass.py", line 627, in __getitem__
    coefficients=[coeff[index] for coeff in self.coefficients],
  File "/Users/Juraj/anaconda3/envs/uncertainpy/lib/python3.9/site-packages/numpoly/baseclass.py", line 627, in <listcomp>
    coefficients=[coeff[index] for coeff in self.coefficients],
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Any idea what's the problem? I've seen similar problems with the example in #48 or #28

Switch CI provider away from travis

With the changes to travis the CI have to be anyway. Instead of moving to the new travis the CI should probably be moved to another provider such as CircleCI or Github actions.

Add uncertainpy to Open Neuroscience

Hello!

We are reaching out because we would love to have your project listed on Open Neuroscience, and also share information about this project:

Open Neuroscience is a community run project, where we are curating and highlighting open source projects related to neurosciences!

Briefly, we have a website where short descritptions about projects are listed, with links to the projects themselves, their authors, together with images and other links.

Once a new entry is made, we make a quick check for spam, and publish it.

Once published, we make people aware of the new entry by Twitter and a Facebook group.

To add information about their project, developers only need to fill out this form

In the form, people can add subfields and tags to their entries, so that projects are filterable and searchable on the website!

The reason why we have the form system is that it makes it open for everyone to contribute to the website and allows developers themselves to describe their projects!

Also, there are so many amazing projects coming out in Neurosciences that it would be impossible for us to keep track and log them all!

Open Neuroscience tech stack leverages open source tools as much as possible:

  • The website is based on HUGO + Academic Theme
  • Everything is hosted on github here
  • We use plausible.io to see visit stats on the website. It respects visitors privacy, doesn't install cookies on your computer
    • You can check our visitor stats here

Please get in touch if you have any questions or would like to collaborate!

Error module 'chaospy' has no attribute '__version__'

The call quantify(seed=10, CPUs=None, filename=save_path) causes the error
File "/usr/local/lib/python3.7/site-packages/uncertainpy-1.2.1-py3.7.egg/uncertainpy/uncertainty.py", line 430, in quantify
File "/usr/local/lib/python3.7/site-packages/uncertainpy-1.2.1-py3.7.egg/uncertainpy/uncertainty.py", line 712, in polynomial_chaos
File "/usr/local/lib/python3.7/site-packages/uncertainpy-1.2.1-py3.7.egg/uncertainpy/core/uncertainty_calculations.py", line 1340, in polynomial_chaos
File "/usr/local/lib/python3.7/site-packages/uncertainpy-1.2.1-py3.7.egg/uncertainpy/core/uncertainty_calculations.py", line 253, in dependent
AttributeError: module 'chaospy' has no attribute 'version'

OS is Fedora 31

"lv" feature doesn't work for NetworkFeatures

AttributeError: ("'NetworkFeatures' object has no attribute 'lv'", 'Error in calculation of feature: lv')

with the following constructor:
features=un.NetworkFeatures(features_to_run=["mean_firing_rate", "mean_isi", "cv", "mean_cv", "fanofactor", "lv", "mean_lv", "binned_isi", "corrcoef", "covariance"])

same thing happens for the mean_lv feature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.