From 49558bf98b41cb5412b25826684fd3b0cbad302b Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 07:49:45 +0200 Subject: [PATCH 1/8] fix deprecated imports form numpy.testing.utils to numpy.testing --- elephant/test/test_signal_processing.py | 2 +- elephant/test/test_spike_train_correlation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/elephant/test/test_signal_processing.py b/elephant/test/test_signal_processing.py index 378276250..303e3cdfd 100644 --- a/elephant/test/test_signal_processing.py +++ b/elephant/test/test_signal_processing.py @@ -15,7 +15,7 @@ import scipy.signal as spsig import scipy.stats from numpy.ma.testutils import assert_array_equal, assert_allclose -from numpy.testing.utils import assert_array_almost_equal +from numpy.testing import assert_array_almost_equal import elephant.signal_processing diff --git a/elephant/test/test_spike_train_correlation.py b/elephant/test/test_spike_train_correlation.py index f4230763e..547b12611 100644 --- a/elephant/test/test_spike_train_correlation.py +++ b/elephant/test/test_spike_train_correlation.py @@ -11,7 +11,7 @@ import neo import numpy as np import quantities as pq -from numpy.testing.utils import assert_array_equal, assert_array_almost_equal +from numpy.testing import assert_array_equal, assert_array_almost_equal import elephant.conversion as conv import elephant.spike_train_correlation as sc From 0e048c20ffb95e1e1e6040f578cd6870539799c9 Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 08:09:02 +0200 Subject: [PATCH 2/8] fix numpy warning in granger, set rcond = None --- elephant/causality/granger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/elephant/causality/granger.py b/elephant/causality/granger.py index b7871b80e..d3b52418c 100644 --- a/elephant/causality/granger.py +++ b/elephant/causality/granger.py @@ -284,8 +284,9 @@ def _vector_arm(signals, dimension, order): positive_lag_covariances = np.reshape(lag_covariances[1:], (dimension*order, dimension)) - lstsq_coeffs = \ - np.linalg.lstsq(yule_walker_matrix, positive_lag_covariances)[0] + lstsq_coeffs = np.linalg.lstsq(yule_walker_matrix, + positive_lag_covariances, + rcond=None)[0] coeffs = [] for index in range(order): From 944a17a9d2e4fa14eff6f46e59d108dc13102e9b Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 08:47:16 +0200 Subject: [PATCH 3/8] fix numpy warning Conversion of an array with ndim > 0 to a scalar in gpfa_core.py --- elephant/gpfa/gpfa_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elephant/gpfa/gpfa_core.py b/elephant/gpfa/gpfa_core.py index 74b0621ad..6277a8903 100644 --- a/elephant/gpfa/gpfa_core.py +++ b/elephant/gpfa/gpfa_core.py @@ -494,7 +494,7 @@ def learn_gp_params(seqs_latent, params, verbose=False): res_opt = optimize.minimize(gpfa_util.grad_betgam, initp, args=(precomp[i], const), method='L-BFGS-B', jac=True) - param_opt['gamma'][i] = np.exp(res_opt.x) + param_opt['gamma'][i] = np.exp(res_opt.x.item()) if verbose: print('\n Converged p; xDim:{}, p:{}'.format(i, res_opt.x)) From ca08b5e23b538137eb8d4511d61964a5333ad91d Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 08:47:33 +0200 Subject: [PATCH 4/8] fix numpy warning Conversion of an array with ndim > 0 to a scalar in icsd.py --- elephant/current_source_density_src/icsd.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/elephant/current_source_density_src/icsd.py b/elephant/current_source_density_src/icsd.py index 6322eee2f..3ba02b335 100644 --- a/elephant/current_source_density_src/icsd.py +++ b/elephant/current_source_density_src/icsd.py @@ -691,10 +691,10 @@ def get_csd(self): for j in range(self.num_steps): if out_zs[j] >= z_js[i + 1]: i += 1 - csd[j, ] = a_mat0[i, :] + a_mat1[i, :] * \ - (out_zs[j] - z_js[i]) + \ - a_mat2[i, :] * (out_zs[j] - z_js[i])**2 + \ - a_mat3[i, :] * (out_zs[j] - z_js[i])**3 + csd[j] = (a_mat0[i, :] + a_mat1[i, :] * + (out_zs[j] - z_js[i]) + + a_mat2[i, :] * (out_zs[j] - z_js[i])**2 + + a_mat3[i, :] * (out_zs[j] - z_js[i])**3).item() csd_unit = (self.f_matrix.units**-1 * self.lfp.units).simplified From e46477ffd27d53ce5715f5cc873026499412e6ca Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 08:47:45 +0200 Subject: [PATCH 5/8] fix numpy warning Conversion of an array with ndim > 0 to a scalar in phase_analysis.py --- elephant/phase_analysis.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/elephant/phase_analysis.py b/elephant/phase_analysis.py index 49b0a7288..884c35b8b 100644 --- a/elephant/phase_analysis.py +++ b/elephant/phase_analysis.py @@ -182,8 +182,10 @@ def spike_triggered_phase(hilbert_transform, spiketrains, interpolate): hilbert_transform[phase_i].sampling_period # Save hilbert_transform (interpolate on circle) - p1 = np.angle(hilbert_transform[phase_i][ind_at_spike_j]) - p2 = np.angle(hilbert_transform[phase_i][ind_at_spike_j + 1]) + p1 = np.angle(hilbert_transform[phase_i][ind_at_spike_j] + ).item() + p2 = np.angle(hilbert_transform[phase_i][ind_at_spike_j + 1] + ).item() interpolation = (1 - z) * np.exp(complex(0, p1)) \ + z * np.exp(complex(0, p2)) p12 = np.angle([interpolation]) From a93762e535e0858432cefaf5beb0002c63ac04a1 Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 08:48:28 +0200 Subject: [PATCH 6/8] comment out documentation example in unittest docstring --- elephant/test/test_icsd.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/elephant/test/test_icsd.py b/elephant/test/test_icsd.py index 16d7de6d1..4929cd956 100644 --- a/elephant/test/test_icsd.py +++ b/elephant/test/test_icsd.py @@ -130,10 +130,10 @@ def potential_of_cylinder(z_j, Tested with - >>> from sympy import * - >>> C_i, z_i, h, z_j, z_j, sigma, R = symbols('C_i z_i h z z_j sigma R') - >>> C_i*integrate(1/(2*sigma)*(sqrt((z-z_j)**2 + R**2) - - ... abs(z-z_j)), (z, z_i-h/2, z_i+h/2)) + # >>> from sympy import * + # >>> C_i, z_i, h, z_j, z_j, sigma, R = symbols('C_i z_i h z z_j sigma R') + # >>> C_i*integrate(1/(2*sigma)*(sqrt((z-z_j)**2 + R**2) - + # ... abs(z-z_j)), (z, z_i-h/2, z_i+h/2)) """ From 2d0b81c70958bc456ed438430abb00741d8a0934 Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Tue, 30 May 2023 14:40:20 +0200 Subject: [PATCH 7/8] replaced matrix with regular ndarray in KCSD --- elephant/current_source_density_src/KCSD.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/elephant/current_source_density_src/KCSD.py b/elephant/current_source_density_src/KCSD.py index 3e722cf92..727d41b44 100644 --- a/elephant/current_source_density_src/KCSD.py +++ b/elephant/current_source_density_src/KCSD.py @@ -317,17 +317,18 @@ def compute_cverror(self, lambd, index_generator): V_train = self.pots[idx_train] V_test = self.pots[idx_test] I_matrix = np.identity(len(idx_train)) - B_new = np.matrix(B_train) + (lambd*I_matrix) + B_new = np.array(B_train) + (lambd * I_matrix) try: - beta_new = np.dot(np.matrix(B_new).I, np.matrix(V_train)) + beta_new = np.linalg.inv(B_new) @ V_train B_test = self.k_pot[np.ix_(idx_test, idx_train)] V_est = np.zeros((len(idx_test), self.pots.shape[1])) for ii in range(len(idx_train)): for tt in range(self.pots.shape[1]): V_est[:, tt] += beta_new[ii, tt] * B_test[:, ii] - err += np.linalg.norm(V_est-V_test) - except LinAlgError: - raise LinAlgError('Encoutered Singular Matrix Error: try changing ele_pos slightly') + err += np.linalg.norm(V_est - V_test) + except np.linalg.LinAlgError: + raise np.linalg.LinAlgError( + 'Encountered Singular Matrix Error: try changing ele_pos slightly') return err class KCSD1D(KCSD): From 19de003007846df50bca0591311835de09227296 Mon Sep 17 00:00:00 2001 From: Moritz-Alexander-Kern Date: Wed, 31 May 2023 13:50:59 +0200 Subject: [PATCH 8/8] remove example code from icsd unit test --- elephant/test/test_icsd.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/elephant/test/test_icsd.py b/elephant/test/test_icsd.py index 4929cd956..ebe243a1d 100644 --- a/elephant/test/test_icsd.py +++ b/elephant/test/test_icsd.py @@ -3,7 +3,6 @@ iCSD testing suite """ -import os import numpy as np import numpy.testing as nt import quantities as pq @@ -122,20 +121,6 @@ def potential_of_cylinder(z_j, radius of disk source sigma : float*pq.S/pq.m conductivity of medium in units of S/m - - Notes - ----- - Sympy can't deal with eq. 11 in Pettersen et al 2006, J neurosci Meth, - so we numerically evaluate it in this function. - - Tested with - - # >>> from sympy import * - # >>> C_i, z_i, h, z_j, z_j, sigma, R = symbols('C_i z_i h z z_j sigma R') - # >>> C_i*integrate(1/(2*sigma)*(sqrt((z-z_j)**2 + R**2) - - # ... abs(z-z_j)), (z, z_i-h/2, z_i+h/2)) - - """ try: assert(z_j.units == z_i.units == R_i.units == h_i.units)