-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: Added option to disable special treatment of JAABA PFFs when n=…
…=2. Refactored feat_augment.m to ease precomputing of PFF names.
- Loading branch information
1 parent
4d21963
commit f9e2181
Showing
9 changed files
with
118 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function learn_data = feat_augment_data(data, names) | ||
[logfeat, normfeat] = feat_augment_log_and_norm() ; | ||
epsi = 0.001; | ||
% use floowing wavelets to take 1st and 2nd derivatives of features | ||
wavelets = [0 0.5 -0.5 0 0; % tight 1st deriv gauss | ||
0 0.25 -0.5 0.25 0]; % tight 2nd deriv gauss | ||
n_flies = size(data,1); | ||
n_frames = size(data,2); | ||
n_feats = size(data,3); | ||
learn_data = zeros(n_flies,n_frames,n_feats*3); | ||
% augment each feature for all flies | ||
for s=1:n_flies | ||
for i=1:n_feats | ||
% median normalize certain features | ||
if ismember(names{i},normfeat) | ||
denom = nanmedian(data(s,:,i)); | ||
if denom ~= 0 && ~isnan(denom) | ||
data(s,:,i) = data(s,:,i)/denom; | ||
end | ||
end | ||
% take the log of certain features | ||
if ismember(names{i},logfeat) | ||
if strcmp(names{i},'ang_vel') | ||
data(s,:,i) = log10(data(s,:,i)+epsi*0.001); | ||
else | ||
data(s,:,i) = log10(data(s,:,i)+epsi); | ||
end | ||
end | ||
learn_data(s,:,i) = data(s,:,i); | ||
% apply wavelets to each feature vector | ||
idx = n_feats + (i-1)*2; | ||
responses = conv(learn_data(s,:,i),wavelets(1,:),'valid'); | ||
buff_left = floor((n_frames-numel(responses))/2); | ||
buff_right = ceil((n_frames-numel(responses))/2); | ||
learn_data(s,1:buff_left,idx+1) = responses(1); | ||
learn_data(s,buff_left+1:end-buff_right,idx+1) = responses; | ||
learn_data(s,end-buff_right+1:end,idx+1) = responses(end); | ||
responses = conv(learn_data(s,:,i),wavelets(2,:),'valid'); | ||
buff_left = floor((n_frames-numel(responses))/2); | ||
buff_right = ceil((n_frames-numel(responses))/2); | ||
learn_data(s,1:buff_left,idx+2) = responses(1); | ||
learn_data(s,buff_left+1:end-buff_right,idx+2) = responses; | ||
learn_data(s,end-buff_right+1:end,idx+2) = responses(end); | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function [logfeat, normfeat] = feat_augment_log_and_norm() | ||
% take log of the following features | ||
logfeat = {'vel','ang_vel','min_wing_ang','max_wing_ang','fg_body_ratio'}; | ||
% normalize the following features | ||
normfeat = {'mean_wing_length','axis_ratio','contrast'}; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function aug_names = feat_augment_names(names) | ||
[logfeat, normfeat] = feat_augment_log_and_norm() ; | ||
% update names to match their augmentation | ||
simple_aug_names = cell(1,0) ; | ||
diff_aug_names = cell(1,0) ; | ||
for i=1:numel(names) | ||
name = names{i} ; | ||
if ismember(names{i},normfeat) | ||
aug_name = ['norm_' name]; | ||
elseif ismember(names{i},logfeat) | ||
aug_name = ['log_' name]; | ||
else | ||
aug_name = names{i} ; | ||
end | ||
simple_aug_names{1,i} = aug_name ; | ||
diff_aug_names{1,end+1} = [aug_name '_diff1']; %#ok<AGROW> | ||
diff_aug_names{1,end+1} = [aug_name '_diff2']; %#ok<AGROW> | ||
end | ||
aug_names = horzcat(simple_aug_names, diff_aug_names) ; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function [personal_feat, enviro_feat, relative_feat, personal_units, enviro_units, relative_units] = feat_names_and_units() | ||
% names of features to be computed | ||
personal_feat = {'vel','ang_vel','min_wing_ang','max_wing_ang',... | ||
'mean_wing_length','axis_ratio','fg_body_ratio','contrast'}; | ||
enviro_feat = {'dist_to_wall'}; | ||
relative_feat = {'dist_to_other','angle_between','facing_angle','leg_dist'}; | ||
% units of features to be computed | ||
personal_units = {'mm/s','rad/s','rad','rad','mm','ratio','ratio',''}; | ||
enviro_units = {'mm'}; | ||
relative_units = {'mm','rad','rad','mm'}; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function [personal_feat, enviro_feat, relative_feat, personal_units, enviro_units, relative_units] = flytracker_jaaba_features_and_units() | ||
% names of features to be computed | ||
personal_feat = {'vel','ang_vel','min_wing_ang','max_wing_ang',... | ||
'mean_wing_length','axis_ratio','fg_body_ratio','contrast'}; | ||
enviro_feat = {'dist_to_wall'}; | ||
relative_feat = {'dist_to_other','angle_between','facing_angle','leg_dist'}; | ||
% units of features to be computed | ||
personal_units = {'mm/s','rad/s','rad','rad','mm','ratio','ratio',''}; | ||
enviro_units = {'mm'}; | ||
relative_units = {'mm','rad','rad','mm'}; | ||
end |