cmfrec 0.3.4 → 0.4.0
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/CHANGELOG.md +4 -0
- data/LICENSE.txt +1 -1
- data/lib/cmfrec/data.rb +14 -30
- data/lib/cmfrec/recommender.rb +29 -29
- data/lib/cmfrec/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69ad906f81dd246a338be341b9e80ed3737fcda945be654128116e16bef07626
|
|
4
|
+
data.tar.gz: 8430bd95b51e2f00dd57976d963fa60bb0d82e334951349be32f0a54f3a0aa1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59212029fa16618b83b11a9f3e9a5d32feac79c6aa9d017333c6b652d39edb72080efdab2020d5b0ce5b969ca0ca23ca2dfeb846d83f91883bd7d4c024004ac5
|
|
7
|
+
data.tar.gz: d0a3d418eac306dba55a2aa4d5ef605e31f1ac4fa5d2a87adcc0d2c298b374b90b724df88e61910b18aa965e9b76105113164aedf1943200d5b77e0c576d8d26
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/lib/cmfrec/data.rb
CHANGED
|
@@ -54,9 +54,7 @@ module Cmfrec
|
|
|
54
54
|
|
|
55
55
|
def download_file(fname, origin, file_hash:)
|
|
56
56
|
require "digest"
|
|
57
|
-
require "
|
|
58
|
-
require "net/http"
|
|
59
|
-
require "tmpdir"
|
|
57
|
+
require "open-uri"
|
|
60
58
|
|
|
61
59
|
cache_home = ENV["XDG_CACHE_HOME"] || "#{ENV.fetch("HOME")}/.cache"
|
|
62
60
|
dest = "#{cache_home}/cmfrec/#{fname}"
|
|
@@ -64,38 +62,24 @@ module Cmfrec
|
|
|
64
62
|
|
|
65
63
|
return dest if File.exist?(dest)
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
# and deflateresponses unless a Range header was sent.
|
|
76
|
-
# https://ruby-doc.org/stdlib-2.6.4/libdoc/net/http/rdoc/Net/HTTP.html
|
|
77
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
78
|
-
request = Net::HTTP::Get.new(uri)
|
|
79
|
-
|
|
80
|
-
puts "Downloading data from #{origin}"
|
|
81
|
-
File.open(temp_path, "wb") do |f|
|
|
82
|
-
http.request(request) do |response|
|
|
83
|
-
response.read_body do |chunk|
|
|
84
|
-
f.write(chunk)
|
|
85
|
-
digest.update(chunk)
|
|
86
|
-
end
|
|
65
|
+
puts "Downloading data from #{origin}"
|
|
66
|
+
URI.parse(origin).open(redirect: false) do |download|
|
|
67
|
+
digest =
|
|
68
|
+
if download.respond_to?(:path)
|
|
69
|
+
download.flush
|
|
70
|
+
Digest::SHA256.file(download.path).hexdigest
|
|
71
|
+
else
|
|
72
|
+
Digest::SHA256.hexdigest(download.string)
|
|
87
73
|
end
|
|
74
|
+
|
|
75
|
+
if digest != file_hash
|
|
76
|
+
raise Error, "Bad hash: #{digest}"
|
|
88
77
|
end
|
|
89
|
-
|
|
78
|
+
puts "Hash verified: #{file_hash}"
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
raise Error, "Bad hash: #{digest.hexdigest}"
|
|
80
|
+
IO.copy_stream(download, dest)
|
|
93
81
|
end
|
|
94
82
|
|
|
95
|
-
puts "Hash verified: #{file_hash}"
|
|
96
|
-
|
|
97
|
-
FileUtils.mv(temp_path, dest)
|
|
98
|
-
|
|
99
83
|
dest
|
|
100
84
|
end
|
|
101
85
|
end
|
data/lib/cmfrec/recommender.rb
CHANGED
|
@@ -158,10 +158,10 @@ module Cmfrec
|
|
|
158
158
|
@lambda_, @l1_lambda, @alpha, @w_main, @w_user,
|
|
159
159
|
@w_main_multiplier,
|
|
160
160
|
@apply_log_transf,
|
|
161
|
-
nil, #BeTBe
|
|
162
|
-
nil, #BtB
|
|
163
|
-
nil, #BeTBeChol
|
|
164
|
-
nil, #CtUbias
|
|
161
|
+
nil, # BeTBe
|
|
162
|
+
nil, # BtB
|
|
163
|
+
nil, # BeTBeChol
|
|
164
|
+
nil, # CtUbias
|
|
165
165
|
include_ix, n_include,
|
|
166
166
|
exclude_ix, n_exclude,
|
|
167
167
|
outp_ix, outp_score,
|
|
@@ -194,15 +194,15 @@ module Cmfrec
|
|
|
194
194
|
@scale_bias_const, scaling_bias_a,
|
|
195
195
|
@w_main, @w_user, @w_implicit,
|
|
196
196
|
n_max, @include_all_x,
|
|
197
|
-
nil, #BtB
|
|
198
|
-
nil, #TransBtBinvBt
|
|
199
|
-
nil, #BtXbias
|
|
200
|
-
nil, #BeTBeChol
|
|
201
|
-
nil, #BiTBi
|
|
202
|
-
nil, #CtCw
|
|
203
|
-
nil, #TransCtCinvCt
|
|
204
|
-
nil, #CtUbias
|
|
205
|
-
nil, #B_plus_bias
|
|
197
|
+
nil, # BtB
|
|
198
|
+
nil, # TransBtBinvBt
|
|
199
|
+
nil, # BtXbias
|
|
200
|
+
nil, # BeTBeChol
|
|
201
|
+
nil, # BiTBi
|
|
202
|
+
nil, # CtCw
|
|
203
|
+
nil, # TransCtCinvCt
|
|
204
|
+
nil, # CtUbias
|
|
205
|
+
nil, # B_plus_bias
|
|
206
206
|
include_ix, n_include,
|
|
207
207
|
exclude_ix, n_exclude,
|
|
208
208
|
outp_ix, outp_score,
|
|
@@ -275,7 +275,7 @@ module Cmfrec
|
|
|
275
275
|
# mean
|
|
276
276
|
obj[:global_mean] = @global_mean
|
|
277
277
|
|
|
278
|
-
unless (@user_info_map.keys + @item_info_map.keys).all?
|
|
278
|
+
unless (@user_info_map.keys + @item_info_map.keys).all?(Symbol)
|
|
279
279
|
raise "Side info keys must be symbols to save"
|
|
280
280
|
end
|
|
281
281
|
|
|
@@ -449,10 +449,10 @@ module Cmfrec
|
|
|
449
449
|
@use_cg, @max_cg_steps, @precondition_cg, @finalize_chol,
|
|
450
450
|
@nonneg, @max_cd_steps, @nonneg_c, @nonneg_d,
|
|
451
451
|
@precompute_for_predictions,
|
|
452
|
-
nil, #precomputedBtB
|
|
453
|
-
nil, #precomputedBeTBe
|
|
454
|
-
nil, #precomputedBeTBeChol
|
|
455
|
-
nil #precomputedCtUbias
|
|
452
|
+
nil, # precomputedBtB
|
|
453
|
+
nil, # precomputedBeTBe
|
|
454
|
+
nil, # precomputedBeTBeChol
|
|
455
|
+
nil # precomputedCtUbias
|
|
456
456
|
]
|
|
457
457
|
check_status FFI.fit_collective_implicit_als(*fiddle_args(args))
|
|
458
458
|
|
|
@@ -505,15 +505,15 @@ module Cmfrec
|
|
|
505
505
|
@nonneg, @max_cd_steps, @nonneg_c, @nonneg_d,
|
|
506
506
|
@precompute_for_predictions,
|
|
507
507
|
@include_all_x,
|
|
508
|
-
nil, #B_plus_bias
|
|
509
|
-
nil, #precomputedBtB
|
|
510
|
-
nil, #precomputedTransBtBinvBt
|
|
511
|
-
nil, #precomputedBtXbias
|
|
512
|
-
nil, #precomputedBeTBeChol
|
|
513
|
-
nil, #precomputedBiTBi
|
|
514
|
-
nil, #precomputedTransCtCinvCt
|
|
515
|
-
nil, #precomputedCtCw
|
|
516
|
-
nil #precomputedCtUbias
|
|
508
|
+
nil, # B_plus_bias
|
|
509
|
+
nil, # precomputedBtB
|
|
510
|
+
nil, # precomputedTransBtBinvBt
|
|
511
|
+
nil, # precomputedBtXbias
|
|
512
|
+
nil, # precomputedBeTBeChol
|
|
513
|
+
nil, # precomputedBiTBi
|
|
514
|
+
nil, # precomputedTransCtCinvCt
|
|
515
|
+
nil, # precomputedCtCw
|
|
516
|
+
nil # precomputedCtUbias
|
|
517
517
|
]
|
|
518
518
|
check_status FFI.fit_collective_explicit_als(*fiddle_args(args))
|
|
519
519
|
|
|
@@ -604,7 +604,7 @@ module Cmfrec
|
|
|
604
604
|
unless ratings.all? { |r| !r.nil? }
|
|
605
605
|
raise ArgumentError, "Missing ratings"
|
|
606
606
|
end
|
|
607
|
-
unless ratings.all?
|
|
607
|
+
unless ratings.all?(Numeric)
|
|
608
608
|
raise ArgumentError, "Ratings must be numeric"
|
|
609
609
|
end
|
|
610
610
|
end
|
|
@@ -660,7 +660,7 @@ module Cmfrec
|
|
|
660
660
|
def prepare_top_n(count: nil, rated: nil, item_ids: nil)
|
|
661
661
|
if item_ids
|
|
662
662
|
# remove missing ids
|
|
663
|
-
item_ids = item_ids.
|
|
663
|
+
item_ids = item_ids.filter_map { |v| @item_map[v] }
|
|
664
664
|
return [] if item_ids.empty?
|
|
665
665
|
|
|
666
666
|
include_ix = int_ptr(item_ids)
|
data/lib/cmfrec/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cmfrec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
@@ -59,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
59
59
|
requirements:
|
|
60
60
|
- - ">="
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '3.
|
|
62
|
+
version: '3.3'
|
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
68
|
requirements: []
|
|
69
|
-
rubygems_version:
|
|
69
|
+
rubygems_version: 4.0.6
|
|
70
70
|
specification_version: 4
|
|
71
71
|
summary: Recommendations for Ruby using collective matrix factorization
|
|
72
72
|
test_files: []
|