Skip to content
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
13 changes: 13 additions & 0 deletions src/Math-CompatibilityUpToPharo11/Float.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Extension { #name : #Float }

{ #category : #'*Math-CompatibilityUpToPharo11' }
Float class >> machineEpsilon [
"Answer the machine epsilon or macheps, defined by wikipedia asCalypsoItemContext
https://en.wikipedia.org/wiki/Machine_epsilon

*an upper bound on the relative approximation error due to rounding in floating point arithmetic*

Compute it as the difference between 1.0 and previous representable value"

^1.0 timesTwoPower: 1 - self precision
]
12 changes: 6 additions & 6 deletions src/Math-TSNE/PMTSNE.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PMTSNE class >> entropyOf: distanceVector andPRow: pVector withBeta: beta [

| pVectorTemp sumP entropy |
pVectorTemp := (-1 * distanceVector * beta) exp.
sumP := pVectorTemp sum max: (Float epsilon).
sumP := pVectorTemp sum max: (Float machineEpsilon).
entropy := sumP ln + (beta * (distanceVector * pVectorTemp) / sumP).
pVector copyFrom: (pVectorTemp / sumP).
^ entropy
Expand Down Expand Up @@ -189,9 +189,9 @@ PMTSNE >> computeGradient [
| num sumNum pq dY tmp yiDiff |
"Calculates num and q"
num := self computeLowDimensionalStudentT.
sumNum := num sum sum max: (Float epsilon).
sumNum := num sum sum max: (Float machineEpsilon).
q := num collect: [:element |
(element / sumNum) max: (Float epsilon)
(element / sumNum) max: (Float machineEpsilon)
].

pq := p - q.
Expand All @@ -215,9 +215,9 @@ PMTSNE >> computeLowDimensionalAffinities [

| num sumNum |
num := self computeLowDimensionalStudentT.
sumNum := num sum sum max: (Float epsilon).
sumNum := num sum sum max: (Float machineEpsilon).
q := num collect: [:element |
(element / sumNum) max: (Float epsilon)
(element / sumNum) max: (Float machineEpsilon)
].
^ q
]
Expand Down Expand Up @@ -245,7 +245,7 @@ PMTSNE >> computePValues [
sumP := p sum sum.
p := p collect: [ :element |
"4 is for early exaggeration, will be removed after 100 iterations"
(element / sumP * 4) asFloat max: (Float epsilon).
(element / sumP * 4) asFloat max: (Float machineEpsilon).
].
^ p
]
Expand Down