def stability_M(csd_profile, csd_seed, n_src, ele_lims, true_csd_xlims, total_ele): """ Investigates stability of reconstruction for different number of basis sources Parameters ---------- csd_profile: function Function to produce csd profile. csd_seed: int Seed for random generator to choose random CSD profile. n_src: int Number of basis sources. ele_lims: list Boundaries for electrodes placement. true_csd_xlims: list Boundaries for ground truth space. total_ele: int Number of electrodes. Returns ------- obj_all: class object rms: float Normalized error of reconstruction. point_error_all: numpy array Normalized error of reconstruction calculated separetly at every point point of estimation space. eigenvalues: numpy array Eigenvalues of k_pot matrix. eigenvectors: numpy array Eigen vectors of k_pot matrix. """ obj_all = [] rms = np.zeros((len(n_src))) point_error_all = [] eigenvectors = np.zeros((len(n_src), total_ele, total_ele)) eigenvalues = np.zeros((len(n_src), total_ele)) for i, value in enumerate(n_src): KK = ValidateKCSD1D(csd_seed, n_src_init=value, R_init=0.23, ele_lims=ele_lims, true_csd_xlims=true_csd_xlims, sigma=0.3, h=0.25, src_type='gauss') obj, rms[i], point_error = KK.make_reconstruction(csd_profile, csd_seed, total_ele=total_ele, noise=0, Rs=np.arange( 0.2, 0.5, 0.1)) ss = SpectralStructure(obj) eigenvectors[i], eigenvalues[i] = ss.evd() point_error_all.append(point_error) obj_all.append(obj) return obj_all, rms, point_error_all, eigenvalues, eigenvectors
def targeted_basis(val, csd_at, true_csd, ele_pos, pots, n_src, R, MU, true_csd_xlims, ele_lims, title, h=0.25, sigma=0.3, csd_res=100): ''' Function investigating kCSD analysis for targeted bases. Parameters ---------- val: object of the class ValidateKCSD. csd_at: numpy array Coordinates of ground truth data. true_csd: numpy array Values of ground truth data (true_csd). ele_pos: numpy array Locations of electrodes. pots: numpy array Potentials measured (calculated) on electrodes. n_src: int Number of basis sources. R: float Thickness of the groundtruth source. MU: float x coordinate of maximum ampliude of groundtruth source. true_csd_xlims: list Boundaries for ground truth space. ele_lims: list Boundaries for electrodes placement. h: float Thickness of analyzed cylindrical slice. Default: 0.25. sigma: float Space conductance of the medium. Default: 0.3. csd_res: int Resolution of ground truth. Default: 100. Returns ------- obj: object of the class KCSD1D k: object of the class ValidateKCSD1D ''' k = ValidateKCSD1D(1, n_src_init=n_src, R_init=0.23, ele_lims=ele_lims, true_csd_xlims=true_csd_xlims, sigma=sigma, h=h, src_type='gauss') obj, est_csd = k.recon(pots, ele_pos, method='cross-validation', Rs=np.arange(0.2, 0.5, 0.1)) test_csd = csd_profile(obj.estm_x, [R, MU]) rms = val.calculate_rms(test_csd, est_csd) titl = "Lambda: %0.2E; R: %0.2f; RMS_Error: %0.2E;" % (obj.lambd, obj.R, rms) fig = k.make_plot(csd_at, true_csd, obj, est_csd, ele_pos, pots, titl) save_as = (SAVE_PATH) fig.savefig(os.path.join(SAVE_PATH, save_as + '/' + title + '.png')) plt.close() return obj, k
def default_setting(self, dim, csd_instance): if dim == 1: utils = ValidateKCSD1D(csd_seed=42) elif dim == 2: utils = ValidateKCSD2D(csd_seed=43) else: utils = ValidateKCSD3D(csd_seed=44) ele_pos = utils.generate_electrodes(total_ele=3) csd_at, csd = utils.generate_csd(csd_instance, csd_seed=2) lfp = utils.calculate_potential(csd, csd_at, ele_pos, h=1, sigma=0.3) return ele_pos, lfp
def setUp(self): dim = 1 utils = ValidateKCSD1D(csd_seed=42) self.ele_pos = utils.generate_electrodes(total_ele=10, ele_lims=[0.1, 0.9]) self.csd_profile = CSD.gauss_1d_mono self.csd_at, self.csd = utils.generate_csd(self.csd_profile, csd_seed=42) pots = utils.calculate_potential(self.csd, self.csd_at, self.ele_pos, h=1., sigma=0.3) self.pots = np.reshape(pots, (-1, 1)) self.test_method = 'KCSD1D' self.test_params = { 'h': 1., 'sigma': 0.3, 'R_init': 0.2, 'n_src_init': 100, 'xmin': 0., 'xmax': 1., }
def stability_M(csd_profile, csd_seed, n_src, ele_lims, true_csd_xlims, total_ele, noise=0, method='cross-validation', Rs=None, lambdas=None): """ Investigates stability of reconstruction for different number of basis sources Parameters ---------- csd_profile: function Function to produce csd profile. csd_seed: int Seed for random generator to choose random CSD profile. n_src: int Number of basis sources. ele_lims: list Boundaries for electrodes placement. true_csd_xlims: list Boundaries for ground truth space. total_ele: int Number of electrodes. noise: float Determines the level of noise in the data. Default: 0. 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 ------- obj_all: class object rms: float Normalized error of reconstruction. point_error_all: numpy array Normalized error of reconstruction calculated separetly at every point point of estimation space. eigenvalues: numpy array Eigenvalues of k_pot matrix. eigenvectors: numpy array Eigen vectors of k_pot matrix. """ obj_all = [] rms = np.zeros((len(n_src))) point_error_all = [] eigenvectors = np.zeros((len(n_src), total_ele, total_ele)) eigenvalues = np.zeros((len(n_src), total_ele)) for i, value in enumerate(n_src): KK = ValidateKCSD1D(csd_seed, n_src_init=value, R_init=0.23, ele_lims=ele_lims, true_csd_xlims=true_csd_xlims, sigma=0.3, h=0.25, src_type='gauss', est_xres=0.01) obj, rms[i], point_error = KK.make_reconstruction(csd_profile, csd_seed, total_ele=total_ele, noise=noise, Rs=Rs, lambdas=lambdas) ss = SpectralStructure(obj) eigenvectors[i], eigenvalues[i] = ss.evd() point_error_all.append(point_error) obj_all.append(obj) return obj_all, rms, point_error_all, eigenvalues, eigenvectors