pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Stochastic Volatility model

Open jiz17043 opened this issue 2 years ago • 9 comments

When I am doing the Stochastic Volatility Model example, I had a bug as follows: image

It was at the step of executing the code of building the stochastic volatility model

stochastic_vol_model = make_stochastic_volatility_model(returns)

jiz17043 avatar May 29 '22 14:05 jiz17043

We'll need more info to help you. Which operating system? How did you install PyMC? Which version? Can you import pymc and run a simple model Form the Quickstart tutorial? What is the full error traceback?

michaelosthege avatar May 29 '22 17:05 michaelosthege

I use windows and use anaconda to install PyMC3 I could import pymc but there is an error when defining the model

ImportError                               Traceback (most recent call last)
Input In [4], in <cell line: 3>()
      1 N = len(hits)
      3 with pm.Model() as baseball_model:
----> 5     phi = pm.Uniform("phi", lower=0.0, upper=1.0)
      7     kappa_log = pm.Exponential("kappa_log", lam=1.5)
      8     kappa = pm.Deterministic("kappa", tt.exp(kappa_log))

File ~\anaconda3\envs\pymc_env\lib\site-packages\pymc3\distributions\distribution.py:124, in Distribution.__new__(cls, name, *args, **kwargs)
    122     dist = cls.dist(*args, **kwargs, shape=shape)
    123 else:
--> 124     dist = cls.dist(*args, **kwargs)
    125 return model.Var(name, dist, data, total_size, dims=dims)

File ~\anaconda3\envs\pymc_env\lib\site-packages\pymc3\distributions\distribution.py:133, in Distribution.dist(cls, *args, **kwargs)
    130 @classmethod
    131 def dist(cls, *args, **kwargs):
    132     dist = object.__new__(cls)
--> 133     dist.__init__(*args, **kwargs)
    134     return dist

File ~\anaconda3\envs\pymc_env\lib\site-packages\pymc3\distributions\continuous.py:228, in Uniform.__init__(self, lower, upper, *args, **kwargs)
    226 self.lower = lower = tt.as_tensor_variable(floatX(lower))
    227 self.upper = upper = tt.as_tensor_variable(floatX(upper))
--> 228 self.mean = (upper + lower) / 2.0
    229 self.median = self.mean
    231 super().__init__(lower=lower, upper=upper, *args, **kwargs)

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\tensor\var.py:101, in _tensor_py_operators.__add__(self, other)
     99 def __add__(self, other):
    100     try:
--> 101         return theano.tensor.basic.add(self, other)
    102     # We should catch the minimum number of exception here.
    103     # Otherwise this will convert error when Theano flags
    104     # compute_test_value is used
    105     # Evidently, we need to catch NotImplementedError
    106     # TypeError from as_tensor_variable are caught in Elemwise.make_node
    107     # Oterwise TensorVariable * SparseVariable won't work!
    108     except (NotImplementedError, TypeError):
    109         # We must return NotImplemented and not an
    110         # NotImplementedError or raise an NotImplementedError.
    111         # That way python will give a good error message like this
    112         # `TypeError: unsupported operand type(s) for +:
    113         # 'TensorVariable' and 'TensorVariable'`

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\graph\op.py:253, in Op.__call__(self, *inputs, **kwargs)
    250 node = self.make_node(*inputs, **kwargs)
    252 if config.compute_test_value != "off":
--> 253     compute_test_value(node)
    255 if self.default_output is not None:
    256     rval = node.outputs[self.default_output]

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\graph\op.py:126, in compute_test_value(node)
    123     compute_map[o] = [False]
    125 # Create a thunk that performs the computation
--> 126 thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
    127 thunk.inputs = [storage_map[v] for v in node.inputs]
    128 thunk.outputs = [storage_map[v] for v in node.outputs]

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\graph\op.py:634, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
    630 self.prepare_node(
    631     node, storage_map=storage_map, compute_map=compute_map, impl="c"
    632 )
    633 try:
--> 634     return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
    635 except (NotImplementedError, MethodNotDefined):
    636     # We requested the c code, so don't catch the error.
    637     if impl == "c":

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\graph\op.py:600, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling)
    598         print(f"Disabling C code for {self} due to unsupported float16")
    599         raise NotImplementedError("float16")
--> 600 outputs = cl.make_thunk(
    601     input_storage=node_input_storage, output_storage=node_output_storage
    602 )
    603 thunk, node_input_filters, node_output_filters = outputs
    605 def rval():

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\basic.py:1203, in CLinker.make_thunk(self, input_storage, output_storage, storage_map)
   1175 """
   1176 Compiles this linker's fgraph and returns a function to perform the
   1177 computations, as well as lists of storage cells for both the inputs
   (...)
   1200   first_output = ostor[0].data
   1201 """
   1202 init_tasks, tasks = self.get_init_tasks()
-> 1203 cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
   1204     input_storage, output_storage, storage_map
   1205 )
   1207 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
   1208 res.nodes = self.node_order

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\basic.py:1138, in CLinker.__compile__(self, input_storage, output_storage, storage_map)
   1136 input_storage = tuple(input_storage)
   1137 output_storage = tuple(output_storage)
-> 1138 thunk, module = self.cthunk_factory(
   1139     error_storage,
   1140     input_storage,
   1141     output_storage,
   1142     storage_map,
   1143 )
   1144 return (
   1145     thunk,
   1146     module,
   (...)
   1155     error_storage,
   1156 )

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\basic.py:1634, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map)
   1632     for node in self.node_order:
   1633         node.op.prepare_node(node, storage_map, None, "c")
