Skip to content

Commit 9d01092

Browse files
committed
Merge branch 'random-failing-tests' into use-pharo-constants
2 parents 6f35e68 + a697e14 commit 9d01092

14 files changed

+448
-382
lines changed

src/Math-Core-Process/PMIterativeProcess.class.st

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ PMIterativeProcess >> initialize [
8484
super initialize.
8585

8686
desiredPrecision := self class defaultPrecision.
87-
maximumIterations := self class defaultMaximumIterations.
88-
^ self
87+
maximumIterations := self class defaultMaximumIterations
8988
]
9089

9190
{ #category : #operation }

src/Math-FunctionFit/PMAnotherChromosomeManager.class.st

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Class {
88
#instVars : [
99
'hammersley',
1010
'rateOfLC',
11-
'rateOfEir'
11+
'rateOfEir',
12+
'randomGenerator'
1213
],
1314
#classVars : [
1415
'Primes'
@@ -33,28 +34,29 @@ PMAnotherChromosomeManager class >> integerDigitsFor: anInteger base: aBase [
3334
]
3435

3536
{ #category : #utilities }
36-
PMAnotherChromosomeManager class >> numberOfHamersleyPoints: n dimension: d randomized: aBoolean [
37+
PMAnotherChromosomeManager class >> numberOfHamersleyPoints: n dimension: d randomGenerator: randomGenerator [
3738
"a bit randomized "
38-
| dist randomNumberGenerator |
39+
40+
| dist |
3941
dist := 1.0 / n.
40-
randomNumberGenerator := Random new.
41-
42-
^(1 to: n) collect: [ :number |
43-
(1 to: d) collect: [ :dim |
44-
(dim=1)
45-
ifTrue: [ aBoolean
46-
ifTrue: [ (number/n) - (randomNumberGenerator nextBetween: 0 and: dist) ]
47-
ifFalse: [ number/n ] ]
48-
ifFalse: [ |sum prime|
49-
sum := 0.
50-
prime := Primes at: dim - 1.
51-
52-
(self integerDigitsFor: number base: prime) reverse withIndexDo: [ :i :index |
53-
sum := i / (prime raisedToInteger: index) + sum ].
54-
55-
aBoolean
56-
ifTrue: [ sum + (randomNumberGenerator nextBetween: 0 and: dist) ]
57-
ifFalse: [ sum ] ] ]].
42+
43+
^ (1 to: n) collect: [ :number |
44+
(1 to: d) collect: [ :dim |
45+
dim = 1
46+
ifTrue: [
47+
randomGenerator
48+
ifNotNil: [ number / n - (randomGenerator nextBetween: 0 and: dist) ]
49+
ifNil: [ number / n ] ]
50+
ifFalse: [
51+
| sum prime |
52+
sum := 0.
53+
prime := Primes at: dim - 1.
54+
55+
(self integerDigitsFor: number base: prime) reverse withIndexDo: [ :i :index | sum := i / (prime raisedToInteger: index) + sum ].
56+
57+
randomGenerator
58+
ifNotNil: [ sum + (randomGenerator nextBetween: 0 and: dist) ]
59+
ifNil: [ sum ] ] ] ]
5860
]
5961

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

109111
{ #category : #initialization }
110112
PMAnotherChromosomeManager >> initialize [
111-
super initialize .
112-
populationSize :=100.
113-
hammersley :=true.
114-
rateOfEir :=0.16.
115-
rateOfLC:=0.29.
116-
rateOfMutation :=0.4.
117-
rateOfCrossover :=0.15.
118-
Primes ifNil:[Primes :=Integer primesUpTo: 500]. "sufficient for up to 95 dimensions (parameters)"
113+
114+
super initialize.
115+
populationSize := 100.
116+
hammersley := true.
117+
rateOfEir := 0.16.
118+
rateOfLC := 0.29.
119+
rateOfMutation := 0.4.
120+
rateOfCrossover := 0.15.
121+
Primes ifNil: [ Primes := Integer primesUpTo: 500 ] "sufficient for up to 95 dimensions (parameters)"
119122
]
120123

121124
{ #category : #information }
@@ -205,16 +208,29 @@ PMAnotherChromosomeManager >> process: aChromosome1 and: aChromosome2 [
205208
add: (self clone: aChromosome2)]]]]
206209
]
207210

211+
{ #category : #accessing }
212+
PMAnotherChromosomeManager >> randomGenerator [
213+
214+
^ randomGenerator
215+
]
216+
217+
{ #category : #accessing }
218+
PMAnotherChromosomeManager >> randomGenerator: anObject [
219+
220+
randomGenerator := anObject
221+
]
222+
208223
{ #category : #private }
209224
PMAnotherChromosomeManager >> randomRangeAt: aPosition [
210225
^(range at: aPosition )*(self smallDistribution )
211226
]
212227

213228
{ #category : #operation }
214229
PMAnotherChromosomeManager >> randomizePopulation [
215-
hammersley ifFalse: [^super randomizePopulation ].
216-
population :=self class numberOfHamersleyPoints: populationSize dimension: origin size randomized: true.
217-
population := population collect: [:aChr| aChr *range +origin ]
230+
231+
hammersley ifFalse: [ ^ super randomizePopulation ].
232+
population := self class numberOfHamersleyPoints: populationSize dimension: origin size randomGenerator: (self randomGenerator ifNil: [ Random new ]).
233+
population := population collect: [ :aChr | aChr * range + origin ]
218234
]
219235

220236
{ #category : #accessing }

src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ PMAnotherGeneticOptimizer >> computePrecision: whateverData [ "can be changed t
9696

9797
{ #category : #operation }
9898
PMAnotherGeneticOptimizer >> evaluate [
99-
^Cursor wait showWhile: [super evaluate]
99+
100+
^ Cursor wait showWhile: [ super evaluate ]
100101
]
101102

102103
{ #category : #operation }
@@ -130,12 +131,12 @@ statistics :=false
130131

131132
{ #category : #operation }
132133
PMAnotherGeneticOptimizer >> initializeIterations [
133-
bestPoints size>=chromosomeManager populationSize
134-
ifTrue: [bestPoints := bestPoints copyFrom: 1 to: (bestPoints size // 2 max: 1)].
134+
135+
bestPoints size >= chromosomeManager populationSize ifTrue: [ bestPoints := bestPoints copyFrom: 1 to: (bestPoints size // 2 max: 1) ].
135136
super initializeIterations.
136-
bestValueHistory:=OrderedCollection new.
137-
worstValueHistory:=OrderedCollection new.
138-
whateverHistory:=OrderedCollection new
137+
bestValueHistory := OrderedCollection new.
138+
worstValueHistory := OrderedCollection new.
139+
whateverHistory := OrderedCollection new
139140
]
140141

141142
{ #category : #operation }

src/Math-FunctionFit/PMErrorMinimizer.class.st

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PMErrorMinimizer class >> function: aBlock data: aCollection [
2929

3030
{ #category : #accessing }
3131
PMErrorMinimizer >> maxFunction [
32-
"The number of data partitions used."
33-
^dataHolder size
32+
"The number of data partitions used."
33+
34+
^ dataHolder size
3435
]

src/Math-FunctionFit/PMFunctionFit.class.st

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ PMFunctionFit >> accumulate: aWeightedPoint [
4343

4444
{ #category : #operation }
4545
PMFunctionFit >> computeChanges [
46-
^[super computeChanges]on: PMSingularMatrixError do:[:signal|signal messageText: 'singular error matrix, set better parameters'.signal pass]
46+
47+
^ [ super computeChanges ]
48+
on: PMSingularMatrixError
49+
do: [ :signal |
50+
signal messageText: 'singular error matrix, set better parameters'.
51+
signal pass ]
4752
]
4853

4954
{ #category : #information }

src/Math-FunctionFit/PMGeneralFunctionFit.class.st

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Class {
1010
#name : #PMGeneralFunctionFit,
1111
#superclass : #Object,
1212
#instVars : [
13-
'go',
1413
'manager',
1514
'errorFunction',
1615
'result',
1716
'firstResult',
1817
'verbose',
1918
'data',
20-
'dataTruncated'
19+
'dataTruncated',
20+
'geneticOptimizer'
2121
],
2222
#category : #'Math-FunctionFit'
2323
}
@@ -100,8 +100,9 @@ PMGeneralFunctionFit >> evaluate [
100100
ff parameters ] onErrorDo: [
101101
verbose ifTrue: [ self inform: 'ErrorMinimizer was not successful' ].
102102
nil ].
103-
firstResult ifNotNil: [ go addPointAt: firstResult ].
104-
firstResult := go evaluate.
103+
104+
firstResult ifNotNil: [ geneticOptimizer addPointAt: firstResult ].
105+
firstResult := geneticOptimizer evaluate.
105106
self errorType = #squared ifTrue: [ ff := PMFunctionFit function: errorFunction function data: errorFunction data ].
106107
ff parameters: firstResult.
107108
ff desiredPrecision: Float machineEpsilon.
@@ -169,16 +170,19 @@ errorFunction function: aBlock
169170

170171
{ #category : #initialization }
171172
PMGeneralFunctionFit >> initialize [
172-
super initialize .
173-
errorFunction :=PMErrorOfParameterFunction new.
174-
manager :=PMAnotherChromosomeManager new.
175-
manager populationSize: 50.
176-
go :=PMAnotherGeneticOptimizer minimizingFunction: errorFunction .
177-
go chromosomeManager: manager.
178-
go maximumIterations: 170.
179-
self errorType: #squared.
180-
verbose:=false.
181-
dataTruncated :=false
173+
174+
super initialize.
175+
errorFunction := PMErrorOfParameterFunction new.
176+
manager := PMAnotherChromosomeManager new
177+
populationSize: 50;
178+
yourself.
179+
geneticOptimizer := (PMAnotherGeneticOptimizer minimizingFunction: errorFunction)
180+
chromosomeManager: manager;
181+
maximumIterations: 170;
182+
yourself.
183+
self errorType: #squared.
184+
verbose := false.
185+
dataTruncated := false
182186
]
183187

184188
{ #category : #accessing }
@@ -190,7 +194,7 @@ PMGeneralFunctionFit >> manager [
190194
{ #category : #accessing }
191195
PMGeneralFunctionFit >> maximumIterations: anInteger [
192196
"default is 170."
193-
go maximumIterations: anInteger.
197+
geneticOptimizer maximumIterations: anInteger.
194198
^anInteger
195199
]
196200

@@ -211,7 +215,7 @@ manager range: (array2 - array1)
211215
{ #category : #accessing }
212216
PMGeneralFunctionFit >> optimizer [
213217
"if you want to change parameters of AnotherGeneticOptimizer not directly available in GeneralFunctionFit"
214-
^go
218+
^geneticOptimizer
215219
]
216220

217221
{ #category : #accessing }
@@ -225,7 +229,7 @@ manager populationSize: anInteger .
225229
{ #category : #accessing }
226230
PMGeneralFunctionFit >> precision [
227231
"not really useful to look at, you might better look at #error"
228-
^go precision
232+
^geneticOptimizer precision
229233
]
230234

231235
{ #category : #printing }
@@ -234,7 +238,7 @@ PMGeneralFunctionFit >> printOn: aStream [
234238
nextPutAll: 'a ';
235239
nextPutAll: self class name;
236240
nextPut: $(;
237-
print: go;
241+
print: geneticOptimizer;
238242
nextPutAll: ' with data of size: ';
239243
print: data size .
240244
dataTruncated ifTrue:
@@ -276,7 +280,7 @@ self data: data
276280
PMGeneralFunctionFit >> resetResult [
277281
result :=nil.
278282
firstResult :=nil.
279-
go resetBestPoints
283+
geneticOptimizer resetBestPoints
280284
]
281285

282286
{ #category : #accessing }

src/Math-Numerical/PMFunctionOptimizer.class.st

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ PMFunctionOptimizer >> initialValue: aVector [
6060

6161
{ #category : #initialization }
6262
PMFunctionOptimizer >> initialize [
63-
"Private"
64-
bestPoints := SortedCollection sortBlock: [ :a :b | a betterThan: b].
65-
^super initialize
63+
"Private"
64+
65+
super initialize.
66+
bestPoints := SortedCollection sortBlock: [ :a :b | a betterThan: b ]
6667
]
6768

6869
{ #category : #initialization }

0 commit comments

Comments
 (0)