Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pyrecest/distributions/circle/wrapped_normal_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,21 @@ def pdf(self, xs):

for i in range(n_inputs):
old_result = 0.0
result[i] = exp(x[i] * x[i] * tmp)
xi = x[i]
if hasattr(xi, "item"):
xi = xi.item()
result[i] = exp(xi * xi * tmp)

for k in range(1, max_iterations + 1):
xp = x[i] + 2 * pi * k
xm = x[i] - 2 * pi * k
xp = xi + 2 * pi * k
xm = xi - 2 * pi * k
tp = xp * xp * tmp
tm = xm * xm * tmp
old_result = result[i]
result[i] += (exp(tp) + exp(tm)).squeeze()
addendum = exp(tp) + exp(tm)
if hasattr(addendum, "item"):
addendum = addendum.item()
result[i] += addendum

if result[i] == old_result:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def integrand(*phis):
# Applying the multiplicative factors for each additional dimension
for i in range(2, dim + 1):
result *= sin(phis[i - 1]) ** (i - 1)
return result
if hasattr(result, "item"):
return result.item()
return float(result)

int_result, _ = nquad(integrand, integration_boundaries)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,23 @@ def from_function_via_integral_sph(fun, degree, transformation="identity"):

coeff_mat = full((degree + 1, 2 * degree + 1), float("NaN"), dtype=complex128)

def _to_scalar(val):
if hasattr(val, "item"):
return val.item()
return float(val)

def _fun_scalar(phi, theta):
return _to_scalar(fun_with_trans(array(phi), array(theta)))

def real_part(phi, theta, n, m):
return real(
fun_with_trans(array(phi), array(theta))
* conj(array(sph_harm_y(n, m, theta, phi)))
* sin(theta)
)
val = _fun_scalar(phi, theta)
val = val * conj(sph_harm_y(n, m, theta, phi)) * sin(theta)
return float(real(val))

def imag_part(phi, theta, n, m):
return imag(
fun_with_trans(array(phi), array(theta))
* conj(array(sph_harm_y(n, m, theta, phi)))
* sin(theta)
)
val = _fun_scalar(phi, theta)
val = val * conj(sph_harm_y(n, m, theta, phi)) * sin(theta)
return float(imag(val))

for n in range(degree + 1): # Use n instead of l to comply with PEP 8
for m in range(-n, n + 1):
Expand Down
Loading