more work on loggaussian

This commit is contained in:
Dominik Demuth
2023-04-23 19:55:53 +02:00
parent 2d472bd44e
commit dd1c26e285
4 changed files with 52 additions and 24 deletions

View File

@ -52,8 +52,8 @@ class LogGaussian(Distribution):
res_real = _integration_parallel(_omega, _tau, sigma, _integrate_process_imag)
res_imag = _integration_parallel(_omega, _tau, sigma, _integrate_process_real)
else:
res_real = None
res_imag = None
res_real = _integration_parallel(_omega, _tau, sigma, _integrate_process_imag)
res_imag = _integration_parallel(_omega, _tau, sigma, _integrate_process_real)
return (res_real + 1j * res_imag).squeeze()
@ -95,8 +95,8 @@ def _integrate_specdens_c(omega: np.ndarray, tau: np.ndarray, sigma: float) -> n
c = (ctypes.c_double * 3)(o, t, sigma)
user_data = ctypes.cast(ctypes.pointer(c), ctypes.c_void_p)
area = quad(LowLevelCallable(lib.logGaussianSD_high, user_data), 0, np.infty)[0]
area += quad(LowLevelCallable(lib.logGaussianSD_low, user_data), -np.infty, 0)[0]
area = quad(LowLevelCallable(lib.logGaussianSD_high, user_data), 0, np.infty, epsabs=1e-12, epsrel=1e-12)[0]
area += quad(LowLevelCallable(lib.logGaussianSD_low, user_data), -np.infty, 0, epsabs=1e-12, epsrel=1e-12)[0]
res.append(area)
@ -105,9 +105,10 @@ def _integrate_specdens_c(omega: np.ndarray, tau: np.ndarray, sigma: float) -> n
return res
def _integrate_process_imag(omega_i, tau_j, sigma):
area = quad(_integrand_freq_imag_high, 0, 50, args=(omega_i, tau_j, sigma))[0]
area += quad(_integrand_freq_imag_low, -50, 0, args=(omega_i, tau_j, sigma))[0]
def _integrate_process_imag(args):
omega_i, tau_j, sigma = args
area = quad(_integrand_freq_imag_high, 0, 50, args=(omega_i, tau_j, sigma), epsabs=1e-12, epsrel=1e-12)[0]
area += quad(_integrand_freq_imag_low, -50, 0, args=(omega_i, tau_j, sigma), epsabs=1e-12, epsrel=1e-12)[0]
return area
@ -166,10 +167,3 @@ def _integrand_freq_real_low(u, omega, tau, sigma):
def _integrand_freq_real_high(u, omega, tau, sigma):
uu = np.exp(-2*u)
return LogGaussian.distribution(np.exp(u), tau, sigma) * uu / (uu + omega**2)
if __name__ == '__main__':
import matplotlib.pyplot as plt
xx = np.logspace(-5, 5)
plt.loglog(xx, LogGaussian.specdens(xx, 1, 2))
plt.show()