Agglomerate hierarchical clustering is a widely used clustering method that groups data into a hierarchy or binary tree of subgroups. It merges clusters in a bottom-up strategy based on a dissimilarity measure. This method does not require the number of clusters to be specified and can be used for data summarization and visualization. The algorithm supports different metrics and linkage criteria. If the input data has category attributes, the Gower Distance can be used to calculate the distance matrix. The Gower Distance is calculated differently for continuous and category attributes.
------

SET SCHEMA DM_PAL;

DROP TABLE PAL_HIERARCHICAL_CLUSTERING_DATA_TBL;
CREATE COLUMN TABLE PAL_HIERARCHICAL_CLUSTERING_DATA_TBL ("POINT" NVARCHAR(100), "X1" DOUBLE, "X2" DOUBLE ,  "X3" INTEGER);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('0', 0.5, 0.5, 1);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('1', 1.5, 0.5, 2);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('2', 1.5, 1.5, 2);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('3', 0.5, 1.5, 2);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('4', 1.1, 1.2, 2);
INSERT INTO PAL_HIERARCHICAL_CLUSTERING_DATA_TBL VALUES ('5', 0.5, 15.5, 2);

DROP TABLE #PAL_PARAMETER_TBL;
CREATE LOCAL TEMPORARY COLUMN TABLE #PAL_PARAMETER_TBL ("PARAM_NAME" VARCHAR(256), "INT_VALUE" INTEGER, "DOUBLE_VALUE" DOUBLE, "STRING_VALUE" VARCHAR(1000));
INSERT INTO #PAL_PARAMETER_TBL VALUES ('THREAD_RATIO', NULL, 0.5, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('CLUSTER_NUM', 4, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('CLUSTER_METHOD', 4, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('DISTANCE_FUNC', 10, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('DISTANCE_DIMENSION', NULL, 3, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('NORMALIZE_TYPE', 0, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('CATEGORICAL_VARIABLE', NULL, NULL, 'X3');
INSERT INTO #PAL_PARAMETER_TBL VALUES ('CATEGORY_WEIGHTS', NULL, 0.1, NULL);

CALL _SYS_AFL.PAL_HIERARCHICAL_CLUSTERING (PAL_HIERARCHICAL_CLUSTERING_DATA_TBL, #PAL_PARAMETER_TBL, ?, ?);

