Skip to content

Commit

Permalink
[Fix] deprecation warnings numpy 1.25.0 (NeuralEnsemble#568)
Browse files Browse the repository at this point in the history
* fix deprecated imports form numpy.testing.utils to numpy.testing

* fix numpy warning in granger, set rcond = None

* fix numpy warning Conversion of an array with ndim > 0 to a scalar in gpfa_core.py

* fix numpy warning Conversion of an array with ndim > 0 to a scalar in icsd.py

* fix numpy warning Conversion of an array with ndim > 0 to a scalar in phase_analysis.py

* comment out documentation example in unittest docstring

* replaced matrix with regular ndarray in KCSD

* remove example code from icsd unit test
  • Loading branch information
Moritz-Alexander-Kern committed Jun 26, 2023
1 parent 17fa66d commit 2651da9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 31 deletions.
5 changes: 3 additions & 2 deletions elephant/causality/granger.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,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):
Expand Down
11 changes: 6 additions & 5 deletions elephant/current_source_density_src/KCSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions elephant/current_source_density_src/icsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion elephant/gpfa/gpfa_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions elephant/phase_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
15 changes: 0 additions & 15 deletions elephant/test/test_icsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
iCSD testing suite
"""

import os
import numpy as np
import numpy.testing as nt
import quantities as pq
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion elephant/test/test_signal_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion elephant/test/test_spike_train_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2651da9

Please sign in to comment.