Module: MDS::Test::BundleMetric

Includes:
MatrixAssertions
Defined in:
lib/mds/test/bundles/bundle_metric.rb

Overview

Module containing standarized tests for MDS::Metric.

Instance Method Summary collapse

Methods included from MatrixAssertions

#assert_delta_matrices, #assert_equal_matrices

Instance Method Details

#test_d_2dObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mds/test/bundles/bundle_metric.rb', line 47

def test_d_2d
  x = MDS::Matrix.create_rows(
    [1.0, 2.0], 
    [4.0, 3.0],
    [0.0, 1.0]
  )
  d = MDS::Metric.squared_distances(x)
  
  proj = MDS::Metric.projectd(d, 2)   
  dd = MDS::Metric.squared_distances(proj)    
  assert_delta_matrices(d, dd, 1e-5)
end

#test_d_5dObject



73
74
75
76
77
78
79
# File 'lib/mds/test/bundles/bundle_metric.rb', line 73

def test_d_5d
  x = MDS::Matrix.create_random(10, 5, -10, 10)   
  d = MDS::Metric.squared_distances(x)
  proj = MDS::Metric.projectd(d, 10)   
  dd = MDS::Metric.squared_distances(proj)    
  assert_delta_matrices(d, dd, 1e-5)
end

#test_k_2dObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mds/test/bundles/bundle_metric.rb', line 35

def test_k_2d
  x = MDS::Matrix.create_rows(
    [1.0, 2.0], 
    [4.0, 3.0],
    [0.0, 1.0]
  )
  d = MDS::Metric::squared_distances(x)
  proj = MDS::Metric.projectk(d, 0.99)   
  dd = MDS::Metric.squared_distances(proj)    
  assert_delta_matrices(d, dd, 1e-5)
end

#test_k_5dObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mds/test/bundles/bundle_metric.rb', line 60

def test_k_5d
  x = MDS::Matrix.create_random(10, 5, -10, 10)   
  d = MDS::Metric.squared_distances(x)
  
  proj = MDS::Metric.projectk(d, 1.0)   
  dd = MDS::Metric.squared_distances(proj)    
  assert_delta_matrices(d, dd, 1e-5)
  
  proj = MDS::Metric.projectk(d, 0.8)   
  dd = MDS::Metric.squared_distances(proj)    
  assert_delta_matrices(d, dd, 5e2)
end

#test_squared_distancesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mds/test/bundles/bundle_metric.rb', line 18

def test_squared_distances
  input = MDS::Matrix.create_rows(
    [1.0, 2.0], 
    [4.0, 3.0],
    [0.0, 1.0]
  )
  
  output = MDS::Matrix.create_rows(
    [0.0, 10.0, 2.0], 
    [10.0, 0.0, 20.0], 
    [2.0, 20.0, 0.0]
  )
  
  d = MDS::Metric.squared_distances(input)
  assert_equal_matrices(output, d)
end