Hello, and I’m happy with the update of BART.
I currently have used the new version of BART, but I got an error.
Here is the code.
Running on arviz v0.14.0
Running on PyMC v5.0.1
Running on Numpy v1.21.6
Running on pymc_bart v0.3.0
Running on Numba v0.56.4
with pm.Model() as model_oriki:
model_params = {
"MCMC": {
"random_seed": RANDOM_SEED,
"draws": 20,
"tune": 20,
"target_accept": 0.99,
# "chains": 1,
"idata_kwargs": dict(log_likelihood=True)
}
}
# data
data_X = pm.MutableData("data_X", df_X[use_cols].values)
σ = pm.HalfCauchy("σ", beta=0.1) #beta=0.1
μ = pmb.BART("μ", data_X, df_y[target_cols[0]].values, m=30, alpha=0.75)
Ny = pm.Normal("Ny", mu=μ, sigma=σ, observed=df_y[target_cols[0]].values)
# trace = pm.sampling_jax.sample_numpyro_nuts(**model_params["MCMC"])
trace = pm.sample(**model_params["MCMC"])
And here is the error.
ValueError Traceback (most recent call last)
/usr/local/lib/python3.9/site-packages/pytensor/link/vm.py in __call__(self)
413 ):
--> 414 thunk()
415 for old_s in old_storage:
21 frames
ValueError: non-broadcastable output operand with shape (652,1) doesn't match the broadcast shape (652,652)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/local/lib/python3.9/site-packages/pymc_bart/utils.py in _sample_posterior(all_trees, X, rng, size, excluded)
48 for ind, p in enumerate(pred):
49 for tree in stacked_trees[idx[ind]]:
---> 50 p += np.array([tree.predict(x, excluded) for x in X])
51 pred.reshape((*size, shape, -1))
52 return pred
ValueError: non-broadcastable output operand with shape (652,1) doesn't match the broadcast shape (652,652)
Apply node that caused the error: BART_rv{1, (2, 1, 0, 0, 1), floatX, True}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7FCA69DFDAC0>), TensorConstant{[]}, TensorConstant{11}, data_X, TensorConstant{[0.3255892...32962963]}, TensorConstant{30}, TensorConstant{0.75}, TensorConstant{[]})
Toposort index: 1
Inputs types: [RandomGeneratorType, TensorType(int64, (0,)), TensorType(int64, ()), TensorType(float64, (?, ?)), TensorType(float64, (652,)), TensorType(int8, ()), TensorType(float32, ()), TensorType(float64, (0,))]
Inputs shapes: ['No shapes', (0,), (), (652, 19), (652,), (), (), (0,)]
Inputs strides: ['No strides', (8,), (), (8, 5216), (8,), (), (), (8,)]
Inputs values: [Generator(PCG64) at 0x7FCA69DFDAC0, array([], dtype=int64), array(11), 'not shown', 'not shown', array(30, dtype=int8), array(0.75, dtype=float32), array([], dtype=float64)]
Outputs clients: [['output'], [Elemwise{second,no_inplace}(μ, TensorConstant{(1,) of 0...5409031397})]]
HINT: Re-running with most PyTensor optimizations disabled could provide a back-trace showing when this node was created. This can be done by setting the PyTensor flag 'optimizer=fast_compile'. If that does not work, PyTensor optimizations can be disabled with 'optimizer=None'.
HINT: Use the PyTensor flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
Shape of my data is certainly (652, 19).
I have never met error like this before.
But it works fine and no error when I ran a sampling with “sampling_jax.“
(But maybe Bart doesn’t support sampling_jax yet.)
I guess I need to specify shape of these variables, but I have no idea for it.
And when I change the code of μ to not using bart such as pm.Normal, it works fine.
So, how could I solve the error?
Thanks and sorry for my poor English.