ruby-svd 0.4.0 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/lsa.rb +7 -5
- metadata +3 -3
data/lib/lsa.rb
CHANGED
@@ -11,16 +11,18 @@ class LSA
|
|
11
11
|
# and all the clusters (columns) used in the original matrix.
|
12
12
|
# Returns a sorted list of indexes and distances,
|
13
13
|
def classify_vector(values)
|
14
|
-
raise "Unsupported vector length" unless values.size == @u.row_size
|
14
|
+
raise "Unsupported vector length" unless values.size == @u.row_size || values.size == @v.row_size
|
15
15
|
vector = Matrix.row_vector(values)
|
16
|
-
|
17
|
-
|
16
|
+
mult_matrix = (values.size == @u.row_size ? @u : @v)
|
17
|
+
comp_matrix = (values.size == @u.row_size ? @v : @u)
|
18
|
+
|
19
|
+
position = vector * mult_matrix * @s.inverse
|
18
20
|
x = position[0,0]
|
19
21
|
y = position[0,1]
|
20
22
|
results = []
|
21
23
|
|
22
|
-
|
23
|
-
results << [index, cosine_similarity(x, y,
|
24
|
+
comp_matrix.row_size.times do |index|
|
25
|
+
results << [index, cosine_similarity(x, y, comp_matrix[index, 0], comp_matrix[index, 1])]
|
24
26
|
end
|
25
27
|
|
26
28
|
results.sort {|a, b| b[1] <=> a[1]}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 5
|
9
|
+
version: 0.4.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Will Cannings
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-19 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|