• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PolyMathOrg / PolyMath / 4385132063

pending completion
4385132063

push

github

GitHub
Merge pull request #316 from jecisc/divers-cleanings

2977 of 2977 new or added lines in 214 files covered. (100.0%)

19725 of 24212 relevant lines covered (81.47%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.05
/src/Math-Numerical/PMSimplexOptimizer.class.st
1
Class {
2
        #name : #PMSimplexOptimizer,
3
        #superclass : #PMFunctionOptimizer,
4
        #instVars : [
5
                'worstVector'
6
        ],
7
        #category : #'Math-Numerical-Math-FunctionIterator'
8
}
9

10
{ #category : #information }
11
PMSimplexOptimizer class >> defaultPrecision [
3✔
12
                "Private"
3✔
13
        ^PMFloatingPointMachine new defaultNumericalPrecision * 1000
3✔
14
]
3✔
15

16
{ #category : #operation }
17
PMSimplexOptimizer >> buildInitialSimplex [
3✔
18
        "Private"
3✔
19

3✔
20
        | projectedFunction finder partialResult |
3✔
21
        projectedFunction := PMProjectedOneVariableFunction
3✔
22
                                function: functionBlock.
3✔
23
        finder := PMOneVariableFunctionOptimizer forOptimizer: self.
3✔
24
        finder setFunction: projectedFunction.
3✔
25
        [bestPoints size < (result size + 1)] whileTrue:
3✔
26
                        [projectedFunction
3✔
27
                                setArgument: result;
3✔
28
                                bumpIndex.
3✔
29
                        partialResult := finder
3✔
30
                                                reset;
3✔
31
                                                evaluate.
3✔
32
                        bestPoints add: (optimizingPointClass
3✔
33
                                                vector: (projectedFunction argumentWith: partialResult)
3✔
34
                                                function: functionBlock)]
3✔
35
]
3✔
36

37
{ #category : #initialization }
38
PMSimplexOptimizer >> computeInitialValues [
3✔
39
        bestPoints
3✔
40
                add: (optimizingPointClass vector: result function: functionBlock).
3✔
41
        self buildInitialSimplex.
3✔
42
        worstVector := bestPoints removeLast position
3✔
43
]
3✔
44

45
{ #category : #operation }
46
PMSimplexOptimizer >> computePrecision [
3✔
47
                "Private"
3✔
48
        | functionValues bestFunctionValue |
3✔
49
        functionValues := bestPoints collect: [ :each | each value].
3✔
50
        bestFunctionValue := functionValues removeFirst.
3✔
51
        ^functionValues inject: 0
3✔
52
                                        into: [ :max :each | ( self precisionOf: ( each - bestFunctionValue) abs relativeTo: bestFunctionValue abs) max: max]
3✔
53
]
3✔
54

55
{ #category : #operation }
56
PMSimplexOptimizer >> contract [
3✔
57
        "Private"
3✔
58

3✔
59
        | bestVector oldVectors |
3✔
60
        bestVector := bestPoints first position.
3✔
61
        oldVectors := OrderedCollection with: worstVector.
3✔
62
        [bestPoints size > 1] whileTrue: [oldVectors add: bestPoints removeLast position].
3✔
63
        oldVectors do: [:each | self contract: each around: bestVector].
3✔
64
        worstVector := bestPoints removeLast position.
3✔
65
        ^self computePrecision
3✔
66
]
3✔
67

68
{ #category : #operation }
69
PMSimplexOptimizer >> contract: aVector around: bestVector [
3✔
70
        "Private"
3✔
71

3✔
72
        bestPoints
3✔
73
                add: (optimizingPointClass vector: bestVector * 0.5 + (aVector * 0.5)
3✔
74
                                function: functionBlock)
3✔
75
]
3✔
76

77
{ #category : #operation }
78
PMSimplexOptimizer >> evaluateIteration [
3✔
79
        | centerOfGravity newPoint nextPoint |
3✔
80
        centerOfGravity := (bestPoints inject: ((worstVector copy)
3✔
81
                                                atAllPut: 0;
3✔
82
                                                yourself)
3✔
83
                                into: [:sum :each | each position + sum]) * (1 / bestPoints size).
3✔
84
        newPoint := optimizingPointClass vector: 2 * centerOfGravity - worstVector
3✔
85
                                function: functionBlock.
3✔
86
        (newPoint betterThan: bestPoints first)
3✔
87
                ifTrue:
3✔
88
                        [nextPoint := optimizingPointClass
3✔
89
                                                vector: newPoint position * 2 - centerOfGravity
3✔
90
                                                function: functionBlock.
3✔
91
                        (nextPoint betterThan: newPoint) ifTrue: [newPoint := nextPoint]]
3✔
92
                ifFalse:
3✔
93
                        [newPoint := optimizingPointClass
3✔
94
                                                vector: centerOfGravity * 0.666667 + (worstVector * 0.333333)
3✔
95
                                                function: functionBlock.
3✔
96
                        (newPoint betterThan: bestPoints first) ifFalse: [^self contract]].
3✔
97
        worstVector := bestPoints removeLast position.
3✔
98
        bestPoints add: newPoint.
3✔
99
        result := bestPoints first position.
3✔
100
        ^self computePrecision
3✔
101
]
3✔
102

103
{ #category : #display }
104
PMSimplexOptimizer >> printOn: aStream [
×
105
        super printOn: aStream.
×
106
        aStream cr.
×
107
        worstVector printOn: aStream
×
108
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc