Skip to content

Commit

Permalink
combine update_temporal_compoents & parallel
Browse files Browse the repository at this point in the history
combine update_temporal_compoents & update_temporal_components_parallel
into a single function. The default option is to use the parallel
implementation if the parallel processing toolbox is present
  • Loading branch information
epnev committed Jan 28, 2016
1 parent 5bb34aa commit e4c0694
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 383 deletions.
8 changes: 1 addition & 7 deletions @Sources2D/Sources2D.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ function updateTemporal(obj, Y)
[obj.C, obj.f, obj.P, obj.S] = update_temporal_components(...
Y, obj.A, obj.b, obj.C, obj.f, obj.P, obj.options);
end

%% update temporal components in parallel
function updateTemporalParallel(obj, Y)
[obj.C, obj.f, obj.P, obj.S] = update_temporal_components_parallel(...
Y, obj.A, obj.b, obj.C, obj.f, obj.P, obj.options);
end


%% merge found components
function [nr, merged_ROIs] = merge(obj, Y)
[obj.A, obj.C, nr, merged_ROIs, obj.P, obj.S] = merge_components(...
Expand Down
118 changes: 60 additions & 58 deletions CNMFSetParms.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,77 @@

Names = [
% dataset info
'd1 ' % number of rows
'd2 ' % number of cols
'd1 ' % number of rows
'd2 ' % number of cols
% INITIALIZATION (initialize_components.m)
'ssub ' % spatial downsampling factor (default: 1)
'tsub ' % temporal downsampling factor (default: 1)
'init_method ' % initialization method ('greedy','sparse_NMF') (default: 'greedy')
'ssub ' % spatial downsampling factor (default: 1)
'tsub ' % temporal downsampling factor (default: 1)
'init_method ' % initialization method ('greedy','sparse_NMF') (default: 'greedy')
% greedyROI parameters (greedyROI2d.m)
'gSig ' % half size of neurons to be found (default: [5,5])
'gSiz ' % half size of bounding box for each neuron (default: 2*gSig+1)
'nb ' % number of background components (default: 1)
'nIter ' % maximum number of rank-1 NMF iterations during refining
'med_app ' % number of timesteps to be interleaved for fast (approximate) median calculation (default: 1)
'save_memory ' % process data sequentially to save memory (default: 0)
'chunkSiz ' % filter this number of timesteps each time (default: 100)
'windowSiz ' % size of window over which is computed sequentially (default: 32 x 32)
'gSig ' % half size of neurons to be found (default: [5,5])
'gSiz ' % half size of bounding box for each neuron (default: 2*gSig+1)
'nb ' % number of background components (default: 1)
'nIter ' % maximum number of rank-1 NMF iterations during refining
'med_app ' % number of timesteps to be interleaved for fast (approximate) median calculation (default: 1)
'save_memory ' % process data sequentially to save memory (default: 0)
'chunkSiz ' % filter this number of timesteps each time (default: 100)
'windowSiz ' % size of window over which is computed sequentially (default: 32 x 32)
% sparse_NMF parameters (sparse_NMF_initialization.m)
'snmf_max_iter ' % max # of sparse NMF iterations
'err_thr ' % relative change threshold for stopping sparse_NMF
'eta ' % frobenious norm factor *max(Y(:))^2
'beta ' % sparsity factor
'snmf_max_iter ' % max # of sparse NMF iterations
'err_thr ' % relative change threshold for stopping sparse_NMF
'eta ' % frobenious norm factor *max(Y(:))^2
'beta ' % sparsity factor
% HALS parameters (HALS_2d.m)
'bSiz ' % expand kernel for HALS growing (default: 3)
'maxIter ' % maximum number of HALS iterations (default: 5)
'bSiz ' % expand kernel for HALS growing (default: 3)
'maxIter ' % maximum number of HALS iterations (default: 5)
% Noise and AR coefficients calculation (preprocess_data.m)
'noise_range ' % frequency range over which to estimate the noise (default: [0.25,0.5])
'noise_method ' % method for which to estimate the noise level (default: 'logmexp')
'flag_g ' % compute global AR coefficients (default: false)
'lags ' % number of extra lags when computing the AR coefficients (default: 5)
'include_noise ' % include early lags when computing AR coefs (default: 0)
'pixels ' % pixels to include when computing the AR coefs (default: 1:numel(Y)/size(Y,ndims(Y)))
'split_data ' % split data into patches for memory reasons (default: 0)
'block_size ' % block size for estimating noise std in patches (default: [64,64])
'noise_range ' % frequency range over which to estimate the noise (default: [0.25,0.5])
'noise_method ' % method for which to estimate the noise level (default: 'logmexp')
'flag_g ' % compute global AR coefficients (default: false)
'lags ' % number of extra lags when computing the AR coefficients (default: 5)
'include_noise ' % include early lags when computing AR coefs (default: 0)
'pixels ' % pixels to include when computing the AR coefs (default: 1:numel(Y)/size(Y,ndims(Y)))
'split_data ' % split data into patches for memory reasons (default: 0)
'block_size ' % block size for estimating noise std in patches (default: [64,64])
% UPDATING SPATIAL COMPONENTS (unpdate_spatial_components.m)
'search_method ' % method for determining footprint of spatial components 'ellipse' or 'dilate' (default: 'ellipse')
'use_parallel ' % update pixels in parallel (default: 1 if present)
'search_method ' % method for determining footprint of spatial components 'ellipse' or 'dilate' (default: 'ellipse')
'use_parallel ' % update pixels in parallel (default: 1 if present)
% determine_search_location.m
'min_size ' % minimum size of ellipse axis (default: 3)
'max_size ' % maximum size of ellipse axis (default: 8)
'dist ' % expansion factor of ellipse (default: 3)
'se ' % morphological element for dilation (default: strel('disk',4,0))
'min_size ' % minimum size of ellipse axis (default: 3)
'max_size ' % maximum size of ellipse axis (default: 8)
'dist ' % expansion factor of ellipse (default: 3)
'se ' % morphological element for dilation (default: strel('disk',4,0))
% threshold_components.m
'nrgthr ' % energy threshold (default: 0.9999)
'clos_op ' % morphological element for closing (default: strel('square',3))
'medw ' % size of median filter (default: [3,3])
'nrgthr ' % energy threshold (default: 0.9999)
'clos_op ' % morphological element for closing (default: strel('square',3))
'medw ' % size of median filter (default: [3,3])
% UPDATING TEMPORAL COMPONENTS (update_temporal_components.m)
'deconv_method ' % method for spike deconvolution (default: 'constrained_foopsi')
'restimate_g ' % flag for updating the time constants for each component (default: 1)
'temporal_iter ' % number of block-coordinate descent iterations (default 2)
'deconv_method ' % method for spike deconvolution (default: 'constrained_foopsi')
'restimate_g ' % flag for updating the time constants for each component (default: 1)
'temporal_iter ' % number of block-coordinate descent iterations (default: 2)
'temporal_parallel ' % flag for parallel updating of temporal components (default: true if present)
% CONSTRAINED DECONVOLUTION (constrained_foopsi.m)
'method ' % methods for performing spike inference ('dual','cvx','spgl1','lars') (default:'cvx')
'bas_nonneg ' % flag for setting the baseline lower bound. if 1, then b >= 0 else b >= min(y) (default 0)
'fudge_factor ' % scaling constant to reduce bias in the time constant estimation (default 1 - no scaling)
'resparse ' % number of times that the solution is resparsened (default: 0)
'method ' % methods for performing spike inference ('dual','cvx','spgl1','lars') (default:'cvx')
'bas_nonneg ' % flag for setting the baseline lower bound. if 1, then b >= 0 else b >= min(y) (default 0)
'fudge_factor ' % scaling constant to reduce bias in the time constant estimation (default 1 - no scaling)
'resparse ' % number of times that the solution is resparsened (default: 0)
% MERGING (merge_ROIs.m)
'merge_thr ' % merging threshold (default: 0.85)
'fast_merge ' % flag for using fast merging (default 1)
'merge_thr ' % merging threshold (default: 0.85)
'fast_merge ' % flag for using fast merging (default 1)
% VIDEO (make_patch_video.m)
'ind ' % indeces of components to be shown (deafult: 1:4)
'skip_frame ' % skip frames when showing the video (default: 1 (no skipping))
'sx ' % half size of representative patches (default: 16)
'make_avi ' % flag for saving avi video (default: 0)
'show_background' % flag for displaying the background in the denoised panel (default: 1)
'show_contours ' % flag for showing the contour plots of the patches in the FoV (default: 0)
'cmap ' % colormap for plotting (default: 'default')
'name ' % name of saved video file (default: based on current date)
'ind ' % indeces of components to be shown (deafult: 1:4)
'skip_frame ' % skip frames when showing the video (default: 1 (no skipping))
'sx ' % half size of representative patches (default: 16)
'make_avi ' % flag for saving avi video (default: 0)
'show_background ' % flag for displaying the background in the denoised panel (default: 1)
'show_contours ' % flag for showing the contour plots of the patches in the FoV (default: 0)
'cmap ' % colormap for plotting (default: 'default')
'name ' % name of saved video file (default: based on current date)
% PLOT COMPONENTS (view_patches.m)
'plot_df ' % flag for displaying DF/F estimates (default: 1)
'make_gif ' % save animation (default: 0)
'save_avi ' % save video (default: 0)
'pause_time ' % time to pause between each component (default: Inf, user has to click)
'plot_df ' % flag for displaying DF/F estimates (default: 1)
'make_gif ' % save animation (default: 0)
'save_avi ' % save video (default: 0)
'pause_time ' % time to pause between each component (default: Inf, user has to click)
];

[m,n] = size(Names);
Expand Down Expand Up @@ -207,6 +208,7 @@
{'constrained_foopsi'}
{1}
{2}
{~isempty(which('parpool'))}
% CONSTRAINED DECONVOLUTION (constrained_foopsi.m)
{'cvx'}
{0}
Expand All @@ -216,7 +218,7 @@
{0.85}
{1}
% VIDEO (make_patch_video.m)
{[1:4]}
{1:4}
{1}
{16}
{0}
Expand Down
4 changes: 2 additions & 2 deletions demo_script.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
num2read=2000; % user input: how many frames to read (optional, default until the end)

Y = bigread2(nam,sframe,num2read);
Y = Y - min(Y(:));
if ~isa(Y,'double'); Y = double(Y); end % convert to double

[d1,d2,T] = size(Y); % dimensions of dataset
Expand All @@ -25,7 +26,7 @@
'search_method','ellipse','dist',3,... % search locations when updating spatial components
'deconv_method','constrained_foopsi',... % activity deconvolution method
'temporal_iter',2,... % number of block-coordinate descent steps
'fudge_factor',0.98,... % bias correction for AR coefficients
'fudge_factor',0.98,... % bias correction for AR coefficients
'merge_thr',merge_thr... % merging threshold
);
%% Data pre-processing
Expand All @@ -50,7 +51,6 @@
[A,b] = update_spatial_components(Yr,Cin,fin,Ain,P,options);

%% update temporal components
% consider using update_temporal_components_parallel for increased speed
[C,f,P,S] = update_temporal_components(Yr,A,b,Cin,fin,P,options);

%% merge found components
Expand Down
Loading

0 comments on commit e4c0694

Please sign in to comment.