• 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

77.0
/src/Math-Distributions/PMProbabilityDensity.class.st
1
Class {
2
        #name : #PMProbabilityDensity,
3
        #superclass : #Object,
4
        #instVars : [
5
                'flatGenerator'
6
        ],
7
        #category : #'Math-Distributions-Core'
8
}
9

10
{ #category : #information }
11
PMProbabilityDensity class >> distributionName [
×
12

×
13
        ^'Unknown distribution'
×
14
]
×
15

16
{ #category : #creation }
17
PMProbabilityDensity class >> fromHistogram: aHistogram [
×
18
        "Create an instance of the receiver with parameters estimated from the given histogram using best guesses. This method can be used to find the initial values for a fit. Default returns nil (must be implemented by subclass)."
×
19
        self flag: #todo. "Why not subclassResponsibility?"
×
20
        ^ nil
×
21
]
×
22

23
{ #category : #information }
24
PMProbabilityDensity >> acceptanceBetween: aNumber1 and: aNumber2 [
3✔
25
        "Answers the probability of observing a random variable distributed according to the receiver with a value larger than aNumber 1 and lower than or equal to aNumber2. "
3✔
26

3✔
27
        ^ (self distributionValue: aNumber2) - (self distributionValue: aNumber1)
3✔
28
]
3✔
29

30
{ #category : #information }
31
PMProbabilityDensity >> approximatedValueAndGradient: aNumber [
3✔
32
        "Private - gradients an Array containing the value of the receiver at aNumber and the gradient of the receiver's respective to the receiver's parameters evaluated at aNumber.
3✔
33
         The gradient is computed by approximation."
3✔
34
        | delta parameters dp gradient n |
3✔
35
        parameters := self parameters.
3✔
36
        n := parameters size.
3✔
37
        dp := self value: aNumber.
3✔
38
        delta := Array new: n.
3✔
39
        delta atAllPut: 0.
3✔
40
        gradient := PMVector new: n.
3✔
41
        1 to: n do:
3✔
42
                [ :k |
3✔
43
                  delta at: k put: ( parameters at: k) * 0.0001.
3✔
44
                  self changeParametersBy: delta.
3✔
45
                  gradient at: k put: ( ( ( self value: aNumber) - dp) / ( delta at: k)).
3✔
46
                  delta at: k put: ( delta at: k ) negated.
3✔
47
                  k > 1
3✔
48
                        ifTrue: [ delta at: ( k - 1) put: 0].
3✔
49
                ].
3✔
50
        self changeParametersBy: delta.
3✔
51
        ^Array with: dp with: gradient
3✔
52
]
3✔
53

54
{ #category : #information }
55
PMProbabilityDensity >> average [
56
        "Answer the average of the receiver."
57
        self subclassResponsibility
58
]
59

60
{ #category : #transformation }
61
PMProbabilityDensity >> changeParametersBy: aVector [
62
        self subclassResponsibility
63
]
64

65
{ #category : #creation }
66
PMProbabilityDensity >> distributionFunction [
×
67

×
68
        ^PMProbabilityDistributionFunction density: self
×
69
]
×
70

71
{ #category : #information }
72
PMProbabilityDensity >> distributionValue: aNumber [
73
        "Answers the probability of observing a random variable distributed according to the receiver with a value lower than or equal to aNumber."
74
        ^self subclassResponsibility
75
]
76

77
{ #category : #accessing }
78
PMProbabilityDensity >> flatGenerator: aGenerator [
×
79
        "To change the default generator (which by default is flat between 0 and 1).
×
80
        aGenerator should know how to answer floatValue."
×
81

×
82
        flatGenerator := aGenerator
×
83
]
×
84

85
{ #category : #initialization }
86
PMProbabilityDensity >> initialize [
3✔
87

3✔
88
        super initialize.
3✔
89
        flatGenerator := PMMitchellMooreGenerator new
3✔
90
]
3✔
91

92
{ #category : #information }
93
PMProbabilityDensity >> inverseDistributionValue: aNumber [
3✔
94
        "Answer the number whose distribution value is aNumber.
3✔
95
         NOTE: Subclass MUST NOT overwrite this method."
3✔
96
        ^(aNumber between: 0 and: 1)
3✔
97
                        ifTrue: [ self privateInverseDistributionValue: aNumber]
3✔
98
                        ifFalse:[ self error: 'Illegal argument for inverse distribution value']
3✔
99
]
3✔
100

101
{ #category : #information }
102
PMProbabilityDensity >> kurtosis [
103
        "Answer the kurtosis of the receiver.
104
        Must be implemented by subclass."
105

106
        self subclassResponsibility
107
]
108

109
{ #category : #information }
110
PMProbabilityDensity >> parameters [
111

112
        "Returns an Array containing the parameters of the distribution.
113
        It is used to print out the distribution and for fitting."
114

115
        self subclassResponsibility
116
]
117

118
{ #category : #display }
119
PMProbabilityDensity >> printOn: aStream [
3✔
120

3✔
121
        | params |
3✔
122
        aStream nextPutAll: self class distributionName.
3✔
123
        (params := self parameters) ifNotNil: [
3✔
124
                | first |
3✔
125
                first := true.
3✔
126
                aStream nextPut: $(.
3✔
127
                params do: [ :each |
3✔
128
                        first
3✔
129
                                ifTrue: [ first := false ]
3✔
130
                                ifFalse: [ aStream nextPut: $, ].
3✔
131
                        aStream space.
3✔
132
                        each printOn: aStream ].
3✔
133
                aStream nextPut: $) ]
3✔
134
]
3✔
135

136
{ #category : #private }
137
PMProbabilityDensity >> privateInverseDistributionValue: aNumber [
3✔
138
        "Private - Answer the number whose distribution is aNumber.
3✔
139
        NOTE: Subclass may overwrite this method for faster computation."
3✔
140
        ^( PMCDFNewtonZeroFinder function: [ :x | ( self distributionValue: x) - aNumber] derivative: self)
3✔
141
                initialValue: self average ; evaluate
3✔
142
]
3✔
143

144
{ #category : #information }
145
PMProbabilityDensity >> random [
×
146
        "Answer a random number distributed according to the receiver."
×
147
        ^self privateInverseDistributionValue: flatGenerator floatValue
×
148
]
×
149

150
{ #category : #information }
151
PMProbabilityDensity >> skewness [
152
        "Answer the skewness of the receiver.
153
         Must be implemented by subclass."
154

155
        self subclassResponsibility
156
]
157

158
{ #category : #information }
159
PMProbabilityDensity >> standardDeviation [
3✔
160
        "Answer the standard deviation of the receiver.
3✔
161
        NOTE: At least one of the methods variance or standardDeviation must be implemented by the subclass."
3✔
162
        ^self variance sqrt
3✔
163
]
3✔
164

165
{ #category : #information }
166
PMProbabilityDensity >> value: aNumber [
167
        "Answers the probability that a random variable distributed according to the receiver
168
        gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
169
        self subclassResponsibility
170
]
171

172
{ #category : #information }
173
PMProbabilityDensity >> valueAndGradient: aNumber [
3✔
174
        "Answers an Array containing the value of the receiver at aNumber
3✔
175
         and the gradient of the receiver's respective to the receiver's
3✔
176
         parameters evaluated at aNumber."
3✔
177
        ^self approximatedValueAndGradient: aNumber
3✔
178
]
3✔
179

180
{ #category : #information }
181
PMProbabilityDensity >> variance [
3✔
182
        "Answer the variance of the receiver.
3✔
183
        NOTE: At least one of the methods variance or standardDeviation must be implemented by the subclass."
3✔
184
        ^self standardDeviation squared
3✔
185
]
3✔
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