-> 1634     module = get_module_cache().module_from_key(key=key, lnk=self)
   1636 vars = self.inputs + self.outputs + self.orphans
   1637 # List of indices that should be ignored when passing the arguments
   1638 # (basically, everything that the previous call to uniq eliminated)

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\cmodule.py:1191, in ModuleCache.module_from_key(self, key, lnk)
   1189 try:
   1190     location = dlimport_workdir(self.dirname)
-> 1191     module = lnk.compile_cmodule(location)
   1192     name = module.__file__
   1193     assert name.startswith(location)

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\basic.py:1543, in CLinker.compile_cmodule(self, location)
   1541 try:
   1542     _logger.debug(f"LOCATION {location}")
-> 1543     module = c_compiler.compile_str(
   1544         module_name=mod.code_hash,
   1545         src_code=src_code,
   1546         location=location,
   1547         include_dirs=self.header_dirs(),
   1548         lib_dirs=self.lib_dirs(),
   1549         libs=libs,
   1550         preargs=preargs,
   1551     )
   1552 except Exception as e:
   1553     e.args += (str(self.fgraph),)

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\cmodule.py:2557, in GCC_compiler.compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2555 open(os.path.join(location, "__init__.py"), "w").close()
   2556 assert os.path.isfile(lib_filename)
-> 2557 return dlimport(lib_filename)

File ~\anaconda3\envs\pymc_env\lib\site-packages\theano\link\c\cmodule.py:294, in dlimport(fullpath, suffix)
    292 with warnings.catch_warnings():
    293     warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
--> 294     rval = __import__(module_name, {}, {}, [module_name])
    295 t1 = time.time()
    296 import_time += t1 - t0

ImportError: DLL load failed while importing mf6917bb35eaa79d4a20c20b9dc13c0435e656b1bdb67265fed3d06258ff43ef9: The specified module could not be found.

jiz17043 avatar May 29 '22 21:05 jiz17043

Which PyMC version is that??

If you're working with Anaconda, it's likely that the PyMC version is outdated. Please follow the installation instructions from our wiki: https://github.com/pymc-devs/pymc/wiki/Installation-Guide-(Windows)

michaelosthege avatar May 29 '22 21:05 michaelosthege

[image: image.png] The version is 3.11.5. I have followed the guide on the wiki. But I still got the error.

On Sun, May 29, 2022 at 5:32 PM Michael Osthege @.***> wrote:

Message sent from a system outside of UConn.

Which PyMC version is that??

If you're working with Anaconda, it's likely that the PyMC version is outdated. Please follow the installation instructions from our wiki: https://github.com/pymc-devs/pymc/wiki/Installation-Guide-(Windows)

— Reply to this email directly, view it on GitHub https://github.com/pymc-devs/pymc/issues/5820#issuecomment-1140528312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQHMRW36TJE4OSFU2AVXJTVMPO63ANCNFSM5XIH5TAA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sincerely, Jintao Zhang

​Jintao Zhang, Ph.D. candidate Department of Civil & Environmental Engineering University of Connecticut, Storrs, CT 06269

He/Him/His Mobile: (858)247-8401

jiz17043 avatar May 29 '22 21:05 jiz17043

Please try with the pymc==4.0.0b6 version, or install from the main branch - this is the new version and it's almost released anyhow. There is an increasing number of installation problems with Theano.

There are multiple closed issues with the same error message: https://github.com/pymc-devs/pymc/issues?q=is%3Aissue+DLL+load+failed+is%3Aclosed

michaelosthege avatar May 31 '22 08:05 michaelosthege

Thank you. Michael. When I update to 4.0.0b6, it does not show this error message. But it shows another error message which I think it's because of the issue with the new version. The error message is displayed below: [image: image.png]

On Tue, May 31, 2022 at 4:59 AM Michael Osthege @.***> wrote:

Message sent from a system outside of UConn.

Please try with the pymc==4.0.0b6 version, or install from the main branch - this is the new version and it's almost released anyhow. There is an increasing number of installation problems with Theano.

There are multiple closed issues with the same error message: https://github.com/pymc-devs/pymc/issues?q=is%3Aissue+DLL+load+failed+is%3Aclosed

— Reply to this email directly, view it on GitHub https://github.com/pymc-devs/pymc/issues/5820#issuecomment-1141864983, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQHMRSXZTLEXTH6XAPAUTLVMXIF3ANCNFSM5XIH5TAA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sincerely, Jintao Zhang

​Jintao Zhang, Ph.D. candidate Department of Civil & Environmental Engineering University of Connecticut, Storrs, CT 06269

He/Him/His Mobile: (858)247-8401

jiz17043 avatar May 31 '22 15:05 jiz17043

@jiz17043 your image attachment to the email is not visible in GitHub

michaelosthege avatar May 31 '22 15:05 michaelosthege

Sorry, Michael, I have reattached the figure for your reference. Thank you again for your explanation. 1654011817(1)

jiz17043 avatar May 31 '22 15:05 jiz17043

Okay, I see. So first of all it's good that you got a v4 installation.

It looks like the Stochastic Volatility depends on the GaussianRandomWalk which in version 4.0.0b6 was not yet refactored. But it was migrated just recently. So tit should work with the main branch.

I'm currently re-running it with the latest main and it looks like it's sampling. If it succeeds I will open a PR over at https://github.com/pymc-devs/pymc-examples/ and ping you there.

michaelosthege avatar May 31 '22 16:05 michaelosthege