From 78ee041ac208b22950ad2e51d9378a3782a34982 Mon Sep 17 00:00:00 2001
From: gcalongi <87454626+gcalongi@users.noreply.github.com>
Date: Tue, 31 Aug 2021 15:18:39 -0700
Subject: [PATCH 1/2] AddNumPts

Add num_pts as a variable to allow the user to choose the number of contour pts to apply
---
 .../UnsupervisedClustering_Callback.m         | 28 +++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/Functions/Call Classification/UnsupervisedClustering_Callback.m b/Functions/Call Classification/UnsupervisedClustering_Callback.m
index 4d6235d3..38686705 100644
--- a/Functions/Call Classification/UnsupervisedClustering_Callback.m	
+++ b/Functions/Call Classification/UnsupervisedClustering_Callback.m	
@@ -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);
@@ -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');
@@ -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,...

From 138b1493a6e98756f4cab918549af3df74e645ec Mon Sep 17 00:00:00 2001
From: gcalongi <87454626+gcalongi@users.noreply.github.com>
Date: Fri, 3 Sep 2021 16:34:10 -0700
Subject: [PATCH 2/2] Fix Dim Issue

Fix a dimensional issue that was causing a hang up in the iter loop in Calculate Stats
---
 Functions/Call Classification/UnsupervisedClustering_Callback.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Functions/Call Classification/UnsupervisedClustering_Callback.m b/Functions/Call Classification/UnsupervisedClustering_Callback.m
index 38686705..340ca538 100644
--- a/Functions/Call Classification/UnsupervisedClustering_Callback.m	
+++ b/Functions/Call Classification/UnsupervisedClustering_Callback.m	
@@ -170,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');