Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"
This test checks that the Jacobi transform based PCA meets the acceptance requirements defined in PMPrincipalComponentAnalysisTest
"
Class {
#name : #PMPCAJacobiTransformationTest,
#superclass : #PMPrincipalComponentAnalyserTest,
#category : #'Math-Tests-PrincipalComponentAnalysis'
}

{ #category : #running }
PMPCAJacobiTransformationTest >> setUp [
pca := PMPrincipalComponentAnalyserJacobiTransformation new
componentsNumber: 2
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"
This test checks that the SVD transform based PCA meets the acceptance requirements defined in PMPrincipalComponentAnalysisTest
"
Class {
#name : #PMPCASingularValueDecompositionTest,
#superclass : #PMPrincipalComponentAnalyserTest,
#category : #'Math-Tests-PrincipalComponentAnalysis'
}

{ #category : #running }
PMPCASingularValueDecompositionTest >> setUp [
pca := PMPrincipalComponentAnalyserSVD new componentsNumber: 2
]

{ #category : #'scikit-learn-example' }
PMPCASingularValueDecompositionTest >> testPCAwithPCAandJacobiTransformationReturnSame [
| m pca1 pca2 |
m := PMMatrix rows: #(#(-1 -1) #(-2 -1) #(-3 -2) #(1 1) #(2 1) #(3 2)).
pca1 := PMPrincipalComponentAnalyserSVD new componentsNumber: 2.
pca1 fit: m.
pca2 := PMPrincipalComponentAnalyserJacobiTransformation new componentsNumber: 2.
pca2 fit: m.

self assert: pca1 transformMatrix abs closeTo: pca2 transformMatrix abs
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,33 @@ Class {
#name : #PMPrincipalComponentAnalyserTest,
#superclass : #TestCase,
#instVars : [
'average',
'covarianceMatrix',
'accumulator',
'server'
'pca'
],
#category : #'Math-Tests-PrincipalComponentAnalysis'
}

{ #category : #'pca tutorial' }
PMPrincipalComponentAnalyserTest >> testJacobiBasedTransformWithMeanCentredMeasurements [
"As acceptance tests we use the worked example of the PCA tutorial of Lindsay Smith"
| m pca transformedData expected |
m := PMMatrix rows: #(
#(0.69 0.49)
#(-1.31 -1.21)
#(0.39 0.99)
#(0.09 0.29)
#(1.29 1.09)
#(0.49 0.79)
#(0.19 -0.31)
#(-0.81 -0.81)
#(-0.31 -0.31)
#(-0.71 -1.01)
).
pca := PMPrincipalComponentAnalyserJacobiTransformation new componentsNumber: 2.

pca fit: m.
transformedData := pca transform: m.

expected := PMMatrix rows: #(
#(-0.827970186 -0.175115307)
#(1.77758033 0.142857227)
#(-0.992197494 0.384374989)
#(-0.274210416 0.130417207)
#(-1.67580142 -0.209498461)
#(-0.912949103 0.175282444)
#(0.0991094375 -0.349824698)
#(1.14457216 0.0464172582)
#(0.438046137 0.0177646297)
#(1.22382056 -0.162675287)).
self assert: (transformedData abs) closeTo: expected abs.
{ #category : #testing }
PMPrincipalComponentAnalyserTest class >> isAbstract [
^ self name = #PMPrincipalComponentAnalyserTest
]

{ #category : #tests }
PMPrincipalComponentAnalyserTest >> testPCAwithPCAandJacobiTransformationReturnSame [
| m pca1 pca2 |
m := PMMatrix rows: #(#(-1 -1) #(-2 -1) #(-3 -2) #(1 1) #(2 1) #(3 2)).
pca1 := PMPrincipalComponentAnalyserSVD new componentsNumber: 2.
pca1 fit: m.
pca2 := PMPrincipalComponentAnalyserJacobiTransformation new componentsNumber: 2.
pca2 fit: m.
{ #category : #'scikit-learn-example' }
PMPrincipalComponentAnalyserTest >> testTransformMatrix [
| m expected |
m := PMMatrix
rows: #(#(-1 -1) #(-2 -1) #(-3 -2) #(1 1) #(2 1) #(3 2)).

self assert: pca1 transformMatrix abs closeTo: pca2 transformMatrix abs
pca fit: m.

expected := (PMMatrix
rows: #(#(-0.83849224 -0.54491354) #(0.54491354 -0.83849224))) abs.
self assert: pca transformMatrix abs closeTo: expected
]

{ #category : #'pca tutorial' }
PMPrincipalComponentAnalyserTest >> testSVDBasedTransformWithMeanCentredMeasurements [
"As acceptance tests we use the worked example of the PCA tutorial of Lindsay Smith"

| m pca transformedData expected |
m := PMMatrix rows: #(
{ #category : #'lindsay-smith-pca-tutorial' }
PMPrincipalComponentAnalyserTest >> testTransformWithMeanCentredMeasurements [
| meanCentredData transformedData expected |
meanCentredData := PMMatrix rows: #(
#(0.69 0.49)
#(-1.31 -1.21)
#(0.39 0.99)
Expand All @@ -80,10 +46,8 @@ PMPrincipalComponentAnalyserTest >> testSVDBasedTransformWithMeanCentredMeasurem
#(-0.31 -0.31)
#(-0.71 -1.01)
).
pca := PMPrincipalComponentAnalyserSVD new componentsNumber: 2.

pca fit: m.
transformedData := pca transform: m.
transformedData := pca fitAndTransform: meanCentredData.

expected := PMMatrix rows: #(
#(-0.827970186 -0.175115307)
Expand All @@ -98,32 +62,3 @@ PMPrincipalComponentAnalyserTest >> testSVDBasedTransformWithMeanCentredMeasurem
#(1.22382056 -0.162675287)).
self assert: (transformedData abs) closeTo: expected abs.
]

{ #category : #tests }
PMPrincipalComponentAnalyserTest >> testTransformMatrixWithJacobiTransformation [
| m pca expected |
m := PMMatrix
rows: #(#(-1 -1) #(-2 -1) #(-3 -2) #(1 1) #(2 1) #(3 2)).
pca := PMPrincipalComponentAnalyserJacobiTransformation new
componentsNumber: 2.

pca fit: m.

expected := (PMMatrix
rows: #(#(-0.83849224 -0.54491354) #(0.54491354 -0.83849224))) abs.
self assert: pca transformMatrix abs closeTo: expected
]

{ #category : #tests }
PMPrincipalComponentAnalyserTest >> testTransformMatrixWithSVD [
| m pca expected |
m := PMMatrix
rows: #(#(-1 -1) #(-2 -1) #(-3 -2) #(1 1) #(2 1) #(3 2)).
pca := PMPrincipalComponentAnalyserSVD new componentsNumber: 2.

pca fit: m.

expected := (PMMatrix
rows: #(#(-0.83849224 -0.54491354) #(0.54491354 -0.83849224))) abs.
self assert: pca transformMatrix abs closeTo: expected
]