|
| 1 | +Class { |
| 2 | + #name : #PMMultivariateNormalDistribution, |
| 3 | + #superclass : #PMProbabilityDensity, |
| 4 | + #instVars : [ |
| 5 | + 'meanVector', |
| 6 | + 'covarianceMatrix' |
| 7 | + ], |
| 8 | + #category : #'Math-Core-Distribution' |
| 9 | +} |
| 10 | + |
| 11 | +{ #category : #'instance creation' } |
| 12 | +PMMultivariateNormalDistribution class >> meanVector: aMeanVector covarianceMatrix: aCovarianceMatrix [ |
| 13 | + ^ self new |
| 14 | + initializeMeanVector: aMeanVector |
| 15 | + covarianceMatrix: aCovarianceMatrix; |
| 16 | + yourself |
| 17 | +] |
| 18 | + |
| 19 | +{ #category : #information } |
| 20 | +PMMultivariateNormalDistribution >> average [ |
| 21 | + ^ self meanVector |
| 22 | +] |
| 23 | + |
| 24 | +{ #category : #transformation } |
| 25 | +PMMultivariateNormalDistribution >> changeParametersBy: aVector [ |
| 26 | + "Modify the parameters of the receiver by aVector." |
| 27 | + meanVector := meanVector + aVector first. |
| 28 | + covarianceMatrix := covarianceMatrix + aVector second. |
| 29 | +] |
| 30 | + |
| 31 | +{ #category : #information } |
| 32 | +PMMultivariateNormalDistribution >> covarianceMatrix [ |
| 33 | + ^ covarianceMatrix |
| 34 | +] |
| 35 | + |
| 36 | +{ #category : #information } |
| 37 | +PMMultivariateNormalDistribution >> distributionValue: aNumber [ |
| 38 | + "Answers the probability of observing a random variable distributed according to the receiver with a value lower than or equal to aNumber. Also known as the cumulative density function (CDF)." |
| 39 | + |
| 40 | + self shouldBeImplemented |
| 41 | +] |
| 42 | + |
| 43 | +{ #category : #initialization } |
| 44 | +PMMultivariateNormalDistribution >> initializeMeanVector: aMeanVector covarianceMatrix: aCovarianceMatrix [ |
| 45 | + meanVector := aMeanVector. |
| 46 | + covarianceMatrix := aCovarianceMatrix. |
| 47 | +] |
| 48 | + |
| 49 | +{ #category : #information } |
| 50 | +PMMultivariateNormalDistribution >> kurtosis [ |
| 51 | + "Kurtosis is a measure of the 'tailedness' of the probability distribution of a real-valued random variable. Not defined for a multivariate normal distribution" |
| 52 | + self shouldNotImplement |
| 53 | +] |
| 54 | + |
| 55 | +{ #category : #information } |
| 56 | +PMMultivariateNormalDistribution >> meanVector [ |
| 57 | + ^ meanVector |
| 58 | +] |
| 59 | + |
| 60 | +{ #category : #information } |
| 61 | +PMMultivariateNormalDistribution >> parameters [ |
| 62 | + "Returns an Array containing the parameters of the distribution. |
| 63 | + It is used to print out the distribution and for fitting." |
| 64 | + |
| 65 | + ^ { meanVector . covarianceMatrix } |
| 66 | +] |
| 67 | + |
| 68 | +{ #category : #information } |
| 69 | +PMMultivariateNormalDistribution >> power [ |
| 70 | + "Number of dimensions of a multivariate normal distribution" |
| 71 | + ^ meanVector size |
| 72 | +] |
| 73 | + |
| 74 | +{ #category : #information } |
| 75 | +PMMultivariateNormalDistribution >> random [ |
| 76 | + "Answer a vector of random numbers distributed accroding to the receiver." |
| 77 | + | standardNormalRandom upperTriangular | |
| 78 | + |
| 79 | + standardNormalRandom := (1 to: self power) asPMVector |
| 80 | + collect: [ :each | PMNormalDistribution random ]. |
| 81 | + |
| 82 | + upperTriangular := covarianceMatrix choleskyDecomposition. |
| 83 | + |
| 84 | + ^ upperTriangular transpose * standardNormalRandom + meanVector |
| 85 | +] |
| 86 | + |
| 87 | +{ #category : #information } |
| 88 | +PMMultivariateNormalDistribution >> skewness [ |
| 89 | + "Skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean. Not defined for a multivariate normal distribution" |
| 90 | + self shouldNotImplement |
| 91 | +] |
| 92 | + |
| 93 | +{ #category : #information } |
| 94 | +PMMultivariateNormalDistribution >> value: aVector [ |
| 95 | + "Answers the probability that a random variable distributed according to the receiver gives a value between aVector and aVector + espilon (infinitesimal interval)." |
| 96 | + |
| 97 | + ^ (-1/2 * (aVector - meanVector) * covarianceMatrix inverse * (aVector - meanVector)) exp / (((2 * Float pi) raisedTo: self power) * covarianceMatrix determinant) sqrt |
| 98 | +] |
0 commit comments