ISmKmeansClusterAnalysis.FuzzyMembership

Syntax

FuzzyMembership: Array;

Description

The FuzzyMembership property determines probabilistic matrix of object membership to each cluster.

Comments

To get the output result of whether objects belong to clusters, use the ISmKmeansClusterAnalysis.Membership property.

Example

To execute the example, add a link to the Stat system assembly.

Sub UserProc;
Var
    KCA: SmKmeansClusterAnalysis;
    Obj: ISlSeries;
    x1: Array[5Of 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(1Do
            str := "";
            For j := 0 To KCA.FuzzyMembership.GetUpperBound(2Do
                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:

See also:

ISmKmeansClusterAnalysis