Skip to content

Commit

Permalink
MNT: quick notebook to test MRS during development
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-Prates committed Nov 28, 2024
1 parent ed87081 commit 766bd58
Showing 1 changed file with 176 additions and 0 deletions.
176 changes: 176 additions & 0 deletions test_mrs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quick test notebook for MRS"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"# We import these lines for debugging purposes, only works on Jupyter Notebook\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {},
"outputs": [],
"source": [
"from rocketpy.simulation.multivariate_rejection_sampler import MultivariateRejectionSampler\n",
"from rocketpy import MonteCarlo\n",
"from scipy.stats import norm\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [],
"source": [
"montecarlo_filepath = \"docs/notebooks/monte_carlo_analysis/monte_carlo_analysis_outputs/monte_carlo_class_example\"\n",
"mrs_filepath = \"mrs\"\n",
"old_mass_pdf = norm(15.426, 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",
" 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,
"metadata": {},
"outputs": [],
"source": [
"mrs.sample()"
]
},
{
"cell_type": "code",
"execution_count": 91,
"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",
"\n",
"The following error file was imported: mrs.errors.txt\n"
]
}
],
"source": [
"mrs_results = MonteCarlo(mrs_filepath, None, None, None)"
]
},
{
"cell_type": "code",
"execution_count": 92,
"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",
"\n",
"The following input file was imported: mrs.inputs.txt\n",
"The following error file was imported: mrs.errors.txt\n"
]
}
],
"source": [
"mrs_results.import_results()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MRS mass mean after resample: 15.029610376989238\n",
"MRS mass std after resample: 0.5213162519453568\n"
]
}
],
"source": [
"mrs_mass_list = []\n",
"for single_input_dict in mrs_results.inputs_log:\n",
" mrs_mass_list.append(single_input_dict[\"mass\"])\n",
"\n",
"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)}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "testnotebook",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 766bd58

Please sign in to comment.