steve-the-bayesian / BOOM

A C++ library for Bayesian modeling, mainly through Markov chain Monte Carlo, but with a few other methods supported. BOOM = "Bayesian Object Oriented Modeling". It is also the sound your computer makes when it crashes.
GNU Lesser General Public License v2.1
36 stars 15 forks source link

Python: TypeError in lm_spike when initializing sampler #68

Closed edwardstm closed 1 year ago

edwardstm commented 2 years ago

When attempting to instantiate lm_spike, a TypeError occurs.

System info:

Minimal example:

import numpy as np
import pandas as pd
from BayesBoom.spikeslab import dot, lm_spike

data = pd.DataFrame(np.random.random(3000).reshape(1000,3), columns=['y', 'X1', 'X2'])
model = lm_spike(f'y ~ {dot(data)}', niter=100, data=data)

Expectation:

Actual result:

(...)/site-packages/BayesBoom/spikeslab/spikeslab.py in __init__(self, formula, niter, data, prior, ping, seed, **kwargs)
    161             prior = RegressionSpikeSlabPrior(x=X, y=y, **kwargs)
    162 
--> 163         sampler = boom.BregVsSampler(
    164             self._model,
    165             prior.slab(self._model.Sigsq_prm),

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. _boom.BregVsSampler(model: _boom.RegressionModel, slab: _boom.MvnGivenScalarSigma, residual_precision_prior: _boom.GammaModelBase, spike: _boom.VariableSelectionPrior, seeding_rng: _boom.RNG = <_boom.RNG object at 0x7f63d5604670>)

Invoked with: <_boom.RegressionModel object at 0x7f639e0bf4b0>, <_boom.MvnGivenScalarSigma object at 0x7f639e0aa930>, <_boom.ChisqModel object at 0x7f639e0b95b0>, <_boom.VariableSelectionPrior object at 0x7f639efb2770>

Aside from looking for an obvious error on my part (step 1), I have also tried simple modifications of lm_spike to isolate the issue. Notably:

The first of these confirms that the issue is specifically caused by the provided GammaModelBase (ChisqModel) instance, while the second demonstrates that it is not a unique issue affecting the chi-squared model but one which also applies to other implementations of GammaModelBase.

steve-the-bayesian commented 1 year ago

The supplied code does not generate an error as of BayesBoom.0.1.11. This looks to be fixed.