Skip to content

Commit

Permalink
FIX: make notebooks runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed May 22, 2024
1 parent 4061b62 commit 451170e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 60 deletions.
24 changes: 6 additions & 18 deletions docs/report/030.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand All @@ -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": {
Expand Down
35 changes: 17 additions & 18 deletions docs/report/031.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))"
]
},
{
Expand Down Expand Up @@ -274,7 +266,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"@unevaluated(real=False)\n",
Expand Down Expand Up @@ -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",
Expand Down
53 changes: 29 additions & 24 deletions docs/report/032.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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",
"}"
]
},
Expand Down Expand Up @@ -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"
]
Expand Down Expand Up @@ -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"
]
},
{
Expand All @@ -1567,15 +1568,19 @@
"metadata": {},
"outputs": [],
"source": [
"bic"
"aic = 2 * n_real_par - 2 * log_likelihood\n",
"aic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"bic = n_real_par * np.log(n_events) - 2 * log_likelihood\n",
"bic"
]
}
],
"metadata": {
Expand Down

0 comments on commit 451170e

Please sign in to comment.