• 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

25.71
/src/Math-FunctionFit/PMFunctionFit.class.st
1
"
2
FunctionFit fits a function to some data. the data has to be a collection of points x@f(x). the fitting minimizes the squared error.
3
f:=[:x :a :b|a*x / (b+x)].
4
col:=(1 to: 20)collect: [:i|i@(f cull: i cull: 2 cull: 0.4) ].
5
fit:= FunctionFit function: f data: col .
6
fit evaluate . 
7
fit result parameters .   --->  #(1.9999999999999998 0.39999999999999863)
8
"
9
Class {
10
        #name : #PMFunctionFit,
11
        #superclass : #PMLeastSquareFit,
12
        #category : #'Math-FunctionFit'
13
}
14

15
{ #category : #creation }
16
PMFunctionFit class >> function: aBlock data: aDataHolder [
3✔
17
^super points: aDataHolder  function:  (PMSimpleParameterFunction function: aBlock)
3✔
18
]
3✔
19

20
{ #category : #creation }
21
PMFunctionFit class >> histogram: aHistogram distributionClass: aProbabilityDensityFunctionClass [
×
22
^self shouldNotImplement
×
23
]
×
24

25
{ #category : #creation }
26
PMFunctionFit class >> points: aDataHolder function: aBlock [
×
27
^self shouldNotImplement
×
28
]
×
29

30
{ #category : #operation }
31
PMFunctionFit >> accumulate: aWeightedPoint [
3✔
32
        | f g |
3✔
33
        f := result valueAndGradient: aWeightedPoint xValue.
3✔
34
        g := f last.
3✔
35
        f := f first.
3✔
36
        f isNaN ifTrue:[^self].
3✔
37
        constants accumulate: g * ( ( aWeightedPoint yValue - f) * aWeightedPoint weight).
3✔
38
        1 to: g size do:
3✔
39
                [ :k |
3✔
40
                  ( equations at: k) accumulate: g * ( ( g at: k) * aWeightedPoint weight).
3✔
41
                ]
3✔
42
]
3✔
43

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

49
{ #category : #information }
50
PMFunctionFit >> computeChiSquare [
×
51
"does not make much sense to use in most cases, but then, the superclass has it and if its here, the calculation should be correct and the superclass's way does not work here eg because of the way DataHolder>>pointsAndErrorsDo: works"
×
52
        chiSquare := 0.
×
53
        degreeOfFreedom := self numberOfFreeParameters negated.
×
54
        dataHolder pointsAndErrorsDo:
×
55
                [ :each | |y|
×
56
                  y :=result value: each xValue .
×
57
                  (y closeTo: 0) ifFalse:
×
58
                          [chiSquare := (each yValue - y) squared / y abs +chiSquare  .
×
59
                          degreeOfFreedom := degreeOfFreedom + 1].
×
60
                ]
×
61
]
×
62

×
63
{ #category : #initialization }
×
64
PMFunctionFit >> initialize: aDataHolder data: aParametricFunction [
×
65
        (aDataHolder isCollection and: [aDataHolder allSatisfy: [:aPoint| aPoint isPoint]])
×
66
                        ifTrue:  [dataHolder:= aDataHolder as: PMDataHolder ]
×
67
                        ifFalse: [self error: 'DataHolder must be a Collection of Points'].
×
68
        dataHolder size < aParametricFunction parameterSize ifTrue:[self error: 'Problem is underdeterminated. aDataHolders size to small'].
×
69
        result := aParametricFunction.
×
70
        self finalizeIterations.
×
71
        ^self
×
72
]
×
73

×
74
{ #category : #information }
×
75
PMFunctionFit >> parameters [
×
76
^result parameters
×
77
]
×
78

×
79
{ #category : #initialization }
×
80
PMFunctionFit >> parameters: indexableCollection [
×
81

×
82
        indexableCollection do: [ :e |
×
83
                (e closeTo: 0.0) ifTrue: [
×
84
                        self error: 'parameters shouldnt be set to practically zero' ] ].
×
85
        result parameters: indexableCollection.
×
86
        self finalizeIterations
×
87
]
×
88

×
89
{ #category : #printing }
×
90
PMFunctionFit >> printOn: aStream [
×
91
        super printOn: aStream.
×
92
        aStream nextPutAll: ' for '.
×
93
        result printOn: aStream .
×
94
        aStream nextPutAll: ' with data of size: '; print: dataHolder size
×
95
]
×
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

© 2025 Coveralls, Inc