Affinity Propagation (AP) is a clustering algorithm that identifies exemplars among data points and forms clusters around these exemplars. It does this by considering all data points as potential exemplars and exchanging messages between them until a good set of exemplars and clusters is found. One advantage of AP is that the number of clusters does not need to be predetermined.
------

SET SCHEMA DM_PAL;

DROP TABLE PAL_AP_DATA_TBL;
CREATE COLUMN TABLE PAL_AP_DATA_TBL(
	ID INTEGER, 
	ATTRIB1 DOUBLE,
	ATTRIB2 DOUBLE
);
INSERT INTO PAL_AP_DATA_TBL VALUES(1, 0.10, 0.10);
INSERT INTO PAL_AP_DATA_TBL VALUES(2, 0.11, 0.10);
INSERT INTO PAL_AP_DATA_TBL VALUES(3, 0.10, 0.11);
INSERT INTO PAL_AP_DATA_TBL VALUES(4, 0.11, 0.11);
INSERT INTO PAL_AP_DATA_TBL VALUES(5, 0.12, 0.11);

DROP TABLE PAL_AP_SEED_TBL;
CREATE COLUMN TABLE PAL_AP_SEED_TBL(
	ID INTEGER,
	SEED INTEGER
);

DROP TABLE #PAL_PARAMETER_TBL;
CREATE LOCAL TEMPORARY COLUMN TABLE #PAL_PARAMETER_TBL(
	"PARAM_NAME" NVARCHAR(256),
	"INT_VALUE" INTEGER,
	"DOUBLE_VALUE" DOUBLE,
	"STRING_VALUE" NVARCHAR(1000)
);
INSERT INTO #PAL_PARAMETER_TBL VALUES('THREAD_RATIO', NULL, 0.3, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('MAX_ITERATION', 500, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('CON_ITERATION', 100, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('DAMP', NULL, 0.9, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('PREFERENCE', NULL, 0.5, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('DISTANCE_METHOD', 2, NULL, NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('CLUSTER_NUMBER', 0, NULL, NULL);

CALL _SYS_AFL.PAL_AFFINITY_PROPAGATION(PAL_AP_DATA_TBL, PAL_AP_SEED_TBL, "#PAL_PARAMETER_TBL", ?, ?);

