Skip to content

Commit 6a0c2f8

Browse files
committed
Simplify more conditions
1 parent 9bc6705 commit 6a0c2f8

28 files changed

+209
-244
lines changed

src/Math-Clustering/PMCovarianceCluster.class.st

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Class {
22
#name : #PMCovarianceCluster,
33
#superclass : #PMCluster,
4-
#category : 'Math-Clustering'
4+
#category : #'Math-Clustering'
55
}
66

77
{ #category : #initialization }
8-
PMCovarianceCluster >> centerOn: aVector [
8+
PMCovarianceCluster >> centerOn: aVector [
99

10-
accumulator := aVector isNil
11-
ifTrue: [nil]
12-
ifFalse: [ PMMahalanobisCenter onVector: aVector ]
10+
accumulator := aVector
11+
ifNil: [ nil ]
12+
ifNotNil: [ PMMahalanobisCenter onVector: aVector ]
1313
]
1414

1515
{ #category : #transformation }

src/Math-Distributions/PMBetaDistribution.class.st

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,21 @@ PMBetaDistribution >> computeNorm [
7474
{ #category : #information }
7575
PMBetaDistribution >> distributionValue: aNumber [
7676
"Answers the probability of observing a random variable distributed according to the receiver with a value lower than or equal to aNumber."
77-
78-
incompleteBetaFunction isNil
79-
ifTrue: [ incompleteBetaFunction := PMIncompleteBetaFunction shape: alpha1 shape: alpha2].
80-
^aNumber <= 0.0 ifTrue:[0]ifFalse:[aNumber >= 1.0 ifTrue:[1] ifFalse:[incompleteBetaFunction value: aNumber]]
77+
78+
incompleteBetaFunction ifNil: [ incompleteBetaFunction := PMIncompleteBetaFunction shape: alpha1 shape: alpha2 ].
79+
^ aNumber <= 0.0
80+
ifTrue: [ 0 ]
81+
ifFalse: [
82+
aNumber >= 1.0
83+
ifTrue: [ 1 ]
84+
ifFalse: [ incompleteBetaFunction value: aNumber ] ]
8185
]
8286

8387
{ #category : #information }
8488
PMBetaDistribution >> firstGammaDistribution [
8589

86-
gamma1 isNil
87-
ifTrue: [ gamma1 := PMGammaDistribution shape: alpha1 scale: 1].
88-
^gamma1
90+
gamma1 ifNil: [ gamma1 := PMGammaDistribution shape: alpha1 scale: 1 ].
91+
^ gamma1
8992
]
9093

9194
{ #category : #initialization }
@@ -122,10 +125,9 @@ PMBetaDistribution >> random [
122125

123126
{ #category : #information }
124127
PMBetaDistribution >> secondGammaDistribution [
125-
126-
gamma2 isNil
127-
ifTrue: [ gamma2 := PMGammaDistribution shape: alpha2 scale: 1].
128-
^gamma2
128+
129+
gamma2 ifNil: [ gamma2 := PMGammaDistribution shape: alpha2 scale: 1 ].
130+
^ gamma2
129131
]
130132

131133
{ #category : #information }

src/Math-Distributions/PMCongruentialRandomNumberGenerator.class.st

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ PMCongruentialRandomNumberGenerator class >> constant: aNumber1 multiplicator: a
2525
{ #category : #creation }
2626
PMCongruentialRandomNumberGenerator class >> new [
2727
"Create a new instance of the receiver with D. Knuth's constants."
28-
UniqueInstance isNil
29-
ifTrue: [ UniqueInstance := super new initialize.
30-
UniqueInstance setSeed: 1.
31-
].
32-
^UniqueInstance
28+
29+
UniqueInstance ifNil: [
30+
UniqueInstance := super new initialize.
31+
UniqueInstance setSeed: 1 ].
32+
^ UniqueInstance
3333
]
3434

3535
{ #category : #creation }

src/Math-Distributions/PMErfApproximation.class.st

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ Class {
4646
{ #category : #creation }
4747
PMErfApproximation class >> new [
4848
"Answer a unique instance. Create it if it does not exist."
49-
UniqueInstance isNil
50-
ifTrue: [ UniqueInstance := super new.
51-
UniqueInstance initialize ].
52-
^UniqueInstance
49+
50+
UniqueInstance ifNil: [
51+
UniqueInstance := super new.
52+
UniqueInstance initialize ].
53+
^ UniqueInstance
5354
]
5455

5556
{ #category : #creation }

src/Math-Distributions/PMFisherSnedecorDistribution.class.st

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ PMFisherSnedecorDistribution >> distributionValue: aNumber [
9999
PMFisherSnedecorDistribution >> incompleteBetaFunction [
100100
"Private - Answers the incomplete beta function used to compute the symmetric acceptance integral of the receiver. "
101101

102-
incompleteBetaFunction isNil
103-
ifTrue:
104-
[incompleteBetaFunction := PMIncompleteBetaFunction shape: dof2 / 2
105-
shape: dof1 / 2].
106-
^incompleteBetaFunction
102+
incompleteBetaFunction ifNil: [ incompleteBetaFunction := PMIncompleteBetaFunction shape: dof2 / 2 shape: dof1 / 2 ].
103+
^ incompleteBetaFunction
107104
]
108105

109106
{ #category : #initialization }
@@ -132,11 +129,11 @@ PMFisherSnedecorDistribution >> parameters [
132129
{ #category : #information }
133130
PMFisherSnedecorDistribution >> random [
134131
"Answer a random number distributed according to the receiver."
135-
chiSquareDistribution1 isNil
136-
ifTrue: [ chiSquareDistribution1 := PMChiSquareDistribution degreeOfFreedom: dof1.
137-
chiSquareDistribution2 := PMChiSquareDistribution degreeOfFreedom: dof2.
138-
].
139-
^chiSquareDistribution1 random * dof2 / ( chiSquareDistribution2 random * dof1)
132+
133+
chiSquareDistribution1 ifNil: [
134+
chiSquareDistribution1 := PMChiSquareDistribution degreeOfFreedom: dof1.
135+
chiSquareDistribution2 := PMChiSquareDistribution degreeOfFreedom: dof2 ].
136+
^ chiSquareDistribution1 random * dof2 / (chiSquareDistribution2 random * dof1)
140137
]
141138

142139
{ #category : #information }

src/Math-Distributions/PMGammaDistribution.class.st

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ PMGammaDistribution >> distributionValue: aNumber [
7373
PMGammaDistribution >> incompleteGammaFunction [
7474
"Private"
7575

76-
incompleteGammaFunction isNil
77-
ifTrue:
78-
[incompleteGammaFunction := PMIncompleteGammaFunction shape: alpha].
79-
^incompleteGammaFunction
76+
incompleteGammaFunction ifNil: [ incompleteGammaFunction := PMIncompleteGammaFunction shape: alpha ].
77+
^ incompleteGammaFunction
8078
]
8179

8280
{ #category : #initialization }
@@ -131,17 +129,17 @@ PMGammaDistribution >> random [
131129
{ #category : #information }
132130
PMGammaDistribution >> randomCoefficientsForLargeAlpha [
133131
"Private"
134-
randomCoefficients isNil
135-
ifTrue: [ randomCoefficients := self initializeRandomCoefficientsForLargeAlpha].
136-
^randomCoefficients
132+
133+
randomCoefficients ifNil: [ randomCoefficients := self initializeRandomCoefficientsForLargeAlpha ].
134+
^ randomCoefficients
137135
]
138136

139137
{ #category : #information }
140138
PMGammaDistribution >> randomCoefficientsForSmallAlpha [
141139
"Private"
142-
randomCoefficients isNil
143-
ifTrue: [ randomCoefficients := self initializeRandomCoefficientsForSmallAlpha].
144-
^randomCoefficients
140+
141+
randomCoefficients ifNil: [ randomCoefficients := self initializeRandomCoefficientsForSmallAlpha ].
142+
^ randomCoefficients
145143
]
146144

147145
{ #category : #information }

src/Math-Distributions/PMIncompleteBetaFunction.class.st

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,27 @@ PMIncompleteBetaFunction class >> shape: aNumber1 shape: aNumber2 [
1919
]
2020

2121
{ #category : #private }
22-
PMIncompleteBetaFunction >> evaluateFraction: aNumber [
22+
PMIncompleteBetaFunction >> evaluateFraction: aNumber [
2323

24-
fraction isNil
25-
ifTrue:
26-
[fraction := PMIncompleteBetaFractionTermServer new.
27-
fraction setParameter: alpha1 second: alpha2].
24+
fraction ifNil: [
25+
fraction := PMIncompleteBetaFractionTermServer new.
26+
fraction setParameter: alpha1 second: alpha2 ].
2827
fraction setArgument: aNumber.
29-
^(PMContinuedFraction server: fraction)
30-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
31-
evaluate
28+
^ (PMContinuedFraction server: fraction)
29+
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
30+
evaluate
3231
]
3332

3433
{ #category : #private }
35-
PMIncompleteBetaFunction >> evaluateInverseFraction: aNumber [
34+
PMIncompleteBetaFunction >> evaluateInverseFraction: aNumber [
3635

37-
inverseFraction isNil
38-
ifTrue:
39-
[inverseFraction := PMIncompleteBetaFractionTermServer new.
40-
inverseFraction setParameter: alpha2 second: alpha1].
41-
inverseFraction setArgument: (1 - aNumber).
42-
^(PMContinuedFraction server: inverseFraction)
43-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
44-
evaluate
36+
inverseFraction ifNil: [
37+
inverseFraction := PMIncompleteBetaFractionTermServer new.
38+
inverseFraction setParameter: alpha2 second: alpha1 ].
39+
inverseFraction setArgument: 1 - aNumber.
40+
^ (PMContinuedFraction server: inverseFraction)
41+
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
42+
evaluate
4543
]
4644

4745
{ #category : #initialization }

src/Math-Distributions/PMIncompleteGammaFunction.class.st

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,27 @@ PMIncompleteGammaFunction class >> shape: aNumber [
1717
]
1818

1919
{ #category : #private }
20-
PMIncompleteGammaFunction >> evaluateFraction: aNumber [
20+
PMIncompleteGammaFunction >> evaluateFraction: aNumber [
2121

22-
fraction isNil
23-
ifTrue:
24-
[fraction := PMIncompleteGammaFractionTermServer new.
25-
fraction setParameter: alpha].
22+
fraction ifNil: [
23+
fraction := PMIncompleteGammaFractionTermServer new.
24+
fraction setParameter: alpha ].
2625
fraction setArgument: aNumber.
27-
^(PMContinuedFraction server: fraction)
28-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
29-
evaluate
26+
^ (PMContinuedFraction server: fraction)
27+
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
28+
evaluate
3029
]
3130

3231
{ #category : #private }
3332
PMIncompleteGammaFunction >> evaluateSeries: aNumber [
3433

35-
series isNil
36-
ifTrue: [ series := PMIncompleteGammaSeriesTermServer new.
37-
series setParameter: alpha.
38-
].
34+
series ifNil: [
35+
series := PMIncompleteGammaSeriesTermServer new.
36+
series setParameter: alpha ].
3937
series setArgument: aNumber.
40-
^(PMInfiniteSeries server: series)
41-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
42-
evaluate
38+
^ (PMInfiniteSeries server: series)
39+
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
40+
evaluate
4341
]
4442

4543
{ #category : #initialization }
@@ -54,13 +52,13 @@ PMIncompleteGammaFunction >> initialize: aNumber [
5452
PMIncompleteGammaFunction >> value: aNumber [
5553

5654
| x norm |
57-
aNumber = 0
58-
ifTrue: [ ^0].
55+
aNumber = 0 ifTrue: [ ^ 0 ].
5956
x := aNumber asFloat.
60-
norm := [ ( x ln * alpha - x - alphaLogGamma) exp] on: Error do: [ :signal | signal return: nil].
61-
norm isNil
62-
ifTrue: [ ^1].
63-
^x - 1 < alpha
64-
ifTrue: [ ( self evaluateSeries: x) * norm]
65-
ifFalse:[ 1 - ( norm / ( self evaluateFraction: x))]
57+
norm := [ (x ln * alpha - x - alphaLogGamma) exp ]
58+
on: Error
59+
do: [ :signal | signal return: nil ].
60+
norm ifNil: [ ^ 1 ].
61+
^ x - 1 < alpha
62+
ifTrue: [ (self evaluateSeries: x) * norm ]
63+
ifFalse: [ 1 - (norm / (self evaluateFraction: x)) ]
6664
]

src/Math-Distributions/PMMitchellMooreGenerator.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ PMMitchellMooreGenerator class >> generateSeeds: congruentialGenerator [
3535

3636
{ #category : #creation }
3737
PMMitchellMooreGenerator class >> new [
38-
UniqueInstance isNil
39-
ifTrue: [ UniqueInstance := self default].
40-
^UniqueInstance
38+
39+
UniqueInstance ifNil: [ UniqueInstance := self default ].
40+
^ UniqueInstance
4141
]
4242

4343
{ #category : #creation }

src/Math-Distributions/PMProbabilityDensity.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ PMProbabilityDensity >> printOn: aStream [
120120

121121
| params |
122122
aStream nextPutAll: self class distributionName.
123-
(params := self parameters) isNotNil ifTrue: [
123+
(params := self parameters) ifNotNil: [
124124
| first |
125125
first := true.
126126
aStream nextPut: $(.

0 commit comments

Comments
 (0)