Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up clustering #5

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Speed up clustering
This change has two goal. Reduce the usage of classes from Moose linear algebra. I'm using the infinite implementation of Float instead of AIUnlimited. And the second is to speed up the clustering but changing the order of comparison so that we cast less things.
  • Loading branch information
jecisc committed Jan 11, 2024
commit a9189cf3b5eeb2a8cf31dfb9ca9c1788e6ab0b61
2 changes: 1 addition & 1 deletion src/AI-HierarchicalClustering/AIClusteringData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AIClusteringData >> findMinimum [
"This method is written such that it uses primitives only."

| columnVector |
value := AIUnlimited positive.
value := Float infinity.
2
to: indices size
do:
Expand Down
14 changes: 7 additions & 7 deletions src/AI-HierarchicalClustering/AIClusteringVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ AIClusteringVector >> min [

{ #category : #accessing }
AIClusteringVector >> unsetAt: index [
super at: index put: AIUnlimited positive.
super at: index put: Float infinity.
found = index ifTrue: [ found := nil ]
]

{ #category : #private }
AIClusteringVector >> update [
min := AIUnlimited positive.
self
doWithIndex: [ :each :ind |
each < min
ifTrue: [ min := each.
found := ind ] ]

min := Float infinity.
self doWithIndex: [ :each :ind | "This was originally `each < min` but a lot of time we compare a float to an integer and it is faster to ask a float to compare itself to an integer than the other way around because it tries to cast the float as a fraction."
min >= each ifTrue: [
min := each.
found := ind ] ]
]
2 changes: 1 addition & 1 deletion src/AI-HierarchicalClustering/AICorrelationVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AICorrelationVector >> defaultElement [
AICorrelationVector >> min [

^(self reject: #isNil)
inject: AIUnlimited positive
inject: Float infinity
into: [:each :min | min min: each]
]

Expand Down