avsd 0.0.1 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/avsd.rb +53 -50
- data/lib/avsd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1b9d6846cba3cc3b0ba4d633d935888876ba8e
|
4
|
+
data.tar.gz: d479e01f10d5253800042af9dcc05127b8980446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d5b9860bba1f1389584a58d09a36a8c1e4296496b5fc2cdb9cf6a6621588c95ccddf17bbe9da7288ae07ce47d0f9024054c840968acc3d0c1f6bf54fd7c7b07
|
7
|
+
data.tar.gz: e01332f6a6c3643a093f0fe687a2ac6f137fb013e9889e04f0af9e398d617aef3340ff934081ce45b19625d3ee0fec6a2abf7777cf1a0ad34d64305ef864d669
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Avsd
|
2
2
|
|
3
|
-
|
3
|
+
###THIS GEM IS UNDEREXPERIMENT
|
4
|
+
|
5
|
+
Avsd is AVSD Recommend Algorithm implimatation on Ruby gem. AVSD Recommend Algorithm recommends sets of items based on multiple exisiting sets of items with a measure of creativity.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
data/lib/avsd.rb
CHANGED
@@ -92,72 +92,75 @@ class Array
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
module Avsd
|
96
|
+
class Avsd
|
97
|
+
def initialize(records)
|
98
|
+
@labels = records.flatten.uniq
|
99
|
+
@co_mat = Matrix.unit(labels.length)
|
100
|
+
self.band_matrix records
|
101
|
+
self.g_short_mat
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
def band label1, label2
|
105
|
+
@co_mat[@labels.index(label1), @labels.index(label2)] += 1
|
106
|
+
end
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
def band_matrix records
|
109
|
+
@labels.each do |label_a|
|
110
|
+
records.each do |record|
|
111
|
+
if record.include? label_a
|
112
|
+
record.each do |label_b|
|
113
|
+
band(label_a, label_b)
|
114
|
+
end
|
113
115
|
end
|
114
116
|
end
|
115
117
|
end
|
118
|
+
@co_mat.mirror_diagonal.zero_diagonal
|
116
119
|
end
|
117
|
-
@co_mat.mirror_diagonal.zero_diagonal
|
118
|
-
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
121
|
+
def g_short_mat
|
122
|
+
@short_mat = Matrix.zero(@co_mat.column_size)
|
123
|
+
@short_mat = @short_mat.collect { |x| x = nil }
|
124
|
+
for s_id in 0..@co_mat.column_size - 1
|
125
|
+
q = PriorityQueue.new
|
126
|
+
q[s_id] = 0
|
127
|
+
while not q.empty?
|
128
|
+
f = q.delete_min
|
129
|
+
@short_mat[s_id, f[0]] = f[1]
|
130
|
+
@short_mat.inspect
|
131
|
+
@co_mat.row(f[0]).each_with_index do |val, i|
|
132
|
+
next if i == f[0] or val == 0 or @short_mat[s_id, i] != nil
|
133
|
+
if q[i] == nil or q[i] < f[1] + val
|
134
|
+
q[i] = f[1] + val
|
135
|
+
end
|
134
136
|
end
|
135
137
|
end
|
136
138
|
end
|
137
139
|
end
|
138
|
-
end
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
def sample num
|
142
|
+
arr = Array.new(@short_mat.column_size) { |idx| idx }
|
143
|
+
set = arr.sample num
|
144
|
+
arr = []
|
145
|
+
set.length.times do |i|
|
146
|
+
for k in i + 1..set.length - 1
|
147
|
+
arr << [set[i], set[k]]
|
148
|
+
end
|
147
149
|
end
|
150
|
+
sampled_labels = Hash.new
|
151
|
+
set.each do |id|
|
152
|
+
sampled_labels[@labels[id]] = id
|
153
|
+
end
|
154
|
+
vals = []
|
155
|
+
arr.each do |id_set|
|
156
|
+
vals << @short_mat[id_set[0], id_set[1]]
|
157
|
+
end
|
158
|
+
[sampled_labels, vals, vals.mean, vals.sd].inspect
|
148
159
|
end
|
149
|
-
|
150
|
-
|
151
|
-
sampled_labels[@labels[id]] = id
|
152
|
-
end
|
153
|
-
vals = []
|
154
|
-
arr.each do |id_set|
|
155
|
-
vals << @short_mat[id_set[0], id_set[1]]
|
156
|
-
end
|
157
|
-
[sampled_labels, vals, vals.mean, vals.sd].inspect
|
160
|
+
|
161
|
+
attr_accessor :short_mat, :co_mat, :labels
|
158
162
|
end
|
159
163
|
|
160
|
-
attr_accessor :short_mat, :co_mat, :labels
|
161
164
|
end
|
162
165
|
|
163
166
|
|
data/lib/avsd/version.rb
CHANGED