@@ -60,175 +60,155 @@ def _params_validation(self, data_collector: Any, params: dict[str, float | rv_c
6060 raise ValueError ("Gamma cant be zero" )
6161 return data_class
6262
63- def _classical_moment (self , n : int , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
63+ def _classical_moment (self , n : int , integrator : Integrator = QuadIntegrator () ) -> tuple [float , float ]:
6464 """
6565 Compute n-th moment of classical NMM
6666
6767 Args:
6868 n (): Moment ordinal
69- params (): Parameters of integration algorithm
70- integrator (): type of integrator to computing
69+ integrator (): class of integrator with params to computing
7170
7271 Returns: moment approximation and error tolerance
7372
7473 """
7574 mixture_moment = 0
7675 error_tolerance = 0
77- integrator = integrator or QuadIntegrator ()
7876 for k in range (0 , n + 1 ):
7977 for l in range (0 , k + 1 ):
8078 coefficient = binom (n , n - k ) * binom (k , k - l ) * (self .params .beta ** (k - l )) * (
8179 self .params .gamma ** l )
82- mixing_moment = integrator .compute_integral (lambda u : self .params .distribution .ppf (u ) ** (k - l ),
83- {"a" : 0 , "b" : 1 , ** params })
80+ mixing_moment = integrator .compute (lambda u : self .params .distribution .ppf (u ) ** (k - l ))
8481 error_tolerance += (self .params .beta ** (k - l )) * mixing_moment .error
8582 mixture_moment += coefficient * (self .params .alpha ** (n - k )) * mixing_moment .value * norm .moment (l )
8683 return mixture_moment , error_tolerance
8784
8885
89- def _canonical_moment (self , n : int , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
86+ def _canonical_moment (self , n : int , integrator : Integrator = QuadIntegrator () ) -> tuple [float , float ]:
9087 """
9188 Compute n-th moment of canonical NMM
9289
9390 Args:
9491 n (): Moment ordinal
95- params (): Parameters of integration algorithm
96- integrator (): type of integrator to computing
92+ integrator (): class of integrator with params to computing
9793
9894 Returns: moment approximation and error tolerance
9995
10096 """
10197 mixture_moment = 0
10298 error_tolerance = 0
103- integrator = integrator or QuadIntegrator ()
10499 for k in range (0 , n + 1 ):
105100 coefficient = binom (n , n - k ) * (self .params .sigma ** k )
106- mixing_moment = integrator .compute_integral (lambda u : self .params .distribution .ppf (u ) ** (n - k ),
107- {"a" : 0 , "b" : 1 , ** params })
101+ mixing_moment = integrator .compute (lambda u : self .params .distribution .ppf (u ) ** (n - k ))
108102 error_tolerance += mixing_moment .error
109103 mixture_moment += coefficient * mixing_moment .value * norm .moment (k )
110104 return mixture_moment , error_tolerance
111105
112- def compute_moment (self , n : int , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
106+ def compute_moment (self , n : int , integrator : Integrator = QuadIntegrator ) -> tuple [float , float ]:
113107 """
114108 Compute n-th moment of NMM
115109
116110 Args:
117111 n (): Moment ordinal
118- params (): Parameters of integration algorithm
119- integrator (): type of integrator to computing
112+ integrator (): class of integrator with params to computing
120113
121114 Returns: moment approximation and error tolerance
122115
123116 """
124117 if isinstance (self .params , _NMMClassicDataCollector ):
125- return self ._classical_moment (n , params , integrator )
126- return self ._canonical_moment (n , params , integrator )
118+ return self ._classical_moment (n , integrator )
119+ return self ._canonical_moment (n , integrator )
127120
128- def _canonical_compute_cdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
121+ def _canonical_compute_cdf (self , x : float , integrator : Integrator = RQMCIntegrator ) -> tuple [float , float ]:
129122 """
130123 Equation for canonical cdf
131124 Args:
132125 x (): point
133- params (): parameters of RQMC algorithm
134- integrator (): type of integrator to computing
126+ integrator (): class of integrator with params to computing
135127
136128 Returns: computed cdf and error tolerance
137129
138130 """
139- integrator = integrator or RQMCIntegrator ()
140- rqmc = integrator .compute_integral (func = lambda u : norm .cdf ((x - self .params .distribution .ppf (u )) / np .abs (self .params .sigma )), ** params )
141- return rqmc .value , rqmc .error
131+ result = integrator .compute (func = lambda u : norm .cdf ((x - self .params .distribution .ppf (u )) / np .abs (self .params .sigma )))
132+ return result .value , result .error
142133
143- def _classical_compute_cdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
134+ def _classical_compute_cdf (self , x : float , integrator : Integrator = RQMCIntegrator ) -> tuple [float , float ]:
144135 """
145136 Equation for classic cdf
146137 Args:
147138 x (): point
148- params (): parameters of RQMC algorithm
149- integrator (): type of integrator to computing
139+ integrator (): class of integrator with params to computing
150140
151141 Returns: computed cdf and error tolerance
152142
153143 """
154- integrator = integrator or RQMCIntegrator ()
155- rqmc = integrator .compute_integral (func =
144+ result = integrator .compute (func =
156145 lambda u : norm .cdf (
157146 (x - self .params .alpha - self .params .beta * self .params .distribution .ppf (u )) / np .abs (self .params .gamma )
158- ),
159- ** params
147+ )
160148 )
161- return rqmc .value , rqmc .error
149+ return result .value , result .error
162150
163- def compute_cdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
151+ def compute_cdf (self , x : float , integrator : Integrator = RQMCIntegrator ) -> tuple [float , float ]:
164152 """
165153 Choose equation for cdf estimation depends on Mixture form
166154 Args:
167155 x (): point
168- params (): parameters of RQMC algorithm
169- integrator (): type of integrator to computing
156+ integrator (): class of integrator with params to computing
170157
171158 Returns: Computed pdf and error tolerance
172159
173160 """
174161 if isinstance (self .params , _NMMCanonicalDataCollector ):
175- return self ._canonical_compute_cdf (x , params , integrator )
176- return self ._classical_compute_cdf (x , params , integrator )
162+ return self ._canonical_compute_cdf (x , integrator )
163+ return self ._classical_compute_cdf (x , integrator )
177164
178- def _canonical_compute_pdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
165+ def _canonical_compute_pdf (self , x : float , integrator : Integrator = RQMCIntegrator ) -> tuple [float , float ]:
179166 """
180167 Equation for canonical pdf
181168 Args:
182169 x (): point
183- params (): parameters of RQMC algorithm
184- integrator (): type of integrator to computing
170+ integrator (): class of integrator with params to computing
185171
186172 Returns: computed pdf and error tolerance
187173
188174 """
189- integrator = integrator or RQMCIntegrator ()
190- rqmc = integrator .compute_integral (func =
175+ result = integrator .compute (func =
191176 lambda u : (1 / np .abs (self .params .sigma ))
192177 * norm .pdf ((x - self .params .distribution .ppf (u )) / np .abs (self .params .sigma )),
193- ** params
194178 )
195- return rqmc .value , rqmc .error
179+ return result .value , result .error
196180
197- def _classical_compute_pdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
181+ def _classical_compute_pdf (self , x : float , integrator : Integrator = RQMCIntegrator () ) -> tuple [float , float ]:
198182 """
199183 Equation for classic pdf
200184 Args:
201185 x (): point
202- params (): parameters of RQMC algorithm
203- integrator (): type of integrator to computing
186+ integrator (): class of integrator with params to computing
204187
205188 Returns: computed pdf and error tolerance
206189
207190 """
208- integrator = integrator or RQMCIntegrator ()
209- rqmc = integrator .compute_integral (func =
191+ result = integrator .compute (func =
210192 lambda u : (1 / np .abs (self .params .gamma ))
211193 * norm .pdf (
212194 (x - self .params .alpha - self .params .beta * self .params .distribution .ppf (u )) / np .abs (self .params .gamma )
213195 ),
214- ** params
215196 )
216- return rqmc .value , rqmc .error
197+ return result .value , result .error
217198
218- def compute_pdf (self , x : float , params : dict , integrator : Integrator = None ) -> tuple [float , float ]:
199+ def compute_pdf (self , x : float , integrator : Integrator = RQMCIntegrator () ) -> tuple [float , float ]:
219200 """
220201 Choose equation for pdf estimation depends on Mixture form
221202 Args:
222203 x (): point
223- params (): parameters of RQMC algorithm
224- integrator (): type of integrator to computing
204+ integrator (): class of integrator with params to computing
225205
226206 Returns: Computed pdf and error tolerance
227207
228208 """
229209 if isinstance (self .params , _NMMCanonicalDataCollector ):
230- return self ._canonical_compute_pdf (x , params , integrator )
231- return self ._classical_compute_pdf (x , params , integrator )
210+ return self ._canonical_compute_pdf (x , integrator )
211+ return self ._classical_compute_pdf (x , integrator )
232212
233213 def _classical_compute_log_pdf (self , x : float , params : dict ) -> tuple [float , float ]:
234214 """
0 commit comments