Skip to content

Commit

Permalink
Various experimental edits, removal of parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtdev committed Sep 16, 2016
1 parent f913b16 commit 2f7f28c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 45 deletions.
99 changes: 55 additions & 44 deletions robustCAR4_winsz.m
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
function [data_out, ref_est, nn_ref_est] = robustCAR4_winsz(data_in, dt, n_min_contributing_channels, n_cores)

% New internal functions for robust CAR
%
% Modded by MDT -- temporary. Need to fix all of the parallel processing!
%
% IN PROGRESS!
%
% NOT FOR USE!

%win_sz = 10*dt; %.2 % seconds. % daFuq?
n_win_sz = 1; % floor( win_sz / dt );
n = size( data_in, 2 );
n_win = floor( n / n_win_sz );

%win_sz = 10*dt; %.2 % seconds.
n_win_sz = 1; %floor( win_sz / dt );
n = size( data_in, 2 );
n_win = floor( n / n_win_sz );
if( n_win == 0 )
fprintf( '\n\nShould not happen.\n\n' );
keyboard
[ data_out, ref_est, nn_ref_est ] = robustCAR_helper( data_in, dt, n_min_contributing_channels, nm, taxis );
else
data_out = zeros( size( data_in, 1 ), n );
ref_est = zeros( 1, n );
nn_ref_est = zeros( 1, n );
fprintf( '\n\nrobustCAR4: Entering for jj = 1 : n ...\n\n' )
tic
if matlabpool( 'size' ) == 0
matlabpool( n_cores );
end
parfor jj = 1 : n
if mod( jj, 100 ) == 0
fprintf( 'Sample No: %d\n', jj )
end
i_start = jj; i_stop = i_start + n_win_sz - 1;
i_stop = min( [ n i_stop ] );
inds = i_start:i_stop;
if std( data_in(:,inds)) > 1e-20
[ tmp_out, ref_out, nn_out ] = robustCAR_helper( data_in(:,inds), dt, n_min_contributing_channels );

try
data_out(:,jj) = tmp_out(1,:)';
ref_est(jj) = ref_out(1);
nn_ref_est(jj) = nn_out(1);
catch me
me.message
dbstack
if( n_win == 0 )
fprintf( '\n\nShould not happen.\n\n' );
keyboard
end
[ data_out, ref_est, nn_ref_est ] = robustCAR_helper( data_in, dt, n_min_contributing_channels, nm, taxis );
else
data_out = zeros( size( data_in, 1 ), n );
ref_est = zeros( 1, n );
nn_ref_est = zeros( 1, n );
fprintf( '\n\nrobustCAR4_winsz: Entering for jj = 1 : n ...\n\n' )
tic
% if isempty(gcp('nocreate')) % matlabpool( 'size' ) == 0
% matlabpool( n_cores );
% end

%% here is where things are hanging!!!
%parfor jj = 1 : n
for jj = 1:n

if mod( jj, 1 ) == 0 % orig mod was to 100
fprintf( 'Sample No: %d\n', jj )
end

i_start = jj; i_stop = i_start + n_win_sz - 1
i_stop = min( [ n i_stop ] )
inds = i_start:i_stop

if std( data_in(:,inds)) > 1e-20
[ tmp_out, ref_out, nn_out ] = robustCAR_helper( data_in(:,inds), dt, n_min_contributing_channels );

try
data_out(:,jj) = tmp_out(1,:)';
ref_est(jj) = ref_out(1);
nn_ref_est(jj) = nn_out(1);
catch me
me.message
dbstack
keyboard
end

else
data_out(:,jj) = 0; ref_est(jj) = mean(data_in(:,jj)); nn_ref_est(jj) = size( data_in, 1 );
end
end % for jj
matlabpool close
fprintf( '\n\nrobustCAR4_winsz_1b: Exiting for jj = 1 : n ...\n\n' )
toc
data_out = data_out';
end
else
data_out(:,jj) = 0; ref_est(jj) = mean(data_in(:,jj)); nn_ref_est(jj) = size( data_in, 1 );
end
end % for jj

%% end of the parfor loop!

%delete(gcp('nocreate')) %matlabpool close
fprintf( '\n\nrobustCAR4_winsz: Exiting for jj = 1 : n ...\n\n' )
toc
data_out = data_out';
end
end

3 changes: 2 additions & 1 deletion robustCAR_helper.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@

try
n_candidates = length( candidate_deltas );
new_mus = mu + make_col( candidate_deltas )';
%new_mus = mu + make_col( candidate_deltas )';
new_mus = mu + candidate_deltas';
x = ( d*ones(1,n_candidates) - ones(size(d,1),1)*new_mus ) ./ ( scales * ones(1,n_candidates));
newe_s = sum( bisquarePsiFunction( x,c ));
[ tmp i_mu ] = min( abs( newe_s ));
Expand Down

0 comments on commit 2f7f28c

Please sign in to comment.