HCStoppingCriterion: HCStoppingCriterionType;
The HCStoppingCriterion property determines stopping criterion.
To determine threshold value of distance between clusters, use the ISmHierarchicalClusterAnalysis.ThresholdClusterDistance property.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
hc: SmHierarchicalClusterAnalysis;
Dist: ISlDistance;
Cls: IClustersType;
Obj: ISlSeries;
ClustCompOrd: IClustersCompositionOrderItem;
masDouble, std: Array Of Double;
masInteger: Array Of Integer;
x1: Array[2] Of Double;
res, i, j: Integer;
Begin
hc := New SmHierarchicalClusterAnalysis.Create;
//list of values
Obj := hc.Objects;
Obj.Clear;
//adding values
x1[0] := 27; x1[1] := 19;
Obj.Add.Value := x1;
x1[0] := Double.Nan; x1[1] := 46;
Obj.Add.Value := x1;
x1[0] := 25; x1[1] := 15;
Obj.Add.Value := x1;
x1[0] := 36; x1[1] := 27;
Obj.Add.Value := x1;
//number of clusters, to which the set of objects is to be divided
hc.ClusterCount := 2;
//method of calculating distance between clusters
hc.ClusterLink := ClusterLinkType.Centroid;
//parameters of calculating distance between objects
Dist := hc.Distance;
//method of calculating distance between objects
hc.Distance.Type := ObjectDistanceType.EuclideanSqr;
//method of attributes standardization
hc.Distance.Standartization := StandartizationType.ScaleStd; // using standard deviation
std := New Double[hc.Objects.Count];
For i := 0 To std.Length - 1 Do
std[i] := 1 + i / 2;
End For;
//standardization coefficients
hc.Distance.StandartizationCoefficients := std;
//criterion of stopping
hc.HCStoppingCriterion := HCStoppingCriterionType.NumberOfClusters;
//ThresholdDistance
//threshold value of distance between clusters
hc.ThresholdClusterDistance := 0.00;
//creating a dendrogram
hc.CreateDendrogram := True;
//dendrogram orientation
hc.DendrogramOrientation := DendrogramOrientationType.East;
// Method of missing data treatment
hc.MissingData.Method := MissingDataMethod.Casewise;
res := hc.Execute;
Debug.WriteLine(hc.Errors);
Debug.WriteLine("=== Membership ===");
Debug.WriteLine("Object-Cluster");
//membership in clusters
masDouble := hc.Membership.Value;
For i := 0 To masDouble.Length - 1 Do
Debug.WriteLine(i.ToString + " - " + masDouble[i].ToString);
End For;
Debug.WriteLine("");
Debug.WriteLine("=== Distances ===");
//order of cluster composition
For i := 0 To hc.ClustersCompositionOrder.Count - 1 Do
ClustCompOrd := hc.ClustersCompositionOrder.Item(i);
Debug.WriteLine(i.ToString + " - " + ClustCompOrd.ClusterDistance.ToString);
End For;
Debug.WriteLine("");
Debug.WriteLine("=== Cluster centers ===");
//order of clusters
Cls := hc.Clusters;
For i := 0 To Cls.Count - 1 Do //by clusters
Debug.WriteLine("Cluster #" + (i + 1).ToString + " ");
masDouble := Cls.Item(i).Center;
For j := 0 To masDouble.Length - 1 Do //by all characteristics in cluster
Debug.WriteLine(masDouble[j].ToString);
End For;
End For;
Debug.WriteLine("");
Debug.WriteLine("=== Lists of objects ===");
For i := 0 To hc.Clusters.Count - 1 Do //by clusters
Debug.WriteLine("Cluster #" + i.ToString);
masInteger := hc.Clusters.Item(i).ObjectsList;
For j := 0 To hc.Clusters.Item(i).Size - 1 Do //by all objects in cluster
Debug.WriteLine(masInteger[j].ToString);
End For;
End For;
End Sub UserProc;
As a result of the example execution, the following settings are defined:
Method of calculating distance between clusters.
Number of clusters, to which the set of objects is to be divided.
Method of calculating distance between objects.
Method of attributes standardization.
Criterion of stopping.
Threshold value of distance between clusters.
Settings of coefficients standardization.
Dendrogram settings.
The console window shows the lists of objects belonging to clusters, order of clusters, order of cluster composition.
See also: