Note
Go to the end to download the full example code
Examples for error propagation
Hear we use the same config in particle_amplitude.py
9 config_str = """
10 decay:
11 A:
12 - [R1, B]
13 - [R2, C]
14 - [R3, D]
15 R1: [C, D]
16 R2: [B, D]
17 R3: [B, C]
18
19 particle:
20 $top:
21 A: { mass: 1.86, J: 0, P: -1}
22 $finals:
23 B: { mass: 0.494, J: 0, P: -1}
24 C: { mass: 0.139, J: 0, P: -1}
25 D: { mass: 0.139, J: 0, P: -1}
26 R1: [ R1_a, R1_b ]
27 R1_a: { mass: 0.7, width: 0.05, J: 1, P: -1}
28 R1_b: { mass: 0.5, width: 0.05, J: 0, P: +1}
29 R2: { mass: 0.824, width: 0.05, J: 0, P: +1}
30 R3: { mass: 0.824, width: 0.05, J: 0, P: +1}
31
32 """
33
34 import matplotlib.pyplot as plt
35 import yaml
36
37 from tf_pwa.config_loader import ConfigLoader
38 from tf_pwa.histogram import Hist1D
39
40 config = ConfigLoader(yaml.full_load(config_str))
41 input_params = {
42 "A->R1_a.BR1_a->C.D_total_0r": 6.0,
43 "A->R1_b.BR1_b->C.D_total_0r": 1.0,
44 "A->R2.CR2->B.D_total_0r": 2.0,
45 "A->R3.DR3->B.C_total_0r": 1.0,
46 }
47 config.set_params(input_params)
48
49 data = config.generate_toy(1000)
50 phsp = config.generate_phsp(10000)
9.7%[▓▓▓▓>---------------------------------------------] 0.51/5.22s eff: 90.000000%
82.6%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>--------] 1.48/1.79s eff: 8.013083%
102.1%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓>] 2.04/2.00s eff: 6.072845%
100.0%[▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 2.04/2.04s eff: 6.094579%
After we calculated the parameters error, we will have an error matrix config.inv_he
(using the inverse hessain).
It is possible to save such matrix directly by numpy.save
and to load it by numpy.load
.
57 config.get_params_error(data=[data], phsp=[phsp])
Using Model
Time for calculating errors: 0.6394963264465332
hesse_error: [0.06368466266913815, 0.10248136357962974, 0.1194471318835248, 0.10732464158763698, 0.0810388678367542, 0.12337668814702782]
{'A->R1_b.BR1_b->C.D_total_0r': 0.06368466266913815, 'A->R1_b.BR1_b->C.D_total_0i': 0.10248136357962974, 'A->R2.CR2->B.D_total_0r': 0.1194471318835248, 'A->R2.CR2->B.D_total_0i': 0.10732464158763698, 'A->R3.DR3->B.C_total_0r': 0.0810388678367542, 'A->R3.DR3->B.C_total_0i': 0.12337668814702782}
We can use the following method to profamance the error propagation
by adding some calculation here. We need to use tensorflow
functions instead of those of math
or numpy
.
68 import tensorflow as tf
69
70 with config.params_trans() as pt:
71 a2_r = pt["A->R2.CR2->B.D_total_0r"]
72 a2_i = pt["A->R2.CR2->B.D_total_0r"]
73 a2_x = a2_r * tf.cos(a2_i)
And then we can calculate the error we needed as
78 print(a2_x.numpy(), pt.get_error(a2_x).numpy())
-0.8322936730942848 0.2669334853947521
We can also calculate some more complex examples, such as the ratio in mass range (0.75, 0.85) over full phace space. Even further, we can get the error of error in the meaning of error propagation.
84 from tf_pwa.data import data_mask
85
86 m_R2 = phsp.get_mass("(B, D)")
87 cut_cond = (m_R2 < 0.85) & (m_R2 > 0.75)
88
89 amp = config.get_amplitude()
90
91 with config.params_trans() as pt1:
92 with config.params_trans() as pt:
93 int_mc = tf.reduce_sum(amp(phsp))
94 cut_phsp = data_mask(phsp, cut_cond)
95 cut_int_mc = tf.reduce_sum(amp(cut_phsp))
96 ratio = cut_int_mc / int_mc
97 error = pt.get_error(ratio)
98
99 print(ratio.numpy(), "+/-", error.numpy())
100 print(error.numpy(), "+/-", pt1.get_error(error).numpy())
0.385674297531734 +/- 0.010879651404439906
0.010879651404439906 +/- 0.0006798527108116393
Total running time of the script: (0 minutes 3.883 seconds)