Skip to content

Commit

Permalink
Test all ClaytonCopula.computeQuantile return path
Browse files Browse the repository at this point in the history
following Michael's review
  • Loading branch information
josephmure committed Apr 24, 2024
1 parent f9bf77f commit 8bb6060
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/test/t_ClaytonCopula_std.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ int main(int, char *[])
fullprint << "PDF(" << x.__str__() << ")=" << std::setprecision(12) << copula.computePDF(x) << std::endl;
fullprint << "CDF(" << x.__str__() << ")=" << std::setprecision(12) << copula.computeCDF(x) << std::endl;
}

// Test all scenarios of quantile computation
copula = ClaytonCopula(0.5);
Scalar large_p = 0.75;
Point large_ref(2, 0.86156);
assert_almost_equal(copula.computeQuantile(1.0 - large_p, true), large_ref, 1e-5, 0.0);
assert_almost_equal(copula.computeQuantile(large_p, false), large_ref, 1e-5, 0.0);
Scalar small_p = SpecFunc::ScalarEpsilon / 2.0;
Point small_ref(2, 1.0 - small_p / 2.0);
assert_almost_equal(copula.computeQuantile(small_p, true), small_ref, 0.0);
assert_almost_equal(copula.computeQuantile(1.0 - small_p, false), small_ref, 1e-5, 0.0);
}
catch (TestFailed & ex)
{
Expand Down
11 changes: 11 additions & 0 deletions python/test/t_ClaytonCopula_std.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott

ot.TESTPREAMBLE()

Expand Down Expand Up @@ -132,3 +133,13 @@

print("chi=", copula.computeUpperTailDependenceMatrix())
print("chiL=", copula.computeLowerTailDependenceMatrix())

# Test all scenarios of quantile computation
copula = ot.ClaytonCopula(0.5)
large_p = 0.75
ref = [0.86156] * 2
ott.assert_almost_equal(copula.computeQuantile(1.0 - large_p, True), ref, 1e-5, 0.0)
ott.assert_almost_equal(copula.computeQuantile(large_p, False), ref, 1e-5, 0.0)
small_p = ot.SpecFunc.ScalarEpsilon / 2.0
ott.assert_almost_equal(copula.computeQuantile(small_p, True), [1.0 - small_p / 2.0] * 2, 1e-5, 0.0)
ott.assert_almost_equal(copula.computeQuantile(1.0 - small_p, False), [1.0 - small_p / 2.0] * 2, 1e-5, 0.0)

0 comments on commit 8bb6060

Please sign in to comment.