Skip to content

Commit

Permalink
MNT: refactoring class to match review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-Prates committed Dec 20, 2024
1 parent d3ab5f2 commit 3a3c9e6
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 153 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
"statsmodels",
"STFT",
"subintervals",
"supremum",
"suptitle",
"supxlabel",
"supylabel",
Expand Down
98 changes: 54 additions & 44 deletions test_mrs.ipynb → docs/notebooks/test_mrs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": 30,
"metadata": {},
"outputs": [
{
Expand All @@ -29,78 +29,61 @@
},
{
"cell_type": "code",
"execution_count": 81,
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"from rocketpy.simulation.multivariate_rejection_sampler import MultivariateRejectionSampler\n",
"from rocketpy.simulation.multivariate_rejection_sampler import (\n",
" MultivariateRejectionSampler,\n",
")\n",
"from rocketpy import MonteCarlo\n",
"from scipy.stats import norm\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 88,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"montecarlo_filepath = \"docs/notebooks/monte_carlo_analysis/monte_carlo_analysis_outputs/monte_carlo_class_example\"\n",
"mrs_filepath = \"mrs\"\n",
"monte_carlo_filepath = (\n",
" \"monte_carlo_analysis/monte_carlo_analysis_outputs/monte_carlo_class_example\"\n",
")\n",
"mrs_filepath = \"monte_carlo_analysis/monte_carlo_analysis_outputs/mrs\"\n",
"old_mass_pdf = norm(15.426, 0.5).pdf\n",
"new_mass_pdf = norm(15, 0.5) .pdf\n",
"new_mass_pdf = norm(15, 0.5).pdf\n",
"distribution_dict = {\n",
" \"mass\": (old_mass_pdf, new_mass_pdf),\n",
"}\n",
"mrs = MultivariateRejectionSampler(\n",
" montecarlo_filepath=montecarlo_filepath,\n",
" monte_carlo_filepath=monte_carlo_filepath,\n",
" mrs_filepath=mrs_filepath,\n",
" distribution_dict=distribution_dict,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"107.0"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mrs.expected_sample_size"
]
},
{
"cell_type": "code",
"execution_count": 90,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"mrs.sample()"
"mrs.sample(distribution_dict=distribution_dict)"
]
},
{
"cell_type": "code",
"execution_count": 91,
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The following input file was imported: mrs.inputs.txt\n",
"A total of 109 simulations results were loaded from the following output file: mrs.outputs.txt\n",
"The following input file was imported: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.inputs.txt\n",
"A total of 116 simulations results were loaded from the following output file: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.outputs.txt\n",
"\n",
"The following error file was imported: mrs.errors.txt\n"
"The following error file was imported: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.errors.txt\n"
]
}
],
Expand All @@ -110,17 +93,17 @@
},
{
"cell_type": "code",
"execution_count": 92,
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A total of 109 simulations results were loaded from the following output file: mrs.outputs.txt\n",
"A total of 116 simulations results were loaded from the following output file: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.outputs.txt\n",
"\n",
"The following input file was imported: mrs.inputs.txt\n",
"The following error file was imported: mrs.errors.txt\n"
"The following input file was imported: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.inputs.txt\n",
"The following error file was imported: monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.errors.txt\n"
]
}
],
Expand All @@ -130,15 +113,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MRS mass mean after resample: 15.029610376989238\n",
"MRS mass std after resample: 0.5213162519453568\n"
"MRS mass mean after resample: 15.041934326472004\n",
"MRS mass std after resample: 0.48924085702427966\n"
]
}
],
Expand All @@ -150,11 +133,38 @@
"print(f\"MRS mass mean after resample: {np.mean(mrs_mass_list)}\")\n",
"print(f\"MRS mass std after resample: {np.std(mrs_mass_list)}\")"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"107.0"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mrs.expected_sample_size"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "testnotebook",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -168,7 +178,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 3a3c9e6

Please sign in to comment.