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

Example code does not work #28

Closed jonathanoesterle closed 5 years ago

jonathanoesterle commented 5 years ago

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'
simetenn commented 5 years ago

Thank you for the notification! This error is caused due to an updated in the dependencies of Uncertainpy. Using an older version of Chaospy (for example version 2.3.5) should work as a temporary solution, until I get to update Uncertainpy.

simetenn commented 5 years ago

This is now fixed in the newest version (1.2.0).