Skip to content

Commit

Permalink
Do not use deprecated ConstantData, MutableData, and `coords_muta…
Browse files Browse the repository at this point in the history
…ble`

* Also don't specify `mutable = True` in `add_data_to_active_model`
  • Loading branch information
jessegrabowski authored and ricardoV94 committed Apr 16, 2024
1 parent f191993 commit a05001b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pymc_experimental/linearmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def build_model(self, X: pd.DataFrame, y: pd.Series):

# Data array size can change but number of dimensions must stay the same.
with pm.Model() as self.model:
x = pm.MutableData("x", np.zeros((1,)), dims="observation")
y_data = pm.MutableData("y_data", np.zeros((1,)), dims="observation")
x = pm.Data("x", np.zeros((1,)), dims="observation")
y_data = pm.Data("y_data", np.zeros((1,)), dims="observation")

# priors
intercept = pm.Normal(
Expand Down
6 changes: 3 additions & 3 deletions pymc_experimental/statespace/core/statespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _print_data_requirements(self) -> None:
out = out.rstrip()

_log.info(
"The following MutableData variables should be assigned to the model inside a PyMC "
"The following Data variables should be assigned to the model inside a PyMC "
f"model block: \n"
f"{out}"
)
Expand Down Expand Up @@ -366,7 +366,7 @@ def param_info(self) -> dict[str, dict[str, Any]]:
@property
def data_info(self) -> dict[str, dict[str, Any]]:
"""
Information about MutableData variables that need to be declared in the PyMC model block.
Information about Data variables that need to be declared in the PyMC model block.
Returns a dictionary of data_name: dictionary of property-name:property description pairs. The return value is
used by the ``_print_data_requirements`` method, to print a message telling users how to define the necessary
Expand Down Expand Up @@ -877,7 +877,7 @@ def build_statespace_graph(
or a Pytensor tensor variable.
register_data : bool, optional, default=True
If True, the observed data will be registered with PyMC as a pm.MutableData variable. In addition,
If True, the observed data will be registered with PyMC as a pm.Data variable. In addition,
a "time" dim will be created an added to the model's coords.
mode : Optional[str], optional, default=None
Expand Down
4 changes: 2 additions & 2 deletions pymc_experimental/statespace/utils/data_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def add_data_to_active_model(values, index):
if OBS_STATE_DIM in pymc_mod.coords:
data_dims = [TIME_DIM, OBS_STATE_DIM]

pymc_mod.add_coord(TIME_DIM, index, mutable=True)
data = pm.ConstantData("data", values, dims=data_dims)
pymc_mod.add_coord(TIME_DIM, index)
data = pm.Data("data", values, dims=data_dims)

return data

Expand Down
8 changes: 4 additions & 4 deletions pymc_experimental/tests/model/test_marginal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,17 +608,17 @@ def test_is_conditional_dependent_static_shape():

def test_data_container():
"""Test that MarginalModel can handle Data containers."""
with MarginalModel(coords_mutable={"obs": [0]}) as marginal_m:
x = pm.MutableData("x", 2.5)
with MarginalModel(coords={"obs": [0]}) as marginal_m:
x = pm.Data("x", 2.5)
idx = pm.Bernoulli("idx", p=0.7, dims="obs")
y = pm.Normal("y", idx * x, dims="obs")

marginal_m.marginalize([idx])

logp_fn = marginal_m.compile_logp()

with pm.Model(coords_mutable={"obs": [0]}) as m_ref:
x = pm.MutableData("x", 2.5)
with pm.Model(coords={"obs": [0]}) as m_ref:
x = pm.Data("x", 2.5)
y = pm.NormalMixture("y", w=[0.3, 0.7], mu=[0, x], dims="obs")

ref_logp_fn = m_ref.compile_logp()
Expand Down
4 changes: 2 additions & 2 deletions pymc_experimental/tests/statespace/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def data():
@pytest.fixture(scope="session")
def pymc_model(data):
with pm.Model() as mod:
data = pm.ConstantData("data", data.values)
data = pm.Data("data", data.values)
P0_diag = pm.Exponential("P0_diag", 1, shape=(2,))
P0 = pm.Deterministic("P0", pt.diag(P0_diag))
initial_trend = pm.Normal("initial_trend", shape=(2,))
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_lgss_with_time_varying_inputs(output_name, rng):
}

with pm.Model(coords=coords):
exog_data = pm.MutableData("data_exog", X)
exog_data = pm.Data("data_exog", X)
P0_diag = pm.Exponential("P0_diag", 1, shape=(mod.k_states,))
P0 = pm.Deterministic("P0", pt.diag(P0_diag))
initial_trend = pm.Normal("initial_trend", shape=(2,))
Expand Down
2 changes: 1 addition & 1 deletion pymc_experimental/tests/statespace/test_statespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def exog_pymc_mod(exog_ss_mod, rng):
X = rng.normal(size=(100, 3)).astype(floatX)

with pm.Model(coords=exog_ss_mod.coords) as m:
exog_data = pm.MutableData("data_exog", X)
exog_data = pm.Data("data_exog", X)
initial_trend = pm.Normal("initial_trend", dims=["trend_state"])
P0_sigma = pm.Exponential("P0_sigma", 1)
P0 = pm.Deterministic(
Expand Down
4 changes: 2 additions & 2 deletions pymc_experimental/tests/statespace/test_structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def test_filter_scans_time_varying_design_matrix(rng):
mod = reg.build(verbose=False)

with pm.Model(coords=mod.coords) as m:
data_exog = pm.MutableData("data_exog", data.values)
data_exog = pm.Data("data_exog", data.values)

x0 = pm.Normal("x0", dims=["state"])
P0 = pm.Deterministic("P0", pt.eye(mod.k_states), dims=["state", "state_aux"])
Expand Down Expand Up @@ -781,7 +781,7 @@ def test_extract_components_from_idata(rng):
mod = (ll + season + reg + me).build(verbose=False)

with pm.Model(coords=mod.coords) as m:
data_exog = pm.MutableData("data_exog", data.values)
data_exog = pm.Data("data_exog", data.values)

x0 = pm.Normal("x0", dims=["state"])
P0 = pm.Deterministic("P0", pt.eye(mod.k_states), dims=["state", "state_aux"])
Expand Down
4 changes: 2 additions & 2 deletions pymc_experimental/tests/test_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def build_model(self, X: pd.DataFrame, y: pd.Series, model_config=None):
with pm.Model(coords=coords) as self.model:
if model_config is None:
model_config = self.model_config
x = pm.MutableData("x", self.X["input"].values)
y_data = pm.MutableData("y_data", self.y)
x = pm.Data("x", self.X["input"].values)
y_data = pm.Data("y_data", self.y)

# prior parameters
a_loc = model_config["a"]["loc"]
Expand Down

0 comments on commit a05001b

Please sign in to comment.