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

Pushforward problems #125

Open
cscherrer opened this issue Aug 17, 2023 · 4 comments
Open

Pushforward problems #125

cscherrer opened this issue Aug 17, 2023 · 4 comments

Comments

@cscherrer
Copy link
Collaborator

Say we have

using MeasureTheory, MeasureBase, BenchmarkTools, AffineMaps
μ = Normal(3.0, 2.0)
ν = pushfwd(MulAdd(2.0, 3.0), StdNormal())
x = rand(Normal(3.0, 2.0) ^ 100);

Then benchmarking gives

julia> @btime logdensityof($μ  ^ 100, $x)
  60.594 ns (0 allocations: 0 bytes)
-222.1504504107993

julia> @btime logdensityof($ν ^ 100, $x)
  12.734 μs (12 allocations: 192 bytes)
-222.15045041079918

I'm also confused by the basemeasure sequence here:

julia> basemeasure_sequence(ν) .|> println;
PushforwardMeasure(MulAdd{Float64, Float64}(2.0, 3.0), StdNormal())
PushforwardMeasure(MulAdd{Float64, Float64}(2.0, 3.0), 0.3989 * MeasureBase.LebesgueBase())
PushforwardMeasure(MulAdd{Float64, Float64}(2.0, 3.0), MeasureBase.LebesgueBase())

I'd think there are always a couple of laws in place around these things:

logdensity_def(μ, x) == logdensity_rel(μ, basemeasure(μ), x)

logdensity_rel(pushfwd(f, μ), pushfwd(f, ν), x) == logdensity_rel(μ, ν, inverse(f)(x))

But then we'd expect logdensityof(ν, x) == logdensityof(StdNormal(), x), which is not the case.

@oschulz any idea what's going on here?

@cscherrer
Copy link
Collaborator Author

I think I have at least a partial approach that may help. First, we enforce laws

# Law 1
logdensity_def(μ, x) == logdensity_rel(μ, basemeasure(μ), x)

# Law 2
logdensity_rel(pushfwd(f, μ), pushfwd(f, ν), x) == logdensity_rel(μ, ν, inverse(f)(x))

Then we add some new smart constructors:

  • The pushforward of a weighted measure is a weighted pushforward
  • A scalar affine pushforward of Lebesgue measure is a weighted Lebesgue measure

Then in the above basemeasure sequence, instead of

pushfwd(MulAdd(2.0, 3.0), 0.3989 * LebesgueBase())

we'd get

0.3989 * pushfwd(MulAdd(2.0, 3.0), LebesgueBase())

which further reduces to

0.19945 * LebesgueBase()

So the full basemeasure sequence of the pushforward would be

pushfwd(MulAdd(2.0, 3.0), StdNormal())
0.19945 * LebesgueBase()
LebesgueBase()

I especially like that this makes it easier (I think) to work with the logjac - we need only compute it once, at the same time we take the log-density relative to LebesgueBase().

@oschulz
Copy link
Collaborator

oschulz commented Aug 21, 2023

Let me think this over for a day :-)

@cscherrer
Copy link
Collaborator Author

@oschulz
Copy link
Collaborator

oschulz commented Sep 4, 2023

I think for the general case (opaque f without known mathematical properties) we need to define

@inline basemeasure(ν::PushforwardMeasure) = basemeasure(parent(ν))

And require that the shape of y and x are the same, so require that f is an automorphism, and check that in logdensity_def.

For specific kinds of f, like affine transformations, we can specialize.

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

2 participants