% This is a Wrapper Script for performing Cluster Analysis 
% [function "Clustering_V2_*"]  of the data resulting after
% performing Transformation to Equivalent Dimensions [by 
% using "ED_ToolBox_Wrapper" script]. Some comments for 
% Cluster Analysis are within 'Clustering_V2_*' code. Here
% the input data & parameters (functions arguments) are
% defined by the User. Please modify the script accordingly.
% The lines that can be modified are followed by a comment 
% "- PLEASE SET". 
% PLEASE REFER ALSO TO APPILCATION DOCUMENTATION:
% "READ_ME_App_1B_v2_Description_Cluster_Analysis.docx"

clc;clear;tic

% STEP 1.  DATA Selection. Please Note that the Cluster Analysis concerns data after 
%             Transformation to Equivalent Dimensions, therefore the Output *.mat file 
%             obtained from "ED_ToolBox_Wrapper" script Application must be used as 
%             input data for this Application: 
 cd Transformed_Data                                            % - PLEASE SET - specify the path to Data Directory
 load ST2_Tdata.mat                                               % - PLEASE SET - specify the input data filename (MATLAB forrmat: Output of T2ED Application)
 cd ../
 % Choose vector(s) from the Transformed Data Structure 
vectors=[4,7,23];                                                    % - PLEASE SET - specify columns (parameters) to be analyzed

% STEP 2.  Define the Number of Clusters: 
N=4;                                                                     % - PLEASE SET - specify number of clusters to be formed

% STEP 3.  Select Clustering Algorith: 
Meth='Hierarchical';                                                 % - PLEASE SET , Select from ['Partitioning', 'Hierarchical', 'Fuzzy']
  
% STEP 4.  Select Method for Cluster Tree (only applicable for Meth=='Hierarchical']: 
CTmeth='average';                                                  % - PLEASE SET, Select from ['average’,‘centroid’,‘complete’,’median’,‘single’,‘ward’,‘weighted’]

% STEP 5 Number of leaf nodes
% only for FOR PLOTTING WARD DIAGRAM - 'Hierarchical' 
Lnodes=87;                                                            % - PLEASE SET

% STEP 6 Run Function "Clustering"
[a,Cluster,ClusterColumns,L]=Clustering_V2_8(vectors,N,Meth,CTmeth,Tdata);

% STEP 7 Plotting Results (2D and 3D cases)           % PLEASE Comment the next line to disable visualization
plotClustering

% STEP 8 Store Outputs

cd Outputs_Clustering\
save('Cluster.mat','Cluster')
save('ClusterColumns.mat','ClusterColumns')
cd ../
toc


