HCStoppingCriterion: HCStoppingCriterionType;
HCStoppingCriterion: Prognoz.Platform.Interop.Stat.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;
str: String;
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;
//create dendogram
hc.CreateDendogram := True;
//dendrogram orientation
hc.DendogramOrientation := DendogramOrientationType.East;
// Method of missing data treatment
hc.MissingData.Method := MissingDataMethod.LinTrend;
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;
Debug.WriteLine("");
Debug.WriteLine("=== Dendogram ===");
//return dendogram (array of characters)
For j := 0 To hc.Dendogram.GetUpperBound(1) Do
str := "";
For i := 0 To hc.Dendogram.GetUpperBound(2) Do
str := str + hc.Dendogram[j, i];
End For;
Debug.WriteLine(str);
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.
Dendogram settings.
The console window shows the lists of objects, membership of clusters, order of clusters, order of cluster composition and the dendogram.
The requirements and result of executing the Fore.NET Example match those of the Fore Example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
hc: SmHierarchicalClusterAnalysis;
Dist: ISlDistance;
Cls: IClustersType;
Obj: ISlSeries;
ClustCompOrd: IClustersCompositionOrderItem;
std: Array Of Double;
x1: Array[2] Of Double;
res, i, j: Integer;
str: String;
Dendogram, masDouble, masInteger: Array;
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.cltCentroid;
//parameters of calculating distance between objects
Dist := hc.Distance;
//method of calculating distance between objects
hc.Distance.Type := ObjectDistanceType.odEuclideanSqr;
//method of attributes standardization
hc.Distance.Standartization := StandartizationType.stScaleStd; // 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.hcscNumberOfClusters;
//threshold value of distance between clusters
hc.ThresholdClusterDistance := 0.00;
//create dendogram
hc.CreateDendogram := True;
//dendrogram orientation
hc.DendogramOrientation := DendogramOrientationType.doEast;
// Method of missing data treatment
hc.MissingData.Method := MissingDataMethod.mdmLinTrend;
res := hc.Execute();
System.Diagnostics.Debug.WriteLine(hc.Errors);
System.Diagnostics.Debug.WriteLine("=== Membership ===");
System.Diagnostics.Debug.WriteLine("Object-Cluster");
//membership in clusters
masDouble := hc.Membership.Value;
For i := 0 To masDouble.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + " - " + masDouble[i].ToString());
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("=== Distances ===");
//order of cluster composition
For i := 0 To hc.ClustersCompositionOrder.Count - 1 Do
ClustCompOrd := hc.ClustersCompositionOrder.Item[i];
System.Diagnostics.Debug.WriteLine(i.ToString() + " - " + ClustCompOrd.ClusterDistance.ToString());
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("=== Cluster centers ===");
//order of clusters
Cls := hc.Clusters;
For i := 0 To Cls.Count - 1 Do //by clusters
System.Diagnostics.Debug.WriteLine("Cluster #" + (i + 1).ToString() + " ");
masDouble := Cls.Item[i].Center;
For j := 0 To masDouble.Length - 1 Do //by all characteristics in cluster
System.Diagnostics.Debug.WriteLine(masDouble[j].ToString());
End For;
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("=== Lists of objects ===");
For i := 0 To hc.Clusters.Count - 1 Do //by clusters
System.Diagnostics.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
System.Diagnostics.Debug.WriteLine(masInteger[j].ToString());
End For;
End For;
System.Diagnostics.Debug.WriteLine("");
System.Diagnostics.Debug.WriteLine("=== Dendogram ===");
//return dendogram (array of characters)
Dendogram := hc.Dendogram;
For j := 0 To hc.Dendogram.GetUpperBound(0) Do
str := "";
For i := 0 To hc.Dendogram.GetUpperBound(1) Do
str := str + Dendogram[j, i];
End For;
System.Diagnostics.Debug.WriteLine(str);
End For;
End Sub;
See also: