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

PolyMathOrg / PolyMath / 5083166661

pending completion
5083166661

push

github

GitHub
Merge branch 'master' into plot_pca

5606 of 5606 new or added lines in 220 files covered. (100.0%)

19619 of 24149 relevant lines covered (81.24%)

2.44 hits per line

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

30.67
/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

3✔
47
        ^ [ super computeChanges ]
3✔
48
                  on: PMSingularMatrixError
3✔
49
                  do: [ :signal |
3✔
50
                          signal messageText: 'singular error matrix, set better parameters'.
3✔
51
                          signal pass ]
3✔
52
]
3✔
53

54
{ #category : #information }
55
PMFunctionFit >> computeChiSquare [
×
56
"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"
×
57
        chiSquare := 0.
×
58
        degreeOfFreedom := self numberOfFreeParameters negated.
×
59
        dataHolder pointsAndErrorsDo:
×
60
                [ :each | |y|
×
61
                  y :=result value: each xValue .
×
62
                  (y closeTo: 0) ifFalse:
×
63
                          [chiSquare := (each yValue - y) squared / y abs +chiSquare  .
×
64
                          degreeOfFreedom := degreeOfFreedom + 1].
×
65
                ]
×
66
]
×
67

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

×
79
{ #category : #information }
×
80
PMFunctionFit >> parameters [
×
81
^result parameters
×
82
]
×
83

×
84
{ #category : #initialization }
×
85
PMFunctionFit >> parameters: indexableCollection [
×
86

×
87
        indexableCollection do: [ :e |
×
88
                (e closeTo: 0.0) ifTrue: [
×
89
                        self error: 'parameters shouldnt be set to practically zero' ] ].
×
90
        result parameters: indexableCollection.
×
91
        self finalizeIterations
×
92
]
×
93

×
94
{ #category : #printing }
×
95
PMFunctionFit >> printOn: aStream [
×
96
        super printOn: aStream.
×
97
        aStream nextPutAll: ' for '.
×
98
        result printOn: aStream .
×
99
        aStream nextPutAll: ' with data of size: '; print: dataHolder size
×
100
]
×
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