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
6 changes: 3 additions & 3 deletions src/BaselineOfPolyMath/BaselineOfPolyMath.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ BaselineOfPolyMath >> baseline: spec [
package: 'Math-Complex' with: [ spec requires: #( 'Math-Numerical' 'Math-Polynomials' ) ];
package: 'Math-Helpers';
package: 'Math-Distributions' with: [ spec requires: #( 'MathVectorMatrix' 'Math-Quantile' 'Math-Core-Process' ) ];
package: 'Math-Core-Process' with: [ spec requires: #( 'Math-Helpers' ) ];
package: 'Math-Core-Process';
package: 'Math-Numerical'
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Helpers' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
'Math-Series' ) ];
package: 'Math-Polynomials'
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Helpers' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
'Math-Series' ) ];
package: 'Math-FastFourierTransform' with: [ spec requires: #( 'Math-Complex' ) ];
package: 'Math-FunctionFit'
Expand Down
6 changes: 6 additions & 0 deletions src/Math-CompatibilityUpToPharo11/Float.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Extension { #name : #Float }

{ #category : #'*Math-CompatibilityUpToPharo11' }
Float class >> defaultComparisonPrecision [

^ self machineEpsilon sqrt
]

{ #category : #'*Math-CompatibilityUpToPharo11' }
Float class >> machineEpsilon [
"Answer the machine epsilon or macheps, defined by wikipedia asCalypsoItemContext
Expand Down
24 changes: 14 additions & 10 deletions src/Math-Core-Process/PMIterativeProcess.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ PMIterativeProcess class >> defaultMaximumIterations [
{ #category : #default }
PMIterativeProcess class >> defaultPrecision [
"Private - Answers the default precision for newly created instances."
^PMFloatingPointMachine new defaultNumericalPrecision

self flag: #todo. "In Pharo 12 the default comparision precision of Float will be improved. When Pharo 12 will be the minimal version of Polymath we can use `Float defaultComparisonPrecision"
^ Float machineEpsilon sqrt
]

{ #category : #initialization }
Expand Down Expand Up @@ -82,8 +84,7 @@ PMIterativeProcess >> initialize [
super initialize.

desiredPrecision := self class defaultPrecision.
maximumIterations := self class defaultMaximumIterations.
^ self
maximumIterations := self class defaultMaximumIterations
]

{ #category : #operation }
Expand All @@ -99,10 +100,13 @@ PMIterativeProcess >> iterations [

{ #category : #private }
PMIterativeProcess >> limitedSmallValue: aNumber [
"Private - prevent aNumber from being smaller in absolute value than a small number."
^aNumber abs < PMFloatingPointMachine new smallNumber
ifTrue: [ PMFloatingPointMachine new smallNumber]
ifFalse:[ aNumber]
"Private - prevent aNumber from being smaller in absolute value than a small."

| smallestAccepted |
smallestAccepted := Float fmin sqrt.
^ aNumber abs < smallestAccepted
ifTrue: [ smallestAccepted ]
ifFalse: [ aNumber ]
]

{ #category : #initialization }
Expand All @@ -122,9 +126,9 @@ PMIterativeProcess >> precision [
{ #category : #information }
PMIterativeProcess >> precisionOf: aNumber1 relativeTo: aNumber2 [

^aNumber2 > PMFloatingPointMachine new defaultNumericalPrecision
ifTrue: [ aNumber1 / aNumber2]
ifFalse:[ aNumber1]
^ aNumber2 > Float defaultComparisonPrecision
ifTrue: [ aNumber1 / aNumber2 ]
ifFalse: [ aNumber1 ]
]

{ #category : #information }
Expand Down
17 changes: 10 additions & 7 deletions src/Math-Distributions/PMFisherTippettDistribution.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PMFisherTippettDistribution >> distributionValue: aNumber [
the receiver with a value lower than or equal to aNumber."
| arg |
arg := ( aNumber - alpha) / beta.
arg := arg < PMFloatingPointMachine new largestExponentArgument negated
arg := arg < Float fmax ln negated
ifTrue: [ ^0]
ifFalse:[arg negated exp].
^arg negated exp
Expand Down Expand Up @@ -126,14 +126,17 @@ PMFisherTippettDistribution >> standardDeviation [

{ #category : #information }
PMFisherTippettDistribution >> value: aNumber [
"Answers the probability that a random variable distributed according to the receiver
"Answers the probability that a random variable distributed according to the receiver
gives a value between aNumber and aNumber + espilon (infinitesimal interval)."

| arg |
arg := ( aNumber - alpha) / beta.
arg := arg > PMFloatingPointMachine new largestExponentArgument ifTrue: [ ^0]
ifFalse:[arg negated exp + arg].
^arg > PMFloatingPointMachine new largestExponentArgument ifTrue: [ 0]
ifFalse:[ arg negated exp / beta]
arg := aNumber - alpha / beta.
arg := arg > Float fmax ln
ifTrue: [ ^ 0 ]
ifFalse: [ arg negated exp + arg ].
^ arg > Float fmax ln
ifTrue: [ 0 ]
ifFalse: [ arg negated exp / beta ]
]

{ #category : #information }
Expand Down
4 changes: 2 additions & 2 deletions src/Math-Distributions/PMIncompleteBetaFunction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PMIncompleteBetaFunction >> evaluateFraction: aNumber [
fraction setParameter: alpha1 second: alpha2 ].
fraction setArgument: aNumber.
^ (PMContinuedFraction server: fraction)
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
desiredPrecision: Float defaultComparisonPrecision;
evaluate
]

Expand All @@ -38,7 +38,7 @@ PMIncompleteBetaFunction >> evaluateInverseFraction: aNumber [
inverseFraction setParameter: alpha2 second: alpha1 ].
inverseFraction setArgument: 1 - aNumber.
^ (PMContinuedFraction server: inverseFraction)
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
desiredPrecision: Float defaultComparisonPrecision;
evaluate
]

Expand Down
4 changes: 2 additions & 2 deletions src/Math-Distributions/PMIncompleteGammaFunction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PMIncompleteGammaFunction >> evaluateFraction: aNumber [
fraction setParameter: alpha ].
fraction setArgument: aNumber.
^ (PMContinuedFraction server: fraction)
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
desiredPrecision: Float defaultComparisonPrecision;
evaluate
]

Expand All @@ -36,7 +36,7 @@ PMIncompleteGammaFunction >> evaluateSeries: aNumber [
series setParameter: alpha ].
series setArgument: aNumber.
^ (PMInfiniteSeries server: series)
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
desiredPrecision: Float defaultComparisonPrecision;
evaluate
]

Expand Down
80 changes: 48 additions & 32 deletions src/Math-FunctionFit/PMAnotherChromosomeManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Class {
#instVars : [
'hammersley',
'rateOfLC',
'rateOfEir'
'rateOfEir',
'randomGenerator'
],
#classVars : [
'Primes'
Expand All @@ -33,28 +34,29 @@ PMAnotherChromosomeManager class >> integerDigitsFor: anInteger base: aBase [
]

{ #category : #utilities }
PMAnotherChromosomeManager class >> numberOfHamersleyPoints: n dimension: d randomized: aBoolean [
PMAnotherChromosomeManager class >> numberOfHamersleyPoints: n dimension: d randomGenerator: randomGenerator [
"a bit randomized "
| dist randomNumberGenerator |

| dist |
dist := 1.0 / n.
randomNumberGenerator := Random new.

^(1 to: n) collect: [ :number |
(1 to: d) collect: [ :dim |
(dim=1)
ifTrue: [ aBoolean
ifTrue: [ (number/n) - (randomNumberGenerator nextBetween: 0 and: dist) ]
ifFalse: [ number/n ] ]
ifFalse: [ |sum prime|
sum := 0.
prime := Primes at: dim - 1.

(self integerDigitsFor: number base: prime) reverse withIndexDo: [ :i :index |
sum := i / (prime raisedToInteger: index) + sum ].

aBoolean
ifTrue: [ sum + (randomNumberGenerator nextBetween: 0 and: dist) ]
ifFalse: [ sum ] ] ]].

^ (1 to: n) collect: [ :number |
(1 to: d) collect: [ :dim |
dim = 1
ifTrue: [
randomGenerator
ifNotNil: [ number / n - (randomGenerator nextBetween: 0 and: dist) ]
ifNil: [ number / n ] ]
ifFalse: [
| sum prime |
sum := 0.
prime := Primes at: dim - 1.

(self integerDigitsFor: number base: prime) reverse withIndexDo: [ :i :index | sum := i / (prime raisedToInteger: index) + sum ].

randomGenerator
ifNotNil: [ sum + (randomGenerator nextBetween: 0 and: dist) ]
ifNil: [ sum ] ] ] ]
]

{ #category : #'instance creation' }
Expand Down Expand Up @@ -108,14 +110,15 @@ PMAnotherChromosomeManager >> eirCrossover: aChromosome1 and: aChromosome2 [

{ #category : #initialization }
PMAnotherChromosomeManager >> initialize [
super initialize .
populationSize :=100.
hammersley :=true.
rateOfEir :=0.16.
rateOfLC:=0.29.
rateOfMutation :=0.4.
rateOfCrossover :=0.15.
Primes ifNil:[Primes :=Integer primesUpTo: 500]. "sufficient for up to 95 dimensions (parameters)"

super initialize.
populationSize := 100.
hammersley := true.
rateOfEir := 0.16.
rateOfLC := 0.29.
rateOfMutation := 0.4.
rateOfCrossover := 0.15.
Primes ifNil: [ Primes := Integer primesUpTo: 500 ] "sufficient for up to 95 dimensions (parameters)"
]

{ #category : #information }
Expand Down Expand Up @@ -205,16 +208,29 @@ PMAnotherChromosomeManager >> process: aChromosome1 and: aChromosome2 [
add: (self clone: aChromosome2)]]]]
]

{ #category : #accessing }
PMAnotherChromosomeManager >> randomGenerator [

^ randomGenerator
]

{ #category : #accessing }
PMAnotherChromosomeManager >> randomGenerator: anObject [

randomGenerator := anObject
]

{ #category : #private }
PMAnotherChromosomeManager >> randomRangeAt: aPosition [
^(range at: aPosition )*(self smallDistribution )
]

{ #category : #operation }
PMAnotherChromosomeManager >> randomizePopulation [
hammersley ifFalse: [^super randomizePopulation ].
population :=self class numberOfHamersleyPoints: populationSize dimension: origin size randomized: true.
population := population collect: [:aChr| aChr *range +origin ]

hammersley ifFalse: [ ^ super randomizePopulation ].
population := self class numberOfHamersleyPoints: populationSize dimension: origin size randomGenerator: (self randomGenerator ifNil: [ Random new ]).
population := population collect: [ :aChr | aChr * range + origin ]
]

{ #category : #accessing }
Expand Down
16 changes: 9 additions & 7 deletions src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Class {

{ #category : #information }
PMAnotherGeneticOptimizer class >> defaultPrecision [
^PMFloatingPointMachine new machinePrecision

^ Float machineEpsilon
]

{ #category : #'instance creation' }
Expand Down Expand Up @@ -95,7 +96,8 @@ PMAnotherGeneticOptimizer >> computePrecision: whateverData [ "can be changed t

{ #category : #operation }
PMAnotherGeneticOptimizer >> evaluate [
^Cursor wait showWhile: [super evaluate]

^ Cursor wait showWhile: [ super evaluate ]
]

{ #category : #operation }
Expand Down Expand Up @@ -129,12 +131,12 @@ statistics :=false

{ #category : #operation }
PMAnotherGeneticOptimizer >> initializeIterations [
bestPoints size>=chromosomeManager populationSize
ifTrue: [bestPoints := bestPoints copyFrom: 1 to: (bestPoints size // 2 max: 1)].

bestPoints size >= chromosomeManager populationSize ifTrue: [ bestPoints := bestPoints copyFrom: 1 to: (bestPoints size // 2 max: 1) ].
super initializeIterations.
bestValueHistory:=OrderedCollection new.
worstValueHistory:=OrderedCollection new.
whateverHistory:=OrderedCollection new
bestValueHistory := OrderedCollection new.
worstValueHistory := OrderedCollection new.
whateverHistory := OrderedCollection new
]

{ #category : #operation }
Expand Down
5 changes: 3 additions & 2 deletions src/Math-FunctionFit/PMErrorMinimizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PMErrorMinimizer class >> function: aBlock data: aCollection [

{ #category : #accessing }
PMErrorMinimizer >> maxFunction [
"The number of data partitions used."
^dataHolder size
"The number of data partitions used."

^ dataHolder size
]
7 changes: 6 additions & 1 deletion src/Math-FunctionFit/PMFunctionFit.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ PMFunctionFit >> accumulate: aWeightedPoint [

{ #category : #operation }
PMFunctionFit >> computeChanges [
^[super computeChanges]on: PMSingularMatrixError do:[:signal|signal messageText: 'singular error matrix, set better parameters'.signal pass]

^ [ super computeChanges ]
on: PMSingularMatrixError
do: [ :signal |
signal messageText: 'singular error matrix, set better parameters'.
signal pass ]
]

{ #category : #information }
Expand Down
Loading