simetenn / uncertainpy

Uncertainpy: a Python toolbox for uncertainty quantification and sensitivity analysis, tailored towards computational neuroscience.
http://uncertainpy.readthedocs.io
GNU General Public License v3.0
220 stars 50 forks source link

Coffe cup example #57

Closed goghino closed 3 years ago

goghino commented 3 years ago

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

goghino commented 3 years ago

I've managed to resolve the error reinstalling the numpoly dependency, it seems that chaospy 3.3.8 requires numpoly==1.0.6, but numpoly 1.2.3 is installed by default which is incompatible.

git clone https://github.com/jonathf/numpoly.git
cd numpoly/
git checkout v1.0.6
pip install .

After the update, the environment is

$ conda list -n uncertainpy
# Name                    Version                   Build  Channel
chaospy                   3.3.8                      py_0    conda-forge
numpoly                   1.0.6                    pypi_0    pypi
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