No worries. I am attempting to create a dirichlet-arma model, as outlined here: https://arxiv.org/pdf/2303.17478v3. The details are not of super importance; basically you take compositional data; perform a log additive transform on the data, and then model the data as VAR/VARMAX etc etc.
I am currently on windows 10:
pymc 5.16.2 pypi_0 pypi
pymc-bart 0.5.14 pypi_0 pypi
pymc-experimental 0.1.1 pypi_0 pypi
numba 0.59.1 py311hf62ec03_0
numexpr 2.8.7 py311h1fcbade_0
numpy 1.25.2 py311h0b4df5a_0 conda-forge
numpydoc 1.7.0 py311haa95532_0
nutpie 0.9.1 py311h2282fe9_0 conda-forge
I have to use nutpie and resort to using a single core due to windows
Here’s my code: I’ve just attempted to pass my data into the varmax example directly; as I also am only considering normal priors on the lag coefficients for now
import numpy as np
import statsmodels.api as sm
import pandas as pd
import pymc as pm
import pytensor.tensor as pt
import arviz as az
import matplotlib.pyplot as plt
import sys
sys.path.append("..")
import pymc_experimental.statespace as pmss
import re
import math
import time
import datetime
from datetime import datetime as dt
#simulated dataframe of log additive data, data are draws from the set of real numbers
sim_data = np.array([[ 0.13524486, -1.1680408 , -0.4627132 , -1.07898902],
[ 0.13524486, -1.1680408 , -0.4627132 , -1.07898902],
[ 0.17348344, -1.13016065, -0.86557991, -0.84368122],
[ 0.17348344, -1.13016065, -0.86557991, -0.84368122],
[ 0.09825569, -1.24614773, -0.79229954, -0.90967549],
[ 0.17348344, -1.13016065, -0.86557991, -0.84368122],
[ 0.09825569, -1.24614773, -0.79229954, -0.90967549],
[ 0.19480222, -1.08613163, -0.47031765, -1.16346483],
[ 0.13983526, -1.0769267 , -0.58610174, -0.64219121],
[ 0.18496357, -1.02961942, -0.44430494, -1.18302963],
[-0.07265442, -1.67731906, -1.06149012, -1.43064501],
[-0.17185026, -1.65658469, -1.11519642, -1.16666575],
[-0.07265442, -1.67731906, -1.06149012, -1.43064501],
[ 0.18259519, -1.28785429, -0.59768774, -0.71472478],
[ 0.07878088, -1.18575916, -0.7561965 , -0.87397953],
[-0.15600425, -1.48918878, -1.11541941, -1.23405026],
[ 0.13524486, -1.1680408 , -0.4627132 , -1.07898902],
[-0.07265442, -1.67731906, -1.06149012, -1.43064501],
[ 0.37208589, -1.08731273, -0.48835277, -0.69314718],
[ 0.21577998, -1.18867311, -0.59162176, -0.9315582 ],
[ 0.13563163, -1.44615475, -0.69314718, -0.7927479 ],
[ 0.05446526, -0.98032509, -0.7411812 , -0.93307221],
[ 0.13983526, -1.0769267 , -0.58610174, -0.64219121],
[ 0.37208589, -1.08731273, -0.48835277, -0.69314718],
[-0.16154443, -1.53493539, -1.10749137, -1.21694796],
[ 0.22608521, -1.04445893, -0.33975093, -1.16807289],
[ 0.17348344, -1.13016065, -0.86557991, -0.84368122],
[ 0.26383774, -1.10663158, -0.46299946, -1.1923263 ],
[ 0.09825569, -1.24614773, -0.79229954, -0.90967549],
[ 0.21577998, -1.18867311, -0.59162176, -0.9315582 ],
[ 0.07878088, -1.18575916, -0.7561965 , -0.87397953],
[-0.1268721 , -1.57442339, -1.20918309, -1.14417826],
[ 0.22608521, -1.04445893, -0.33975093, -1.16807289],
[ 0.22608521, -1.04445893, -0.33975093, -1.16807289],
[-0.15600425, -1.48918878, -1.11541941, -1.23405026],
[ 0.11401858, -1.21097526, -0.56486303, -0.69798981],
[ 0.16717795, -1.07947295, -0.67242931, -0.85917705],
[-0.17185026, -1.65658469, -1.11519642, -1.16666575],
[ 0.11401858, -1.21097526, -0.56486303, -0.69798981],
[-0.1268721 , -1.57442339, -1.20918309, -1.14417826],
[-0.07985733, -1.89600826, -1.01438565, -1.26001949],
[ 0.13563163, -1.44615475, -0.69314718, -0.7927479 ],
[-0.16086151, -1.7266788 , -1.15322196, -1.16358474],
[ 0.22608521, -1.04445893, -0.33975093, -1.16807289],
[-0.16086151, -1.7266788 , -1.15322196, -1.16358474],
[ 0.09825569, -1.24614773, -0.79229954, -0.90967549],
[ 0.17348344, -1.13016065, -0.86557991, -0.84368122],
[ 0.18259519, -1.28785429, -0.59768774, -0.71472478],
[ 0.26383774, -1.10663158, -0.46299946, -1.1923263 ],
[ 0.26383774, -1.10663158, -0.46299946, -1.1923263 ]])
sim_data = pd.DataFrame(sim_data,columns=['series 1','series 2','series 3','series 4'])
def create_train_test(data:pd.DataFrame, prop:float):
N=data.shape[0]
N=int(round(N*prop,0))
Train = data[:N]
Test = data[N:]
return Train, Test
X_train, X_test = create_train_test(X, .85)
n_lags = 2
bvar_mod = pmss.BayesianVARMAX(
endog_names=X_train.columns,
order=(2, 0),
stationary_initialization=False,
measurement_error=False,
filter_type="standard",
verbose=True,
)
bvar_mod.param_dims.values()
bvar_mod.coords
x0_dims, P0_dims, state_cov_dims, ar_dims = bvar_mod.param_dims.values()
coords = bvar_mod.coords
ar_dims
data = X_train
with pm.Model(coords=coords) as var_mod:
x0 = pm.Normal("x0", dims=x0_dims)
P0_diag = pm.Gamma("P0_diag", alpha=2, beta=1, size=data.shape[1] * 2, dims=P0_dims[0])
P0 = pm.Deterministic("P0", pt.diag(P0_diag), dims=P0_dims)
state_chol, _, _ = pm.LKJCholeskyCov(
"state_chol", eta=1, n=bvar_mod.k_posdef, sd_dist=pm.Exponential.dist(lam=1)
)
ar_params = pm.Normal("ar_params", mu=0, sigma=1, dims=ar_dims)
state_cov = pm.Deterministic("state_cov", state_chol @ state_chol.T, dims=state_cov_dims)
bvar_mod.build_statespace_graph(data,)
idata = pm.sample(nuts_sampler="nutpie", chains=8, cores= 1, draws=500)
When I run this, the following error is passed to me; i a currently looking through numba documentation to try to understand better
The following parameters should be assigned priors inside a PyMC model block:
x0 -- shape: (8,), constraints: None, dims: ('state',)
P0 -- shape: (8, 8), constraints: Positive Semi-definite, dims: ('state', 'state_aux')
ar_params -- shape: (8, 2, 8), constraints: None, dims: ('observed_state', 'ar_lag', 'observed_state_aux')
state_cov -- shape: (4, 4), constraints: Positive Semi-definite, dims: ('shock', 'shock_aux')
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pymc_experimental\statespace\utils\data_tools.py:97: UserWarning: No frequency was specific on the data's DateTimeIndex.
warnings.warn(NO_FREQ_INFO_WARNING)
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:657: UserWarning: Numba will use object mode to allow the `compute_uv` argument to `numpy.linalg.svd`.
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:657: UserWarning: Numba will use object mode to allow the `compute_uv` argument to `numpy.linalg.svd`.
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:657: UserWarning: Numba will use object mode to allow the `compute_uv` argument to `numpy.linalg.svd`.
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\basic.py:377: UserWarning: Numba will use object mode to run AdvancedSetSubtensor's perform method
warnings.warn(
Traceback (most recent call last):
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\broth\forecasting_scorecard\untitled3.py:198
idata = pm.sample(nuts_sampler="nutpie", chains=8, cores= 1, draws=500)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\pymc\sampling\mcmc.py:725 in sample
return _sample_external_nuts(
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\pymc\sampling\mcmc.py:307 in _sample_external_nuts
compiled_model = nutpie.compile_pymc_model(model)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py:184 in compile_pymc_model
logp_numba = numba.cfunc(c_sig, **kwargs)(logp_numba_raw)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\decorators.py:279 in wrapper
res.compile()
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_lock.py:35 in _acquire_compile_lock
return func(*args, **kwargs)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\ccallback.py:68 in compile
cres = self._compile_uncached()
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\ccallback.py:82 in _compile_uncached
return self._compiler.compile(sig.args, sig.return_type)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\dispatcher.py:129 in compile
raise retval
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\dispatcher.py:139 in _compile_cached
retval = self._compile_core(args, return_type)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\dispatcher.py:152 in _compile_core
cres = compiler.compile_extra(self.targetdescr.typing_context,
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler.py:751 in compile_extra
return pipeline.compile_extra(func)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler.py:445 in compile_extra
return self._compile_bytecode()
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler.py:513 in _compile_bytecode
return self._compile_core()
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler.py:492 in _compile_core
raise e
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler.py:479 in _compile_core
pm.run(self.state)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_machinery.py:368 in run
raise patched_exception
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_machinery.py:356 in run
self._runPass(idx, pass_inst, state)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_lock.py:35 in _acquire_compile_lock
return func(*args, **kwargs)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_machinery.py:311 in _runPass
mutated |= check(pss.run_pass, internal_state)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\compiler_machinery.py:273 in check
mangled = func(compiler_state)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\typed_passes.py:112 in run_pass
typemap, return_type, calltypes, errs = type_inference_stage(
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\typed_passes.py:93 in type_inference_stage
errs = infer.propagate(raise_errors=raise_errors)
File ~\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\typeinfer.py:1091 in propagate
raise errors[0]
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function numba_funcify_Elemwise.<locals>.elemwise at 0x0000017317C1F100>) found for signature:
elemwise(float64, readonly array(float64, 0d, C), array(float64, 0d, C))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'numba_funcify_Elemwise.<locals>.ov_elemwise': File: pytensor\link\numba\dispatch\elemwise.py: Line 541.
With argument(s): '(float64, readonly array(float64, 0d, C), array(float64, 0d, C))':
Rejected as the implementation raised a specific error:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<intrinsic _vectorized>) found for signature:
_vectorized(type(CPUDispatcher(<function store_core_outputs at 0x0000017317C1DBC0>)), Literal[str](gASVBgAAAAAAAAApKSmHlC4=
), Literal[str](gASVBAAAAAAAAAAphZQu
), Literal[str](gASVDQAAAAAAAACMB2Zsb2F0NjSUhZQu
), Literal[str](gASVCQAAAAAAAABLAEsAhpSFlC4=
), Tuple(), StarArgTuple(float64, readonly array(float64, 0d, C), array(float64, 0d, C)), UniTuple(Tuple() x 1), none)
There are 2 candidate implementations:
- Of which 1 did not match due to:
Intrinsic in function '_vectorized': File: pytensor\link\numba\dispatch\vectorize_codegen.py: Line 74.
With argument(s): '(type(CPUDispatcher(<function store_core_outputs at 0x0000017317C1DBC0>)), Literal[str](gASVBgAAAAAAAAApKSmHlC4=
), Literal[str](gASVBAAAAAAAAAAphZQu
), Literal[str](gASVDQAAAAAAAACMB2Zsb2F0NjSUhZQu
), Literal[str](gASVCQAAAAAAAABLAEsAhpSFlC4=
), Tuple(), StarArgTuple(float64, readonly array(float64, 0d, C), array(float64, 0d, C)), UniTuple(Tuple() x 1), none)':
Rejected as the implementation raised a specific error:
TypingError: Vectorized inputs must be arrays.
raised from C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\vectorize_codegen.py:130
- Of which 1 did not match due to:
Intrinsic in function '_vectorized': File: pytensor\link\numba\dispatch\vectorize_codegen.py: Line 74.
With argument(s): '(type(CPUDispatcher(<function store_core_outputs at 0x0000017317C1DBC0>)), unicode_type, unicode_type, unicode_type, unicode_type, Tuple(), StarArgTuple(float64, readonly array(float64, 0d, C), array(float64, 0d, C)), UniTuple(Tuple() x 1), none)':
Rejected as the implementation raised a specific error:
TypingError: input_bc_patterns must be literal.
raised from C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\vectorize_codegen.py:100
During: resolving callee type: Function(<intrinsic _vectorized>)
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\elemwise.py (501)
File "..\Anaconda3\envs\pymc_env\Lib\site-packages\pytensor\link\numba\dispatch\elemwise.py", line 501:
def elemwise_wrapper(*inputs):
return _vectorized(
^
raised from C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\numba\core\typeinfer.py:1091
During: resolving callee type: Function(<function numba_funcify_Elemwise.<locals>.elemwise at 0x0000017317C1F100>)
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpv4jtugby (79)
File "..\AppData\Local\Temp\tmpv4jtugby", line 79:
def numba_funcified_fgraph(nominal_tensor_variable, nominal_tensor_variable_2, nominal_tensor_variable_1, nominal_tensor_variable_6, nominal_tensor_variable_3, nominal_tensor_variable_4, nominal_tensor_variable_7, nominal_tensor_variable_5):
<source elided>
# Composite{(i1 + log(i0) + i2)}(Det.0, 1.8378770664093453, dot.0)
tensor_variable_38 = elemwise_4(tensor_variable_29, tensor_constant_9, tensor_variable_33)
^
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F50900>))
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpw513poex (30)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F50900>))
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpw513poex (30)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F50900>))
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpw513poex (30)
File "..\AppData\Local\Temp\tmpw513poex", line 30:
def scan(n_steps, outer_in_1, outer_in_2, outer_in_3, outer_in_4, outer_in_5, outer_in_6, outer_in_7, outer_in_8, outer_in_9, outer_in_10, outer_in_11, outer_in_12, outer_in_13):
<source elided>
(inner_out_0, inner_out_1, inner_out_2, inner_out_3, inner_out_4, inner_out_5, inner_out_6) = scan_inner_func(np.asarray(outer_in_1[i]), np.asarray(outer_in_2[i]), np.asarray(outer_in_3[i]), np.asarray(outer_in_4_sitsot_storage[(i) % outer_in_4_len]), np.asarray(outer_in_5_sitsot_storage[(i) % outer_in_5_len]), outer_in_11, outer_in_12, outer_in_13)
^
During: resolving callee type: type(CPUDispatcher(<function scan at 0x00000173178D7420>))
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpe8q8d1_l (401)
During: resolving callee type: type(CPUDispatcher(<function scan at 0x00000173178D7420>))
During: typing of call at C:\Users\broth\AppData\Local\Temp\tmpe8q8d1_l (401)
File "..\AppData\Local\Temp\tmpe8q8d1_l", line 401:
def numba_funcified_fgraph(_unconstrained_point, data):
<source elided>
# Scan{forward_kalman_pass, while_loop=False, inplace=all}(Shape_i{0}.0, Composite{...}.0, Composite{...}.1, data, SetSubtensor{:stop}.0, SetSubtensor{:stop}.0, Composite{...}.0, Composite{...}.0, Composite{...}.0, Composite{...}.0, Shape_i{0}.0, DropDims{axis=0}.0, Composite{(0.5 * (i0 + i1))}.0, DimShuffle{order=[2,1]}.0)
tensor_variable_237, tensor_variable_238, tensor_variable_239, tensor_variable_240, tensor_variable_241, tensor_variable_242, loglike_obs = scan(tensor_variable_6, tensor_variable_7, tensor_variable_8, data, tensor_variable_222, tensor_variable_223, tensor_variable_124, tensor_variable_116, tensor_variable_108, tensor_variable_100, tensor_variable_6, tensor_variable_55, tensor_variable_225, tensor_variable_54)
^
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x0000017317F689A0>))
During: typing of call at C:\Users\broth\Anaconda3\envs\pymc_env\Lib\site-packages\nutpie\compile_pymc.py (448)