Replaced manual calculation with builtin numpy functions

This commit is contained in:
Andreas Tsouchlos 2022-11-07 14:49:05 +01:00
parent cbb6036beb
commit 6af243efba

View File

@ -55,13 +55,9 @@ class ProximalDecoder:
# Calculate second term
for k, x_k in enumerate(x):
# TODO: Perform the summation with np.sum()
sum_result = 0
for i in self._B[k]:
prod = 1
for j in self._A[i]:
prod *= x[j]
prod = np.prod(x[self._A[i]])
sum_result += prod**2 - prod
term_2 = 2 / x_k * sum_result
@ -70,7 +66,7 @@ class ProximalDecoder:
return np.array(result)
# TODO: Is this correct?
# TODO: Is the 'projection onto [-eta, eta]' actually just clipping?
def _projection(self, x):
"""Project a vector onto [-eta, eta]^n in order to avoid numerical instability.
Detailed in 3.2, p. 3 (Equation (15)).