@@ -97,18 +97,14 @@ def tau(self, value: Optional[float]) -> None:
9797 raise TypeError ("tau must be a float or None" )
9898 self ._tau = value
9999
100- def on_fit_end (self , ** kwargs ) -> None :
101- """On fit end method."""
102- self .incremental_mean .num_values = len (kwargs ["X" ])
103-
104100 def on_update_end (self , value : Union [int , float ], ** kwargs ) -> None :
105101 """On update end method.
106102
107103 :param value: value to update detector
108104 :type value: int
109105 """
110106 self .incremental_mean .update (value = value )
111- self .p_value , likelihood = self ._calculate_p_value (value = value )
107+ self .p_value , likelihood = self ._calculate_p_value ()
112108
113109 self .logs .update (
114110 {
@@ -134,14 +130,13 @@ def _calculate_tau_squared(
134130 tau_squared = sigma_squared * minus_b_cdf / (1 / b * norm .pdf (b ) - minus_b_cdf )
135131 return tau_squared
136132
137- def _calculate_p_value (self , value : float ) -> Tuple [float , float ]:
133+ def _calculate_p_value (self ) -> Tuple [float , float ]:
138134 likelihood = self ._likelihood_normal_mixing_distribution (
139135 mean = self .incremental_mean .get (),
140136 sigma = self .sigma ,
141137 sigma_squared = self .sigma_squared ,
142138 tau_squared = self .tau_squared ,
143139 two_sigma_squared = self .two_sigma_squared ,
144- value = value ,
145140 n = self .detector .num_instances , # type: ignore
146141 )
147142 p_value = min (
@@ -157,15 +152,14 @@ def _likelihood_normal_mixing_distribution(
157152 sigma_squared : float ,
158153 tau_squared : float ,
159154 two_sigma_squared : float ,
160- value : float ,
161155 n : int ,
162156 ) -> float :
163157 n_tau_squared = n * tau_squared
164158 sigma_squared_plus_n_tau_squared = sigma_squared + n_tau_squared
165159 likelihood = (sigma / np .sqrt (sigma_squared_plus_n_tau_squared )) * np .exp (
166160 n
167161 * n_tau_squared
168- * (mean - value ) ** 2
169- / (two_sigma_squared * ( sigma_squared_plus_n_tau_squared ) )
162+ * mean ** 2 # (mean - theta ) ** 2, theta = 0 (H_0 value, no distance)
163+ / (two_sigma_squared * sigma_squared_plus_n_tau_squared )
170164 )
171165 return likelihood
0 commit comments