diff --git a/examples/RequestedBBRCProblem.ipynb b/examples/RequestedBBRCProblem.ipynb index 7b4f34e..f0a38e6 100644 --- a/examples/RequestedBBRCProblem.ipynb +++ b/examples/RequestedBBRCProblem.ipynb @@ -21,11 +21,18 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "RP8\n" + } + ], "source": [ - "problem = otb.RequestedBBRCProblem(\"testuser\", \"testpass\", -1, 1)" + "problem = otb.RequestedBBRCProblem(\"testuser\", \"testpass\", -1, 1)\n", + "print(problem.name)" ] }, { @@ -44,14 +51,12 @@ "metadata": {}, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "0.0007888456943755395" - ] + "text/plain": "0.0007888456943755395" }, - "execution_count": 4, "metadata": {}, - "output_type": "execute_result" + "execution_count": 4 } ], "source": [ @@ -76,7 +81,7 @@ "kernelspec": { "display_name": "python3_cours", "language": "python", - "name": "python3" + "name": "cours_micka" }, "language_info": { "codemirror_mode": { @@ -88,9 +93,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.6-final" } }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file diff --git a/otbenchmark/BBRCDistribution.py b/otbenchmark/BBRCDistribution.py index cb4d496..aa4a378 100644 --- a/otbenchmark/BBRCDistribution.py +++ b/otbenchmark/BBRCDistribution.py @@ -5,7 +5,7 @@ problem""" import openturns as ot -import pandas as pd +import numpy as np class BBRCDistribution: @@ -53,15 +53,20 @@ def switch_build_dist(dist_name, a, b, mean, std): ) return a_dist - bbrc_dist_table = pd.read_csv("./distributions/probabilistic_models.csv") + types = ["i4", "i4", "i4", "i4", "U15", "f8", "f8", "f8", "f8", "f8", "f8"] + bbrc_dist_table = np.genfromtxt( + "./distributions/probabilistic_models.csv", + dtype=types, + delimiter=",", + names=True, + ) my_dist_table = bbrc_dist_table[ (bbrc_dist_table["problem_id"] == self.problem_id) & (bbrc_dist_table["set_id"] == self.set_id) ] ot_dist_list = [] - for raw_index in my_dist_table.index: - raw = my_dist_table.loc[raw_index] + for raw in my_dist_table: ot_dist_list.append( switch_build_dist( raw["distribution_type"], diff --git a/otbenchmark/RequestedBBRCProblem.py b/otbenchmark/RequestedBBRCProblem.py index e7cd0ad..6ae3f3b 100644 --- a/otbenchmark/RequestedBBRCProblem.py +++ b/otbenchmark/RequestedBBRCProblem.py @@ -8,7 +8,6 @@ from otbenchmark import evaluate import openturns as ot import numpy as np -import pandas as pd class RequestedBBRCProblem(ReliabilityBenchmarkProblem): @@ -47,13 +46,16 @@ def g_fun(x): inputRandomVector = ot.RandomVector(inputDistribution) input_dim = inputDistribution.getDimension() # BBRCResults - bbrc_result_table = pd.read_csv("./distributions/beta_results.csv") + types = ["i4", "i4", "i4", "f8"] + bbrc_result_table = np.genfromtxt( + "./distributions/beta_results.csv", dtype=types, delimiter=",", names=True + ) my_result = bbrc_result_table[ (bbrc_result_table["problem_id"] == self.problem_id) & (bbrc_result_table["set_id"] == self.set_id) ] - name = "RP" + str(my_result["reliability_problem_id"].values[0]) - beta = my_result["beta"].values[0] + name = "RP" + str(my_result["reliability_problem_id"][0]) + beta = my_result["beta"][0] limitStateFunction = ot.PythonFunction(input_dim, 1, g_fun) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector diff --git a/tests/test_ReliabilityProblem110.py b/tests/test_ReliabilityProblem110.py index 230f59d..e74378a 100644 --- a/tests/test_ReliabilityProblem110.py +++ b/tests/test_ReliabilityProblem110.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem89(unittest.TestCase): - def test_ReliabilityBenchmarkProblem110(self): problem = otb.ReliabilityProblem110() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem110(self): # Check probability pf = problem.getProbability() pf_exacte = 0.0000319 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 0.85) def test_UseCase(self): @@ -46,13 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem111.py b/tests/test_ReliabilityProblem111.py index 0740eeb..a50822e 100644 --- a/tests/test_ReliabilityProblem111.py +++ b/tests/test_ReliabilityProblem111.py @@ -12,7 +12,6 @@ class CheckReliabilityProblem111(unittest.TestCase): - def test_ReliabilityBenchmarkProblem111(self): problem = otb.ReliabilityProblem111() print(problem) @@ -20,14 +19,14 @@ def test_ReliabilityBenchmarkProblem111(self): # Check probability pf = problem.getProbability() pf_exacte = 7.65e-7 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 12.5) def test_UseCase(self): @@ -45,13 +44,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem22.py b/tests/test_ReliabilityProblem22.py index f43b2f1..5bebf48 100644 --- a/tests/test_ReliabilityProblem22.py +++ b/tests/test_ReliabilityProblem22.py @@ -14,7 +14,6 @@ class CheckReliabilityProblem22(unittest.TestCase): - def test_ReliabilityBenchmarkProblem22(self): problem = otb.ReliabilityProblem22() print(problem) @@ -22,14 +21,14 @@ def test_ReliabilityBenchmarkProblem22(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00416 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 2.5) def test_UseCase(self): @@ -47,12 +46,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_ReliabilityProblem24.py b/tests/test_ReliabilityProblem24.py index 0e009d0..801304e 100644 --- a/tests/test_ReliabilityProblem24.py +++ b/tests/test_ReliabilityProblem24.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem24(unittest.TestCase): - def test_ReliabilityBenchmarkProblem24(self): problem = otb.ReliabilityProblem24() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem24(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00286 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [10.0, 10.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 2.5) def test_UseCase(self): @@ -46,12 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_ReliabilityProblem25.py b/tests/test_ReliabilityProblem25.py index 201d262..acfb5f9 100644 --- a/tests/test_ReliabilityProblem25.py +++ b/tests/test_ReliabilityProblem25.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem25(unittest.TestCase): - def test_ReliabilityBenchmarkProblem25(self): problem = otb.ReliabilityProblem25() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem25(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00000614 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 32.0) def test_UseCase(self): @@ -46,12 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_ReliabilityProblem28.py b/tests/test_ReliabilityProblem28.py index d67580d..353fa8b 100644 --- a/tests/test_ReliabilityProblem28.py +++ b/tests/test_ReliabilityProblem28.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem28(unittest.TestCase): - def test_ReliabilityBenchmarkProblem28(self): problem = otb.ReliabilityProblem28() print(problem) @@ -21,15 +20,15 @@ def test_ReliabilityBenchmarkProblem28(self): # Check probability pf = problem.getProbability() pf_exacte = 0.000000146 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) - np.testing.assert_allclose(Y[0], - 146.14) + assert type(Y) is ot.Point + np.testing.assert_allclose(Y[0], -146.14) def test_UseCase(self): problem = otb.ReliabilityProblem28() @@ -46,13 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem31.py b/tests/test_ReliabilityProblem31.py index 50ebeda..33b6dad 100644 --- a/tests/test_ReliabilityProblem31.py +++ b/tests/test_ReliabilityProblem31.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem31(unittest.TestCase): - def test_ReliabilityBenchmarkProblem31(self): problem = otb.ReliabilityProblem31() print(problem) @@ -21,17 +20,16 @@ def test_ReliabilityBenchmarkProblem31(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00018 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 2) if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem35.py b/tests/test_ReliabilityProblem35.py index a9bbd94..b3ef9e3 100644 --- a/tests/test_ReliabilityProblem35.py +++ b/tests/test_ReliabilityProblem35.py @@ -12,7 +12,6 @@ class CheckReliabilityProblem35(unittest.TestCase): - def test_ReliabilityBenchmarkProblem35(self): problem = otb.ReliabilityProblem35() print(problem) @@ -20,14 +19,14 @@ def test_ReliabilityBenchmarkProblem35(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00354 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 3) def test_UseCase(self): @@ -45,12 +44,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_ReliabilityProblem53.py b/tests/test_ReliabilityProblem53.py index a78cf4d..e0a8c8b 100644 --- a/tests/test_ReliabilityProblem53.py +++ b/tests/test_ReliabilityProblem53.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem53(unittest.TestCase): - def test_ReliabilityBenchmarkProblem53(self): problem = otb.ReliabilityProblem53() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem53(self): # Check probability pf = problem.getProbability() pf_exacte = 0.0313 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 1.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 2) def test_UseCase(self): @@ -46,14 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() - - diff --git a/tests/test_ReliabilityProblem55.py b/tests/test_ReliabilityProblem55.py index 9037b3f..8b74cba 100644 --- a/tests/test_ReliabilityProblem55.py +++ b/tests/test_ReliabilityProblem55.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem55(unittest.TestCase): - def test_ReliabilityBenchmarkProblem55(self): problem = otb.ReliabilityProblem55() print(problem) @@ -21,18 +20,16 @@ def test_ReliabilityBenchmarkProblem55(self): # Check probability pf = problem.getProbability() pf_exacte = 0.36 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-7) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-7) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 0.2) - if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem57.py b/tests/test_ReliabilityProblem57.py index 05bb297..dcfd2ed 100644 --- a/tests/test_ReliabilityProblem57.py +++ b/tests/test_ReliabilityProblem57.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem57(unittest.TestCase): - def test_ReliabilityBenchmarkProblem57(self): problem = otb.ReliabilityProblem57() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem57(self): # Check probability pf = problem.getProbability() pf_exacte = 0.0284 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 3) def test_UseCase(self): @@ -46,13 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() - diff --git a/tests/test_ReliabilityProblem75.py b/tests/test_ReliabilityProblem75.py index 0ee05f4..da7e831 100644 --- a/tests/test_ReliabilityProblem75.py +++ b/tests/test_ReliabilityProblem75.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem75(unittest.TestCase): - def test_ReliabilityBenchmarkProblem75(self): problem = otb.ReliabilityProblem75() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem75(self): # Check probability pf = problem.getProbability() pf_exacte = 0.0107 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 3) def test_UseCase(self): @@ -46,12 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() diff --git a/tests/test_ReliabilityProblem89.py b/tests/test_ReliabilityProblem89.py index ebb31b4..03e5334 100644 --- a/tests/test_ReliabilityProblem89.py +++ b/tests/test_ReliabilityProblem89.py @@ -13,7 +13,6 @@ class CheckReliabilityProblem89(unittest.TestCase): - def test_ReliabilityBenchmarkProblem89(self): problem = otb.ReliabilityProblem89() print(problem) @@ -21,14 +20,14 @@ def test_ReliabilityBenchmarkProblem89(self): # Check probability pf = problem.getProbability() pf_exacte = 0.00543 - np.testing.assert_allclose(pf, pf_exacte, rtol=1.e-15) + np.testing.assert_allclose(pf, pf_exacte, rtol=1.0e-15) # Check function event = problem.getEvent() function = event.getFunction() X = [0.0, 0.0] Y = function(X) - assert(type(Y) is ot.Point) + assert type(Y) is ot.Point np.testing.assert_allclose(Y[0], 6) def test_UseCase(self): @@ -46,13 +45,13 @@ def test_UseCase(self): result = algo.getResult() computed_pf = result.getProbabilityEstimate() exact_pf = problem.getProbability() - print('exact_pf=', exact_pf) - print('computed_pf=', computed_pf) + print("exact_pf=", exact_pf) + print("computed_pf=", computed_pf) samplesize = result.getOuterSampling() * result.getBlockSize() print("Sample size : ", samplesize) atol = 1.0 / np.sqrt(samplesize) np.testing.assert_allclose(computed_pf, exact_pf, atol=atol) + if __name__ == "__main__": unittest.main() -