Private Const MAX_ITEMS As Integer = 11 Private Const MAX_CUSTOMERS As Integer = 14 Private Const TOTAL_PROTOTYPE_VECTORS As Integer = 10 Private Const BETA As Double = 1.0 'Small positive number. Private Const VIGILANCE As Double = 0.6 '0 <= VIGILANCE < 1 Private PrototypeVectors As Integer = 0 'Total populated prototype vectors. Private PrototypeVector(TOTAL_PROTOTYPE_VECTORS, MAX_ITEMS) As Integer 'Number of occupants of cluster. Private Members(TOTAL_PROTOTYPE_VECTORS) As Integer 'Identifies which cluster a member belongs to. Private Membership(MAX_CUSTOMERS) As Integer Private Database As Integer(,) = New Integer(,) {{0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0}, _ {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1}, _ {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}, _ {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1}, _ {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, _ {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, _ {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _ {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}, _ {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}, _ {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}, _ {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _ {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, _ {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _ {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}} Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load InitializeStructures() PerformART1() DisplayCustomerClusters() DisplayMemberships() DisplayCustomerDatabase() End Sub Private Sub InitializeStructures() Dim Kounter1 As Integer Dim Kounter2 As Integer For Kounter1 = 0 To TOTAL_PROTOTYPE_VECTORS - 1 For Kounter2 = 0 To MAX_ITEMS - 1 PrototypeVector(Kounter1, Kounter2) = 0 Next Next For Kounter2 = 0 To MAX_CUSTOMERS - 1 Membership(Kounter2) = -1 Next End Sub Private Sub PerformART1() Dim ANDResult(MAX_ITEMS) As Integer Dim PVec As Integer Dim MagPE As Integer Dim MagP As Integer Dim MagE As Integer Dim Result As Double Dim Test As Double Dim Index As Integer Dim Done As Integer = 0 Dim Count As Integer = 50 Dim Kounter As Integer Dim TotalOnes As Integer = 0 While Not Done Done = 1 'Cycle through each of the customers. For Index = 0 To MAX_CUSTOMERS - 1 'Step 3. For PVec = 0 To TOTAL_PROTOTYPE_VECTORS - 1 'Check to see if this vector has any members. If Members(PVec) Then VectorBitwiseAND(ANDResult, Database, Index, PrototypeVector, PVec) MagPE = VectorMagnitude(ANDResult) MagP = VectorMagnitude(PrototypeVector, PVec) MagE = VectorMagnitude(Database, Index) Result = CDbl(MagPE) / (BETA + CDbl(MagP)) Test = CDbl(MagE) / (BETA + CDbl(MAX_ITEMS)) 'MsgBox("MagPE: " + Str(CDbl(MagPE)) + " / BETA: " + Str(BETA) + _ ' " + MagP: " + Str(CDbl(MagP)) + " = " + Str(Result) + Chr(13) + Chr(10) + _ ' "MagE: " + Str(CDbl(MagE)) + " / BETA: " + Str(BETA) + _ ' " + MAX_ITEMS: " + Str(CDbl(MAX_ITEMS)) + " = " + Str(Test), MsgBoxStyle.OKOnly) 'Equation 2. If Result > Test Then 'Test for vigilance acceptability (Equation 3). If (CDbl(MagPE) / CDbl(MagE)) < VIGILANCE Then Dim Old As Integer 'Ensure this is a different cluster. If Membership(Index) <> PVec Then 'Move customer to the new cluster Old = Membership(Index) Membership(Index) = PVec If Old >= 0 Then Members(Old) -= 1 If Members(Old) = 0 Then PrototypeVectors -= 1 End If Members(PVec) += 1 'Recalculate the prototype vectors for the 'old and new clusters. If (Old >= 0) And (Old < TOTAL_PROTOTYPE_VECTORS) Then UpdatePrototypeVectors(Old) End If UpdatePrototypeVectors(PVec) Done = 0 Exit For 'Exit vector loop. End If Else 'Already in this cluster. End If End If 'for Vigilance test. End If End If Next 'End of vector loop. 'Check to see if the current vector was processed. If Membership(Index) = -1 Then 'No prototype vector was found to be close to the example 'vector. Create a new prototype vector for this example. Membership(Index) = CreateNewPrototypeVector(Database, Index) Done = 0 End If Next 'for Customers loop. If Not Count Then 'Count -= 1 Exit While Else 'Not Done yet. Count -= 1 End If End While End Sub Private Sub DisplayCustomerClusters() Dim Customer As Integer Dim Item As Integer Dim Cluster As Integer Dim TempString As String For Cluster = 0 To TOTAL_PROTOTYPE_VECTORS - 1 TempString += Chr(13) + Chr(10) TempString += "ProtoType Vector: " + Str(Cluster) + ": " For Item = 0 To MAX_ITEMS - 1 TempString += Str(CInt(PrototypeVector(Cluster, Item))) Next TempString += Chr(13) + Chr(10) For Customer = 0 To MAX_CUSTOMERS - 1 If Membership(Customer) = Cluster Then TempString += "Customer: " + Str(Customer) + ": " For Item = 0 To MAX_ITEMS - 1 TempString += Str(CInt(Database(Customer, Item))) Next 'TempString += Str(Membership(Customer)) TempString += Chr(13) + Chr(10) End If Next TempString += Chr(13) + Chr(10) Next TempString += Chr(13) + Chr(10) Text1.Text = TempString End Sub Private Sub DisplayMemberships() Dim Customer As Integer Dim Item As Integer Dim TempString As String For Customer = 0 To MAX_CUSTOMERS - 1 TempString += "Membership: " + Str(Membership(Customer)) TempString += Chr(13) + Chr(10) Next TempString += Chr(13) + Chr(10) Text1.Text += TempString End Sub Private Sub DisplayCustomerDatabase() Dim Customer As Integer Dim Item As Integer Dim TempString As String For Customer = 0 To MAX_CUSTOMERS - 1 TempString += Chr(13) + Chr(10) TempString += "Customer: " + Str(Customer) + ": " For Item = 0 To MAX_ITEMS - 1 TempString += Str(CInt(Database(Customer, Item))) Next Next Text1.Text += TempString End Sub Private Sub UpdatePrototypeVectors(ByVal Cluster As Integer) Dim Item As Integer Dim Customer As Integer Dim First As Integer = 1 Dim ANDResult As Integer If Cluster >= 0 Then For Item = 0 To MAX_ITEMS - 1 PrototypeVector(Cluster, Item) = 0 Next For Customer = 0 To MAX_CUSTOMERS - 1 If Membership(Customer) = Cluster Then If First Then For Item = 0 To MAX_ITEMS - 1 PrototypeVector(Cluster, Item) = Database(Customer, Item) Next First = 0 Else For Item = 0 To MAX_ITEMS - 1 PrototypeVector(Cluster, Item) = (PrototypeVector(Cluster, Item) _ AndAlso Database(Customer, Item)) Next End If End If Next End If End Sub Private Function CreateNewPrototypeVector(ByVal Vector As Integer(,), _ ByVal vRow As Integer) As Integer Dim Kounter As Integer Dim Cluster As Integer For Cluster = 0 To TOTAL_PROTOTYPE_VECTORS - 1 If Members(Cluster) = 0 Then Exit For End If Next If Cluster = TOTAL_PROTOTYPE_VECTORS - 1 Then PrototypeVectors += 1 End If For Kounter = 0 To MAX_ITEMS - 1 'PrototypeVector(Cluster, Kounter) = Example(element) PrototypeVector(Cluster, Kounter) = Vector(vRow, Kounter) Next Members(Cluster) = 1 CreateNewPrototypeVector = Cluster End Function Private Sub VectorBitwiseAND(ByVal Result As Integer(), ByVal v As Integer(,), _ ByVal vRow As Integer, _ ByVal w As Integer(,), _ ByVal wRow As Integer) Dim Kounter As Integer For Kounter = 0 To MAX_ITEMS - 1 'Resulting array = v(Kounter) and w(Kounter) Result(Kounter) = (v(vRow, Kounter) AndAlso w(wRow, Kounter)) Next End Sub Private Function VectorMagnitude(ByVal Vector As Integer()) As Integer 'This function counts up all the 1's in a given vector. Dim Kounter As Integer Dim TotalOnes As Integer = 0 For Kounter = 0 To MAX_ITEMS - 1 'If Vector(Kounter) = 1 Then If Vector(Kounter) = True Then TotalOnes += 1 End If Next VectorMagnitude = TotalOnes End Function Private Function VectorMagnitude(ByVal Vector As Integer(,), ByVal vRow As Integer) As Integer 'This function counts up all the 1's in a given vector. Dim Kounter As Integer Dim TotalOnes As Integer = 0 For Kounter = 0 To MAX_ITEMS - 1 If Vector(vRow, Kounter) = 1 Then TotalOnes += 1 End If Next VectorMagnitude = TotalOnes End Function