-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
BUG: Unable to apply Interval
foward transformation
#7193
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
Comments
The signature of forward expects all inputs of the RV besides the value. For your goal, if you don't care about the jacobian term you can remove the value transforms with https://www.pymc.io/projects/docs/en/stable/api/model/generated/pymc.model.transform.conditioning.remove_value_transforms.html Otherwise you need to define a function that pushes all the values forward. That's not straightforward and something we want to offer users: #6721 Help there would be much welcome. Unless I missed something I would close this issue as duplicated. The code doesn't show a bug but an incorrect use of the transform objects |
@ricardoV94 Thanks for the insight. Following your response here I was able to get this to work by also passing import pymc as pm
print(pm.__version__)
with pm.Model() as model:
x = pm.Normal("x", mu=0.0, sigma=1.0)
y = pm.LogNormal("y", mu=1.0, sigma=1.0)
z = pm.TruncatedNormal("z", mu=0.0, sigma=1.0, lower=-1.0, upper=1.0)
point = {"x": 1.0, "y": 0.5, "z": 0.0}
point_transformed = {}
for rv in model.free_RVs:
name = rv.name
param = model.rvs_to_values[rv]
transform = model.rvs_to_transforms[rv]
print(f"name: {name} param: {param} transform: {transform}")
if transform is None:
point_transformed[param] = point[name]
else:
point_transformed[param] = transform.forward(
point[name], *rv.owner.inputs
).eval()
print(f"value: {point[name]} transformed_value: {point_transformed[param]}")
print(f"Log prob: {model.logp().eval(point_transformed)}") |
Note that only works because lower/upper are constants. If they depended on other parameters you would get wrong results |
Describe the issue:
Description
I wish to evaluate the log probability of a model at a specific point. Since some RVs may be transformed, I must apply the transformation to the input point in order to pass the transformed point to
model.logp
. If one of the RV transforms isInterval
, then the call toforward()
fails with an obscure error.Expected Behavior
Applying
forward
to a RV transformed viaInterval
should not raise an exception.Actual Behavior
Applying
forward
to a RV transformed viaInterval
raises an exception.Minimum working example
The following example demonstrates what I want to do. I have a model where
x
is not transformed,y
has aLogTransform
, andz
has anInterval
transform. I want to evaluatelogp
at a givenx, y, z
. Sincelogp
requires the transformed point in order to evaluate the expression, I must apply the transformations and pass the transformed point tologp().eval()
.The output of this MWE is below:
Reproduceable code example:
Error message:
PyMC version information:
Context for the issue:
I would like to be able to capture and apply
forward
to any transform.The text was updated successfully, but these errors were encountered: