forked from PolyMathOrg/PolyMath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMPrincipalComponentAnalyserJacobiTransformation.class.st
More file actions
63 lines (51 loc) · 2.26 KB
/
PMPrincipalComponentAnalyserJacobiTransformation.class.st
File metadata and controls
63 lines (51 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"
I'm implementing a principle component analysis with Jacobi transformation of the covariante matrix.
Clients should first
- create myself specifying a size which represents the number of elements on which I should be working.
- accumulate: (give a certain amount of vectors of the elements to compare)
- then ask for the components
"
Class {
#name : 'PMPrincipalComponentAnalyserJacobiTransformation',
#superclass : 'PMPrincipalComponentAnalyser',
#instVars : [
'accumulatorForCovarianceMatrix',
'jacobiTransform'
],
#category : 'Math-PrincipalComponentAnalysis',
#package : 'Math-PrincipalComponentAnalysis'
}
{ #category : 'instance creation' }
PMPrincipalComponentAnalyserJacobiTransformation class >> new: anInteger [
"anInteger is the size of the elements you will accumulate: the elements you want to compare using the component analysis."
^ self basicNew initialize: anInteger; yourself
]
{ #category : 'transformation' }
PMPrincipalComponentAnalyserJacobiTransformation >> accumulate: aPMVectorOrArray [
accumulatorForCovarianceMatrix accumulate: aPMVectorOrArray
]
{ #category : 'accessing' }
PMPrincipalComponentAnalyserJacobiTransformation >> components [
"Precondition: accumulate: should have been used."
^ self jacobiTransform eigenValues copyFrom: 1 to: componentsNumber
]
{ #category : 'accessing' }
PMPrincipalComponentAnalyserJacobiTransformation >> fit: aPMMatrix [
accumulatorForCovarianceMatrix := PMCovarianceAccumulator new: aPMMatrix numberOfColumns.
aPMMatrix rowsDo: [ :eachRow | self accumulate: eachRow ].
self components
]
{ #category : 'accessing' }
PMPrincipalComponentAnalyserJacobiTransformation >> jacobiTransform [
^ jacobiTransform ifNil: [ jacobiTransform := PMJacobiTransformation matrix: accumulatorForCovarianceMatrix covarianceMatrix ]
]
{ #category : 'accessing' }
PMPrincipalComponentAnalyserJacobiTransformation >> transform: aPMMatrix [
"Apply dimensionality reduction to aPMMatrix"
^ aPMMatrix * self transformMatrix transpose
]
{ #category : 'accessing' }
PMPrincipalComponentAnalyserJacobiTransformation >> transformMatrix [
"Return a matrix that can be applied to any data vector to extract the relevant component of the data vector"
^ PMMatrix rows: (self jacobiTransform eigenVectors rows copyFrom:1 to: componentsNumber )
]