This update adds a new function zef_deep tetra, which takes a volume (a set
of tetrahedra) and selects a subset of those that are deep enough within the
volume. This function is also called in the script lead_field_matrix to make
sure all tetra passed to the lead field routines are deep ones.
The bug fixes include:
adding conversions of old zef.source_model integers to the new
ZefSourceModel enumeration in the forward scripts the conversions were
missing from,
adding a schur_expression parameter to zef_transfer_matrix, which allows
the caller to specify the formula with which the columns of the Schur
complement of the transfer matrix are constructed and
using these to fix the problems with the EEG routine. The new PEM version is
now just about as good as the old routine, both speed- and accuracy-wise.
In addition, small things like indentations that imrove code readability were
added in places. The specific commit messages of this squashed set of over 60
commits can be found below.
Added the beginnings of zef_deep_tetra.m
zef_surface_mesh: added proper indentations
… and a few comments.
zef_deep_tetra: continued writing
zef_surface_mesh: added the beginnings of documentation
zef_deep_tetra: added a private function for finding surface tetra
zef_deep_tetra: added function end comments
zef_surface_mesh: added line breaks for clarity
zef_deep_tetra: fixed a typo
zef_decompose_dof_space: added indentation and a call to zef_tetra_barycentra
zef_surface_mesh: documented return value tetra_ind
zef_deep_tetra: extract surface tetra indices from zef_surface_mesh
zef_deep_tetra: removed call to local function surface_tetra_fn
zef_surface_mesh: added more documentation
zef_deep_tetra: fixed input names in documentation
zef_deep_tetra: removed local function surface_tetra_fn as unnecessary
Added function zef_nearest_points
Originally suggested by Sampsa, but slightly modified to include argument
validation and the need to always pass in the second set from which we are
looking neighbours from (nargin parsing isn't the most fun thing in the
world).
zef_decompose_dof_space: replaced another long line with call to zef_tetra_barycentra
zef_deep_tetra: removed unnecessary whitespace
zef_decompose_dof_space: added the beginnings of documentation
zef_decompose_dof_space: moved documentation outside of the function
Apparently this works with the Matlab help command as well. Good to know…
lead_field_matrix: added indentations and line breaks for clarity
lead_field_matrix: added missing indentations
zef_decompose_dof_space: lattice_index_aux calculated with function lattice_index_fn
zef_nearest_points: moved 'count' case validity check before other operations in the branch
zef_nearest_points: fixed integer check in count branch
zef_deep_tetra: refactored in a rangesearch-based solution for finding nodes deep anough in the volume
zef_deep_tetra: now returns deep nodes, tetra and their indices
Moved zefdeep{tetra → nodes_and_tetra}.m
zef_deep_nodes_and_tetra: updated documentation and ignored an unused return value
zef_deep_nodes_and_tetra: fixed variable names and updated documentation
zef_decompose_dof_space: more descriptive variable names
zef_lead_field_eeg_fem: make sure zef_lead_field_sign only gets the coordinates of the electrodes
lead_field_matrix: set acceptable source depth in gray matter with zef.aux_vec and zef_deep_nodes_and_tetra
Moved EEG lead field sign flip(s) to the end of lead_field_matrix from lead_field_eeg_fem
lead_field_matrix: removed sign flip from end of file
lead_field_eeg_fem: L_eeg = -T' G, not T' G.
In the prior code where the interpolation (matrix G) was built into the PCG
iteration, the column-by-column construction logic was as follows:
L_eeg = - T(:,column index)' * G ,
whereas in the new routine the effects of the interpolation were applied with
a single matrix product
L_eeg = T' * G;
at the end of the file. Notice the lack of the minus sign.
lead_field_eeg_fem: ignore unneeded output of zef_transfer_matrix
lead_field_eeg_fem: changed comment to reflect change in previous commit
Added new test functions {mag,rdm}_fn
This should help with calculating these measures between matrices.
Added function zef_kron_reduction
zef_kron_reduction: improved documentation
zef_kron_reduction: source model taken into consideration
Added function zef_set_lead_field_zero_potential
lead_field_eeg_fem: add product with Schur complement back in
The CEM case seems to at least point in the correct direction now.
zef_hdiv_interpolation: calculate G indices and values before final sparse allocation
Feeding values into an empty sparse array G was much slower. Also increased
the update interval of the waitbar.
zef_lead_field_eeg_multilayer_sphere: added a (hopefully) functional version…
zef_hdiv_interpolation: indexs set building seems to be fixed now
The column indices were set up the wrong way around. Fixing involved repeating
in the other direction and the transposing in the first loop.
Also added some more documentation comments.
zef_whitney_interpolation: reimplemented just like the H(div) case
Routine is now based on building index- and corresponsing value sets, and
placing these into the sparse matrix G all at once. This removes unnecessary
reallocations of G from the routine.
zef_st_venant_interpolation: update waitbar less frequently
As always, printing stuff is sloooow.
zef_st_venant_interpolation: added a sign flip for G at the end
Without this, the produced lead field has a wrong sign.
TODO: find out whether the sources are wrongly oriented, the St. Venant
interpolation equations are missing a sign, or if this is related the the
ill-orientedness of the Schru complement produced by zef_transfer_matrix in
the EEG case.
zef_st_venant_interpolation: added an empty line for readability
zef_st_venant_interpolation: added more empty lines for readability
zef_st_venant_interpolation: removed an inner loop in favour of a simpler assignment to G
zef_transfer_matrix: improved documentation
zef_transfer_matrix: takes a Schur expression as its last parameter
This 2-place function handle schur_expression(Tcol,ind) specifies how the
columns of the Schur complement of the transfer matrix T are to be
calculated, based on the columns of T or Tcol. This means that the
function handle needs to be defined at the call site of zef_transfer_matrix,
so that B and C might be captured in the closure. This definition is now
done in the files lead_field_{eeg,tes}_fem.m.
lead_field_eeg_fem: set zef_transfer_matrix Schur expression as the one in the original EEG routine
Also removed an unnecessary (because of this change) minus sign from the
construction of L_eeg.
lead_field_tes_fem: pass Schur expression into zef_transfer_matrix
forward_scripts: make sure source_model is converted to ZefSourceModel where it is used
lead_field_tes_fem: remove extra parameters from call to zef_build_electrodes
This update adds a new function
zef_deep tetra
, which takes a volume (a set of tetrahedra) and selects a subset of those that are deep enough within the volume. This function is also called in the scriptlead_field_matrix
to make sure all tetra passed to the lead field routines are deep ones.The bug fixes include:
adding conversions of old
zef.source_model
integers to the newZefSourceModel
enumeration in the forward scripts the conversions were missing from,adding a
schur_expression
parameter to zef_transfer_matrix, which allows the caller to specify the formula with which the columns of the Schur complement of the transfer matrix are constructed andusing these to fix the problems with the EEG routine. The new PEM version is now just about as good as the old routine, both speed- and accuracy-wise.
In addition, small things like indentations that imrove code readability were added in places. The specific commit messages of this squashed set of over 60 commits can be found below.
Added the beginnings of zef_deep_tetra.m
zef_surface_mesh: added proper indentations
… and a few comments.
zef_deep_tetra: continued writing
zef_surface_mesh: added the beginnings of documentation
zef_deep_tetra: added a private function for finding surface tetra
zef_deep_tetra: added function end comments
zef_surface_mesh: added line breaks for clarity
zef_deep_tetra: fixed a typo
zef_decompose_dof_space: added indentation and a call to zef_tetra_barycentra
zef_surface_mesh: documented return value tetra_ind
zef_deep_tetra: extract surface tetra indices from zef_surface_mesh
zef_deep_tetra: removed call to local function surface_tetra_fn
zef_surface_mesh: added more documentation
zef_deep_tetra: fixed input names in documentation
zef_deep_tetra: removed local function surface_tetra_fn as unnecessary
Added function zef_nearest_points
Originally suggested by Sampsa, but slightly modified to include argument validation and the need to always pass in the second set from which we are looking neighbours from (nargin parsing isn't the most fun thing in the world).
zef_decompose_dof_space: replaced another long line with call to zef_tetra_barycentra
zef_deep_tetra: removed unnecessary whitespace
zef_decompose_dof_space: added the beginnings of documentation
zef_decompose_dof_space: moved documentation outside of the function
Apparently this works with the Matlab help command as well. Good to know…
lead_field_matrix: added indentations and line breaks for clarity
lead_field_matrix: added missing indentations
zef_decompose_dof_space: lattice_index_aux calculated with function lattice_index_fn
zef_nearest_points: moved 'count' case validity check before other operations in the branch
zef_nearest_points: fixed integer check in count branch
zef_deep_tetra: refactored in a rangesearch-based solution for finding nodes deep anough in the volume
zef_deep_tetra: now returns deep nodes, tetra and their indices
Moved zefdeep{tetra → nodes_and_tetra}.m
zef_deep_nodes_and_tetra: updated documentation and ignored an unused return value
zef_deep_nodes_and_tetra: fixed variable names and updated documentation
zef_decompose_dof_space: more descriptive variable names
zef_lead_field_eeg_fem: make sure zef_lead_field_sign only gets the coordinates of the electrodes
lead_field_matrix: set acceptable source depth in gray matter with zef.aux_vec and zef_deep_nodes_and_tetra
Moved EEG lead field sign flip(s) to the end of lead_field_matrix from lead_field_eeg_fem
lead_field_matrix: removed sign flip from end of file
lead_field_eeg_fem: L_eeg = -T' G, not T' G.
In the prior code where the interpolation (matrix G) was built into the PCG iteration, the column-by-column construction logic was as follows:
whereas in the new routine the effects of the interpolation were applied with a single matrix product
at the end of the file. Notice the lack of the minus sign.
lead_field_eeg_fem: ignore unneeded output of zef_transfer_matrix
lead_field_eeg_fem: changed comment to reflect change in previous commit
Added new test functions {mag,rdm}_fn
This should help with calculating these measures between matrices.
Added function zef_kron_reduction
zef_kron_reduction: improved documentation
zef_kron_reduction: source model taken into consideration
Added function zef_set_lead_field_zero_potential
lead_field_eeg_fem: add product with Schur complement back in
The CEM case seems to at least point in the correct direction now.
zef_hdiv_interpolation: calculate G indices and values before final sparse allocation
Feeding values into an empty sparse array G was much slower. Also increased the update interval of the waitbar.
zef_lead_field_eeg_multilayer_sphere: added a (hopefully) functional version…
zef_hdiv_interpolation: indexs set building seems to be fixed now
The column indices were set up the wrong way around. Fixing involved repeating in the other direction and the transposing in the first loop.
Also added some more documentation comments.
zef_whitney_interpolation: reimplemented just like the H(div) case
Routine is now based on building index- and corresponsing value sets, and placing these into the sparse matrix G all at once. This removes unnecessary reallocations of G from the routine.
zef_whitney_interpolation: added missing print_interval definition
zef_st_venant_interpolation: update waitbar less frequently
As always, printing stuff is sloooow.
zef_st_venant_interpolation: added a sign flip for G at the end
Without this, the produced lead field has a wrong sign.
TODO: find out whether the sources are wrongly oriented, the St. Venant interpolation equations are missing a sign, or if this is related the the ill-orientedness of the Schru complement produced by zef_transfer_matrix in the EEG case.
zef_st_venant_interpolation: added an empty line for readability
zef_st_venant_interpolation: added more empty lines for readability
zef_st_venant_interpolation: removed an inner loop in favour of a simpler assignment to G
zef_transfer_matrix: improved documentation
zef_transfer_matrix: takes a Schur expression as its last parameter
This 2-place function handle
schur_expression(Tcol,ind)
specifies how the columns of the Schur complement of the transfer matrixT
are to be calculated, based on the columns ofT
orTcol
. This means that the function handle needs to be defined at the call site ofzef_transfer_matrix
, so thatB
andC
might be captured in the closure. This definition is now done in the fileslead_field_{eeg,tes}_fem.m
.lead_field_eeg_fem: set zef_transfer_matrix Schur expression as the one in the original EEG routine
Also removed an unnecessary (because of this change) minus sign from the construction of L_eeg.
lead_field_tes_fem: pass Schur expression into zef_transfer_matrix
forward_scripts: make sure source_model is converted to ZefSourceModel where it is used
lead_field_tes_fem: remove extra parameters from call to zef_build_electrodes