From 451170eb089a51157d8d356a93e1edad16ee0e5c Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Wed, 22 May 2024 17:39:58 +0200 Subject: [PATCH] FIX: make notebooks runnable --- docs/report/030.ipynb | 24 +++++--------------- docs/report/031.ipynb | 35 ++++++++++++++-------------- docs/report/032.ipynb | 53 +++++++++++++++++++++++-------------------- 3 files changed, 52 insertions(+), 60 deletions(-) diff --git a/docs/report/030.ipynb b/docs/report/030.ipynb index b921b0fa..3fdbaf0a 100644 --- a/docs/report/030.ipynb +++ b/docs/report/030.ipynb @@ -1193,9 +1193,9 @@ "source": [ "for p in optimized_parameters_F:\n", " print(p)\n", - " print(f\" initial: {initial_parameters_fvector[p]:.3}\")\n", - " print(f\" optimized F vector: {optimized_parameters_F[p]:.3}\")\n", - " print(f\" original: {original_parameters[p]:.3}\")\n", + " print(f\" initial: {initial_parameters_fvector[p]:.3f}\")\n", + " print(f\" optimized F vector: {optimized_parameters_F[p]:.3f}\")\n", + " print(f\" original: {original_parameters[p]:.3f}\")\n", "latest_parameters_F = CSVSummary.load_latest_parameters(\"fit_traceback.csv\")\n", "latest_parameters_F" ] @@ -1208,24 +1208,12 @@ "source": [ "for p in optimized_parameters_BW:\n", " print(p)\n", - " print(f\" initial: {initial_parameters_bw[p]:.3}\")\n", - " print(f\" optimized Breit-Wigner: {optimized_parameters_BW[p]:.3}\")\n", - " print(f\" original: {original_parameters[p]:.3}\")\n", + " print(f\" initial: {initial_parameters_bw[p]:.3f}\")\n", + " print(f\" optimized Breit-Wigner: {optimized_parameters_BW.get(p, -9999):3f}\")\n", + " print(f\" original: {original_parameters.get(p, -9999):.3f}\")\n", "latest_parameters_BW = CSVSummary.load_latest_parameters(\"fit_traceback.csv\")\n", "latest_parameters_BW" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/report/031.ipynb b/docs/report/031.ipynb index e5f923fd..e400258c 100644 --- a/docs/report/031.ipynb +++ b/docs/report/031.ipynb @@ -100,7 +100,7 @@ "from ampform.io import aslatex\n", "from ampform.kinematics.phasespace import Kallen\n", "from ampform.sympy import unevaluated\n", - "from IPython.display import Latex, display\n", + "from IPython.display import Latex, Math, display\n", "from qrules.particle import Particle, ParticleCollection\n", "from sympy import Abs\n", "from tensorwaves.data import SympyDataTransformer\n", @@ -201,36 +201,28 @@ "source": [ "model_builder = ampform.get_builder(reaction)\n", "model_builder.adapter.permutate_registered_topologies()\n", - "model_builder.scalar_initial_state_mass = True\n", - "model_builder.stable_final_state_ids = [0, 1, 2]\n", + "model_builder.config.scalar_initial_state_mass = True\n", + "model_builder.config.stable_final_state_ids = [0, 1, 2]\n", "for name in reaction.get_intermediate_particles().names:\n", " model_builder.set_dynamics(name, create_dynamics_symbol)\n", "model = model_builder.formulate()\n", "model.intensity.cleanup()" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "amp, *_ = model.amplitudes.values()\n", - "amp" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": { - "tags": [] + "jupyter": { + "source_hidden": true + } }, "outputs": [], "source": [ "selected_amplitudes = {\n", - " k: v for i, (k, v) in enumerate(model.amplitudes.items()) if i < 3\n", + " k: v for i, (k, v) in enumerate(model.amplitudes.items()) if i < 2\n", "}\n", - "src = aslatex(selected_amplitudes)" + "Math(aslatex(selected_amplitudes, terms_per_line=1))" ] }, { @@ -274,7 +266,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "@unevaluated(real=False)\n", @@ -933,7 +929,10 @@ "sub_phase_bw = {\n", " p: np.angle(\n", " compute_sub_intensity(\n", - " dynamics_func_bw, data, resonances=[p.latex], coupling_pattern=r\"Dummy_\"\n", + " dynamics_func_bw,\n", + " data,\n", + " resonances=[p.latex],\n", + " coupling_pattern=r\"Dummy_\",\n", " )\n", " )\n", " for p, _ in resonances\n", diff --git a/docs/report/032.ipynb b/docs/report/032.ipynb index 546ed068..051f09dd 100644 --- a/docs/report/032.ipynb +++ b/docs/report/032.ipynb @@ -827,22 +827,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [ - "full-width" - ] - }, + "metadata": {}, "outputs": [], "source": [ "combined_expressions = {**K_expressions, **rho_expressions, **P_expressions}\n", - "F_expressions = np.array([\n", - " perform_cached_doit(F_vector[i].xreplace(combined_expressions))\n", - " for i in range(n_channels)\n", - "])" + "F_exprs = F_vector.xreplace(combined_expressions)\n", + "F_exprs[0].simplify(doit=False)" ] }, { @@ -858,6 +848,15 @@ "### Model $F$ vector" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "F_unfolded_exprs = np.array([perform_cached_doit(expr) for expr in F_exprs])" + ] + }, { "cell_type": "code", "execution_count": null, @@ -873,7 +872,8 @@ "DYNAMICS_EXPRESSIONS_FVECTOR = []\n", "for i in range(n_channels):\n", " exprs = {\n", - " symbol: F_expressions[i] for symbol, resonances in COLLECTED_X_SYMBOLS.items()\n", + " symbol: F_unfolded_exprs[i]\n", + " for symbol, resonances in COLLECTED_X_SYMBOLS.items()\n", " }\n", " DYNAMICS_EXPRESSIONS_FVECTOR.append(exprs)\n", "\n", @@ -956,11 +956,15 @@ "metadata": {}, "outputs": [], "source": [ + "m_res = 1.82\n", + "g_res_ch0 = 1.8\n", + "g_res_ch1 = 2.5\n", + "\n", "new_parameters_fvector = {\n", " R\"m_{N(Fakestar)^+}\": 1.71,\n", " R\"\\beta_{N(Fakestar)^+}\": 1 + 0j,\n", - " R\"g_{N(Fakestar)^+,0}\": 0.8,\n", - " R\"g_{N(Fakestar)^+,1}\": 0.9,\n", + " R\"g_{N(Fakestar)^+,0}\": g_res_ch0,\n", + " R\"g_{N(Fakestar)^+,1}\": g_res_ch1,\n", "}" ] }, @@ -1273,8 +1277,8 @@ "initial_parameters = {\n", " R\"m_{N(Fakestar)^+}\": 1.9,\n", " R\"\\beta_{N(Fakestar)^+}\": 1 + 0j,\n", - " R\"g_{N(Fakestar)^+,0}\": 0.8,\n", - " R\"g_{N(Fakestar)^+,1}\": 0.6,\n", + " R\"g_{N(Fakestar)^+,0}\": 2.8,\n", + " R\"g_{N(Fakestar)^+,1}\": 1.6,\n", "}\n", "INTENSITY_FUNCS_FVECTOR[0].parameters" ] @@ -1555,10 +1559,7 @@ "n_real_par = fit_result.count_number_of_parameters(complex_twice=True)\n", "n_events = len(next(iter(data.values())))\n", "log_likelihood = -fit_result.estimator_value\n", - "\n", - "aic = 2 * n_real_par - 2 * log_likelihood\n", - "bic = n_real_par * np.log(n_events) - 2 * log_likelihood\n", - "aic" + "log_likelihood" ] }, { @@ -1567,7 +1568,8 @@ "metadata": {}, "outputs": [], "source": [ - "bic" + "aic = 2 * n_real_par - 2 * log_likelihood\n", + "aic" ] }, { @@ -1575,7 +1577,10 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "bic = n_real_par * np.log(n_events) - 2 * log_likelihood\n", + "bic" + ] } ], "metadata": {