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

The log-partition function for the continuous Bernoulli is not continuous. #132

Open
Nimrais opened this issue Aug 15, 2023 · 16 comments
Open
Assignees

Comments

@Nimrais
Copy link
Collaborator

Nimrais commented Aug 15, 2023

I think there is a mistake,

logpartition(::VagueContinuousBernoulli, exponentialfamily::ExponentialFamilyDistribution{ContinuousBernoulli}) =
    log(2.0)

and it's supposed to be

logpartition(::VagueContinuousBernoulli, exponentialfamily::ExponentialFamilyDistribution{ContinuousBernoulli}) = 0
@Nimrais Nimrais assigned Nimrais and ismailsenoz and unassigned Nimrais Aug 15, 2023
@albertpod
Copy link
Member

albertpod commented Aug 15, 2023

Just wonder, @ismailsenoz, shouldn't we refrain from logpartitions resulting in constants?

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

@albertpod It's not possible for this distribution, because the expression is not well-defined at the value 0. But, if you will take it's limit you will obtain 0, not a log(2).

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

Maybe we can to add tiny under exponent but then the result is not precise: log((exp(0 + tiny) - 1)/(0 + tiny))

@bvdmitri
Copy link
Member

What is vague/non-vague? Why do we need this? Why can't we just use the table from Wikipedia?

@bvdmitri
Copy link
Member

bvdmitri commented Aug 15, 2023

Skimming through the code, I still don't understand the purpose of vague/non-vague stuff, the code is basically copy-pasted for both cases with minor differences. I would remove the vague/non-vague stuff entirely and just use the table from the Wikipedia, where logpartition is well defined

I see, the problem is the limit

@bvdmitri
Copy link
Member

Wolfram tells me that the limit is not well-defined, I would probably simply remove all if-checks and let it fail if someone uses it with p=0.5 or make it a non proper exp family member

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

The limit is defined it's easy to check @bvdmitri
IMG_02FECE4659CE-1

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

What is vague/non-vague? Why do we need this? Why can't we just use the table from Wikipedia?

Because this particular distribution is not yet added in the wikipage

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

@bvdmitri @ismailsenoz The guys defining its at $\lambda$ = 0.5 https://arxiv.org/pdf/1907.06845.pdf. And it is well behaving.

@bvdmitri
Copy link
Member

bvdmitri commented Aug 15, 2023

The limit is defined it's easy to check

My bad

Because this particular distribution is not yet added in the wikipage

It is in the table

defining its at lambda = 0.5

Solving for specific case does not seem like a right solution (also in the current code). The function should be approximated with a different function in the whole region around that value, perhaps with linear, Fourier or bspline approximations then. Doing that right is not an easy task (the reason why StatsFuns.jl exists basically)

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

It is in the table

yes, you are right, I found it.

@bvdmitri
Copy link
Member

bvdmitri commented Aug 15, 2023

The "right" way to fix numerically problematic functions usually look something like this 🥲, but I doubt we should spend a lot of time on it. Maybe there is already a package that computes it

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

Solving for specific case does not seem like a right solution (also in the current code). The function should be approximated with a different function in the whole region around that value, perhaps with linear, Fourier or bspline approximations then. Doing that right is not an easy task (the reason why StatsFuns.jl exists basically)

Agree, but it's still better then return 100% wrong value

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

I asked in Julia math slack channel, maybe someone already did it

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 15, 2023

😢
Screenshot 2023-08-15 at 21 28 18

@Nimrais
Copy link
Collaborator Author

Nimrais commented Aug 17, 2023

Jürgen Fuhrmann from this thread did $\frac{x}{e^{x}-1}$:

I have an implementation of the reciprocal (called Bernoulli function): https://github.com/j-fu/VoronoiFVM.jl/blob/faba3b6edbaf9d090feb3df60a06f2a4a14d5aaf/src/vfvm_functions.jl#L38 . See also the pluto notebook documenting the choices: https://github.com/j-fu/VoronoiFVM.jl/blob/master/pluto-examples/bernoulli.jl

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

4 participants