Documentation¶
KCSD Methods¶
This script is used to generate Current Source Density Estimates, using the kCSD method Jan et.al (2012).
- class kcsd.KCSD.CSD(ele_pos, pots)[source]¶
CSD - The base class for CSD methods.
Methods
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
validate
(ele_pos, pots)Basic checks to see if inputs are okay
- sanity(true_csd, pos_csd)[source]¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- class kcsd.KCSD.KCSD(ele_pos, pots, **kwargs)[source]¶
KCSD - The base class for all the KCSD variants.
This estimates the Current Source Density, for a given configuration of electrod positions and recorded potentials, electrodes. The method implented here is based on the original paper by Jan Potworowski et.al. 2012.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)[source]¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- compute_cverror(lambd, index_generator)[source]¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()[source]¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- cross_validate(lambdas=None, Rs=None, regression_test=False)[source]¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- method()[source]¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)[source]¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- process_estimate(estimation)[source]¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()[source]¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)[source]¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()[source]¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()[source]¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()[source]¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)[source]¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- class kcsd.KCSD.KCSD1D(ele_pos, pots, **kwargs)[source]¶
The 1D variant for the Kernel Current Source Density method.
This estimates the Current Source Density, for a given configuration of electrod positions and recorded potentials, in the case of 1D recording electrodes (laminar probes). The method implented here is based on the original paper by Jan Potworowski et.al. 2012.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Defines locations where the estimation is wanted
forward_model
(x, R, h, sigma, src_type)Forward model functions
int_pot_1D
(xp, x, R, h, basis_func)Forward model function for 1D.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize KCSD1D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 300
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed cylindrical slice Defaults to 1.
- xmin, xmaxfloats
boundaries for CSD estimation space Defaults to min(ele_pos(x)), and max(ele_pos(x))
- ext_xfloat
length of space extension: x_min-ext_x … x_max+ext_x Defaults to 0.
- gdxfloat
space increments in the estimation space Defaults to 0.01(xmax-xmin)
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- dist_table_densityint
size of the potential interpolation table Defaults to 20
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()[source]¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Defines locations where the estimation is wanted
Defines: self.n_estm = self.estm_x.size self.ngx = self.estm_x.shape self.estm_x : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)[source]¶
Forward model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 26 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_1D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_1D(xp, x, R, h, basis_func)[source]¶
Forward model function for 1D.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0) Eq 26 kCSD by Jan,2012
- Parameters:
- xpfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_1D.keys() self.R based on R_init self.dist_max as maximum distance between electrode and basis self.nsx = self.src_x.shape self.src_x : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.KCSD2D(ele_pos, pots, **kwargs)[source]¶
The 2D variant for the Kernel Current Source Density method.
This estimates the Current Source Density, for a given configuration of electrod positions and recorded potentials, in the case of 2D recording electrodes. The method implented here is based on the original paper by Jan Potworowski et.al. 2012.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Defines locations where the estimation is wanted
forward_model
(x, R, h, sigma, src_type)FWD model functions
int_pot_2D
(xp, yp, x, R, h, basis_func)FWD model function.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize KCSD2D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- xmin, xmax, ymin, ymaxfloats
boundaries for CSD estimation space Defaults to min(ele_pos(x)), and max(ele_pos(x)) Defaults to min(ele_pos(y)), and max(ele_pos(y))
- ext_x, ext_yfloat
length of space extension: x_min-ext_x … x_max+ext_x length of space extension: y_min-ext_y … y_max+ext_y Defaults to 0.
- gdx, gdyfloat
space increments in the estimation space Defaults to 0.01(xmax-xmin) Defaults to 0.01(ymax-ymin)
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()[source]¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Defines locations where the estimation is wanted
Defines: self.n_estm = self.estm_x.size self.ngx, self.ngy = self.estm_x.shape self.estm_x, self.estm_y : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)[source]¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 22 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_2D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_2D(xp, yp, x, R, h, basis_func)[source]¶
FWD model function.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0)
- Parameters:
- xp, ypfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_2D.keys() self.R based on R_init self.dist_max as maximum distance between electrode and basis self.nsx, self.nsy = self.src_x.shape self.src_x, self.src_y : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.KCSD3D(ele_pos, pots, **kwargs)[source]¶
KCSD3D - The 3D variant for the Kernel Current Source Density method. This estimates the Current Source Density, for a given configuration of electrod positions and recorded potentials, in the case of 2D recording electrodes. The method implented here is based on the original paper by Jan Potworowski et.al. 2012.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Defines locations where the estimation is wanted Defines: self.n_estm = self.estm_x.size self.ngx, self.ngy, self.ngz = self.estm_x.shape self.estm_x, self.estm_y, self.estm_z : Pts.
forward_model
(x, R, h, sigma, src_type)FWD model functions
int_pot_3D
(xp, yp, zp, x, R, h, basis_func)FWD model function.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize KCSD3D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- xmin, xmax, ymin, ymax, zmin, zmaxfloats
boundaries for CSD estimation space Defaults to min(ele_pos(x)), and max(ele_pos(x)) Defaults to min(ele_pos(y)), and max(ele_pos(y)) Defaults to min(ele_pos(z)), and max(ele_pos(z))
- ext_x, ext_y, ext_zfloat
length of space extension: xmin-ext_x … xmax+ext_x length of space extension: ymin-ext_y … ymax+ext_y length of space extension: zmin-ext_z … zmax+ext_z Defaults to 0.
- gdx, gdy, gdzfloat
space increments in the estimation space Defaults to 0.01(xmax-xmin) Defaults to 0.01(ymax-ymin) Defaults to 0.01(zmax-zmin)
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()[source]¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Defines locations where the estimation is wanted Defines: self.n_estm = self.estm_x.size self.ngx, self.ngy, self.ngz = self.estm_x.shape self.estm_x, self.estm_y, self.estm_z : Pts. at which CSD is requested
- forward_model(x, R, h, sigma, src_type)[source]¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Utlizies sk monaco monte carlo method if available, otherwise defaults to scipy integrate
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_3D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_3D(xp, yp, zp, x, R, h, basis_func)[source]¶
FWD model function.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0)
- Parameters:
- xp, yp, zpfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_2D.keys() self.R based on R_init self.dist_max as maximum distance between electrode and basis self.nsx, self.nsy, self.nsz = self.src_x.shape self.src_x, self.src_y, self.src_z : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.MoIKCSD(ele_pos, pots, **kwargs)[source]¶
MoIKCSD - CSD while including the forward modeling effects of saline.
This estimates the Current Source Density, for a given configuration of electrod positions and recorded potentials, in the case of 2D recording electrodes from an MEA electrode plane using the Method of Images. The method implented here is based on kCSD method by Jan Potworowski et.al. 2012, which was extended in Ness, Chintaluri 2015 for MEA.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Defines locations where the estimation is wanted
forward_model
(x, R, h, sigma, src_type)FWD model functions
int_pot_2D
(xp, yp, x, R, h, basis_func)FWD model function.
int_pot_2D_moi
(xp, yp, x, R, h, basis_func)FWD model function.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize MoIKCSD Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- sigma_Sfloat
conductance of the saline (medium) in S/m Default is 5 S/m (5 times more conductive)
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- xmin, xmax, ymin, ymaxfloats
boundaries for CSD estimation space Defaults to min(ele_pos(x)), and max(ele_pos(x)) Defaults to min(ele_pos(y)), and max(ele_pos(y))
- ext_x, ext_yfloat
length of space extension: x_min-ext_x … x_max+ext_x length of space extension: y_min-ext_y … y_max+ext_y Defaults to 0.
- gdx, gdyfloat
space increments in the estimation space Defaults to 0.01(xmax-xmin) Defaults to 0.01(ymax-ymin)
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- MoI_itersint
Number of interations in method of images. Default is 20
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()¶
Defines locations where the estimation is wanted
Defines: self.n_estm = self.estm_x.size self.ngx, self.ngy = self.estm_x.shape self.estm_x, self.estm_y : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)[source]¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 22 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_2D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_2D(xp, yp, x, R, h, basis_func)¶
FWD model function.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0)
- Parameters:
- xp, ypfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- int_pot_2D_moi(xp, yp, x, R, h, basis_func)[source]¶
FWD model function. Incorporates the Method of Images.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0) #Eq 20, Ness(2015)
- Parameters:
- xp, ypfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_2D.keys() self.R based on R_init self.dist_max as maximum distance between electrode and basis self.nsx, self.nsy = self.src_x.shape self.src_x, self.src_y : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.oKCSD1D(ele_pos, pots, **kwargs)[source]¶
oKCSD - The variant for the Kernel Current Source Density method that allows to reconstruct potential and CSD in given 1D space points.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Redefines locations where the estimation is wanted
forward_model
(x, R, h, sigma, src_type)Forward model functions
int_pot_1D
(xp, x, R, h, basis_func)Forward model function for 1D.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize oKCSD1D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- own_est: numpy array
points coordinates of estimation places. If not given estimation places will be taken from own_src
- own_src: numpy array
points coordinates of basis source centers
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Redefines locations where the estimation is wanted
Defines: self.n_estm = self.estm_x.size self.estm_x : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)¶
Forward model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 26 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_1D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_1D(xp, x, R, h, basis_func)¶
Forward model function for 1D.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0) Eq 26 kCSD by Jan,2012
- Parameters:
- xpfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_1D.keys() self.R based on R_init self.dist_max as maximum distance between electrode and basis self.src_x : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.oKCSD2D(ele_pos, pots, **kwargs)[source]¶
oKCSD - The variant for the Kernel Current Source Density method that allows to reconstruct potential and CSD in given 2D space points.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Redefines locations where the estimation is wanted
forward_model
(x, R, h, sigma, src_type)FWD model functions
int_pot_2D
(xp, yp, x, R, h, basis_func)FWD model function.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize oKCSD2D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- own_est: numpy array
points coordinates of estimation places. If not given estimation places will be taken from own_src
- own_src: numpy array
points coordinates of basis source centers
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Redefines locations where the estimation is wanted
Defines: self.n_estm = self.estm_x.size self.estm_x, self.estm_y : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 22 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_2D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_2D(xp, yp, x, R, h, basis_func)¶
FWD model function.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0)
- Parameters:
- xp, ypfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_2D.keys() self.R based on R_init self.src_x, self.src_y : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.KCSD.oKCSD3D(ele_pos, pots, **kwargs)[source]¶
oKCSD - The variant for the Kernel Current Source Density method that allows to reconstruct potential and CSD in given 3D space points.
Methods
L_curve
([lambdas, Rs, n_jobs])Method defines the L-curve.
compute_cverror
(lambd, index_generator)Useful for Cross validation error calculations
Creates a table for easy potential estimation from CSD.
Creates distance tables between sources, electrode and estm points
cross_validate
([lambdas, Rs, regression_test])Method defines the cross validation.
Redefines locations where the estimation is wanted Defines: self.n_estm = self.estm_x.size self.estm_x, self.estm_y, self.estm_z : Locations at which CSD is requested.
forward_model
(x, R, h, sigma, src_type)FWD model functions
int_pot_3D
(xp, yp, zp, x, R, h, basis_func)FWD model function.
method
()Actual sequence of methods called for KCSD
parameters
(**kwargs)Defining the default values of the method passed as kwargs
Places basis sources of the defined type.
process_estimate
(estimation)Function used to rearrange estimation according to dimension, to be used by the fuctions values
sanity
(true_csd, pos_csd)Useful for comparing TrueCSD with reconstructed CSD.
Computes the lambda parameter range for regularization,
update_R
(R)Update the width of the basis fuction - Used in Cross validation
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space.
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
update_lambda
(lambd)Update the lambda parameter of regularization, Used in Cross validation
validate
(ele_pos, pots)Basic checks to see if inputs are okay
values
([estimate])Computes the values of the quantity of interest
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, **kwargs)[source]¶
Initialize oKCSD3D Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the tissue in S/m Defaults to 1 S/m
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 0.23
- hfloat
thickness of analyzed tissue slice Defaults to 1.
- own_est: numpy array
points coordinates of estimation places. If not given estimation places will be taken from own_src
- own_src: numpy array
points coordinates of basis source centers
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()¶
Creates a table for easy potential estimation from CSD.
Updates and Returns the potentials due to a given basis source like a lookup table whose shape=(dist_table_density,)
- Parameters:
- dist_table_densityint
number of distance points at which potentials are computed. Default 100
- create_src_dist_tables()¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Redefines locations where the estimation is wanted Defines: self.n_estm = self.estm_x.size self.estm_x, self.estm_y, self.estm_z : Locations at which CSD is requested.
- forward_model(x, R, h, sigma, src_type)¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Utlizies sk monaco monte carlo method if available, otherwise defaults to scipy integrate
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_3D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_3D(xp, yp, zp, x, R, h, basis_func)¶
FWD model function.
Returns contribution of a point xp,yp, belonging to a basis source support centered at (0,0) to the potential measured at (x,0), integrated over xp,yp gives the potential generated by a basis source element centered at (0,0) at point (x,0)
- Parameters:
- xp, yp, zpfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- hfloat
thickness of slice
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type.
Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_3D.keys() self.R based on R_init self.src_x, self.src_y, self.src_z : Locations at which basis sources are placed.
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot Parameters ———- None
- update_b_pot()¶
Updates the b_pot - array is (#_basis_sources, #_electrodes)
Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD')¶
Computes the values of the quantity of interest
- Parameters:
- estimate‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- class kcsd.sKCSD(ele_pos, pots, morphology, **kwargs)[source]¶
sKCSD - Kernel Current Source Density method on a neuron morphology.
This estimates the Current Source Density, using the skCSD method Cserpan et.al (2017).
Methods
get_src_ele_dists
- L_curve(lambdas=None, Rs=None, n_jobs=1)¶
Method defines the L-curve.
By default calculates L-curve over lambda, When no argument is passed, it takes lambdas = np.logspace(-10,-1,100,base=10) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- L-curve plotting: default True
- lambdasnumpy array
- Rsnumpy array
- Returns:
- curve_surfpost cross validation
- __init__(ele_pos, pots, morphology, **kwargs)[source]¶
Initialize sKCSD Class.
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- morphology: numpy array
morphology of the cell
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
basis function type (‘gauss’, ‘step’, ‘gauss_lim’) Defaults to ‘gauss’
- sigmafloat
space conductance of the medium Defaults to 1.
- hfloat
tissue thickness, unused in sKCSD Defaults to 10 um
- n_src_initint
requested number of sources Defaults to 1000
- R_initfloat
demanded thickness of the basis element Defaults to 23 um
- lambdfloat
regularization parameter for ridge regression Defaults to 0.
- dist_table_densityint
size of the potential interpolation table Defaults to 20
- tolerancefloat
minimum neurite size used for 3D tranformation of CSD and potential Defaults to 2 um
- exactbool
switch for exact computation of b_pot instead of interpolating results (a faster solution for lower number of electrodes and less
complicated morphology)
Defaults to False
- Raises:
- LinAlgError
Could not invert the matrix, try changing the ele_pos slightly
- KeyError
Basis function (src_type) not implemented. See basis_functions.py for available
- compute_cverror(lambd, index_generator)¶
Useful for Cross validation error calculations
- Parameters:
- lambdfloat
- index_generatorlist
- Returns:
- errfloat
the sum of the error computed.
- Raises:
- LinAlgError
If the matrix is not numerically invertible.
- create_lookup()[source]¶
Create two lookup tables for easy potential and CSD estimation. Because maximum source-electrode distance can be two orders of maginutude lower than maximum source-estimation table ( source-estimation table lives on the morphology loop and distance between the furthest source and segment (estimation point) can be of an order of mm), we create two separate look-up tables one for b_pot and one for b_interp_pot.
In case of exact calculations (self.exact=True) the interpolation table for b_interp_pot is not created.
- create_src_dist_tables()[source]¶
Creates distance tables between sources, electrode and estm points
- cross_validate(lambdas=None, Rs=None, regression_test=False)¶
Method defines the cross validation.
By default only cross_validates over lambda, When no argument is passed, it takes lambdas = np.logspace(-2,-25,25,base=10.) and Rs = np.array(self.R).flatten() otherwise pass necessary numpy arrays
- Parameters:
- lambdasnumpy array
- Rsnumpy array
- regression_testbool
- Returns:
- Rpost cross validation
- Lambdapost cross validation
- estimate_at()[source]¶
Defines locations where the estimation is wanted This is done while construction of morphology loop in sKCSDcell Defines: self.n_estm = len(self.cell.estm_x)
- forward_model(x, R, h, sigma, src_type)¶
Forward model functions
Evaluates potential at point (x,0) by a basis source located at (0,0) Eq 26 kCSD by Jan,2012
- Parameters:
- xfloat
- Rfloat
- hfloat
- sigmafloat
- src_typebasis_1D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- forward_model_1D(src, dist, R, sigma, src_type)[source]¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0)
- Parameters:
- xfloat
- Rfloat
- sigmafloat
- src_typebasis_3D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- forward_model_3D(src, dist, R, sigma, src_type)[source]¶
FWD model functions
Evaluates potential at point (x,0) by a basis source located at (0,0)
- Parameters:
- xfloat
- Rfloat
- sigmafloat
- src_typebasis_3D.key
- Returns:
- potfloat
value of potential at specified distance from the source
- int_pot_1D(xp, src, x, R, basis_func)[source]¶
FWD model function. Returns contribution of a point xp belonging to a basis source support centered at src to the potential measured at x, integrated over xp gives the potential generated by a basis source element centered at (src) at point (x) Eq 26 kCSD by Jan,2012
- Parameters:
- xpfloats or np.arrays
point or set of points where function should be calculated
- xfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- int_pot_3D(xp, src, x, y, z, R, basis_func)[source]¶
FWD model function. Returns contribution of a point xp, belonging to a basis source support centered at src to the potential measured at (x,y,z), integrated over xp gives the potential generated by a basis source element centered at (src) at point (x, y, z) Eq 26 kCSD by Jan,2012
- Parameters:
- xpfloats or np.arrays
point or set of points where function should be calculated
- x, y, zfloat
position at which potential is being measured
- Rfloat
The size of the basis function
- basis_funcmethod
Fuction of the basis source
- Returns:
- potfloat
- method()¶
Actual sequence of methods called for KCSD
Defines: self.k_pot and self.k_interp_cross matrices
- parameters(**kwargs)[source]¶
Defining the default values of the method passed as kwargs
- Parameters:
- **kwargs
Same as those passed to initialize the Class
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- place_basis()[source]¶
Places basis sources of the defined type. Checks if a given source_type is defined, if so then defines it self.basis, This function gives locations of the basis sources, Defines source_type : basis_fuctions.basis_2D.keys() self.R based on R_init self.src_x: Locations at which basis sources are placed. self.n_src: amount of placed basis sources
- potential_at_the_electrodes()[source]¶
Reconstruction from CSD of potentials measured at the electrodes
- Returns:
- estimationnp.array
Potential generated by the CSD measured at the electrodes
- process_estimate(estimation)¶
Function used to rearrange estimation according to dimension, to be used by the fuctions values
- Parameters:
- estimationnp.array
- Returns:
- estimationnp.array
estimated quantity of shape (ngx, ngy, ngz, nt)
- sanity(true_csd, pos_csd)¶
Useful for comparing TrueCSD with reconstructed CSD.
Computes, the RMS error between the true_csd and the reconstructed csd at pos_csd using the method defined.
- Parameters:
- true_csdcsd values used to generate potentials
- pos_csdcsd estimatation from the method
- Returns:
- RMSEroot mean squared difference
- suggest_lambda()¶
Computes the lambda parameter range for regularization,
Used in Cross validation and L-curve
- Returns:
- Lambdaslist
- update_R(R)[source]¶
Update the width of the basis fuction - Used in Cross validation
- Parameters:
- Rfloat
- update_b_interp_pot()[source]¶
Compute the matrix of potentials generated by every source basis function at every position in the interpolated space. Updates b_interp_pot Updates k_interp_pot
- update_b_pot()[source]¶
Updates the b_pot - array is (#_basis_sources, #_electrodes) Updates the k_pot - array is (#_electrodes, #_electrodes) K(x,x’) Eq9,Jan2012 Calculates b_pot - matrix containing the values of all the potential basis functions in all the electrode positions (essential for calculating the cross_matrix).
If self.exact is False, an interpolation table created by self.create_lookup() is used, otherwise the potential is calculated for every source and electrode position.
- update_b_src()¶
Updates the b_src in the shape of (#_est_pts, #_basis_sources)
Updates the k_interp_cross - K_t(x,y) Eq17 Calculate b_src - matrix containing containing the values of all the source basis functions in all the points at which we want to calculate the solution (essential for calculating the cross_matrix)
- update_lambda(lambd)¶
Update the lambda parameter of regularization, Used in Cross validation
- Parameters:
- lambdfloat
- validate(ele_pos, pots)¶
Basic checks to see if inputs are okay
- Parameters:
- ele_posnumpy array
positions of electrodes
- potsnumpy array
potentials measured by electrodes
- values(estimate='CSD', transformation='3D')[source]¶
Computes the values of the quantity of interest
- Parameters:
- estimate: ‘CSD’ or ‘POT’
What quantity is to be estimated Defaults to ‘CSD’
- transformation: ‘3D’, ‘segments’, None
Specify representation of the estimated quantity ‘3D’ – quantity is represented in cartesian coordinate system ‘segments’ – quantity is represented insegments None – quantity is represented in the morphology loop
- Returns:
- estimationnp.array
estimated quantity
Spectral Structure¶
- class kcsd.validation.ValidateKCSD.SpectralStructure(k)[source]¶
Class that enables examination of spectral structure of CSD reconstruction with kCSD method.
Methods
evd
()Method that calculates eigenvalue decomposition of kernel (k_pot matrix).
picard_plot
(b)Creates Picard plot according to Hansen's book.
Creates plot of eigenvalues of k_pot matrix.
Creates plots of:
plot_svd_sigma
(sigma)Creates plot of singular values of kernels product (K~*K^-1).
plot_svd_sigma_lambd
(sigma)Creates plots of:
plot_svd_u
(u_svd)Creates plot of left singular values.
plot_svd_v
(v_svd)Creates plot of right singular values
plot_v
(v)Creates plot of eigen vectors.
svd
()Method that calculates singular value decomposition of total kernel matrix.
- __init__(k)[source]¶
Initialize SpectralStructure class.
- Defines:
self.k: instance of the class Instance of ValidationClassKCSD1D, ValidationClassKCSD2D or ValidationClassKCSD3D class.
- Parameters:
- k: instance of the class
Instance of ValidationClassKCSD1D, ValidationClassKCSD2D or ValidationClassKCSD3D class.
- evd()[source]¶
Method that calculates eigenvalue decomposition of kernel (k_pot matrix).
- Returns:
- eigenvectors: numpy array
Eigen vectors of k_pot matrix.
- eigrnvalues: numpy array
Eigenvalues of k_pot matrix.
- Raises:
- LinAlgError
If EVD computation does not converge.
- picard_plot(b)[source]¶
Creates Picard plot according to Hansen’s book.
- Parameters:
- b: numpy array
Right-hand side of the linear equation.
- Raises:
- LinAlgError
If SVD computation does not converge.
- plot_evd_sigma(s)[source]¶
Creates plot of eigenvalues of k_pot matrix.
- Parameters:
- s: numpy array
Eigenvalues of k_pot matrix.
- plot_evd_sigma_lambd(s)[source]¶
- Creates plots of:
1 over (eigenvalues of k_pot matrix + lambda).
eigenvalues over (eigenvalues**2 + lambda)
- Parameters:
- sigma: numpy array
Singular values of kernels product.
- plot_svd_sigma(sigma)[source]¶
Creates plot of singular values of kernels product (K~*K^-1).
- Parameters:
- sigma: numpy array
Singular values of kernels product.
- plot_svd_sigma_lambd(sigma)[source]¶
- Creates plots of:
1 over (singular values of kernels product (K~*K^-1) + lambda).
singular values over (singular values**2 + lambda)
- Parameters:
- sigma: numpy array
Singular values of kernels product.
- plot_svd_u(u_svd)[source]¶
Creates plot of left singular values.
- Parameters:
- u_svd: numpy array
Left singular vectors.
- plot_svd_v(v_svd)[source]¶
Creates plot of right singular values
- Parameters:
- v_svd: numpy array
Right singular vectors.
- svd()[source]¶
Method that calculates singular value decomposition of total kernel matrix. K~*K^-1 from eq. 18 (Potworowski 2012). It calls also plotting methods.
- Returns:
- u_svd: numpy array
Left singular vectors of kernels product.
- sigma: numpy array
Singular values of kernels product.
- v_svd: numpy array
Right singular vectors of kernels product.
- Raises:
- LinAlgError
If the matrix is not numerically invertible. If SVD computation does not converge.
Validation¶
- class kcsd.validation.ValidateKCSD.ValidateKCSD(dim, **kwargs)[source]¶
Base class for validation of the kCSD method
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(dim, **kwargs)[source]¶
Initialize ValidateKCSD class.
- Parameters:
- dim: int
Case dimension (1, 2 or 3D).
- **kwargs
configuration parameters, that may contain the following keys: src_type : str
Basis function type (‘gauss’, ‘step’, ‘gauss_lim’). Default: ‘gauss’.
- sigmafloat
Space conductance of the medium. Default: 0.3.
- R_initfloat
Demanded thickness of the basis element. Default: 0.23.
- hfloat
Thickness of analyzed cylindrical slice. Default: 1.
- nr_basis: int
Number of basis sources. Default: 300.
- ext_xfloat
Length of space extension: x_min-ext_x … x_max+ext_x. Default: 0.
- est_xres: int
Resolution of kcsd estimation. Default: 100.
- true_csd_xlims: list
Boundaries for ground truth space. Default: [0., 1.].
- ele_xlims: list
Boundaries for electrodes placement. Default: [0., 1.].
- csd_xres: int
Resolution of ground truth. Default: 100.
- Raises:
- ValueError
If dimension of estimation space differs from 1, 2 or 3.
- add_noise(pots, seed=0, level=10)[source]¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)[source]¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_mag(true_csd, est_csd)[source]¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)[source]¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)[source]¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)[source]¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)[source]¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)[source]¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)[source]¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)[source]¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)[source]¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)[source]¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)[source]¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- parameters(**kwargs)[source]¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- sigmoid_mean(error)[source]¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.ValidateKCSD.ValidateKCSD1D(csd_seed, **kwargs)[source]¶
ValidateKCSD1D - The 1D variant of validation tests for kCSD method.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD1D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, kcsd, est_csd, ...)Creates plots of ground truth, measured potentials and recontruction
make_reconstruction
(csd_profile, csd_seed, ...)Main method, makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(csd_seed, **kwargs)[source]¶
Initialize ValidateKCSD1D class.
- Parameters:
- csd_seed: int
Seed for random generator to choose random CSD profile.
- **kwargs
Configuration parameters.
- Returns:
- None
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)[source]¶
Calls KCSD1D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- kcsd: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, kcsd, est_csd, ele_pos, pots, fig_title)[source]¶
Creates plots of ground truth, measured potentials and recontruction
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, total_ele, ele_lims=None, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Main method, makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- kcsd: instance of the class
Instance of class KCSD1D.
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.ValidateKCSD.ValidateKCSD2D(csd_seed, **kwargs)[source]¶
ValidateKCSD2D - The 2D variant of validation tests for kCSD method.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD2D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, test_csd, kcsd, ...)Creates plot of ground truth data, calculated potentials and reconstruction
make_reconstruction
(csd_profile, csd_seed, ...)Main method, makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(csd_seed, **kwargs)[source]¶
Initialize ValidateKCSD2D class.
- Parameters:
- csd_seed: int
Seed for random generator to choose random CSD profile.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)[source]¶
Calls KCSD2D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, test_csd, kcsd, est_csd, ele_pos, pots, fig_title)[source]¶
Creates plot of ground truth data, calculated potentials and reconstruction
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, total_ele, ele_lims=None, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Main method, makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.ValidateKCSD.ValidateKCSD3D(csd_seed, **kwargs)[source]¶
ValidateKCSD3D - The 3D variant of validation class for kCSD method.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD3D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, kcsd, est_csd, ...)Creates plot of ground truth data, calculated potentials and reconstruction.
make_reconstruction
(csd_profile, csd_seed, ...)Main method, makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(csd_seed, **kwargs)[source]¶
Initialize ValidateKCSD3D class
- Parameters:
- csd_seed: int
Seed for random generator to choose random CSD profile.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)[source]¶
Calls KCSD3D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, kcsd, est_csd, ele_pos, pots, fig_title)[source]¶
Creates plot of ground truth data, calculated potentials and reconstruction.
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, total_ele, ele_lims=None, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Main method, makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
Reliability Maps¶
These are useful for VisibilityMap estimates in kCSD
- class kcsd.validation.VisibilityMap.VisibilityMap1D(total_ele, **kwargs)[source]¶
Class that produces error map for 1D CSD reconstruction.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_error_map
(csd_profile[, n, noise, ...])Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD1D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, kcsd, est_csd, ...)Creates plots of ground truth, measured potentials and recontruction
make_reconstruction
(csd_profile, csd_seed[, ...])Makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
plot_error_map
(point_error, ele_pos)Creates plot of mean error calculated separately for every point of estimation space
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(total_ele, **kwargs)[source]¶
Initialize ErrorMap1D class.
- Parameters:
- total_ele: int
Number of electrodes.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_error_map(csd_profile, n=100, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- n: int
Number of simulations included in reliability map calculations. Default: 100.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)¶
Calls KCSD1D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- kcsd: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, kcsd, est_csd, ele_pos, pots, fig_title)¶
Creates plots of ground truth, measured potentials and recontruction
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
function to produce csd profile
- csd_seed: int
Seed for random generator to choose random CSD profile.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- plot_error_map(point_error, ele_pos)[source]¶
Creates plot of mean error calculated separately for every point of estimation space
- Parameters:
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- ele_pos: numpy array
Positions of electrodes.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.VisibilityMap.VisibilityMap2D(total_ele, **kwargs)[source]¶
Class that produces error map for 2D CSD reconstruction.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_error_map
(csd_profile[, n, noise, ...])Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD2D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, test_csd, kcsd, ...)Creates plot of ground truth data, calculated potentials and reconstruction
make_reconstruction
(csd_profile, csd_seed[, ...])Makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
plot_error_map
(point_error, ele_pos)Creates plot of mean error calculated separately for every point of estimation space
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(total_ele, **kwargs)[source]¶
Initialize ErrorMap2D class.
- Parameters:
- total_ele: int
Number of electrodes.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_error_map(csd_profile, n=100, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- n: int
Number of simulations included in reliability map calculations. Default: 100.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)¶
Calls KCSD2D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, test_csd, kcsd, est_csd, ele_pos, pots, fig_title)¶
Creates plot of ground truth data, calculated potentials and reconstruction
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
function to produce csd profile
- csd_seed: int
Seed for random generator to choose random CSD profile.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- plot_error_map(point_error, ele_pos)[source]¶
Creates plot of mean error calculated separately for every point of estimation space
- Parameters:
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- ele_pos: numpy array
Positions of electrodes.
- Returns:
- mean_error: numpy array
Accuracy mask.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.VisibilityMap.VisibilityMap2DMoI(total_ele, **kwargs)[source]¶
Class that produces error map for 2D CSD reconstruction.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_error_map
(csd_profile[, n, noise, ...])Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls MoIKCSD class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, test_csd, kcsd, ...)Creates plot of ground truth data, calculated potentials and reconstruction
make_reconstruction
(csd_profile, csd_seed[, ...])Makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
plot_error_map
(point_error, ele_pos)Creates plot of mean error calculated separately for every point of estimation space
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(total_ele, **kwargs)[source]¶
Initialize ErrorMap2D class.
- Parameters:
- total_ele: int
Number of electrodes.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_error_map(csd_profile, n=100, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- n: int
Number of simulations included in reliability map calculations. Default: 100.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)¶
Calls MoIKCSD class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, test_csd, kcsd, est_csd, ele_pos, pots, fig_title)¶
Creates plot of ground truth data, calculated potentials and reconstruction
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
function to produce csd profile
- csd_seed: int
Seed for random generator to choose random CSD profile.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- plot_error_map(point_error, ele_pos)[source]¶
Creates plot of mean error calculated separately for every point of estimation space
- Parameters:
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- ele_pos: numpy array
Positions of electrodes.
- Returns:
- mean_error: numpy array
Accuracy mask.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
- class kcsd.validation.VisibilityMap.VisibilityMap3D(total_ele, **kwargs)[source]¶
Class that produces error map for 3D CSD reconstruction.
Methods
add_noise
(pots[, seed, level])Adds Gaussian noise to potentials.
broken_electrodes
(total_ele, ele_grid, n[, ...])Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
calculate_error_map
(csd_profile[, n, noise, ...])Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
calculate_mag
(true_csd, est_csd)Calculates magnitude ratio between reconstructed source and ground truth.
calculate_point_error
(true_csd, est_csd)Calculates normalized error of reconstruction at every point of estimation space separetly.
calculate_potential
(true_csd, csd_at, ...)Calculates potentials at electrodes' positions.
calculate_potential_parallel
(true_csd, ...)Computes the LFP generated by true_csd (ground truth) using parallel computing.
calculate_rdm
(true_csd, est_csd)Calculates relative difference measure between reconstructed source and ground truth.
calculate_rms
(true_csd, est_csd)Calculates normalized error of reconstruction.
do_kcsd
(pots, ele_pos[, method, Rs, lambdas])Calls KCSD3D class to reconstruct current source density.
electrode_config
(csd_profile, csd_seed, ...)Produces electrodes positions and calculates potentials measured at these points.
generate_csd
(csd_profile[, csd_seed, csd_at])Gives CSD profile at the requested spatial location, at 'res' resolution.
generate_electrodes
(total_ele[, ele_lims, ...])Places electrodes linearly.
grid
(x, y, z[, resX, resY])Convert 3 column data to matplotlib grid
integrate
(csd_at, true_csd, ele_loc, h[, ...])Calculates integrals (potential values) according to Simpson's rule in 1D space.
make_plot
(csd_at, true_csd, kcsd, est_csd, ...)Creates plot of ground truth data, calculated potentials and reconstruction.
make_reconstruction
(csd_profile, csd_seed[, ...])Makes the whole kCSD reconstruction.
parameters
(**kwargs)Defining the default values of the method passed as kwargs.
plot_error_map
(point_error, ele_pos)Creates plot of mean error calculated separately for every point of estimation space
sigmoid_mean
(error)Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- __init__(total_ele, **kwargs)[source]¶
Initialize ErrorMap3D class.
- Parameters:
- total_ele: int
Number of electrodes.
- **kwargs
Configuration parameters.
- add_noise(pots, seed=0, level=10)¶
Adds Gaussian noise to potentials.
- Parameters:
- pots: numpy array
Potentials at measurement points.
- seed: int
Random seed generator. Default: 0.
- level: float, optional
Noise level in percentage. Default: 10.
- Returns:
- pots_noise: numpy array
Potentials with added random Gaussian noise.
- broken_electrodes(total_ele, ele_grid, n, ele_seed=10)¶
Produces electrodes positions for setup with n (pseudo) randomly (ele_seed) removed electrodes.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_grid: numpy array
Positions of electrodes for the complete setup.
- n: int
Number of broken/missing electrodes.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes positions.
- Raises:
- ValueError
If number of broken electrodes is bigger or equal to the total number of electrodes or is negative.
- calculate_error_map(csd_profile, n=5, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes reconstructions for n random simulated ground truth profiles and returns errors of CSD estimation with kCSD method.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- n: int
Number of simulations included in reliability map calculations. Default: 5.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- calculate_mag(true_csd, est_csd)¶
Calculates magnitude ratio between reconstructed source and ground truth.
- Parameters:
- test_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- mag: float
Magnitude ratio.
- calculate_point_error(true_csd, est_csd)¶
Calculates normalized error of reconstruction at every point of estimation space separetly.
- Parameters:
- true_csd: numpy array
Values of true csd at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- point_error: numpy array
Normalized error of reconstruction calculated separetly at every point of estimation space.
- calculate_potential(true_csd, csd_at, ele_pos, h, sigma)¶
Calculates potentials at electrodes’ positions.
- Parameters:
- true_csd: numpy array
Values of generated CSD.
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- Returns:
- pots: numpy array
Normalized values of potentials as in eq.:26 Potworowski(2012).
- calculate_potential_parallel(true_csd, csd_at, ele_pos, h)¶
Computes the LFP generated by true_csd (ground truth) using parallel computing.
- Parameters:
- true_csd: numpy array
Values of ground truth data (true_csd).
- csd_at: numpy array
Coordinates of ground truth data.
- ele_pos: numpy array
Locations of electrodes.
- h: float
Thickness of analyzed cylindrical slice.
- Returns:
- pots: numpy array
Calculated potentials.
- calculate_rdm(true_csd, est_csd)¶
Calculates relative difference measure between reconstructed source and ground truth.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rdm: float
Relative difference measure.
- calculate_rms(true_csd, est_csd)¶
Calculates normalized error of reconstruction.
- Parameters:
- true_csd: numpy array
Values of true CSD at points of kCSD estimation.
- est_csd: numpy array
CSD estimated with kCSD method.
- Returns:
- rms: float
Normalized error of reconstruction.
- do_kcsd(pots, ele_pos, method='cross-validation', Rs=None, lambdas=None)¶
Calls KCSD3D class to reconstruct current source density.
- Parameters:
- pots: numpy array
Values of potentials at ele_pos.
- ele_pos: numpy array
Electrodes positions.
- method: string
Determines the method of regularization. Default: cross-validation.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- Returns:
- k: instance of the class
Instance of class KCSD1D.
- est_csd: numpy array
Estimated csd (with kCSD method).
- electrode_config(csd_profile, csd_seed, total_ele, ele_lims, h, sigma, noise=0.0, nr_broken_ele=None, ele_seed=10)¶
Produces electrodes positions and calculates potentials measured at these points.
- Parameters:
- csd_profile: function
Function to produce ground truth csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- h: float
Thickness of analyzed cylindrical slice.
- sigma: float
Space conductance of the medium.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Electrodes locations in 1D, 2D or 3D.
- pots: numpy array
Potentials measured (calculated) on electrodes.
- generate_csd(csd_profile, csd_seed=5, csd_at=None)¶
Gives CSD profile at the requested spatial location, at ‘res’ resolution.
- Parameters:
- csd_profile: function
Function to produce csd profile.
- csd_seed: int
Seed for random generator to choose random CSD profile. Default: 5.
- csd_at: numpy array
Where to generate CSD. Default: None.
- Returns:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
CSD at csd_at positions.
- generate_electrodes(total_ele, ele_lims=None, nr_broken_ele=None, ele_seed=10)¶
Places electrodes linearly.
- Parameters:
- total_ele: int
Number of electrodes.
- ele_lims: list
Electrodes limits. Default: None.
- nr_broken_ele: int, optional
Determines how many electrodes are broken. Default: None.
- ele_seed: int
Internal state of the random number generator. Default: 10.
- Returns:
- ele_pos: numpy array
Linearly placed electrodes positions.
- grid(x, y, z, resX=100, resY=100)¶
Convert 3 column data to matplotlib grid
- Parameters:
- x
- y
- z
- Returns:
- xi
- yi
- zi
- integrate(csd_at, true_csd, ele_loc, h, csd_lims=None)¶
Calculates integrals (potential values) according to Simpson’s rule in 1D space.
- Parameters:
- csd_at: numpy array
Positions (coordinates) at which CSD is generated.
- true_csd: numpy array
Values of csd (ground truth) at csd_at positions.
- ele_loc: float (1D) or list (2D and 3D)
Single electrode location/position.
- h: float
Thickness of analyzed cylindrical slice.
- csd_lims: list
Limits of true source space
- Returns:
- Integral: float
Calculated potential at x0 position.
- make_plot(csd_at, true_csd, kcsd, est_csd, ele_pos, pots, fig_title)¶
Creates plot of ground truth data, calculated potentials and reconstruction.
- Parameters:
- csd_at: numpy array
Coordinates of ground truth (true_csd).
- true_csd: numpy array
Values of generated CSD.
- kcsd: object of the class
- est_csd: numpy array
Reconstructed csd.
- ele_pos: numpy array
Positions of electrodes.
- pots: numpy array
Potentials measured on electrodes.
- fig_title: string
Title of the plot.
- make_reconstruction(csd_profile, csd_seed, noise=0, nr_broken_ele=None, Rs=None, lambdas=None, method='cross-validation')[source]¶
Makes the whole kCSD reconstruction.
- Parameters:
- csd_profile: function
function to produce csd profile
- csd_seed: int
Seed for random generator to choose random CSD profile.
- noise: float
Determines the level of noise in the data. Default: 0.
- nr_broken_ele: int
How many electrodes are broken (excluded from analysis) Default: None.
- Rs: numpy 1D array
Basis source parameter for crossvalidation. Default: None.
- lambdas: numpy 1D array
Regularization parameter for crossvalidation. Default: None.
- method: string
Determines the method of regularization. Default: cross-validation.
- Returns:
- rms: float
Error of reconstruction.
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- parameters(**kwargs)¶
Defining the default values of the method passed as kwargs.
- Parameters:
- **kwargs
Same as those passed to initialize the Class.
- Raises:
- TypeError
If invalid keyword arguments inserted into **kwargs.
- plot_error_map(point_error, ele_pos)[source]¶
Creates plot of mean error calculated separately for every point of estimation space
- Parameters:
- point_error: numpy array
Error of reconstruction calculated at every point of reconstruction space.
- ele_pos: numpy array
Positions of electrodes.
- Returns:
- mean_error: numpy array
Accuracy mask.
- sigmoid_mean(error)¶
Calculates sigmoidal mean across errors of reconstruction for many different sources - used for error maps.
- Parameters:
- error: numpy array
Normalized point error of reconstruction.
- Returns:
- error_mean: numpy array
Sigmoidal mean error of reconstruction. error_mean -> 1 - very poor reconstruction error_mean -> 0 - perfect reconstruction
Basis functions¶
1-Dimensional¶
- kcsd.basis_functions.gauss_1D(d, three_stdev)[source]¶
Returns normalized gaussian 2D scale function
- Parameters:
- dfloats or np.arrays
Distance array to the point of evaluation
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Z(three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *(d**2))
- kcsd.basis_functions.gauss_lim_1D(d, three_stdev)[source]¶
Returns gausian 2D function cut off after 3 standard deviations.
- Parameters:
- dfloats or np.arrays
Distance array to the point of evaluation
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Z(three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *((x-mu)**2)),
cut off = three_stdev
2-Dimensional¶
- kcsd.basis_functions.gauss_2D(d, three_stdev)[source]¶
Returns normalized gaussian 2D scale function
- Parameters:
- dfloats or np.arrays
distance at which we need the function evaluated
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Zfunction
Normalized gaussian 2D function
- kcsd.basis_functions.gauss_lim_2D(d, three_stdev)[source]¶
Returns gausian 2D function cut off after 3 standard deviations.
- Parameters:
- dfloats or np.arrays
distance at which we need the function evaluated
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Zfunction
Normalized gaussian 2D function cut off after three_stdev
3-Dimensional¶
- kcsd.basis_functions.gauss_3D(d, three_stdev)[source]¶
Returns normalized gaussian 3D scale function
- Parameters:
- dfloats or np.arrays
distance at which we need the function evaluated
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Zfuntion
Normalized gaussian 3D function
- kcsd.basis_functions.gauss_lim_3D(d, three_stdev)[source]¶
Returns normalized gaussian 3D scale function cut off after 3stdev
- Parameters:
- dfloats or np.arrays
distance at which we need the function evaluated
- three_stdevfloat
3 * standard deviation of the distribution
- Returns:
- Zfuntion
Normalized gaussian 3D function cutoff three_Stdev
CSD Test Sources¶
Variable (Seedable)¶
- kcsd.validation.csd_profile.gauss_2d_small(csd_at, seed=0)[source]¶
random quadpolar small source in 2D
- kcsd.validation.csd_profile.gauss_2d_large(csd_at, seed=0)[source]¶
random quadpolar’large source’ profile in 2012 paper in 2D
Fixed (Non seedable)¶
- kcsd.validation.csd_profile.gauss_1d_dipole_f(x)[source]¶
1D Gaussian dipole source is placed between 0 and 1 to be used to test the CSD
- Parameters:
- xnp.array
Spatial pts. at which the true csd is evaluated
- Returns:
- fnp.array
The value of the csd at the requested points
- kcsd.validation.csd_profile.gauss_2d_large_f(csd_at)[source]¶
Fixed ‘large source’ profile in 2012 paper
- kcsd.validation.csd_profile.gauss_3d_mono1_f(csd_at)[source]¶
Fixed monopole in 3D at the center of the volume space