File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -18,3 +18,27 @@ AISzymkiewiczSimpsonCoefficientTest >> testSzymkiewiczSimpsonDistanceTo [
1818
1919 self assert: (metric distanceBetween: #( 12 34 56 7 2 3 ) asSet and : #( 3 5 43 ) asSet) closeTo: 0.33333333333 .
2020]
21+
22+ { #category : ' tests' }
23+ AISzymkiewiczSimpsonCoefficientTest >> testEmptySets [
24+ " Checks that the Szymkiewicz-Simpson coefficient for empty sets is 1.0."
25+ | metric |
26+ metric := AISzymkiewiczSimpsonDistance new .
27+ self assert: (metric distanceBetween: #() asSet and : #() asSet) equals: 1.0 .
28+ ]
29+
30+ { #category : ' tests' }
31+ AISzymkiewiczSimpsonCoefficientTest >> testIdenticalSets [
32+ " Checks that the Szymkiewicz-Simpson coefficient for identical sets is 1.0."
33+ | metric |
34+ metric := AISzymkiewiczSimpsonDistance new .
35+ self assert: (metric distanceBetween: #(1 2 3) asSet and : #(1 2 3) asSet) equals: 1.0 .
36+ ]
37+
38+ { #category : ' tests' }
39+ AISzymkiewiczSimpsonCoefficientTest >> testDisjointSets [
40+ " Checks that the Szymkiewicz-Simpson coefficient for disjoint sets is 0.0."
41+ | metric |
42+ metric := AISzymkiewiczSimpsonDistance new .
43+ self assert: (metric distanceBetween: #(1 2 3) asSet and : #(4 5 6) asSet) equals: 0.0 .
44+ ]
Original file line number Diff line number Diff line change @@ -12,10 +12,15 @@ Class {
1212}
1313
1414{ #category : ' api' }
15- AISzymkiewiczSimpsonDistance >> distanceBetween: aSet and : anotherSet [
15+ AISzymkiewiczSimpsonDistance >> distanceBetween: firstSet and : secondSet [
1616
1717 | intersection minSize |
18- intersection := (aSet intersection: anotherSet ) size.
19- minSize := aSet size min: anotherSet size.
20- ^ (intersection / minSize) asFloat
18+
19+ (firstSet isEmpty and : [ secondSet isEmpty ]) ifTrue: [ ^ 1.0 ].
20+
21+ intersection := firstSet intersection: secondSet.
22+ minSize := (firstSet size min: secondSet size).
23+ minSize = 0 ifTrue: [ ^ 0.0 ].
24+
25+ ^ intersection size / minSize
2126]
You can’t perform that action at this time.
0 commit comments