|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Quick test notebook for MRS" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 80, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [ |
| 15 | + { |
| 16 | + "name": "stdout", |
| 17 | + "output_type": "stream", |
| 18 | + "text": [ |
| 19 | + "The autoreload extension is already loaded. To reload it, use:\n", |
| 20 | + " %reload_ext autoreload\n" |
| 21 | + ] |
| 22 | + } |
| 23 | + ], |
| 24 | + "source": [ |
| 25 | + "# We import these lines for debugging purposes, only works on Jupyter Notebook\n", |
| 26 | + "%load_ext autoreload\n", |
| 27 | + "%autoreload 2" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": 81, |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "from rocketpy.simulation.multivariate_rejection_sampler import MultivariateRejectionSampler\n", |
| 37 | + "from rocketpy import MonteCarlo\n", |
| 38 | + "from scipy.stats import norm\n", |
| 39 | + "import numpy as np" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": 88, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "montecarlo_filepath = \"docs/notebooks/monte_carlo_analysis/monte_carlo_analysis_outputs/monte_carlo_class_example\"\n", |
| 49 | + "mrs_filepath = \"mrs\"\n", |
| 50 | + "old_mass_pdf = norm(15.426, 0.5).pdf\n", |
| 51 | + "new_mass_pdf = norm(15, 0.5) .pdf\n", |
| 52 | + "distribution_dict = {\n", |
| 53 | + " \"mass\": (old_mass_pdf, new_mass_pdf),\n", |
| 54 | + "}\n", |
| 55 | + "mrs = MultivariateRejectionSampler(\n", |
| 56 | + " montecarlo_filepath=montecarlo_filepath,\n", |
| 57 | + " mrs_filepath=mrs_filepath,\n", |
| 58 | + " distribution_dict=distribution_dict,\n", |
| 59 | + ")" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": 89, |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [ |
| 67 | + { |
| 68 | + "data": { |
| 69 | + "text/plain": [ |
| 70 | + "107.0" |
| 71 | + ] |
| 72 | + }, |
| 73 | + "execution_count": 89, |
| 74 | + "metadata": {}, |
| 75 | + "output_type": "execute_result" |
| 76 | + } |
| 77 | + ], |
| 78 | + "source": [ |
| 79 | + "mrs.expected_sample_size" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": 90, |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "mrs.sample()" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "execution_count": 91, |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [ |
| 96 | + { |
| 97 | + "name": "stdout", |
| 98 | + "output_type": "stream", |
| 99 | + "text": [ |
| 100 | + "The following input file was imported: mrs.inputs.txt\n", |
| 101 | + "A total of 109 simulations results were loaded from the following output file: mrs.outputs.txt\n", |
| 102 | + "\n", |
| 103 | + "The following error file was imported: mrs.errors.txt\n" |
| 104 | + ] |
| 105 | + } |
| 106 | + ], |
| 107 | + "source": [ |
| 108 | + "mrs_results = MonteCarlo(mrs_filepath, None, None, None)" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": 92, |
| 114 | + "metadata": {}, |
| 115 | + "outputs": [ |
| 116 | + { |
| 117 | + "name": "stdout", |
| 118 | + "output_type": "stream", |
| 119 | + "text": [ |
| 120 | + "A total of 109 simulations results were loaded from the following output file: mrs.outputs.txt\n", |
| 121 | + "\n", |
| 122 | + "The following input file was imported: mrs.inputs.txt\n", |
| 123 | + "The following error file was imported: mrs.errors.txt\n" |
| 124 | + ] |
| 125 | + } |
| 126 | + ], |
| 127 | + "source": [ |
| 128 | + "mrs_results.import_results()" |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + "cell_type": "code", |
| 133 | + "execution_count": null, |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [ |
| 136 | + { |
| 137 | + "name": "stdout", |
| 138 | + "output_type": "stream", |
| 139 | + "text": [ |
| 140 | + "MRS mass mean after resample: 15.029610376989238\n", |
| 141 | + "MRS mass std after resample: 0.5213162519453568\n" |
| 142 | + ] |
| 143 | + } |
| 144 | + ], |
| 145 | + "source": [ |
| 146 | + "mrs_mass_list = []\n", |
| 147 | + "for single_input_dict in mrs_results.inputs_log:\n", |
| 148 | + " mrs_mass_list.append(single_input_dict[\"mass\"])\n", |
| 149 | + "\n", |
| 150 | + "print(f\"MRS mass mean after resample: {np.mean(mrs_mass_list)}\")\n", |
| 151 | + "print(f\"MRS mass std after resample: {np.std(mrs_mass_list)}\")" |
| 152 | + ] |
| 153 | + } |
| 154 | + ], |
| 155 | + "metadata": { |
| 156 | + "kernelspec": { |
| 157 | + "display_name": "testnotebook", |
| 158 | + "language": "python", |
| 159 | + "name": "python3" |
| 160 | + }, |
| 161 | + "language_info": { |
| 162 | + "codemirror_mode": { |
| 163 | + "name": "ipython", |
| 164 | + "version": 3 |
| 165 | + }, |
| 166 | + "file_extension": ".py", |
| 167 | + "mimetype": "text/x-python", |
| 168 | + "name": "python", |
| 169 | + "nbconvert_exporter": "python", |
| 170 | + "pygments_lexer": "ipython3", |
| 171 | + "version": "3.12.2" |
| 172 | + } |
| 173 | + }, |
| 174 | + "nbformat": 4, |
| 175 | + "nbformat_minor": 2 |
| 176 | +} |
0 commit comments