Closed sofia-calgaro closed 1 week ago
To do this we need to create custom distributions for the cases we care about (I guess they are not defined in Distributions.jl) This can be done like this:
# Define the custom distribution type
struct CustomDist <: ContinuousUnivariateDistribution end
# Define the support as (0, ∞)
Distributions.support(::CustomDist) = (0.0, Inf)
# Define the PDF (Exponential-like PDF)
Distributions.pdf(::CustomDist, x::Float64) = x > 0 ? exp(-x) : 0
# Define how to draw random samples (inverse CDF method for exponential)
Distributions.rand(::CustomDist) = -log(rand())
# Define the log-PDF
Distributions.logpdf(::CustomDist, x::Float64) = x > 0 ? -x : -Inf
# Define the CDF
Distributions.cdf(::CustomDist, x::Float64) = x > 0 ? 1 - exp(-x) : 0
# Create an instance of the distribution
dist = CustomDist()
I tried quickly and it seems to work, Now for the distributions a uniform distribution of log(S) means:
$$ u= \log{(S)}$$
$$g(u) = \text{Uniform}[a,b]$$
So:
$$f(S) dS = g(u) du \implies f(S) = g(u) \frac{du}{dS} = g(u)/s $$
i.e. its a function of $1/S$ but cut from $e^a$ to $e^b$, evidently this distributions cannot be defined to ($S=0$) which is a known thing and we need some cutoff. Similar maths works for $\sqrt{(S)}$ but this time the transformation is to $1/\sqrt{(S)}$. Both of these require a lower cutoff I guess we can see what GERDA used
I tried the following code to get a prior flat on log(S): Several of the methods are annoying to define (maths:
# Define the custom distribution type
struct MyCustomDist <: ContinuousUnivariateDistribution
a::Float64
b::Float64
end
Distributions.support(::MyCustomDist) = (0.0, Inf)
Distributions.pdf(d::MyCustomDist, x) = (x > d.a) && (x<d.b) ? 1/(x*(log(d.b)-log(d.a))) : 0
Distributions.rand(d::MyCustomDist) = exp(rand()*(log(d.b)-log(d.a))+log(d.a))
Distributions.logpdf(d::MyCustomDist, x::Float64) = x > d.a && x<d.b ? -log(x)-log(log(d.b)-log(d.a)) : 0
Distributions.cdf(d::MyCustomDist, x::Float64) = x < d.a ? 0 : x<d.b ? (log(x)-log(d.a))/(log(d.b)-log(d.a)) : 1
dist = MyCustomDist(1,10)
The CDF and PDF (along with some sampled data) look ok, but we have to try to see what happens in BAT.
![image](https://github.com/user-attachments/assets/531af282-76f6-4f62-934a-0df8f6705d61)
![image](https://github.com/user-attachments/assets/397e3bff-9aeb-4133-83bf-75f87b3f0a49)
Ok I tried it in BAT didnt seems to work Also found that in Distributions.jl they already have a log uniform: https://juliastats.org/Distributions.jl/stable/univariate/#Continuous-Distributions but the uniform sqrt(x) isnt there. Need to think of other ideas?
We can try to follow it replacing the 1/x with 1/sqrt(x)
Some ideas