• 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

62.63
/src/Math-Distributions/PMNormalDistribution.class.st
1
Class {
2
        #name : #PMNormalDistribution,
3
        #superclass : #PMProbabilityDensity,
4
        #instVars : [
5
                'mu',
6
                'sigma'
7
        ],
8
        #classVars : [
9
                'NextRandom'
10
        ],
11
        #category : #'Math-Distributions-Normal'
12
}
13

14
{ #category : #information }
15
PMNormalDistribution class >> boxMullerTransform [
3✔
16
        | random v1 v2 w y |
3✔
17
        random := Random new.
3✔
18

3✔
19
        [
3✔
20
                v1 :=random next * 2 - 1.
3✔
21
                v2 := random next * 2 - 1.
3✔
22
                w := v1 squared + v2 squared.
3✔
23
                w > 1
3✔
24
        ] whileTrue.
3✔
25

3✔
26
        y := (w ln * 2 negated / w) sqrt.
3✔
27
        v1 := y * v1.
3✔
28
        NextRandom := y * v2.
3✔
29
        ^v1
3✔
30
]
3✔
31

32
{ #category : #information }
33
PMNormalDistribution class >> distributionName [
×
34

×
35
        ^'Normal distribution'
×
36
]
×
37

38
{ #category : #creation }
39
PMNormalDistribution class >> fromHistogram: aHistogram [
×
40
        "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."
×
41

×
42
        ^ self
×
43
                new: aHistogram average
×
44
                sigma: aHistogram standardDeviation
×
45
]
×
46

47
{ #category : #creation }
48
PMNormalDistribution class >> new [
3✔
49
        "Create a new instance of the receiver with mu=0 and sigma=1."
3✔
50
        ^self new: 0 sigma: 1
3✔
51
]
3✔
52

53
{ #category : #creation }
54
PMNormalDistribution class >> new: aNumber1 sigma: aNumber2 [
3✔
55
                "Create a new instance of the receiver with given mu and sigma."
3✔
56
        ^super new initialize: aNumber1 sigma: aNumber2
3✔
57
]
3✔
58

59
{ #category : #information }
60
PMNormalDistribution class >> random [
3✔
61
        "Answer a random number distributed according to a (0,1) normal distribution."
3✔
62

3✔
63
        | v1  |
3✔
64
        NextRandom
3✔
65
                ifNil: [
3✔
66

3✔
67
                        v1 := self boxMullerTransform ]
3✔
68
                ifNotNil: [ v1 := NextRandom.
3✔
69
                        NextRandom := nil ].
3✔
70
        ^ v1
3✔
71
]
3✔
72

73
{ #category : #information }
74
PMNormalDistribution >> average [
3✔
75
        "Answer the average of the receiver."
3✔
76
        ^mu
3✔
77
]
3✔
78

79
{ #category : #transformation }
80
PMNormalDistribution >> changeParametersBy: aVector [
×
81
        "Modify the parameters of the receiver by aVector."
×
82
        mu := mu + ( aVector at: 1).
×
83
        sigma := sigma + ( aVector at: 2)
×
84
]
×
85

86
{ #category : #information }
87
PMNormalDistribution >> distributionValue: aNumber [
3✔
88
        "Answers the probability of observing a random variable distributed according to the receiver with a value lower than or equal to aNumber."
3✔
89
        ^PMErfApproximation new value: ( ( aNumber - mu) / sigma)
3✔
90
]
3✔
91

92
{ #category : #initialization }
93
PMNormalDistribution >> initialize: aNumber1 sigma: aNumber2 [
3✔
94
        mu := aNumber1.
3✔
95
        sigma := aNumber2
3✔
96
]
3✔
97

98
{ #category : #information }
99
PMNormalDistribution >> kurtosis [
×
100
        "Answer the kurtosis of the receiver."
×
101
        ^0
×
102
]
×
103

104
{ #category : #information }
105
PMNormalDistribution >> parameters [
×
106

×
107
        ^Array with: mu with: sigma
×
108
]
×
109

110
{ #category : #information }
111
PMNormalDistribution >> random [
3✔
112
        "Answer a random number distributed according to the receiver."
3✔
113

3✔
114
        ^ self class random * sigma + mu
3✔
115
]
3✔
116

117
{ #category : #information }
118
PMNormalDistribution >> skewness [
×
119
        "Answer the skewness of the receiver."
×
120
        ^0
×
121
]
×
122

123
{ #category : #information }
124
PMNormalDistribution >> standardDeviation [
3✔
125
        "Answer the standard deviation of the receiver."
3✔
126
        ^sigma
3✔
127
]
3✔
128

129
{ #category : #information }
130
PMNormalDistribution >> value: aNumber [
3✔
131
        "Answers the probability that a random variable distributed according to the receiver gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
3✔
132

3✔
133
        ^( PMErfApproximation new normal: (aNumber - mu) / sigma) / sigma
3✔
134
]
3✔
135

136
{ #category : #information }
137
PMNormalDistribution >> valueAndGradient: aNumber [
×
138
        "Answers 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."
×
139
        | dp y |
×
140
        y := ( aNumber - mu) / sigma.
×
141
        dp := ( PMErfApproximation new normal: y) / sigma.
×
142
        ^Array with: dp
×
143
                   with: ( PMVector with: dp * y / sigma
×
144
                                                         with: dp * ( y squared - 1) / sigma)
×
145
]
×
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