File wellmet/whitebox.py changed (mode: 100644) (index e4d83e5..3699614) |
... |
... |
class Gaussian_Z_sum(WhiteBox): #ё куда ж без этого... |
311 |
311 |
return 'Gaussian_Z_sum(nvar=%s, beta_exact=%s)' % (wt.f.nvar, wt.beta_exact) |
return 'Gaussian_Z_sum(nvar=%s, beta_exact=%s)' % (wt.f.nvar, wt.beta_exact) |
312 |
312 |
|
|
313 |
313 |
|
|
|
314 |
|
def gauss_prod_CDF(z): |
|
315 |
|
"""product Z= X_1 * X_2 has probability density f(z) = K_0(|z|)/pi, |
|
316 |
|
where K_0() is the modified Bessel function of the second kind (zero order) and |
|
317 |
|
$X_1, X_2$ are independent standard normal variables. |
|
318 |
|
The distribution function F(z) = \int_{-\infty}^z f(t) dt can be solved in closed form as follows |
|
319 |
|
F_Z(z)= 1/2 + z/2/pi * (K_0(|z|) * (2 + pi * L_1(z)) + K_1(|z|) * pi * L_0(|z|)), |
|
320 |
|
where L_0() L_1() are the modified Struve functions of orders zero and one respectively. |
|
321 |
|
""" |
|
322 |
|
StruveL0 = special.modstruve(0, np.abs(z)) |
|
323 |
|
StruveL1 = special.modstruve(1, z) |
|
324 |
|
BesselK0 = special.kn(0, np.abs(z)) |
|
325 |
|
BesselK1 = special.kn(1, np.abs(z)) |
|
326 |
|
return 0.5 + z/2/np.pi * (BesselK0 * (2 + np.pi * StruveL1) + BesselK1 * np.pi * StruveL0) |
|
327 |
|
|
314 |
328 |
class Gaussian_Z_prod_2D(WhiteBox): |
class Gaussian_Z_prod_2D(WhiteBox): |
315 |
329 |
def __init__(self, **kwargs): |
def __init__(self, **kwargs): |
316 |
330 |
""" |
""" |
|
... |
... |
class Gaussian_Z_prod_2D(WhiteBox): |
319 |
333 |
#č měníme logiku. |
#č měníme logiku. |
320 |
334 |
#č u této třídy známenko constanty bude ovlivňovat |
#č u této třídy známenko constanty bude ovlivňovat |
321 |
335 |
#č poruchové kvadranty. |
#č poruchové kvadranty. |
|
336 |
|
if 'sign' in kwargs: |
|
337 |
|
self.sign = kwargs['sign'] |
|
338 |
|
else: |
|
339 |
|
self.sign = 1 |
322 |
340 |
if 'const' in kwargs: |
if 'const' in kwargs: |
323 |
341 |
self.const = kwargs['const'] |
self.const = kwargs['const'] |
324 |
342 |
elif 'beta' in kwargs: |
elif 'beta' in kwargs: |
|
... |
... |
class Gaussian_Z_prod_2D(WhiteBox): |
330 |
348 |
|
|
331 |
349 |
#č g-modelu je to samozřejmě šuma, ale bílá skříňka nechť raději |
#č g-modelu je to samozřejmě šuma, ale bílá skříňka nechť raději |
332 |
350 |
#č pečlivěji zpracovává vstup |
#č pečlivěji zpracovává vstup |
333 |
|
self.gm = g_models.Z_prod(const=self.const, sign=np.sign(self.const)) |
|
|
351 |
|
self.gm = g_models.Z_prod(const=self.const, sign=np.sign(self.sign)) |
334 |
352 |
self.f = f_models.SNorm(2) |
self.f = f_models.SNorm(2) |
335 |
353 |
#č na začatku nemáme vzorky - pouze rozdělení a podpís |
#č na začatku nemáme vzorky - pouze rozdělení a podpís |
336 |
354 |
self.sample_box = SampleBox(self.f(), gm_signature=self.gm_signature) |
self.sample_box = SampleBox(self.f(), gm_signature=self.gm_signature) |
|
... |
... |
class Gaussian_Z_prod_2D(WhiteBox): |
339 |
357 |
# kn(n, x) Modified Bessel function of the second kind of integer order n |
# kn(n, x) Modified Bessel function of the second kind of integer order n |
340 |
358 |
# modstruve(v, x) Modified Struve function of order v at x |
# modstruve(v, x) Modified Struve function of order v at x |
341 |
359 |
#č Odvození pf_exact z Maple |
#č Odvození pf_exact z Maple |
342 |
|
const = np.abs(self.const) |
|
343 |
|
StruveL0 = special.modstruve(0, const) |
|
344 |
|
StruveL1 = special.modstruve(1, const) |
|
345 |
|
BesselK0 = special.kn(0, const) |
|
346 |
|
BesselK1 = special.kn(1, const) |
|
347 |
|
self.pf_exact = 0.5 - const/2 * (StruveL1 * BesselK0 + StruveL0 * BesselK1 + 2/np.pi * BesselK0) |
|
|
360 |
|
#self.pf_exact = 0.5 - const/2 * (StruveL1 * BesselK0 + StruveL0 * BesselK1 + 2/np.pi * BesselK0) |
|
361 |
|
if self.sign > 0: |
|
362 |
|
self.pf_exact = gauss_prod_CDF(-self.const) |
|
363 |
|
else: |
|
364 |
|
self.pf_exact = 1 - gauss_prod_CDF(-self.const) |
348 |
365 |
self.pf_exact_method = 'exact (Bessel) solution' |
self.pf_exact_method = 'exact (Bessel) solution' |
349 |
366 |
|
|
350 |
367 |
|
|