Skip to content

Commit

Permalink
Import distribution and beta table with numpy
Browse files Browse the repository at this point in the history
notebook metadata environnement name
  • Loading branch information
efekhari27 committed May 17, 2020
1 parent c438f64 commit d8469db
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 89 deletions.
21 changes: 13 additions & 8 deletions examples/RequestedBBRCProblem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
"cell_type": "code",
"execution_count": 2,
"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)"
]
},
{
Expand All @@ -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": [
Expand Down Expand Up @@ -88,7 +93,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.6-final"
}
},
"nbformat": 4,
Expand Down
13 changes: 9 additions & 4 deletions otbenchmark/BBRCDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
problem"""

import openturns as ot
import pandas as pd
import numpy as np


class BBRCDistribution:
Expand Down Expand Up @@ -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"],
Expand Down
10 changes: 6 additions & 4 deletions otbenchmark/RequestedBBRCProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from otbenchmark import evaluate
import openturns as ot
import numpy as np
import pandas as pd


class RequestedBBRCProblem(ReliabilityBenchmarkProblem):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions tests/test_ReliabilityProblem110.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@


class CheckReliabilityProblem89(unittest.TestCase):

def test_ReliabilityBenchmarkProblem110(self):
problem = otb.ReliabilityProblem110()
print(problem)

# 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):
Expand All @@ -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()

11 changes: 5 additions & 6 deletions tests/test_ReliabilityProblem111.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@


class CheckReliabilityProblem111(unittest.TestCase):

def test_ReliabilityBenchmarkProblem111(self):
problem = otb.ReliabilityProblem111()
print(problem)

# 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):
Expand All @@ -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()

10 changes: 5 additions & 5 deletions tests/test_ReliabilityProblem22.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@


class CheckReliabilityProblem22(unittest.TestCase):

def test_ReliabilityBenchmarkProblem22(self):
problem = otb.ReliabilityProblem22()
print(problem)

# 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):
Expand All @@ -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()
10 changes: 5 additions & 5 deletions tests/test_ReliabilityProblem24.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@


class CheckReliabilityProblem24(unittest.TestCase):

def test_ReliabilityBenchmarkProblem24(self):
problem = otb.ReliabilityProblem24()
print(problem)

# 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):
Expand All @@ -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()
10 changes: 5 additions & 5 deletions tests/test_ReliabilityProblem25.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@


class CheckReliabilityProblem25(unittest.TestCase):

def test_ReliabilityBenchmarkProblem25(self):
problem = otb.ReliabilityProblem25()
print(problem)

# 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):
Expand All @@ -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()
13 changes: 6 additions & 7 deletions tests/test_ReliabilityProblem28.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@


class CheckReliabilityProblem28(unittest.TestCase):

def test_ReliabilityBenchmarkProblem28(self):
problem = otb.ReliabilityProblem28()
print(problem)

# 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()
Expand All @@ -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()

6 changes: 2 additions & 4 deletions tests/test_ReliabilityProblem31.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@


class CheckReliabilityProblem31(unittest.TestCase):

def test_ReliabilityBenchmarkProblem31(self):
problem = otb.ReliabilityProblem31()
print(problem)

# 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()

Loading

0 comments on commit d8469db

Please sign in to comment.