summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2011-11-10 09:20:23 +0100
committerAndreas Maunz <andreas@maunz.de>2011-11-10 09:20:23 +0100
commitb25be2d6cbcf880fe2afe83143a7d47227dcf0e0 (patch)
tree568bcf443d8ea898bf63b52ae7d98abb56cc43f4
parent3845d0407b591599378c92a419734cc252f8954b (diff)
PCA: fixed scaling
-rw-r--r--transform.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/transform.rb b/transform.rb
index 15d1f09..3c3b2da 100644
--- a/transform.rb
+++ b/transform.rb
@@ -24,10 +24,11 @@ class TransformTest < Test::Unit::TestCase
def test_pca
- d = GSL::Matrix.alloc([1,1.1,2,1.9,3,3.3], 3, 2)
- td = GSL::Matrix.alloc([-1.64373917483226, -0.155542754209564, 1.79928192904182],3,1)
+ d = GSL::Matrix.alloc([1.0, -5, 1.1, 2.0, -5, 1.9, 3.0, -5, 3.3], 3, 3) # 2nd col is const -5, gets removed
+ rd = GSL::Matrix.alloc([1.0, 1.1, 1.9, 2.0, 3.1, 3.2], 3, 2)
+
+ td = GSL::Matrix.alloc([-1.4142135623731, -0.14142135623731, 1.5556349186104],3,1)
ev = GSL::Matrix.alloc([0.707106781186548, 0.707106781186548], 2, 1)
- rd = GSL::Matrix.alloc([1.05098674493306, 1.043223563717, 1.91019734898661, 2.0, 3.03881590608033, 3.256776436283], 3, 2)
# Lossy
2.times do # repeat to ensure idempotency
@@ -39,7 +40,8 @@ class TransformTest < Test::Unit::TestCase
assert_equal pca.restore, rd
end
- td = GSL::Matrix.alloc([-1.64373917483226, 0.0883116327366195, -0.155542754209564, -0.155542754209564, 1.79928192904182, 0.0672311214729441],3,2)
+ rd = GSL::Matrix.alloc([1.0, 1.1, 2.0, 1.9, 3.0, 3.3], 3, 2) # 2nd col of d is const -5, gets removed on rd
+ td = GSL::Matrix.alloc([-1.4142135623731, -7.84962372879505e-17, -0.14142135623731, -0.14142135623731, 1.5556349186104, 0.141421356237309],3,2)
ev = GSL::Matrix.alloc([0.707106781186548, -0.707106781186548, 0.707106781186548, 0.707106781186548], 2, 2)
# Lossless
@@ -49,7 +51,7 @@ class TransformTest < Test::Unit::TestCase
assert_equal pca.data_transformed_matrix, td
assert_equal pca.transform(d), td
assert_equal pca.eigenvector_matrix, ev
- assert_equal pca.restore, d
+ assert_equal pca.restore, rd
end
end