-
Notifications
You must be signed in to change notification settings - Fork 10
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
[Bug] RafteryCopula fixes. #137
Conversation
I'm going to read it, in the morning I'm working but later I'll be free and
I hope to review the tests.
I remember that I did the tests with paper and pencil according to the
formula in the document.
El El lun, 12 feb 2024 a la(s) 5:20, Oskar Laverny ***@***.***>
escribió:
… Fixes #98 <#98>
@Santymax98 <https://github.com/Santymax98> it loks like the pdf is now
fixed, but the cdf has values that still do not match what is in the tests
files (see the @test_broken).
two month ago there #98 (comment)
<#98 (comment)>
you proposed to use
function prueba(R::Vector{T}, u::Vector{T}) where T
# Order the vector u
u_ordered = sort(u)
println("Sorted vector: ", u_ordered)
term1 = u_ordered[1]
println("Term 1: ", term1)
term2 = ((1 - R[1]) * (1 - R[2])) / (1 - R[1] - R[2]) * prod(u)^(1/(1 - R[1]))
println("Term 2: ", term2)
term3 = 0.0
for i in 2:length(R) # <<<<<<<<--------------- This should be 2:d and not 2:length(R) since length(R) is not the dimension.
prod_prev = prod(u_ordered[1:i-1])
term3_part = (R[1] * (1 - R[1])) / ((1 - R[1] - i) * (2 - R[1] - i)) * prod_prev^(1/(1 - R[1])) * u_ordered[i]^((2 - R[1] - i) / (1 - R[1]))
println("Term 3 (part $i): ", term3_part)
term3 += term3_part
end
# Combine the terms to get the cumulative distribution function
cdf_value = term1 + term2 - term3
println("Final CDF value: ", cdf_value)
return cdf_valueend
prueba([0.5,3], [0.1,0.2,0.3])
to check that the value's returned by the code are indeed correct. But
your code has a mistake.
It looks to me like the current implementation is mathcing what is in the
article, so maybe the issue is that the tests values are now wrong and
should be updated ?
------------------------------
You can view, comment on, or merge this pull request online at:
#137
Commit Summary
- 75b06de
<75b06de>
Fixing the pdf and clearing out the code.
File Changes
(2 files <https://github.com/lrnv/Copulas.jl/pull/137/files>)
- *M* src/MiscellaneousCopulas/RafteryCopula.jl
<https://github.com/lrnv/Copulas.jl/pull/137/files#diff-683b121951621fad248976c0f09fa07e079e95245b4a504be601475a7293e307>
(49)
- *M* test/RafteryTest.jl
<https://github.com/lrnv/Copulas.jl/pull/137/files#diff-1fac2c1637f27ccc8e7b152e540c588b4b3e4f85668273eac3b05cbb8bbc70bb>
(37)
Patch Links:
- https://github.com/lrnv/Copulas.jl/pull/137.patch
- https://github.com/lrnv/Copulas.jl/pull/137.diff
—
Reply to this email directly, view it on GitHub
<#137>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A7PTWNUNEEULBGBL42NEGJDYTHUGZAVCNFSM6AAAAABDEOZV7KVHI2DSMVQWIX3LMV43ASLTON2WKOZSGEZDSOBRHA4DCOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This is indeed a very good way of insuring that the implementation is OK. Maybe you made a mistake doing this, could you simply re-do it for the trivariate cdf tests ? the only ones that are still broken. |
function prueba_CDF(R::Vector{T}, u::Vector{T}) where T
# Order the vector u
θ = R[1]
println("param:", θ)
d = round(Int, R[2])
println("dimension:", d)
u_ordered = sort(u)
println("Sorted vector: ", u_ordered)
term1 = u_ordered[1]
println("Term 1: ", term1)
term2 = ((1 - θ) * (1 -d)) / (1 - θ - d) * prod(u)^(1/(1 - θ))
println("Term 2: ", term2)
term3 = 0.0
for i in 2:d # <<<<<<<<--------------- This should be 2:d and not 2:length(R) since length(R) is not the dimension.
prod_prev = prod(u_ordered[1:i-1])
term3_part = ((θ * (1 - θ)) / ((1 - θ - i) * (2 - θ - i))) * prod_prev^(1/(1 - θ)) * u_ordered[i]^((2 - θ - i) / (1 - θ))
println("Term 3 (part $i): ", term3_part)
term3 += term3_part
end
# Combine the terms to get the cumulative distribution function
cdf_value = term1 + term2 - term3
println("Final CDF value: ", cdf_value)
return cdf_value
end
prueba_CDF([0.5,3], [0.1,0.2,0.3]) should be 0.08236... I calculated this value manually and the test code works fine. However, when I combine it with Copulas.jl it gives me the error that we have had so far. |
function prueba_PDF(R::Vector{T}, u::Vector{T}) where T
# Order the vector u
θ = R[1]
d = round(Int, R[2])
u_ordered = sort(u)
println("Sorted vector: ", u_ordered)
term1 = (1/(((1-θ)^(d-1))*(1-θ-d)))
println("Term 1: ", term1)
term2 = (1-d-θ*(u_ordered[d])^((1-θ-d)/(1-θ)))
println("Term 2: ", term2)
term3 = (prod(u))^((θ)/(1-θ))
println(term3)
# Combine the terms to get the density distribution function
pdf_value = term1*term2*term3
println("Final PDF value: ", pdf_value)
return pdf_value
end
prueba_PDF([0.5,3], [0.1,0.2,0.3]) Regarding this test, the value in this case should be 1.99450... and on my machine the results are coming out correct. |
@Santymax98 I cleared up the code and fixed the previous value. I included your versions as fallbak testing. Thanks a lot this is now Ok for me ! |
Fixes #98
@Santymax98 it loks like the pdf is now fixed, but the cdf has values that still do not match what is in the tests files (see the @test_broken).
two month ago there #98 (comment) you proposed to use
to check that the value's returned by the code are indeed correct. But your code has a mistake.
It looks to me like the current implementation is mathcing what is in the article, so maybe the issue is that the tests values are now wrong and should be updated ?