Skip to content

Commit

Permalink
Code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 3, 2023
1 parent b7313ae commit 4faf840
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/AI-KMeans/AIKMeans.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,16 @@ AIKMeans >> chooseRandomCentroid: aCollectionOfPoints [
"Choose a random point as centroids"
"The code is like that for performance. Do not rewrite it"

| min max pointDimension result |
| min max pointDimension centroid |
pointDimension := aCollectionOfPoints anyOne size.
result := Array new: pointDimension.
centroid := Array new: pointDimension.

1 to: pointDimension do: [ :i |
max := aCollectionOfPoints first at: i.
min := aCollectionOfPoints first at: i.

1 to: aCollectionOfPoints size do: [ :j |
| point coordinate |
point := aCollectionOfPoints at: j.
coordinate := point at: i.
max := max max: coordinate.
min := min min: coordinate. ].
result at: i put: (rand nextBetween: min and: max) ].
max := aCollectionOfPoints max: [ :arr | arr at: i ].
min := aCollectionOfPoints min: [ :arr | arr at: i ].
centroid at: i put: (rand nextBetween: min and: max) ].

^ result
^ centroid
]

{ #category : #training }
Expand Down

0 comments on commit 4faf840

Please sign in to comment.