Apply transformations to samples before matching it to observed data

Might be a newbie question, but I am struggling in understanding how it is possible to apply transformations to a sample before scoring it against the observed data point.

In general we have this:

pyro.sample("sample", dist.Normal(loc, scale), obs=data['y'])

where we are scoring the sample from the normal distribution to the data point in data.

What I need to do is to score not sample but transformation_function(sample) to the data.

Is it possible?

the degree to which this is easy/possible depends on the nature of transformation_function. for example if it’s invertible and differentiable then it’s easy. if it’s an arbitrary function it’s probably hard. in the former case you can probably use the TransformedDistribution construct (see analog in Pyro).