Skip to content

Conversation

@Moelf
Copy link

@Moelf Moelf commented Dec 29, 2020

I don't know what's the standard for numerical methods, I'd happy to split into a separate package if this is not suitable for Distributions.jl

@codecov-io
Copy link

codecov-io commented Dec 29, 2020

Codecov Report

Merging #1245 (3070888) into master (8b6da89) will decrease coverage by 1.16%.
The diff coverage is 4.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1245      +/-   ##
==========================================
- Coverage   81.83%   80.66%   -1.17%     
==========================================
  Files         117      118       +1     
  Lines        6589     6689     +100     
==========================================
+ Hits         5392     5396       +4     
- Misses       1197     1293      +96     
Impacted Files Coverage Δ
src/Distributions.jl 100.00% <ø> (ø)
src/univariates.jl 66.43% <ø> (ø)
src/univariate/continuous/landau.jl 4.00% <4.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b6da89...39270e4. Read the comment docs.

@Moelf Moelf marked this pull request as draft December 31, 2020 02:42
exp(im*t*d.μ - 2im*d.θ*t/π*log(abs(t)) - d.θ*abs(t))
end

# https://root.cern.ch/doc/v622/PdfFuncMathCore_8cxx_source.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert but I think this is problematic since root uses the LGPL license: https://root.cern/about/license/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, someone pointed out on Slack as well, it is true we cannot put derived code directly. so this may call for a new pkg

Comment on lines +40 to +41
Landau(μ::T) where {T <: Real} = Landau(μ, one(T))
Landau() = Landau(0.0, 1.0, check_args=false)
Copy link
Member

@devmotion devmotion Dec 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Landau::T) where {T <: Real} = Landau(μ, one(T))
Landau() = Landau(0.0, 1.0, check_args=false)
Landau::Real = 0) = Landau(μ, one(μ); check_args=false)

@@ -0,0 +1,191 @@
using StaticArrays
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume dependencies should be loaded in src/Distributions.jl. I'm a bit surprised though that Distributions depends on StaticArrays but StaticArrays doesn't seem to be imported.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it only uses them in test, so technically we should change that in Project.toml to reflect this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought so as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: #1246

Comment on lines +68 to +70
function cf(d::Landau, t::Real)
exp(im*t*d.μ - 2im*d.θ*t/π*log(abs(t)) - d.θ*abs(t))
end
Copy link
Member

@devmotion devmotion Dec 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following definition uses cis(x) = exp(im*x) and avoids NaN values for t = 0:

Suggested change
function cf(d::Landau, t::Real)
exp(im*t*d.μ - 2im*d.θ*t/π*log(abs(t)) - d.θ*abs(t))
end
function cf(d::Landau, t::Real)
z = t * (d.μ + d.θ * (sign(t) * im - twoinvπ * log(abs(t))))
return iszero(t) ? cis(zero(z)) : cis(z)
end

# https://root.cern.ch/doc/v622/PdfFuncMathCore_8cxx_source.html
function _landau_pdf(x, xi=1, x0=0)
# landau pdf : algorithm from cernlib g110 denlan
p1 = @SVector [0.4259894875,-0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think it might be easier to just use evalpoly or @evalpoly.


if (v < -5.5)
u = exp(v+1)
lan = 0.3989422803*exp(-1. /u)*sqrt(u)*(1+(a1[2]+(a1[3]+a1[4]*u)*u)*u)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I guess using evalpoly or @evalpoly would be easier to read.

Moelf and others added 3 commits December 31, 2020 11:41
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
@Moelf Moelf closed this Jul 12, 2021
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 this pull request may close these issues.

3 participants