Skip to content

Commit

Permalink
Tests added for BBRC request classes
Browse files Browse the repository at this point in the history
Add distribution file in otbenchmark rep.

Add distribution file in otbenchmark rep. 2

Add distribution file in otbenchmark rep. 3
  • Loading branch information
efekhari27 committed Jun 8, 2020
1 parent d8469db commit 9be744f
Show file tree
Hide file tree
Showing 10 changed files with 1,093 additions and 8 deletions.
33 changes: 28 additions & 5 deletions examples/RequestedBBRCProblem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test de la classe RequestedBBRCProblem\n",
"# RequestedBBRCProblem class use case\n",
"\n",
"L'objectif de cet exemple est de présenter l'utilisation de la classe RequestedBBRCProblem"
"This example presents a simple use of the RequestedBBRCProblem class."
]
},
{
Expand Down Expand Up @@ -71,15 +71,38 @@
"source": [
"# Create the Monte-Carlo algorithm\n",
"algoProb = ot.ProbabilitySimulationAlgorithm(event)\n",
"# MaximumOuterSampling set to a very low value to make a fast example.\n",
"# More realistic parameter value (e.g. 1000).\n",
"algoProb.setMaximumOuterSampling(10)\n",
"algoProb.setMaximumCoefficientOfVariation(0.01)\n",
"algoProb.run()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Number of function calls = 10\nFailure Probability = 0.0000\n"
}
],
"source": [
"# Get the results\n",
"resultAlgo = algoProb.getResult()\n",
"neval = g.getEvaluationCallsNumber()\n",
"print(\"Number of function calls = %d\" % (neval))\n",
"# Because of the low value of the maximumOuterSampling, the estimate is not very accurate.\n",
"pf = resultAlgo.getProbabilityEstimate()\n",
"print(\"Failure Probability = %.4f\" % (pf))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3_cours",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -93,9 +116,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6-final"
"version": "3.7.3-final"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
4 changes: 3 additions & 1 deletion otbenchmark/BBRCDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class BBRCDistribution:
def __init__(self, set_id, problem_id):
"""
Creates an ot.ComposedDistribution from the BBRC 2019 distribution table.
References
----------
https://rprepo.readthedocs.io/en/latest/
Parameters
----------
set_id: int
Expand Down Expand Up @@ -55,7 +57,7 @@ def switch_build_dist(dist_name, a, b, mean, std):

types = ["i4", "i4", "i4", "i4", "U15", "f8", "f8", "f8", "f8", "f8", "f8"]
bbrc_dist_table = np.genfromtxt(
"./distributions/probabilistic_models.csv",
"otbenchmark/distributions/probabilistic_models.csv",
dtype=types,
delimiter=",",
names=True,
Expand Down
7 changes: 6 additions & 1 deletion otbenchmark/RequestedBBRCProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ class RequestedBBRCProblem(ReliabilityBenchmarkProblem):
def __init__(self, username, password, set_id, problem_id):
"""
Creates a ot.PythonFunction requesting a BBRC 2019 function using http requests.
References
----------
https://rprepo.readthedocs.io/en/latest/
Parameters
----------
username: str
Expand Down Expand Up @@ -48,7 +50,10 @@ def g_fun(x):
# BBRCResults
types = ["i4", "i4", "i4", "f8"]
bbrc_result_table = np.genfromtxt(
"./distributions/beta_results.csv", dtype=types, delimiter=",", names=True
"otbenchmark/distributions/beta_results.csv",
dtype=types,
delimiter=",",
names=True,
)
my_result = bbrc_result_table[
(bbrc_result_table["problem_id"] == self.problem_id)
Expand Down
2 changes: 2 additions & 0 deletions otbenchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
FourBranchSerialSystemReliabilityBenchmarkProblem,
)
from .RequestedBBRCProblem import RequestedBBRCProblem
from .BBRCDistribution import BBRCDistribution

# from .CentralDispersionBenchmarkProblem import
# CentralDispersionBenchmarkProblem
Expand Down Expand Up @@ -66,5 +67,6 @@
"ReliabilityProblem63",
"FourBranchSerialSystemReliabilityBenchmarkProblem",
"RequestedBBRCProblem",
"BBRCDistribution",
]
__version__ = "1.0"
30 changes: 30 additions & 0 deletions otbenchmark/distributions/beta_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set_id,problem_id,reliability_problem_id,beta
-1,1,8,3.16
-1,2,22,2.64
1,1,14,2.42
1,2,24,2.76
1,3,28,5.11
1,4,31,3.58
1,5,38,2.48
1,6,53,1.86
1,7,54,3.09
1,8,63,3.36
1,9,75,2.33
1,10,107,5.0
1,11,111,4.81
1,12,201,3.7
1,13,203,4.92
1,14,213,3.45
1,15,300,3.88
1,16,301,3.81
2,1,25,4.36
2,2,33,2.80
2,3,35,2.70
2,4,55,-0.15
2,5,57,1.91
2,6,60,1.70
2,7,77,5.0
2,8,89,2.55
2,9,91,3.19
2,10,110,4.0
2,11,202,3.43
Loading

0 comments on commit 9be744f

Please sign in to comment.