Skip to content

Commit

Permalink
Remove Distributions
Browse files Browse the repository at this point in the history
```
    xp_low = Distributions.quantile(Distributions.Normal(), low_percentile)
    xp_high = Distributions.quantile(Distributions.Normal(), high_percentile)
    return (gauss_int(xp_high) - gauss_int(xp_low)) / max(
        Distributions.cdf(Distributions.Normal(), xp_high) -
        Distributions.cdf(Distributions.Normal(), xp_low),
        eps(FT),
    )
```

I think that this block is a doing a roundabout way to do nothing.

`Distributions.quantile(percentile)` computes the `x` so that the CDF is
`percentile`. Then, `Distributions.cdf(x)` computes the percentile
corresponding to `x`. The two functions are one the inverse of the
other when the same distribution is used.
  • Loading branch information
Sbozzolo committed Jun 6, 2024
1 parent eb56220 commit 0cf57e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
Insolation = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
Expand Down Expand Up @@ -61,7 +60,6 @@ Colors = "0.12"
Dates = "1"
Dierckx = "0.5"
DiffEqBase = "6"
Distributions = "0.25"
DocStringExtensions = "0.8, 0.9"
FastGaussQuadrature = "0.4, 0.5, 1"
Insolation = "0.9.2"
Expand Down
27 changes: 18 additions & 9 deletions src/prognostic_equations/edmfx_boundary_condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
##### EDMFX SGS boundary condition
#####

import Distributions

function sgs_scalar_first_interior_bc(
ᶜz_int::FT,
ᶜρ_int::FT,
Expand Down Expand Up @@ -49,16 +47,27 @@ function get_first_interior_variance(
end
end

function approximate_inverf(x::FT)
a = FT(0.147)
ln = log(1 - x^2)
term1 = (2 /* a) + ln / 2)
term2 = ln / a
term3 = sqrt(term1^2 - term2)

return sign(x) * sqrt(term3 - term1)
end

function guass_quantile(p::FT)
return sqrt(2) * approximate_inverf(2 * (1 - p))
end

function percentile_bounds_mean_norm(
low_percentile::FT,
high_percentile::FT,
) where {FT <: Real}
gauss_int(x) = -exp(-x * x / 2) / sqrt(2 * pi)
xp_low = Distributions.quantile(Distributions.Normal(), low_percentile)
xp_high = Distributions.quantile(Distributions.Normal(), high_percentile)
return (gauss_int(xp_high) - gauss_int(xp_low)) / max(
Distributions.cdf(Distributions.Normal(), xp_high) -
Distributions.cdf(Distributions.Normal(), xp_low),
eps(FT),
)
xp_high = guass_quantile(high_percentile)
xp_low = guass_quantile(low_percentile)
return (gauss_int(xp_high) - gauss_int(xp_low)) /
max(high_percentile - low_percentile, eps(FT))
end

0 comments on commit 0cf57e4

Please sign in to comment.