-
0
1
1
- 634377989713530085
-
0
8
7
- true
- true
- 1847cba7-7a17-498a-b36e-52fffb0274c4
-
100;150;0;0
-
100;0;120;0
- Shaded
- k_mean2.ghx
- 634376151368389589
- 0
-
56
-3
- 0.3276801
- 0
- 35
- 3581f42a-9592-4549-bd6b-1c0fc39d067b
- Point XYZ
- Point XYZ
- Pt
- Create a point from {xyz} coordinates.
- 320881db-c6d7-4ac0-bb03-28ee4f69e4f8
- true
- true
- true
- longest_list
-
371
612
65
64
-
390
614
24
60
-
402
644
- false
- X component
- X
- {x} component
- fe5dcf7d-d23f-4e5e-9a57-f154d407e2c2
- false
- true
- true
- 1
- 453d634a-d0d5-448c-b399-504ff95afc7c
- 1
-
373
614
14
20
-
373
614
14
20
-
381.5
624
- false
- 0
- Y component
- Y
- {y} component
- 11b64827-0e35-4757-ae75-91bfe9685586
- false
- true
- true
- 1
- b9263c84-0ec3-4e5e-bee6-5ee2237088bc
- 1
-
373
634
14
20
-
373
634
14
20
-
381.5
644
- false
- 0
- Z component
- Z
- {z} component
- 9de5fdf8-4fdf-4395-ba86-c7deea2b6d93
- false
- true
- true
- 0
- 1
-
373
654
14
20
-
373
654
14
20
-
381.5
664
- false
- 0
- Point
- Pt
- Point coordinate
- 2e06ddeb-55c9-4b7a-ab8b-99c7ab9479ff
- true
- true
- true
- 0
-
417
614
17
60
-
417
614
17
60
-
427
644
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- 30103ef8-8353-475f-8d6d-0ba61b983bfe
- true
- true
- true
- longest_list
-
239
548
64
84
-
259
550
24
80
-
271
590
- false
- Range
- R
- Domain of random numeric range
- 3bb3c2f1-9cb0-4cc6-ba1d-d942598b3b86
- false
- true
- true
- 0
- 1
-
241
550
15
20
-
241
550
15
20
-
250
560
- false
-
0
1
- Number
- N
- Number of random values
- 1a4744ce-6c0e-4f1a-b700-c0601265d56f
- false
- true
- true
- 1
- 8035d38b-ff24-435e-a74a-f551f3608aa1
- 1
-
241
570
15
20
-
241
570
15
20
-
250
580
- false
- 1
- Seed
- S
- Seed of random engine
- e663be3e-8a81-4a82-9c89-6d1c677667a1
- false
- true
- true
- 0
- 1
-
241
590
15
20
-
241
590
15
20
-
250
600
- false
- 2
- Integers
- I
- Limit to integers only
- 2d59dbfe-8497-4d6a-82c4-9ea6d72e98ae
- false
- true
- true
- 0
- 1
- false
-
241
610
15
20
-
241
610
15
20
-
250
620
- false
- false
- Range
- R
- Range of random numbers
- 453d634a-d0d5-448c-b399-504ff95afc7c
- false
- true
- true
- 0
-
286
550
15
80
-
286
550
15
80
-
295
590
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- 1c377108-f6e8-42e3-90cb-ee949232d69c
- true
- true
- true
- longest_list
-
236
649
64
84
-
256
651
24
80
-
268
691
- false
- Range
- R
- Domain of random numeric range
- be136e6d-b242-41d5-9c7e-38e791aa0c20
- false
- true
- true
- 0
- 1
-
238
651
15
20
-
238
651
15
20
-
247
661
- false
-
0
1
- Number
- N
- Number of random values
- e6576b5c-5c7c-4c3d-9761-722b22bd87b6
- false
- true
- true
- 1
- 8035d38b-ff24-435e-a74a-f551f3608aa1
- 1
-
238
671
15
20
-
238
671
15
20
-
247
681
- false
- 1
- Seed
- S
- Seed of random engine
- 3f089c05-51e8-4eb5-a82c-8d3ccce523bb
- false
- true
- true
- 1
- ed0e107f-c46b-4585-9d88-8a4e457da46b
- 1
-
238
691
15
20
-
238
691
15
20
-
247
701
- false
- 2
- Integers
- I
- Limit to integers only
- 1c786537-5466-4376-b75c-f37c358da2a0
- false
- true
- true
- 0
- 1
- false
-
238
711
15
20
-
238
711
15
20
-
247
721
- false
- false
- Range
- R
- Range of random numbers
- b9263c84-0ec3-4e5e-bee6-5ee2237088bc
- false
- true
- true
- 0
-
283
651
15
80
-
283
651
15
80
-
292
691
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 8035d38b-ff24-435e-a74a-f551f3608aa1
- false
- true
- true
- 0
- 500
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
88
571
50
20
-
88
571
50
20
-
88.25
571.0543
- false
- 9d0c5284-ea24-4f9f-a183-ef57fc48b5b8
- Convex Hull
- Convex Hull
- Hull
- Compute the planar, convex hull for a collection of points
- 7db4966a-a8c6-4f94-a07f-d2ebaec287d0
- true
- true
- true
- longest_list
-
959
666
71
64
-
981
668
24
60
-
993
698
- false
- Points
- P
- Points for convex hull solution
- 0985eaf1-beb8-402a-a753-ef39ad386521
- true
- true
- true
- 1
- 1
- 168c14ed-e132-4af1-83ca-1503dd56015d
-
961
668
17
30
-
961
668
17
30
-
971
683
- false
- Plane
- Pl
- Optional base plane. If no plane is provided, then the best-fit plane will be used.
- de25f451-469f-483d-aa3f-acb3c2edd374
- true
- true
- true
- 0
- 1
-
961
698
17
30
-
961
698
17
30
-
971
713
- false
-
0
0
0
1
0
0
0
1
0
- Hull
- H
- Convex hull in base plane space
- 65fd8fc1-5058-46c8-b30d-9ea8f995506f
- true
- true
- true
- 0
-
1008
668
20
20
-
1008
668
20
20
-
1019.5
678
- false
- Hull(z)
- Hz
- Convex hull in world space
- 97e28645-448f-416c-bcde-f7d8e2474304
- true
- true
- true
- 0
-
1008
688
20
20
-
1008
688
20
20
-
1019.5
698
- false
- Indices
- I
- Indices of points on convex hull
- ebbbe001-81a5-47d4-9898-c37db0bae624
- false
- true
- true
- 0
-
1008
708
20
20
-
1008
708
20
20
-
1019.5
718
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- ed0e107f-c46b-4585-9d88-8a4e457da46b
- false
- true
- true
- 0
- 12457
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
88
691
50
20
-
88
691
50
20
-
88.8
691.5543
- false
- 1e9e08fc-c31e-49eb-a36c-90de5e62e5f5
- VB Script
- 'your code goes here…
Dim t As Integer = 0
Dim i As Integer = 0
Dim j As Integer = 0
Dim k As Integer = 0
Dim numGroups As Integer
Dim groupNum As Integer
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim minDist As Double
Dim dist As Double
'Dim cluster As Integer
'initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
Dim goupings As New List(Of List(Of Integer))
Dim oldCentroids As New List(Of Point3d)
Dim newCentroids As New List(Of Point3d)
Dim pathList As New List(Of GH_Path)
Dim newCentroid As Point3d
Dim pt As Point3d
Dim isStillMoving As Boolean
Dim groupingsTree As New DataTree(Of Point3d)
Dim inputpts As New List(Of Point3d)
For t = 0 To P.BranchCount - 1
'this mess dose data matching for inputs P and N
'this if is ture is the input branches are equal
If N.BranchCount >= P.BranchCount Then
'check to see if, in the case the branches are equal, that there is only one item in each branch of N
If N.Branch(t).Count = 1 Then
numGroups = N.Branch(t)(0)
'I don't know what to do if the above statment isn't true so let's exit the program
Else
Print("Error: data missmatch between inputs P and N, Please reformat inputs")
Exit Sub
End If
'here we check if it is a simple list...
Else If N.Branch(0).Count = P.BranchCount
numGroups = N.Branch(0)(t)
'here we check if it is a simple list but is shorter or longer than the tree P
Else If N.Branch(0).Count < P.BranchCount Then
If t <= N.Branch(0).Count - 1 Then
numGroups = N.Branch(0)(t)
Else
numGroups = N.Branch(0)(N.Branch(0).Count - 1)
End If
'if all else fails exit the program!
Else
Print("Error: data missmatch between inputs P and N, Please reformat inputs")
Exit Sub
End If
inputpts = P.Branch(t)
print("--------Accessing Branch " & t & "--------")
'***************** Initialize K-Means Algorithm ****************************
print("--------Initializing " & numGroups & " groupings-------")
For i = 0 To numGroups - 1
'Dim pt As Point3d
'Dim group As New List(Of Integer)
Dim tempPath As New GH_Path
goupings.Add(New List(Of Integer))
newCentroids.add(pt)
oldCentroids.Add(pt)
tempPath.FromString(t & ";" & i)
pathList.Add(tempPath)
print("creating grouping " & i)
Next
'radomly assign points from the input list (intialze the k-mean groups)
print("--------Initializing group assinments (random)-------")
For j = 0 To inputpts.Count - 1
groupNum = RandomNumber(r, numGroups - 1)
goupings(groupNum).Add(j)
print("Adding index value " & goupings(groupNum)(goupings(groupNum).Count - 1) & " to group " & groupNum & ".")
Next
'***************** Do K-Means Algorithm ************************************
print("--------entering main k-means loop--------")
isStillMoving = True
Do While isStillMoving
isStillMoving = False
'find new centroids
print(".....finding new centroids")
For i = 0 To numGroups - 1
oldCentroids(i) = newCentroids(i)
For j = 0 To goupings(i).Count - 1
pt = inputpts(goupings(i)(j))
X = X + pt.X
Y = Y + pt.Y
Z = Z + pt.Z
Next
X = X / (j + 1)
Y = Y / (j + 1)
Z = Z / (j + 1)
newCentroid.X = X
newCentroid.Y = Y
newCentroid.Z = Z
newCentroids(i) = newCentroid
print("new centroid for group " & i & " is " & newCentroids(i).ToString)
goupings(i).Clear
dist = newCentroid.DistanceTo(oldCentroids(i))
'print("dist = " & dist)
If dist > D Then
print("need to do more work")
isStillMoving = True
End If
Next
'create new groupings
print(".....creating new groupings")
For j = 0 To inputpts.Count - 1
pt = inputpts(j)
minDist = pt.DistanceTo(newCentroids(0))
For i = 0 To numGroups - 1
dist = pt.DistanceTo(newCentroids(i))
If minDist >= dist Then
groupNum = i
minDist = dist
'print(minDist)
End If
Next
'Print("Adding index value " & j & " to group " & groupNum & ".")
goupings(groupNum).Add(j)
If isStillMoving = False Then
groupingsTree.Add(pt, pathList(groupNum))
End If
Next
If isStillMoving = False Then
print("***************all groups setled exiting loop********************")
print("***************total loop count is " & k & "************************")
End If
'a hard limit on the number of loops to execute....
If k > 1000 Then
isStillMoving = False
End If
k = k + 1
Loop
goupings.Clear
newCentroids.Clear
oldCentroids.Clear
pathList.Clear
Next
G = groupingsTree
- 'function taken from http://www.freevbcode.com/ShowCode.Asp?ID=4451 (and slightly modified)
Public Function RandomNumber(ByVal r As Random, ByVal MaxNumber As Integer, Optional ByVal MinNumber As Integer = 0) As Integer
'if passed incorrect arguments, swap them
'can also throw exception or return 0
If MinNumber > MaxNumber Then
Dim t As Integer = MinNumber
MinNumber = MaxNumber
MaxNumber = t
End If
Return r.Next(MinNumber, MaxNumber)
End Function
- 0
- VB Script
- K-Means
- A VB.NET scriptable component
- d88212fa-a842-406a-b58e-add493da5d38
- 1
- false
- true
- true
- longest_list
-
674
631
87
71
-
710
633
24
67
-
722
667
- false
- 3
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable P
- Script Variable P
- 2
- true
- true
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable N
- Script Variable N
- 2
- true
- true
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable D
- Script Variable D
- true
- true
- 2
- 3ede854e-c753-40eb-84cb-b48008f14fd4
- Output
- Print, Reflect and Error streams
- true
- false
- 8ec86459-bf01-4409-baee-174d0d2b13d0
- Result A
- Output parameter A
- true
- false
- Variable P
- P
- Script Variable P
- 58c4e993-fa1f-4ce2-9939-6d8687753658
- true
- true
- true
- 2
- 1
- 2e06ddeb-55c9-4b7a-ab8b-99c7ab9479ff
- e1937b56-b1da-4c12-8bd8-e34ee81746ef
- true
- true
-
676
633
31
22
-
692
633
15
22
-
701
644.1667
- false
- Variable N
- N
- Script Variable N
- 58e88adc-e875-4b38-b548-3736ce98a1ae
- true
- true
- true
- 2
- 2
- 1
- 9bfddfa4-b059-4a69-96d3-5e599befc626
- efe48ae7-2987-421b-a33a-1f7be1c3f050
- true
- true
-
676
655
31
22
-
676
655
31
22
-
701
666.5
- false
- Variable D
- D
- Script Variable D
- 7f702417-4c2b-4289-84da-1ec8b447ea79
- true
- true
- true
- 1
- 4536c22e-1727-4acd-bc63-780868f961ad
- 8e991e99-5fb8-41e1-928d-1bba8fb9f7d7
- true
- true
-
676
677
31
23
-
692
677
15
23
-
701
688.8334
- false
- Output
- out
- Print, Reflect and Error streams
- ff775d37-d35f-4506-8289-06229356dc89
- false
- true
- true
- 0
-
737
633
22
33
-
737
633
22
33
-
749.5
649.75
- false
- Result A
- G
- Output parameter A
- 168c14ed-e132-4af1-83ca-1503dd56015d
- true
- true
- true
- 0
-
737
666
22
34
-
737
666
22
34
-
749.5
683.25
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- f674a83f-5022-4ea0-8991-6ce663032811
- false
- true
- true
- 1
- ff775d37-d35f-4506-8289-06229356dc89
- Double click to edit panel content…
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
1112
363
497
575
-
1112
363
497
575
-
1112.183
363.8895
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 4536c22e-1727-4acd-bc63-780868f961ad
- false
- true
- true
- 0
- 0.000001
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
523
679
75
20
-
523
679
75
20
-
523.2199
679.1143
- false
- 72a29b54-2e48-474b-a400-d2124c4edf79
- Param Viewer
- false
- 1
- Param Viewer
- Viewer
- A viewer for data structures.
- 5ff29a52-03d8-42a0-b056-3063b39ffcab
- false
- true
- true
- 2
- 1
- 168c14ed-e132-4af1-83ca-1503dd56015d
-
889
741
200
300
-
889
741
200
300
-
889.85
741.9044
- false
- 57da07bd-ecab-415d-9d86-af36d7073abc
- Number Slider
- Number Slider
- Slider
- Numeric slider for single values
- 9bfddfa4-b059-4a69-96d3-5e599befc626
- false
- true
- true
- 0
-
457
656
141
20
-
457
656
41
20
-
457.5
656.8344
- false
- 8
- 0
- 30
- 3
- 1
- 3581f42a-9592-4549-bd6b-1c0fc39d067b
- Point XYZ
- Point XYZ
- Pt
- Create a point from {xyz} coordinates.
- 5a64300b-7133-423c-af42-ee0941a9754a
- false
- true
- true
- longest_list
-
373
1387
65
64
-
392
1389
24
60
-
404
1419
- false
- X component
- X
- {x} component
- 38451c0d-1324-4c62-8c57-46b1eb87a7ff
- false
- true
- true
- 1
- 8cbc3fb8-5e46-4430-9065-7336927ea5e9
- 1
-
375
1389
14
20
-
375
1389
14
20
-
383.5
1399
- false
- 0
- Y component
- Y
- {y} component
- 478378fb-9dd0-43d6-8e80-50a3d78f7f5a
- false
- true
- true
- 1
- 86d8188e-c690-4d9c-ae80-09f4414e9492
- 1
-
375
1409
14
20
-
375
1409
14
20
-
383.5
1419
- false
- 0
- Z component
- Z
- {z} component
- 850d86a1-833d-4cb6-b38d-83818ae0e8fe
- false
- true
- true
- 0
- 1
-
375
1429
14
20
-
375
1429
14
20
-
383.5
1439
- false
- 0
- Point
- Pt
- Point coordinate
- 08fd1dc3-7edf-42c5-bc27-4644b0158af8
- true
- true
- true
- 0
-
419
1389
17
60
-
419
1389
17
60
-
429
1419
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- 1374b164-a2f1-4697-a720-b81c6e0100cd
- true
- true
- true
- longest_list
-
241
1323
64
84
-
261
1325
24
80
-
273
1365
- false
- Range
- R
- Domain of random numeric range
- ddc0484d-fc54-4c32-b0d4-30a82bf061cd
- false
- true
- true
- 0
- 1
-
243
1325
15
20
-
243
1325
15
20
-
252
1335
- false
-
0
1
- Number
- N
- Number of random values
- 699b35a3-a865-4e18-a685-9bd0ab8f31d8
- false
- true
- true
- 1
- cb848737-acc5-4c2b-b10b-3fc5d383e557
- 1
-
243
1345
15
20
-
243
1345
15
20
-
252
1355
- false
- 1
- Seed
- S
- Seed of random engine
- fb54c951-d4df-4563-8f8f-08a4c189a716
- false
- true
- true
- 0
- 1
-
243
1365
15
20
-
243
1365
15
20
-
252
1375
- false
- 2
- Integers
- I
- Limit to integers only
- 8be5181f-73d4-4dbf-9eab-dc56ceab3d79
- false
- true
- true
- 0
- 1
- false
-
243
1385
15
20
-
243
1385
15
20
-
252
1395
- false
- false
- Range
- R
- Range of random numbers
- 8cbc3fb8-5e46-4430-9065-7336927ea5e9
- false
- true
- true
- 0
-
288
1325
15
80
-
288
1325
15
80
-
297
1365
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- 860cd74e-ad2a-4329-8623-c2159917aae0
- true
- true
- true
- longest_list
-
238
1424
64
84
-
258
1426
24
80
-
270
1466
- false
- Range
- R
- Domain of random numeric range
- 45a9ddcb-3539-47c6-8e41-54f5845cf73d
- false
- true
- true
- 0
- 1
-
240
1426
15
20
-
240
1426
15
20
-
249
1436
- false
-
0
1
- Number
- N
- Number of random values
- 03034bd8-d78f-47a1-992d-f62c0ef3180d
- false
- true
- true
- 1
- cb848737-acc5-4c2b-b10b-3fc5d383e557
- 1
-
240
1446
15
20
-
240
1446
15
20
-
249
1456
- false
- 1
- Seed
- S
- Seed of random engine
- 51a35912-db12-46a9-8894-2d61c2d4186b
- false
- true
- true
- 1
- 1fd3d4ce-9c1d-4dde-b96c-c2e26f62df70
- 1
-
240
1466
15
20
-
240
1466
15
20
-
249
1476
- false
- 2
- Integers
- I
- Limit to integers only
- 1be2a6aa-23a8-4379-9b71-27b9640ee12f
- false
- true
- true
- 0
- 1
- false
-
240
1486
15
20
-
240
1486
15
20
-
249
1496
- false
- false
- Range
- R
- Range of random numbers
- 86d8188e-c690-4d9c-ae80-09f4414e9492
- false
- true
- true
- 0
-
285
1426
15
80
-
285
1426
15
80
-
294
1466
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- cb848737-acc5-4c2b-b10b-3fc5d383e557
- false
- true
- true
- 0
- 500
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
90
1346
50
20
-
90
1346
50
20
-
90.4375
1346.679
- false
- 9d0c5284-ea24-4f9f-a183-ef57fc48b5b8
- Convex Hull
- Convex Hull
- Hull
- Compute the planar, convex hull for a collection of points
- ce59661e-eefc-434a-b177-aa27f9c4361e
- false
- true
- true
- longest_list
-
1238
1430
71
64
-
1260
1432
24
60
-
1272
1462
- false
- Points
- P
- Points for convex hull solution
- 905c48e3-90cb-4bd8-bd6d-4e117689710c
- true
- true
- true
- 1
- 1
- 33d455d4-e554-4004-88b0-9876e1647159
-
1240
1432
17
30
-
1240
1432
17
30
-
1250
1447
- false
- Plane
- Pl
- Optional base plane. If no plane is provided, then the best-fit plane will be used.
- 803b6ffb-3734-4dc5-bf76-24e1279b81f7
- true
- true
- true
- 0
- 1
-
1240
1462
17
30
-
1240
1462
17
30
-
1250
1477
- false
-
0
0
0
1
0
0
0
1
0
- Hull
- H
- Convex hull in base plane space
- 468cbb45-18e8-4446-9958-98266fdbf89f
- true
- true
- true
- 0
-
1287
1432
20
20
-
1287
1432
20
20
-
1298.5
1442
- false
- Hull(z)
- Hz
- Convex hull in world space
- 8b7f30bb-543e-4c90-9f51-f5dc5afbeed5
- true
- true
- true
- 0
-
1287
1452
20
20
-
1287
1452
20
20
-
1298.5
1462
- false
- Indices
- I
- Indices of points on convex hull
- eddf5831-4d26-41e8-a0e8-78c27d87d68f
- false
- true
- true
- 0
-
1287
1472
20
20
-
1287
1472
20
20
-
1298.5
1482
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 1fd3d4ce-9c1d-4dde-b96c-c2e26f62df70
- false
- true
- true
- 0
- 12457
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
90
1467
50
20
-
90
1467
50
20
-
90.9875
1467.179
- false
- 1e9e08fc-c31e-49eb-a36c-90de5e62e5f5
- VB Script
- 'your code goes here…
Dim t As Integer = 0
Dim i As Integer = 0
Dim j As Integer = 0
Dim k As Integer = 0
Dim numGroups As Integer
Dim groupNum As Integer
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim minDist As Double
Dim dist As Double
'Dim cluster As Integer
'initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
Dim goupings As New List(Of List(Of Integer))
Dim oldCentroids As New List(Of Point3d)
Dim newCentroids As New List(Of Point3d)
Dim pathList As New List(Of GH_Path)
Dim newCentroid As Point3d
Dim pt As Point3d
Dim isStillMoving As Boolean
Dim groupingsTree As New DataTree(Of Point3d)
Dim inputpts As New List(Of Point3d)
For t = 0 To P.BranchCount - 1
'this mess dose data matching for inputs P and N
'this if is ture is the input branches are equal
If N.BranchCount >= P.BranchCount Then
'check to see if, in the case the branches are equal, that there is only one item in each branch of N
If N.Branch(t).Count = 1 Then
numGroups = N.Branch(t)(0)
'I don't know what to do if the above statment isn't true so let's exit the program
Else
Print("Error: data missmatch between inputs P and N, Please reformat inputs")
Exit Sub
End If
'here we check if it is a simple list...
Else If N.Branch(0).Count = P.BranchCount
numGroups = N.Branch(0)(t)
'here we check if it is a simple list but is shorter or longer than the tree P
Else If N.Branch(0).Count < P.BranchCount Then
If t <= N.Branch(0).Count - 1 Then
numGroups = N.Branch(0)(t)
Else
numGroups = N.Branch(0)(N.Branch(0).Count - 1)
End If
'if all else fails exit the program!
Else
Print("Error: data missmatch between inputs P and N, Please reformat inputs")
Exit Sub
End If
inputpts = P.Branch(t)
print("--------Accessing Branch " & t & "--------")
'***************** Initialize K-Means Algorithm ****************************
print("--------Initializing " & numGroups & " groupings-------")
For i = 0 To numGroups - 1
'Dim pt As Point3d
'Dim group As New List(Of Integer)
Dim tempPath As New GH_Path
goupings.Add(New List(Of Integer))
newCentroids.add(pt)
oldCentroids.Add(pt)
tempPath.FromString(t & ";" & i)
pathList.Add(tempPath)
print("creating grouping " & i)
Next
'radomly assign points from the input list (intialze the k-mean groups)
print("--------Initializing group assinments (random)-------")
For j = 0 To inputpts.Count - 1
groupNum = RandomNumber(r, numGroups - 1)
goupings(groupNum).Add(j)
print("Adding index value " & goupings(groupNum)(goupings(groupNum).Count - 1) & " to group " & groupNum & ".")
Next
'***************** Do K-Means Algorithm ************************************
print("--------entering main k-means loop--------")
isStillMoving = True
Do While isStillMoving
isStillMoving = False
'find new centroids
print(".....finding new centroids")
For i = 0 To numGroups - 1
oldCentroids(i) = newCentroids(i)
For j = 0 To goupings(i).Count - 1
pt = inputpts(goupings(i)(j))
X = X + pt.X
Y = Y + pt.Y
Z = Z + pt.Z
Next
X = X / (j + 1)
Y = Y / (j + 1)
Z = Z / (j + 1)
newCentroid.X = X
newCentroid.Y = Y
newCentroid.Z = Z
newCentroids(i) = newCentroid
print("new centroid for group " & i & " is " & newCentroids(i).ToString)
goupings(i).Clear
dist = newCentroid.DistanceTo(oldCentroids(i))
'print("dist = " & dist)
If dist > D Then
print("need to do more work")
isStillMoving = True
End If
Next
'create new groupings
print(".....creating new groupings")
For j = 0 To inputpts.Count - 1
pt = inputpts(j)
minDist = pt.DistanceTo(newCentroids(0))
For i = 0 To numGroups - 1
dist = pt.DistanceTo(newCentroids(i))
If minDist >= dist Then
groupNum = i
minDist = dist
'print(minDist)
End If
Next
'Print("Adding index value " & j & " to group " & groupNum & ".")
goupings(groupNum).Add(j)
If isStillMoving = False Then
groupingsTree.Add(pt, pathList(groupNum))
End If
Next
If isStillMoving = False Then
print("***************all groups setled exiting loop********************")
print("***************total loop count is " & k & "************************")
End If
'a hard limit on the number of loops to execute....
If k > 1000 Then
isStillMoving = False
End If
k = k + 1
Loop
goupings.Clear
newCentroids.Clear
oldCentroids.Clear
pathList.Clear
Next
G = groupingsTree
- 'function taken from http://www.freevbcode.com/ShowCode.Asp?ID=4451 (and slightly modified)
Public Function RandomNumber(ByVal r As Random, ByVal MaxNumber As Integer, Optional ByVal MinNumber As Integer = 0) As Integer
'if passed incorrect arguments, swap them
'can also throw exception or return 0
If MinNumber > MaxNumber Then
Dim t As Integer = MinNumber
MinNumber = MaxNumber
MaxNumber = t
End If
Return r.Next(MinNumber, MaxNumber)
End Function
- 0
- VB Script
- K-Means
- A VB.NET scriptable component
- 3c14c603-a64e-44aa-b4f0-6c74ef122247
- 1
- false
- true
- true
- longest_list
-
953
1395
87
71
-
989
1397
24
67
-
1001
1431
- false
- 3
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable P
- Script Variable P
- 2
- true
- true
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable N
- Script Variable N
- 2
- true
- true
- 84fa917c-1ed8-4db3-8be1-7bdc4a6495a2
- Variable D
- Script Variable D
- true
- true
- 2
- 3ede854e-c753-40eb-84cb-b48008f14fd4
- Output
- Print, Reflect and Error streams
- true
- false
- 8ec86459-bf01-4409-baee-174d0d2b13d0
- Result A
- Output parameter A
- true
- false
- Variable P
- P
- Script Variable P
- 02f3f604-8f09-47c2-9c5a-e0633117a18f
- true
- true
- true
- 2
- 1
- 66056a5a-c818-423a-824a-f62a0e6b3672
- e1937b56-b1da-4c12-8bd8-e34ee81746ef
- true
- true
-
955
1397
31
22
-
971
1397
15
22
-
980
1408.167
- false
- Variable N
- N
- Script Variable N
- c62e622a-7ec2-4bad-be58-d341026a5252
- true
- true
- true
- 2
- 2
- 2
- 63e97373-7bc1-43f9-b14d-69bf6251587a
- 452be31e-2b80-4cde-a584-0073adb76c29
- efe48ae7-2987-421b-a33a-1f7be1c3f050
- true
- true
-
955
1419
31
22
-
955
1419
31
22
-
980
1430.5
- false
- Variable D
- D
- Script Variable D
- 184f01f8-0d04-4272-aded-a15a4e7835ad
- true
- true
- true
- 1
- e0312e4c-d2e4-46d3-a4b0-7c33ea3ba010
- 8e991e99-5fb8-41e1-928d-1bba8fb9f7d7
- true
- true
-
955
1441
31
22
-
971
1441
15
22
-
980
1452.833
- false
- Output
- out
- Print, Reflect and Error streams
- 8b819b89-0287-4a92-8219-a09ced86cbe1
- false
- true
- true
- 0
-
1016
1397
22
33
-
1016
1397
22
33
-
1028.5
1413.75
- false
- Result A
- G
- Output parameter A
- 33d455d4-e554-4004-88b0-9876e1647159
- true
- true
- true
- 0
-
1016
1430
22
34
-
1016
1430
22
34
-
1028.5
1447.25
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 77d78402-dbe9-42d4-b6c5-13928e76659c
- false
- true
- true
- 1
- 8b819b89-0287-4a92-8219-a09ced86cbe1
- Double click to edit panel content…
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
1391
1128
497
575
-
1391
1128
497
575
-
1391.37
1128.514
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- e0312e4c-d2e4-46d3-a4b0-7c33ea3ba010
- false
- true
- true
- 0
- 0.000001
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
804
1496
75
20
-
804
1496
75
20
-
804.9674
1496.659
- false
- 57da07bd-ecab-415d-9d86-af36d7073abc
- Number Slider
- Number Slider
- Slider
- Numeric slider for single values
- 452be31e-2b80-4cde-a584-0073adb76c29
- false
- true
- true
- 0
-
735
1471
141
20
-
735
1471
41
20
-
735.6875
1471.779
- false
- 9
- 0
- 30
- 3
- 1
- 3581f42a-9592-4549-bd6b-1c0fc39d067b
- Point XYZ
- Point XYZ
- Pt
- Create a point from {xyz} coordinates.
- d694be63-6284-4817-9963-6f47d94fe4a3
- false
- true
- true
- longest_list
-
372
1185
65
64
-
391
1187
24
60
-
403
1217
- false
- X component
- X
- {x} component
- 782fb27f-52ae-48e6-ab07-aaf0a89bd3be
- false
- true
- true
- 1
- c26e18ef-831b-42b9-9aaa-b4e1083d1ad9
- 1
-
374
1187
14
20
-
374
1187
14
20
-
382.5
1197
- false
- 0
- Y component
- Y
- {y} component
- bdd307fa-286f-4103-a581-17d89fcdc92e
- false
- true
- true
- 1
- d6ffb9c2-f84f-49e0-a295-f3b4221e821d
- 1
-
374
1207
14
20
-
374
1207
14
20
-
382.5
1217
- false
- 0
- Z component
- Z
- {z} component
- a23337c8-c032-41a9-9982-1ac176225d83
- false
- true
- true
- 0
- 1
-
374
1227
14
20
-
374
1227
14
20
-
382.5
1237
- false
- 0
- Point
- Pt
- Point coordinate
- e1653c0f-fd89-4755-84f1-5d78525b5c93
- true
- true
- true
- 0
-
418
1187
17
60
-
418
1187
17
60
-
428
1217
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- b6a12def-7014-4580-a4f4-d791fcac46cb
- true
- true
- true
- longest_list
-
240
1121
64
84
-
260
1123
24
80
-
272
1163
- false
- Range
- R
- Domain of random numeric range
- 22894363-4401-40de-acce-298ee129979b
- false
- true
- true
- 0
- 1
-
242
1123
15
20
-
242
1123
15
20
-
251
1133
- false
-
0
1
- Number
- N
- Number of random values
- 91ee86ce-0f76-4369-809c-22b40065c1e0
- false
- true
- true
- 1
- 874a6739-74ba-46da-846a-48a2f000f602
- 1
-
242
1143
15
20
-
242
1143
15
20
-
251
1153
- false
- 1
- Seed
- S
- Seed of random engine
- a1d6df17-6040-4376-91f8-22dc00f2564b
- false
- true
- true
- 1
- 5588fad4-d5d4-41fe-8c2f-63a6e0003f2d
- 1
-
242
1163
15
20
-
242
1163
15
20
-
251
1173
- false
- 2
- Integers
- I
- Limit to integers only
- f86d9d85-4cf0-47f8-8bb2-d7271926b3b9
- false
- true
- true
- 0
- 1
- false
-
242
1183
15
20
-
242
1183
15
20
-
251
1193
- false
- false
- Range
- R
- Range of random numbers
- c26e18ef-831b-42b9-9aaa-b4e1083d1ad9
- false
- true
- true
- 0
-
287
1123
15
80
-
287
1123
15
80
-
296
1163
- false
- b7e4e0ef-a01d-48c4-93be-2a12d4417e22
- Random
- Random
- Random
- Generate a list of pseudo random numbers.
- bd970b43-437f-4738-9af5-105c1fb30d31
- true
- true
- true
- longest_list
-
237
1222
64
84
-
257
1224
24
80
-
269
1264
- false
- Range
- R
- Domain of random numeric range
- 7e03b3bb-068b-4bbe-b8ab-3941a8a71192
- false
- true
- true
- 0
- 1
-
239
1224
15
20
-
239
1224
15
20
-
248
1234
- false
-
0
1
- Number
- N
- Number of random values
- 6415866c-8acb-4020-9028-9adb105641aa
- false
- true
- true
- 1
- 874a6739-74ba-46da-846a-48a2f000f602
- 1
-
239
1244
15
20
-
239
1244
15
20
-
248
1254
- false
- 1
- Seed
- S
- Seed of random engine
- a9e9f2c7-bf16-4365-8de2-5af58a841526
- false
- true
- true
- 1
- 840307b0-1e82-420d-9e5b-06815ea4a618
- 1
-
239
1264
15
20
-
239
1264
15
20
-
248
1274
- false
- 2
- Integers
- I
- Limit to integers only
- d109cf0b-120e-4b68-b269-7d831995adef
- false
- true
- true
- 0
- 1
- false
-
239
1284
15
20
-
239
1284
15
20
-
248
1294
- false
- false
- Range
- R
- Range of random numbers
- d6ffb9c2-f84f-49e0-a295-f3b4221e821d
- false
- true
- true
- 0
-
284
1224
15
80
-
284
1224
15
80
-
293
1264
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 874a6739-74ba-46da-846a-48a2f000f602
- false
- true
- true
- 0
- 500
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
91
1144
50
20
-
91
1144
50
20
-
91.03751
1144.279
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 840307b0-1e82-420d-9e5b-06815ea4a618
- false
- true
- true
- 0
- 8593
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
90
1265
50
20
-
90
1265
50
20
-
90.43751
1265.879
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- A panel for custom notes and String values
- 5588fad4-d5d4-41fe-8c2f-63a6e0003f2d
- false
- true
- true
- 0
- 65830
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;250;90
-
91
1165
50
20
-
91
1165
50
20
-
91.03751
1165.079
- false
- f9b89a46-bc5d-4f7a-9a6f-134f93ac3af9
- Path Mapper
- Path Mapper
- Path Mapper
- Perform lexical operations on data trees.
- e2da698b-7dff-4315-ab5d-af45eab77852
- false
- true
- true
- 2
- 1
- e1653c0f-fd89-4755-84f1-5d78525b5c93
- 1
- {A;B}
- {A;1}
-
489.4375
1197.279
125
40
-
495.4375
1203.279
113
28
-
489.4375
1197.279
- false
- 86866576-6cc0-485a-9cd2-6f7d493f57f7
- Merge
- Merge
- Merge
- Merge two streams into one.
- 910a1345-eefb-460b-942d-516f75682d6f
- false
- true
- true
- longest_list
-
804
1385
62
44
-
823
1387
24
40
-
835
1407
- false
- Stream A
- A
- Input stream #1
- e00b2c89-6057-4ba8-9241-552f65648d22
- true
- true
- true
- 2
- 1
- e2da698b-7dff-4315-ab5d-af45eab77852
-
806
1387
14
20
-
806
1387
14
20
-
814.5
1397
- false
- Stream B
- B
- Input stream #2
- 5105e8cb-6241-4d89-ba98-8587921bf92f
- true
- true
- true
- 2
- 1
- 08fd1dc3-7edf-42c5-bc27-4644b0158af8
-
806
1407
14
20
-
806
1407
14
20
-
814.5
1417
- false
- Stream
- S
- Merged stream
- 66056a5a-c818-423a-824a-f62a0e6b3672
- true
- true
- true
- 0
-
850
1387
14
40
-
850
1387
14
40
-
858.5
1407
- false
- 72a29b54-2e48-474b-a400-d2124c4edf79
- Param Viewer
- false
- 1
- Param Viewer
- Viewer
- A viewer for data structures.
- 93c0a4ed-1d9a-4cfe-909e-961da480745c
- false
- true
- true
- 2
- 1
- 33d455d4-e554-4004-88b0-9876e1647159
-
1170
1510
200
300
-
1170
1510
200
300
-
1170.991
1510.514
- false
- 57da07bd-ecab-415d-9d86-af36d7073abc
- Number Slider
- Number Slider
- Slider
- Numeric slider for single values
- 63e97373-7bc1-43f9-b14d-69bf6251587a
- false
- true
- true
- 0
-
734
1447
141
20
-
734
1447
41
20
-
734.6875
1447.779
- false
- 6
- 0
- 30
- 3
- 1
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- Example 1
- A panel for custom notes and String values
- 906b6392-8a63-4157-932d-009246040fb9
- false
- true
- true
- 0
- A single set
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;89;139;255
-
179
440
160
100
-
179
440
160
100
-
179.75
440.4449
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- Example 2
- A panel for custom notes and String values
- a5271741-3ba2-4d9d-a58d-17c9713033eb
- false
- true
- true
- 0
- Muiltiple Data Trees
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;89;139;255
-
179
999
160
100
-
179
999
160
100
-
179.75
999.7613
- false
- 59e0b89a-e487-49f8-bab8-b5bab16be14c
- Panel
- Panel
- K-Means
- A panel for custom notes and String values
- 49845697-2fbc-4cdb-be03-a70bd0cfc8c1
- false
- true
- true
- 0
- K-Means Algorthims are a automated way of grouping data. For now my implementation only works on points but other types should work in theory. The VB script is also woefully un-optimzed which I hope to revisit.
Check out the K-Means Page on wikipedia @
http://en.wikipedia.org/wiki/K-means_clustering
And the general page on data clustering @
http://en.wikipedia.org/wiki/Cluster_analysis
- true
- true
- true
- 1
- 0
- false
-
255;0;0;0
-
255;255;0;0
-
180
129
728
299
-
180
129
728
299
-
180.2873
129.5116
- false
- Courier New
- 15.75
- false
- false
- bbb4de00-6316-46f5-bf18-b8b8a61092d7
- Random LolCat
- Random LolCat
- LolCat
- Display a new random LolCat image every 30 seconds
- 0f40cb20-c922-475d-8c56-c5a2998ee4d6
-
4644.276
596.147
258
197
-
4644.276
596.147
258
197
-
4644.276
596.147
- true