Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mast malleable contour #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions Functions/Call Classification/UnsupervisedClustering_Callback.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ function UnsupervisedClustering_Callback(hObject, eventdata, handles)
case 'K-means (recommended)'
[ClusteringData, ~, ~, ~, spectrogramOptions] = CreateClusteringData(handles, 'forClustering', true, 'save_data', true);
if isempty(ClusteringData); return; end
clusterParameters= inputdlg({'Shape weight','Frequency weight','Duration weight'},'Choose cluster parameters:',1,{'3','2','1'});
clusterParameters= inputdlg({'Number of Contour Pts','Shape weight','Frequency weight','Duration weight'},'Choose cluster parameters:',1,{'12','3','2','1'});
if isempty(clusterParameters); return; end
slope_weight = str2double(clusterParameters{1});
freq_weight = str2double(clusterParameters{2});
duration_weight = str2double(clusterParameters{3});
data = get_kmeans_data(ClusteringData, slope_weight, freq_weight, duration_weight);
num_pts = str2double(clusterParameters{1});
slope_weight = str2double(clusterParameters{2});
freq_weight = str2double(clusterParameters{3});
duration_weight = str2double(clusterParameters{4});
data = get_kmeans_data(ClusteringData, num_pts, slope_weight, freq_weight, duration_weight);
case 'Variational Autoencoder'
[encoderNet, decoderNet, options, ClusteringData] = create_VAE_model(handles);
data = extract_VAE_embeddings(encoderNet, options, ClusteringData);
Expand All @@ -45,10 +46,15 @@ function UnsupervisedClustering_Callback(hObject, eventdata, handles)
switch choice
case 'K-means (recommended)'
spectrogramOptions = [];
load(fullfile(PathName,FileName),'C','freq_weight','slope_weight','duration_weight','clusterName','spectrogramOptions');
load(fullfile(PathName,FileName),'C','num_pts','freq_weight','slope_weight','duration_weight','clusterName','spectrogramOptions');
ClusteringData = CreateClusteringData(handles, 'forClustering', true, 'spectrogramOptions', spectrogramOptions, 'save_data', true);
if isempty(ClusteringData); return; end
data = get_kmeans_data(ClusteringData, slope_weight, freq_weight, duration_weight)
% Set number of contour pts to default 12 if it
% didn't load as a variable
if exist('num_pts','var') ~= 1
num_pts = 12;
end
data = get_kmeans_data(ClusteringData, num_pts, slope_weight, freq_weight, duration_weight);
case 'Variational Autoencoder'
C = [];
load(fullfile(PathName,FileName),'C','encoderNet','decoderNet','options');
Expand Down Expand Up @@ -164,7 +170,7 @@ function UnsupervisedClustering_Callback(hObject, eventdata, handles)
case 'K-means (recommended)'
[FileName, PathName] = uiputfile(fullfile(handles.data.squeakfolder, 'Clustering Models', 'K-Means Model.mat'), 'Save clustering model');
if ~isnumeric(FileName)
save(fullfile(PathName, FileName), 'C', 'freq_weight', 'slope_weight', 'duration_weight', 'clusterName', 'spectrogramOptions');
save(fullfile(PathName, FileName), 'C', 'num_pts','freq_weight', 'slope_weight', 'duration_weight', 'clusterName', 'spectrogramOptions');
end
case 'ARTwarp'
[FileName, PathName] = uiputfile(fullfile(handles.data.squeakfolder, 'Clustering Models', 'ARTwarp Model.mat'), 'Save clustering model');
Expand Down Expand Up @@ -198,14 +204,14 @@ function UnsupervisedClustering_Callback(hObject, eventdata, handles)
end
end

function data = get_kmeans_data(ClusteringData, slope_weight, freq_weight, duration_weight)
function data = get_kmeans_data(ClusteringData, num_pts, slope_weight, freq_weight, duration_weight)
% Parameterize the data for kmeans
ReshapedX = cell2mat(cellfun(@(x) imresize(x',[1 13]) ,ClusteringData.xFreq,'UniformOutput',0));
ReshapedX = cell2mat(cellfun(@(x) imresize(x',[1 num_pts+1]) ,ClusteringData.xFreq,'UniformOutput',0));
slope = diff(ReshapedX,1,2);
slope = zscore(slope);
freq = cell2mat(cellfun(@(x) imresize(x',[1 12]) ,ClusteringData.xFreq,'UniformOutput',0));
freq = cell2mat(cellfun(@(x) imresize(x',[1 num_pts]) ,ClusteringData.xFreq,'UniformOutput',0));
freq = zscore(freq);
duration = repmat(ClusteringData.Duration,[1 12]);
duration = repmat(ClusteringData.Duration,[1 num_pts]);
duration = zscore(duration);
data = [
freq .* freq_weight+.001,...
Expand Down