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
|
# File 'lib/vector_comparer.rb', line 23
def self.compare_vectors
puts "How many test vectors should there be?"
@number_of_test_vectors = gets.chomp.to_i
puts "What should the threshold be?"
@threshold = gets.chomp.to_i
random_vectors = Array.new(@number_of_random_vectors)
@number_of_random_vectors.times do |i|
random_vector = Array.new(@dimensions)
@dimensions.times do |n|
random_vector[n] = random1
end
random_vectors[i] = random_vector
end
test_vectors = Array.new(@number_of_test_vectors)
@number_of_test_vectors.times do |i|
test_vector = Array.new(@dimensions)
@dimensions.times do |n|
test_vector[n] = random1
end
test_vectors[i] = test_vector
end
puts "For threshold #{@threshold}..."
test_vectors.each do |test_vector|
number_near_orthogonal = 0
random_vectors.each do |random_vector|
dp = dot_prod(test_vector,random_vector)
if dp.abs < @threshold
number_near_orthogonal += 1
end
end
puts "The random test vector was nearly orthogonal to #{number_near_orthogonal} or the initial vectors"
end
end
|