Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in examples/case_studies/probabilistic_matrix_factorization.ipynb #743

Open
wd60622 opened this issue Nov 16, 2024 · 0 comments
Open

Comments

@wd60622
Copy link

wd60622 commented Nov 16, 2024

Error while finding MAP for the model.

────────────────────────────────── Error running examples/case_studies/probabilistic_matrix_factorization.ipynb ──────────────────────────────────

---------------------------------------------------------------------------
Exception encountered at "In [20]":
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[20], line 2
      1 # Find MAP for PMF.
----> 2 pmf.find_map();

Cell In[13], line 6, in _find_map(self)
      4 with self.model:
      5     logging.info("finding PMF MAP using L-BFGS-B optimization...")
----> 6     self._map = pm.find_MAP(method="L-BFGS-B")
      8 elapsed = int(time.time() - tstart)
      9 logging.info("found PMF MAP in %d seconds" % elapsed)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/tuning/starting.py:134, in find_MAP(start, vars, method, return_raw,
include_transformed, progressbar, progressbar_theme, maxeval, model, seed, *args, **kwargs)
    127 ipfn = make_initial_point_fn(
    128     model=model,
    129     jitter_rvs=set(),
    130     return_transformed=True,
    131     overrides=start,
    132 )
    133 start = ipfn(seed)
--> 134 model.check_start_vals(start)
    136 vars_dict = {var.name: var for var in vars}
    137 x0 = DictToArrayBijection.map(
    138     {var_name: value for var_name, value in start.items() if var_name in vars_dict}
    139 )

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/model/core.py:1742, in Model.check_start_vals(self, start, **kwargs)
   1736     valid_keys = ", ".join(value_names_set)
   1737     raise KeyError(
   1738         "Some start parameters do not appear in the model!\n"
   1739         f"Valid keys are: {valid_keys}, but {extra_keys} was supplied"
   1740     )
-> 1742 initial_eval = self.point_logps(point=elem, **kwargs)
   1744 if not all(np.isfinite(v) for v in initial_eval.values()):
   1745     raise SamplingError(
   1746         "Initial evaluation of model at starting point failed!\n"
   1747         f"Starting values:\n{elem}\n\n"
   1748         f"Logp initial evaluation results:\n{initial_eval}\n"
   1749         "You can call `model.debug()` for more details."
   1750     )

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/model/core.py:1774, in Model.point_logps(self, point, round_vals, **kwargs)
   1771     point = self.initial_point()
   1773 factors = self.basic_RVs + self.potentials
-> 1774 factor_logps_fn =
   1775 return {
   1776     factor.name: np.round(np.asarray(factor_logp), round_vals)
   1777     for factor, factor_logp in zip(
   (...)
   1780     )
   1781 }

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/model/core.py:672, in Model.logp(self, vars, jacobian, sum)
    670 rv_logps: list[TensorVariable] = []
    671 if rvs:
--> 672     rv_logps = transformed_conditional_logp(
    673         rvs=rvs,
    674         rvs_to_values=self.rvs_to_values,
    675         rvs_to_transforms=self.rvs_to_transforms,
    676         jacobian=jacobian,
    677     )
    678     assert isinstance(rv_logps, list)
    680 # Replace random variables by their value variables in potential terms

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/logprob/basic.py:595, in transformed_conditional_logp(rvs, rvs_to_values,
rvs_to_transforms, jacobian, **kwargs)
    592     transform_rewrite = TransformValuesRewrite(values_to_transforms)  # type: ignore
    594 kwargs.setdefault("warn_rvs", False)
--> 595 temp_logp_terms = conditional_logp(
    596     rvs_to_values,
    597     extra_rewrites=transform_rewrite,
    598     use_jacobian=jacobian,
    599     **kwargs,
    600 )
    602 # The function returns the logp for every single value term we provided to it.
    603 # This includes the extra values we plugged in above, so we filter those we
    604 # actually wanted in the same order they were given in.
    605 logp_terms = {}

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/logprob/basic.py:479, in conditional_logp(rv_values, warn_rvs, ir_rewriter,
extra_rewrites, **kwargs)
    417 r"""Create a map between variables and conditional logps such that the sum is their joint logp.
    418
    419 The `rv_values` dictionary specifies a joint probability graph defined by
   (...)
    475
    476 """
    477 warn_rvs, kwargs = _deprecate_warn_missing_rvs(warn_rvs, kwargs)
--> 479 fgraph = construct_ir_fgraph(rv_values, ir_rewriter=ir_rewriter)
    481 if extra_rewrites is not None:
    482     extra_rewrites.rewrite(fgraph)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/logprob/rewriting.py:249, in construct_ir_fgraph(rv_values, ir_rewriter)
    246 cloned_values = tuple(v.clone() for v in rv_values.values())
    247 ir_rv_values = dict(zip(fgraph.outputs, cloned_values))
--> 249 replacements = tuple((rv, valued_rv(rv, value)) for rv, value in ir_rv_values.items())
    250 toposort_replace(fgraph, replacements, reverse=True)
    252 if ir_rewriter is None:

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/logprob/rewriting.py:249, in <genexpr>(.0)
    246 cloned_values = tuple(v.clone() for v in rv_values.values())
    247 ir_rv_values = dict(zip(fgraph.outputs, cloned_values))
--> 249 replacements = tuple((rv, valued_rv(rv, value)) for rv, value in ir_rv_values.items())
    250 toposort_replace(fgraph, replacements, reverse=True)
    252 if ir_rewriter is None:

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/op.py:304, in Op.__call__(self, name, return_list, *inputs,
**kwargs)
    301             n.name = f"{name}_{i}"
    303 if config.compute_test_value != "off":
--> 304     compute_test_value(node)
    306 if self.default_output is not None:
    307     rval = node.outputs

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/op.py:125, in compute_test_value(node)
    122 thunk.inputs = [storage_map for v in node.inputs]
    123 thunk.outputs = [storage_map for v in node.outputs]
--> 125 thunk()
    127 for output in node.outputs:
    128     # Check that the output has been computed
    129     assert compute_map[0], (output, storage_map[0])

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/op.py:524, in Op.make_py_thunk.<locals>.rval(p, i, o, n)
    522 @is_thunk_type
    523 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node):
--> 524     r = p(n, [x[0] for x in i], o)
    525     for o in node.outputs:
    526         compute_map[0] = True

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/logprob/abstract.py:245, in ValuedRV.perform(self, node, inputs, out)
    244 def perform(self, node, inputs, out):
--> 245     raise NotImplementedError("ValuedVar should not be present in the final graph!")

NotImplementedError: ValuedVar should not be present in the final graph!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant