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

Initialize RaveledParamsMap with dictionaries #62

Open
rlouf opened this issue Jun 23, 2022 · 0 comments
Open

Initialize RaveledParamsMap with dictionaries #62

rlouf opened this issue Jun 23, 2022 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rlouf
Copy link
Member

rlouf commented Jun 23, 2022

Currently one has to pass an iterable (that is then converted to a tuple) to initialize RaveledParamsMap:

import aesara as at
from aehmc.utils import RaveledParamsMap

tau_vv = at.vector("tau")
lambda_vv = at.vector("lambda")

rp_map = RaveledParamsMap((tau_vv, lambda_vv))

q = rp_map.ravel_params((tau_vv, lambda_vv))
tau_part = rp_map.unravel_params(q)[tau_vv]
lambda_part = rp_map.unravel_params(q)[lambda_vv]

In some circumstances we need the map to be indexed with other variables. For instance when we work with transformed variables and need the map to link the original value variables to the transformed variables (which may have different shapes/dtypes). In this case we need to overwrite the ref_params property:

from aeppl.transforms import LogTransform

lambda_vv_trans = LogTransform().forward(lambda_vv)

rp_map_trans = RaveledParamsMap((tau_vv, lambda_vv_trans))
rp_map_trans.ref_params = (tau_vv, lambda_vv)

q = rp_map_trans.ravel_params((tau_vv, lambda_vv))
tau_part = rp_map_trans.unravel_params(q)[tau_vv]
lambda_trans_part = rp_map_trans.unravel_params(q)[lambda_vv]

I suggest to simplify this by allowing the RaveledParamsMap to be initialized with a dictionary:

rp_map_trans = RaveledParamsMap({tau_vv: tau_vv, lambda_vv: lambda_vv_trans})

Shapes and dtypes are infered from the dictionaries' values, the map is indexed by the dictionaries' keys.

@brandonwillard brandonwillard added enhancement New feature or request help wanted Extra attention is needed labels Jul 6, 2022
@rlouf rlouf closed this as completed Aug 25, 2022
@rlouf rlouf reopened this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants