Skip to content

Commit 2046785

Browse files
abukajccluri
authored andcommitted
Fixed #95 and #93 (#96)
* 'Fixed `gauss_2d_large()`. `kcsd.validation.csd_profile.gauss_2d_large(seed=63)` does not return NaN anymore. `repeatUntilValid()` decorator has been defined for that purpose. A simple test for the fix provided in the `__main__` section of the module. Note: The issue has not been solved by fixing distribution of the `zs` variable in order to provide backward-compatibility. * 2**32 - 1 included as possible alternative seed in the `kcsd.validation.csd_profile.repeatUntilValid()` decorator. * Protection of `repeatUntilValid()` decorator against (extremely unlikely) neverending loop of seeds. * `repeatUntilValid()` decorator reffactored Seed sequence generation moved to `seedSequence()` generator function. * `seedSequence()` generator function simplified (the generated sequence has changed though). * Remove unnecessary imports According to https://docs.python.org/3/library/builtins.html imports from `builtsin` are unnecessary. As `builtsin` is Python 3 only, their removal increases beckward-compatibility of the package. Fixes #77 * `KCSD.values()` vectorized `KCSD.values()` is approximately 4 times faster. Fixes #93 * Increased `KCSD.values()` numerical stability `inv(K) V` is calculated by solving `K X = V` for `X` As a side effect `KCSD.values()` is faster. Fixes #95
1 parent 2ce755a commit 2046785

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

kcsd/KCSD.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ def values(self, estimate='CSD'):
211211
estimation_table = self.k_interp_pot
212212
else:
213213
print('Invalid quantity to be measured, pass either CSD or POT')
214-
k_inv = np.linalg.inv(self.k_pot + self.lambd *
215-
np.identity(self.k_pot.shape[0]))
214+
kernel = self.k_pot + self.lambd * np.identity(self.k_pot.shape[0])
216215
estimation = np.zeros((self.n_estm, self.n_time))
217216
for t in range(self.n_time):
218-
beta = np.dot(k_inv, self.pots[:, t])
219-
for i in range(self.n_ele):
220-
estimation[:, t] += estimation_table[:, i]*beta[i] # C*(x) Eq 18
217+
# C*(x) [Potworowski 2018 Eq 2.18]
218+
# `inv(K) V` calculated by solving `K X = V` for `X`
219+
estimation[:, t] = np.dot(estimation_table,
220+
np.linalg.solve(kernel,
221+
self.pots[:, t]))
221222
return self.process_estimate(estimation)
222223

223224
def process_estimate(self, estimation):

0 commit comments

Comments
 (0)