From c45fabfc6f214728329c67acea4ff1d635db2d50 Mon Sep 17 00:00:00 2001 From: Lucas de Oliveira Prates Date: Thu, 28 Nov 2024 18:23:22 -0300 Subject: [PATCH] MNT: quick notebook to test MRS during development --- test_mrs.ipynb | 176 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 test_mrs.ipynb diff --git a/test_mrs.ipynb b/test_mrs.ipynb new file mode 100644 index 000000000..09015b197 --- /dev/null +++ b/test_mrs.ipynb @@ -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 +}