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

Normalizing a measure #128

Closed
sethaxen opened this issue Aug 6, 2021 · 8 comments · Fixed by JuliaMath/MeasureBase.jl#88 · May be fixed by #130
Closed

Normalizing a measure #128

sethaxen opened this issue Aug 6, 2021 · 8 comments · Fixed by JuliaMath/MeasureBase.jl#88 · May be fixed by #130

Comments

@sethaxen
Copy link
Collaborator

sethaxen commented Aug 6, 2021

In JuliaManifolds/ManifoldMeasures.jl#7 we were discussing that we need a way to map an (unnormalized) Hausdorff measure to the corresponding probability measure by normalizing. This seems general enough that it could be defined here.

What about something like this?

LinearAlgebra.normalize::AbstractMeasure) = inv(total_mass(μ)) * μ
unit() = true  # just a function to use for dispatch.
total_mass::AbstractMeasure) = (unit, μ)
total_mass::AbstractWeightedMeasure) = exp.logweight) * total_mass.base)
is_probability_measure::AbstractMeasure) = isone(total_mass(μ))

Perhaps there is a more measure-theoretic term than "normalization", and we should not then overload normalize. In the case of a Hausdorff measure, total_mass would compute the volume/area of the manifold in some embedded metric space.

It might be preferable to define log_total_mass instead.

@cscherrer
Copy link
Collaborator

Great idea! A few comments:

First, has changed around a bit. It had originally computed the total measure (answer to your other question BTW). But I think it's more convenient as a way to define a new measure. So e.g. you can write ∫(x -> -x^2/2, Lebesgue(ℝ)) (or with do notation) to define an unnormalized Gaussian. This is integration in the sense of being dual to the Radon-Nikodym derivative 𝒹.

It might be preferable to define log_total_mass instead.

I think we can make it flexible, so you can define either. For density, we have

density(μ, ν::AbstractMeasure, x) = exp(logdensity(μ, ν, x))
density(μ, x) = exp(logdensity(μ, x))

Usually logdensity is what you define. But sometimes it can be more natural to define the density, in which case you can just overload logdensity to log the result of that. Or even have specialized methods for each. Julia is pretty great in this way :)

@sethaxen
Copy link
Collaborator Author

sethaxen commented Aug 6, 2021

In that case, I think it makes sense to have an un-implemented logtotalmass, and a default totalmass(x) = Exp(logtotalmass(x)). Then, in order to normalize a measure, one would need to implement one of those two functions directly. Shall I open a PR?

@cscherrer
Copy link
Collaborator

Or to be more precise,
image

I think formally it's total_measure, but I also like the sound of total_mass... or even just mass and logmass. If this is the only way we use it, the total gives no information.

Yes, a PR would be great. Thanks for starting getting this going!

@cscherrer
Copy link
Collaborator

@sethaxen what do you think of having mass or logmass work like Base.sum, with an optional first argument for weighting? This was the idea with Integral:

struct Integral{F,M}
    f::F
    μ::M
end

By default it just stores the request in a struct. In general there's no clear efficient way to do integration, so the user needs to be able to select between lots of different algorithms. And maybe we have an extension package to conenct to QuadGK, etc?

@gdalle
Copy link
Collaborator

gdalle commented Aug 12, 2021

Following up on this, I like the idea of an interface with numerical integration. Could it be a small side package (to outsource the Quadrature dependencies) that mostly defines, say, a function evaluate(::Integral, ::AbstractDomain) ?

@cscherrer
Copy link
Collaborator

Maybe it could be even simpler? A measure "knows" its domain, so the package could just depend on MeasureTheory and Quadrature and only have one function Integral -> QuadratureProblem.

The only reason not to have this in MeasureTheory itself is that Quadrature.jl has lots of dependencies, and we need to keep the main package a little more focused.

@gdalle
Copy link
Collaborator

gdalle commented Aug 12, 2021

Yes but in that case it means that you cannot apply a measure to arbitrary sets. For instance, if you have a Poisson process on R^n but you want to simulate it on a box, you need to define a local measure restricted to that box instead of evaluating the global measure on this box subset.

@cscherrer
Copy link
Collaborator

Oh, I guess we're starting to split the conversation in different threads. I just made a related comment here: #130 (comment)

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

Successfully merging a pull request may close this issue.

3 participants