FuzzyMembership: Array;
FuzzyMembership: System.Array;
The FuzzyMembership property determines probabilistic matrix of object membership to each cluster.
To get the output result of whether objects belong to clusters, use the ISmKmeansClusterAnalysis.Membership property.
Add a link to the Stat system assembly.
Sub UserProc;
Var
KCA: SmKmeansClusterAnalysis;
Obj: ISlSeries;
x1: Array[5] Of Double;
masDouble: Array Of Double;
res, i, j: Integer;
str: String;
Begin
KCA := New SmKmeansClusterAnalysis.Create;
// Set objects for consideration
Obj := KCA.Objects;
x1[0]:= 2; x1[1]:= 2; x1[2]:= 2; x1[3]:= 2; x1[4]:= 1;
KCA.Objects.Add.Value:=x1;
x1[0]:= 2; x1[1]:= 4; x1[2]:= 1; x1[3]:= 4; x1[4]:= 3;
KCA.Objects.Add.Value:=x1;
x1[0]:= 2; x1[1]:= 2; x1[2]:= 2; x1[3]:= 5; x1[4]:= 2;
KCA.Objects.Add.Value:=x1;
x1[0]:= 3; x1[1]:= 1; x1[2]:= 0; x1[3]:= 2; x1[4]:= 3;
KCA.Objects.Add.Value:=x1;
x1[0]:= 1; x1[1]:= 4; x1[2]:= 0; x1[3]:= 3; x1[4]:= 4;
KCA.Objects.Add.Value:=x1;
x1[0]:= 3; x1[1]:= 7; x1[2]:= 5; x1[3]:= 6; x1[4]:= 5;
KCA.Objects.Add.Value:=x1;
x1[0]:= 1; x1[1]:= 4; x1[2]:= 0; x1[3]:= 5; x1[4]:= 2;
KCA.Objects.Add.Value:=x1;
x1[0]:= 3; x1[1]:= 2; x1[2]:= 2; x1[3]:= 3; x1[4]:= 2;
KCA.Objects.Add.Value:=x1;
// Set algorithm type
KCA.Modification := KMeansModification.KModes;
//method of calculating distance between points
KCA.KModesDistance := KModesDistanceType.Hamming;
// Set method of selecting optimal number of fuzzy classes
KCA.ClusterCountSelection := ClusterCountSelectionType.VarDisAutoSelection;
// Set minimum and maximum number of clusters
KCA.ClusterCountMin := 2;
KCA.ClusterCountMax := 4;
// Enable fuzzy clustering
KCA.IsFuzzy := True;
// Run calculation and show results
res := KCA.Execute;
If res <> 0 Then
Debug.WriteLine(KCA.Errors);
Else
Debug.WriteLine("=== Objects membership in clusters ===");
Debug.WriteLine("Object - Cluster");
masDouble := KCA.Membership.Value;
For i := 0 To masDouble.Length - 1 Do
Debug.WriteLine(" " + i.ToString + " - " + masDouble[i].ToString)
End For;
Debug.WriteLine("=== Probabilistic membership of objects in classes ===");
For i := 0 To KCA.FuzzyMembership.GetUpperBound(1) Do
str := "";
For j := 0 To KCA.FuzzyMembership.GetUpperBound(2) Do
str := str + " " + (KCA.FuzzyMembership[i, j] As Double).ToString;
End For;
Debug.WriteLine(str);
End For;
End If;
End Sub UserProc;
After executing the example the console window displays the following:
Membership of objects in clusters.
Probabilistic membership of objects in clusters.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
KCA: SmKmeansClusterAnalysis;
Obj: ISlSeries;
x1: Array[5] Of Double;
masDouble, FuzzyMembership: System.Array;
res, i, j: Integer;
str: String;
Begin
KCA := New SmKmeansClusterAnalysis.Create();
// Set objects for consideration
Obj := KCA.Objects;
x1[0]:= 2; x1[1]:= 2; x1[2]:= 2; x1[3]:= 2; x1[4]:= 1;
KCA.Objects.Add().Value:=x1;
x1[0]:= 2; x1[1]:= 4; x1[2]:= 1; x1[3]:= 4; x1[4]:= 3;
KCA.Objects.Add().Value:=x1;
x1[0]:= 2; x1[1]:= 2; x1[2]:= 2; x1[3]:= 5; x1[4]:= 2;
KCA.Objects.Add().Value:=x1;
x1[0]:= 3; x1[1]:= 1; x1[2]:= 0; x1[3]:= 2; x1[4]:= 3;
KCA.Objects.Add().Value:=x1;
x1[0]:= 1; x1[1]:= 4; x1[2]:= 0; x1[3]:= 3; x1[4]:= 4;
KCA.Objects.Add().Value:=x1;
x1[0]:= 3; x1[1]:= 7; x1[2]:= 5; x1[3]:= 6; x1[4]:= 5;
KCA.Objects.Add().Value:=x1;
x1[0]:= 1; x1[1]:= 4; x1[2]:= 0; x1[3]:= 5; x1[4]:= 2;
KCA.Objects.Add().Value:=x1;
x1[0]:= 3; x1[1]:= 2; x1[2]:= 2; x1[3]:= 3; x1[4]:= 2;
KCA.Objects.Add().Value:=x1;
// Set algorithm type
KCA.Modification := KMeansModification.kmmKModes;
//method of calculating distance between points
KCA.KModesDistance := KModesDistanceType.kmdHamming;
// Set method of selecting optimal number of fuzzy classes
KCA.ClusterCountSelection := ClusterCountSelectionType.ccsVarDisAutoSelection;
// Set minimum and maximum number of clusters
KCA.ClusterCountMin := 2;
KCA.ClusterCountMax := 4;
// Enable fuzzy clustering
KCA.IsFuzzy := True;
// Run calculation and show results
res := KCA.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(KCA.Errors);
Else
System.Diagnostics.Debug.WriteLine("=== Objects membership in clusters ===");
System.Diagnostics.Debug.WriteLine("Object Cluster");
masDouble := KCA.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("=== Probabilistic membership of objects in clusters ===");
FuzzyMembership := KCA.FuzzyMembership;
For i := 0 To KCA.FuzzyMembership.GetUpperBound(1) Do
str := "";
For j := 0 To KCA.FuzzyMembership.GetUpperBound(0) Do
str := str + " " + (FuzzyMembership[j, i] As Double).ToString();
End For;
System.Diagnostics.Debug.WriteLine(str);
End For;
End If;
End Sub;
See also: