From 9a09c44ccfc0927fe172de2c87df9281c3c51206 Mon Sep 17 00:00:00 2001 From: julianarhee Date: Fri, 10 Jun 2016 20:40:19 -0400 Subject: [PATCH] scratch MDS all! re-calculate morph samples to take for V1 feature neighbor-correlation sampling --- matlab/MDSfromDistMatrix_morphs.m~ | 191 ------------------ .../load_correlation_get_samples_neighbor.m | 137 +++++++++++++ matlab/sample_V1_features_pcorr_neighbor.m | 124 ++++++------ 3 files changed, 200 insertions(+), 252 deletions(-) delete mode 100644 matlab/MDSfromDistMatrix_morphs.m~ create mode 100644 matlab/load_correlation_get_samples_neighbor.m diff --git a/matlab/MDSfromDistMatrix_morphs.m~ b/matlab/MDSfromDistMatrix_morphs.m~ deleted file mode 100644 index 4c84f08..0000000 --- a/matlab/MDSfromDistMatrix_morphs.m~ +++ /dev/null @@ -1,191 +0,0 @@ -clear all -close all - -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20/pov20_gray_resize/'; - -% input = 'pixel'; -% input = 'V1features'; - -% corrType='correlation'; -corrTypes={'correlation', 'euclidean'}; -inputs = {'pixel', 'V1features'}; - - -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/'; -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/'; - -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/'; -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/'; -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project2/'; -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl_neighbor/'; -% source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl_fixedref/'; - -source_roots = {'/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project2/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_neighbor/',... - '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_fixedref/'}; %,... -% '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/morph2000_pcorr_fixedref/',... -% '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/morph2000_euclid_fixedref/'}; - -for CORR=1:length(corrTypes) - corrType = corrTypes{CORR} - -for input_idx=1:length(inputs) - input = inputs{input_idx} - - for root=1:length(source_roots) - source_root = source_roots{root} - - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/'; - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/'; - - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/'; - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/'; - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project2/'; - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl_neighbor/'; - % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_correl_fixedref/'; - - parts = strsplit(source_root,'/'); - stimset = parts{end-1} - - out_root=fullfile(parts{1:end-2}); - out_root = ['/', out_root,'/'] - - if ~isdir(out_root) - mkdir(out_root) - sprintf('Created output dir: %s', out_root) - end - - % Get the stimuli for comp matrix: - base_root = ['/', fullfile(parts{1:end-2}), '/']; - - % % input = 'pixel'; - % input = 'V1features'; - - iminfo = dir([source_root,'*.png']); % FIX FOR V@1 faeturemat - - imnames = cell(1, length(iminfo)); - for i=1:length(iminfo) - imnames{i} = iminfo(i).name; - end - imnames = sort_nat(imnames); - -% corrType='correlation'; - % corrType='euclidean'; - %corrType='Spearman'; - % load([out_rootoot,corrType,'Corr_V1features_distMatrix']) - - - % load .mat for V1 feature vector - if strfind(input, 'V1features') - main_mfile = dir([base_root,'*.mat']); - for i=1:length(main_mfile) - main_mfile_name = main_mfile(i).name; - if strfind(corrType, 'correlation') - if strfind(main_mfile_name, '_pcorr_neighbor') - load([base_root, main_mfile_name]) - end - elseif strfind(corrType, 'euclidean') - if strfind(main_mfile_name, '_pcorr_neighbor') - load([base_root, main_mfile_name]) - end - end - - end - - feat_root = '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize/'; - F = []; - for idx=1:length(sample_idxs) - curr_feat = load([feat_root, sprintf('V1_features_morph%i.mat', idx)]); - F = [F; curr_feat.featureVector]; - % F = [F curr_feat.featureVector']; doesn't work.. too big - end - nsamples = length(sample_idxs); - - else - - F = []; - for i=1:length(imnames) - curr_im = double(imread([source_root, imnames{i}])); - F = [F reshape(curr_im, numel(curr_im), 1)]; - end - nsamples = length(imnames); - - end - - % if strfind(corrType, 'Pearson') - % dist_mat = corr(F); - % else - sprintf('Using distance metric: %s', corrType) - dist_mat = pdist(F, corrType); - % end - - dist_mat=squareform(dist_mat); - - %get rid of float-point artifacts that make matrix unsymmetric - dist_mat=round(dist_mat*10000)/10000; - - % opts = statset('Display','iter', 'MaxIter', 1500); - opts = statset('MaxIter', 10000); - - [distMatrixMap,distMatrixStress]=mdscale(dist_mat,2, 'Options', opts); - - - %plot w/ color scatter plot - colorList={'r','b'}; - sz=10; - hF=figure; - hold all - - subplot(1,2,1) - scatter(distMatrixMap(1:nsamples,1),distMatrixMap(1:nsamples,2),sz,colorList{1},'o') - - % scatter(distMatrixMap(nsamples+1:end,1),distMatrixMap(nsamples+1:end,2),sz,colorList{2},'o') - - % saveas(hF,[out_root,corrType,sprintf('Corr_%s_MDS_%s_scatter.png', input, stimset)]) - - %plot w/ images - % imSourceRoot='/home/cesar/Documents/Stimuli/static/trainingObjects/Blobs_HorizontalAzimuthRotation/'; - % im_source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20_gray_resize/'; - im_source_root = source_root; - - sz=.015; - hF=figure; - hold all - subplot(1,2,2, hF) - for i=1:length(imnames) - imName=[im_source_root,imnames{i}]; - im0=double(imread(imName)); - centerX=distMatrixMap(i,1); - centerY=distMatrixMap(i,2); - X1=centerX-(sz/2)*2; - X2=centerX+(sz/2)*2; - Y1=centerY-(sz/2); - Y2=centerY+(sz/2); - image([X2, X1],[Y2, Y1],(im0/255)*64) - end - % axis([-.4 .4 -.4 .4]) - % - % for i=1:length(fnames) - % imName=[im_source_root,fnames{i}]; - % im0=double(imread(imName)); - % centerX=distMatrixMap(length(fnames)+i,1); - % centerY=distMatrixMap(length(fnames)+i,2); - % X1=centerX-(sz/2)*2; - % X2=centerX+(sz/2)*2; - % Y1=centerY-(sz/2); - % Y2=centerY+(sz/2); - % image([X2, X1],[Y2, Y1],(im0/255)*64) - % end - colormap('gray') - title('MDS map') - - saveas(hF,[out_root,corrType,sprintf('Corr_%s_MDS_%s.png', input, stimset)]) - - end -end -end - diff --git a/matlab/load_correlation_get_samples_neighbor.m b/matlab/load_correlation_get_samples_neighbor.m new file mode 100644 index 0000000..bc1eb10 --- /dev/null +++ b/matlab/load_correlation_get_samples_neighbor.m @@ -0,0 +1,137 @@ + +%% LOAD correlation vector mat: +clear all +clc + +[~, user_name] = system('whoami'); + +if strfind(user_name, 'rhee') % ON DIXIE + source_roots = {'/nas/volume1/behavior/stimuli/pnas_morphs/pov20/pov20_gray_resize/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project2/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_neighbor/',... + '/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_fixedref/'}; %,... + alt_base_root = '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/'; + +% '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/morph2000_pcorr_fixedref/',... +% '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/morph2000_euclid_fixedref/'}; +else + source_roots = {'/media/nas/volume1/behavior/stimuli/pnas_morphs/pov20/pov20_gray_resize/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_fixedref/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_euclid_neighbor/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_project2/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_neighbor/',... + '/media/nas/volume1/behavior/stimuli/pnas_morphs/pixels/samples/test_pcorr_fixedref/'}; + alt_base_root = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/'; +end + +source_root = source_roots{3} + +out_root='/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/'; +% out_root='/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_euclid_neighbor/'; + +im_root='/nas/volume1/behavior/stimuli/pnas_morphs/morph2000/morph2000_gray_resize/'; + +base_dir = '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/'; + + +corrType = 'correlation'; +input = 'V1features'; + +parts = strsplit(source_root,'/'); +stimset = parts{end-1} + +base_root = ['/', fullfile(parts{1:end-2}), '/']; + +if strfind(stimset, 'pov20') + nstims = 22; +else + nstims = 2002; +end + +%% +mfiles = dir([base_root,'*.mat']); + +matnames = cell(1, length(mfiles)); +for i=1:length(mfiles) + if strfind(mfiles(i).name, sprintf('neighbor_%i', nstims)) + matnames{i} = mfiles(i).name; + end +end +matnames = matnames(~cellfun('isempty', matnames)) + +% +for f=1:length(matnames) + f + curr_mfile = matnames{f} + load([base_root, curr_mfile]); + + + +% end + + % Get linearly-spaced samples + + nmorphs = 20; + if strfind(stimset, 'euclid') + cumsum_total = cumsum(distance_vect); + else + cumsum_total = cumsum(corr_vect); + end + start_point = cumsum_total(1); + end_point = cumsum_total(end); + lin_samples = linspace(start_point, end_point, nmorphs+2); + + sample_idxs = []; + for i=1:length(lin_samples) + [c index] = min(abs(cumsum_total-lin_samples(i))); + sample_idxs = [sample_idxs; index]; + end + + % x = cumsum_total(sample_idxs); + % plot(x) + + im_info = dir([im_root,'*.png']); + im_names = cell(1, length(im_info)); + for i=1:length(im_info) + im_names{i} = im_info(i).name; + end + im_names = sort_nat(im_names); + % + + % if strfind(stimset, 'pov20') + % sample_idxs = linspace(1, nmorphs+2, nmorphs+2); + % + % end + + + % Save selected samples: + for idx=1:length(sample_idxs) + curr_sample_idx = sample_idxs(idx); + + if idx == 1 + curr_sample = im_names(curr_sample_idx) + else + curr_sample = im_names(curr_sample_idx+1) + + end + src = strcat(im_root, curr_sample); + src = src{1}; + dest = strcat(out_root, curr_sample)%sprintf('morph%i.png', i)); + dest = dest{1} + copyfile(src, dest); + end + + + % Crap sampling due to nonlinear distances? Generally seems okay for neighbor comparisons (both euclid and pcorr) + % only seems to be a problem for fixed-ref... + + save([base_dir,curr_mfile], ... + 'cumsum_total', 'sample_idxs', '-append') + +end \ No newline at end of file diff --git a/matlab/sample_V1_features_pcorr_neighbor.m b/matlab/sample_V1_features_pcorr_neighbor.m index 5e9402e..f24ddda 100644 --- a/matlab/sample_V1_features_pcorr_neighbor.m +++ b/matlab/sample_V1_features_pcorr_neighbor.m @@ -1,13 +1,15 @@ clear all close all +addpath(genpath('/helpers')) +addpath(genpath('./hmaxMatlab')) -source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize/'; -out_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/'; +source_root='/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/morph2000_gray_resize/'; +out_root='/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/morph2000_pcorr_neighbor/'; -im_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/morph2000/morph2000_gray_resize/'; +im_root='/nas/volume1/behavior/stimuli/pnas_morphs/morph2000/morph2000_gray_resize/'; -base_dir = '/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/'; +base_dir = '/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/samples/'; % % source_root='/media/nas/volume1/behavior/stimuli/pnas_morphs/V1_features/pov20/'; % .mat files @@ -21,10 +23,10 @@ stimset = parts{end-1}; -if ~isdir(out_root) - mkdir(out_root) - sprintf('Created output dir: %s', out_root) -end +% if ~isdir(out_root) +% mkdir(out_root) +% sprintf('Created output dir: %s', out_root) +% end finfo = dir([source_root,'*.mat']); fnames = cell(1, length(finfo)); @@ -114,57 +116,57 @@ % copyfile(src, dest); % end -%% -nmorphs = 20; -cumsum_total = cumsum(corr_vect); -start_point = cumsum_total(1); -end_point = cumsum_total(end); -lin_samples = linspace(start_point, end_point, nmorphs+2); - -sample_idxs = []; -for i=1:length(lin_samples) - [c index] = min(abs(cumsum_total-lin_samples(i))) - sample_idxs = [sample_idxs; index]; -end - -% x = cumsum_total(sample_idxs); -% plot(x) - -im_info = dir([im_root,'*.png']); -im_names = cell(1, length(im_info)); -for i=1:length(im_info) - im_names{i} = im_info(i).name; -end -im_names = sort_nat(im_names); +% %% +% nmorphs = 20; +% cumsum_total = cumsum(corr_vect); +% start_point = cumsum_total(1); +% end_point = cumsum_total(end); +% lin_samples = linspace(start_point, end_point, nmorphs+2); % - -if strfind(stimset, 'pov20') - sample_idxs = linspace(1, nmorphs+2, nmorphs+2); -else - sample_idxs(1) = 0; - sample_idxs(end) = length(fnames); - -end - - -% Save selected samples: -for i=1:length(sample_idxs) - curr_sample_idx = sample_idxs(i); - - if i == 1 - curr_sample = im_names(curr_sample_idx) - else - curr_sample = im_names(curr_sample_idx+1) - end - src = strcat(im_root, curr_sample); - src = src{1}; - dest = strcat(out_root, curr_sample); - dest = dest{1} - copyfile(src, dest); -end - -%% Crap sampling due to nonlinear distances? Generally seems okay for neighbor comparisons (both euclid and pcorr) -% only seems to be a problem for fixed-ref... - -save([base_dir,sprintf('V1features_pcorr_neighbor_%s.mat', num2str(length(corr_vect)))], ... - 'cumsum_total', 'sample_idxs', '-append') +% sample_idxs = []; +% for i=1:length(lin_samples) +% [c index] = min(abs(cumsum_total-lin_samples(i))) +% sample_idxs = [sample_idxs; index]; +% end +% +% % x = cumsum_total(sample_idxs); +% % plot(x) +% +% im_info = dir([im_root,'*.png']); +% im_names = cell(1, length(im_info)); +% for i=1:length(im_info) +% im_names{i} = im_info(i).name; +% end +% im_names = sort_nat(im_names); +% % +% +% if strfind(stimset, 'pov20') +% sample_idxs = linspace(1, nmorphs+2, nmorphs+2); +% else +% sample_idxs(1) = 0; +% sample_idxs(end) = length(fnames); +% +% end +% +% +% % Save selected samples: +% for i=1:length(sample_idxs) +% curr_sample_idx = sample_idxs(i); +% +% if i == 1 +% curr_sample = im_names(curr_sample_idx) +% else +% curr_sample = im_names(curr_sample_idx+1) +% end +% src = strcat(im_root, curr_sample); +% src = src{1}; +% dest = strcat(out_root, sprintf('morph%i.png', i)); +% dest = dest{1} +% copyfile(src, dest); +% end +% +% %% Crap sampling due to nonlinear distances? Generally seems okay for neighbor comparisons (both euclid and pcorr) +% % only seems to be a problem for fixed-ref... +% +% save([base_dir,sprintf('V1features_pcorr_neighbor_%s.mat', num2str(length(corr_vect)))], ... +% 'cumsum_total', 'sample_idxs', '-append')