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

chaospy.E evaluation error #436

Closed
andreapasquale94 opened this issue Dec 7, 2024 · 2 comments
Closed

chaospy.E evaluation error #436

andreapasquale94 opened this issue Dec 7, 2024 · 2 comments
Labels

Comments

@andreapasquale94
Copy link

andreapasquale94 commented Dec 7, 2024

Describe the bug
An exception is raised when calling chaospy.E based on a simple example.

To Reproduce

import chaospy

uniform = chaospy.Uniform(0, 4)
chaospy.E(uniform)

Expected behavior
Compute the expected value.

Desktop:

  • OS: Linux Mint 21.1 Cinnamon (5.6.8)
  • Python version: 3.9.19
  • Chaospy version: 4.3.17

Additional context
Stacktrace:

In [2]: uniform = chaospy.Uniform(0, 4)
   ...: chaospy.E(uniform)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 2
      1 uniform = chaospy.Uniform(0, 4)
----> 2 chaospy.E(uniform)

File ~/Documents/Codes/sirius/.venv/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 ~/Documents/Codes/sirius/.venv/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 ~/Documents/Codes/sirius/.venv/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 ~/Documents/Codes/sirius/.venv/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 ~/Documents/Codes/sirius/.venv/lib/python3.9/site-packages/chaospy/distributions/baseclass/lower_upper.py:100, in LowerUpperDistribution._mom(***failed resolving arguments***)
     98 poly = numpoly.variable(len(self))
     99 poly = numpoly.sum(scale * poly, axis=-1) + shift
--> 100 poly = numpoly.set_dimensions(numpoly.prod(poly**kloc), len(self))
    101 out = sum(
    102     dist._get_mom(key) * coeff
    103     for key, coeff in zip(poly.exponents, poly.coefficients)
    104 )
    105 return out

File ~/Documents/Codes/sirius/.venv/lib/python3.9/site-packages/numpoly/array_function/prod.py:87, in prod(a, axis, dtype, out, keepdims, **kwargs)
     84         axis = [axis]
     86 if axis is None:
---> 87     out = _prod(numpoly.reshape(a, -1), axis=0)
     89 elif isinstance(axis, int):
     90     out = _prod(a, axis=axis)

File ~/Documents/Codes/sirius/.venv/lib/python3.9/site-packages/numpoly/array_function/reshape.py:68, in reshape(a, shape, order, newshape)
     28 """
     29 Give a new shape to an array without changing its data.
     30 
   (...)
     65 
     66 """
     67 poly = numpoly.aspolynomial(a)
---> 68 array = numpy.reshape(poly.values, shape=shape, newshape=newshape, order=order)
     69 return numpoly.aspolynomial(array, names=poly.indeterminants)

TypeError: reshape() got an unexpected keyword argument 'shape'

A print-out of pip freeze:

asttokens==3.0.0
chaospy==4.3.17
decorator==5.1.1
exceptiongroup==1.2.2
executing==2.1.0
importlib_metadata==8.5.0
ipython==8.18.1
jedi==0.19.2
llvmlite==0.43.0
matplotlib-inline==0.1.7
numpoly==1.3.6
numpy==2.0.2
parso==0.8.4
pexpect==4.9.0
prompt_toolkit==3.0.48
ptyprocess==0.7.0
pure_eval==0.2.3
Pygments==2.18.0
scipy==1.13.1
stack-data==0.6.3
traitlets==5.14.3
typing_extensions==4.12.2
wcwidth==0.2.13
zipp==3.21.0
@jonathf
Copy link
Owner

jonathf commented Dec 10, 2024

Lower bound for numpy is set incorrectly. You need to update to at least 2.1.

@andreapasquale94
Copy link
Author

Thank you, that solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants