disco 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/disco/data.rb +2 -3
- data/lib/disco/model.rb +2 -2
- data/lib/disco/recommender.rb +6 -64
- data/lib/disco/version.rb +1 -1
- metadata +8 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d7b56a9c40088874bbd79ff7fa5bf8783a4406a9e5dadf1dddb04303ca7fee
|
4
|
+
data.tar.gz: 0d843da83fc246b5da2aa097eba3534d729b51d9b03c368226b884fe33e61795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49341b30e2ffa7348c19af2c0073f8f9e15afe3dcd856922fb5ae3fd3cd6e5ab555731c38bf3678f5f4efb064ecfce994d24b6238aa93fbc62e4621d7de036ab
|
7
|
+
data.tar.gz: 9bb387230927cf55e94c3614c4a68881031206c9ee2dee2d48c06f6053134cdff0af4c4d24eba825acf3429394556368378bd51860f4dfcddf0dd1742309794f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 0.5.1 (2024-12-29)
|
2
|
+
|
3
|
+
- Removed dependency on `base64` gem for serialization
|
4
|
+
|
5
|
+
## 0.5.0 (2024-10-22)
|
6
|
+
|
7
|
+
- Changed dataset directory to match XDG Base Directory Specification
|
8
|
+
- Dropped support for marshal serialization
|
9
|
+
- Dropped support for Ruby < 3.1 and Rails < 7
|
10
|
+
|
1
11
|
## 0.4.2 (2024-06-24)
|
2
12
|
|
3
13
|
- Removed dependency on `csv` gem for `load_movielens`
|
data/README.md
CHANGED
@@ -194,7 +194,7 @@ json = File.read("recommender.json")
|
|
194
194
|
recommender = Disco::Recommender.load_json(json)
|
195
195
|
```
|
196
196
|
|
197
|
-
Alternatively, you can store only the factors and use a library like [Neighbor](https://github.com/ankane/neighbor). See the [examples](https://github.com/ankane/neighbor/tree/master/examples).
|
197
|
+
Alternatively, you can store only the factors and use a library like [Neighbor](https://github.com/ankane/neighbor). See the [examples](https://github.com/ankane/neighbor/tree/master/examples/disco).
|
198
198
|
|
199
199
|
## Algorithms
|
200
200
|
|
data/lib/disco/data.rb
CHANGED
@@ -33,9 +33,8 @@ module Disco
|
|
33
33
|
require "net/http"
|
34
34
|
require "tmpdir"
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
dest = "#{ENV["HOME"]}/.disco/#{fname}"
|
36
|
+
cache_home = ENV["XDG_CACHE_HOME"] || "#{ENV.fetch("HOME")}/.cache"
|
37
|
+
dest = "#{cache_home}/disco/#{fname}"
|
39
38
|
FileUtils.mkdir_p(File.dirname(dest))
|
40
39
|
|
41
40
|
return dest if File.exist?(dest)
|
data/lib/disco/model.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Disco
|
2
2
|
module Model
|
3
3
|
def has_recommended(name, class_name: nil)
|
4
|
-
if ActiveRecord::VERSION::MAJOR <
|
5
|
-
raise Disco::Error, "Requires Active Record
|
4
|
+
if ActiveRecord::VERSION::MAJOR < 7
|
5
|
+
raise Disco::Error, "Requires Active Record 7+"
|
6
6
|
end
|
7
7
|
|
8
8
|
class_name ||= name.to_s.singularize.camelize
|
data/lib/disco/recommender.rb
CHANGED
@@ -64,8 +64,8 @@ module Disco
|
|
64
64
|
end
|
65
65
|
|
66
66
|
if @top_items
|
67
|
-
@item_count =
|
68
|
-
@item_sum =
|
67
|
+
@item_count = Array.new(@item_map.size, 0)
|
68
|
+
@item_sum = Array.new(@item_map.size, 0.0)
|
69
69
|
train_set.each do |v|
|
70
70
|
i = @item_map[v[:item_id]]
|
71
71
|
@item_count[i] += 1
|
@@ -261,7 +261,6 @@ module Disco
|
|
261
261
|
end
|
262
262
|
|
263
263
|
def to_json
|
264
|
-
require "base64"
|
265
264
|
require "json"
|
266
265
|
|
267
266
|
obj = {
|
@@ -270,8 +269,8 @@ module Disco
|
|
270
269
|
item_ids: @item_map.keys,
|
271
270
|
rated: @user_map.map { |_, u| (@rated[u] || {}).keys },
|
272
271
|
global_mean: @global_mean,
|
273
|
-
user_factors:
|
274
|
-
item_factors:
|
272
|
+
user_factors: [@user_factors.to_binary].pack("m0"),
|
273
|
+
item_factors: [@item_factors.to_binary].pack("m0"),
|
275
274
|
factors: @factors,
|
276
275
|
epochs: @epochs,
|
277
276
|
verbose: @verbose
|
@@ -431,72 +430,15 @@ module Disco
|
|
431
430
|
end
|
432
431
|
end
|
433
432
|
|
434
|
-
def marshal_dump
|
435
|
-
warn "[disco] Marshal serialization is deprecated - use JSON instead"
|
436
|
-
|
437
|
-
obj = {
|
438
|
-
implicit: @implicit,
|
439
|
-
user_map: @user_map,
|
440
|
-
item_map: @item_map,
|
441
|
-
rated: @rated,
|
442
|
-
global_mean: @global_mean,
|
443
|
-
user_factors: @user_factors,
|
444
|
-
item_factors: @item_factors,
|
445
|
-
factors: @factors,
|
446
|
-
epochs: @epochs,
|
447
|
-
verbose: @verbose
|
448
|
-
}
|
449
|
-
|
450
|
-
unless @implicit
|
451
|
-
obj[:min_rating] = @min_rating
|
452
|
-
obj[:max_rating] = @max_rating
|
453
|
-
end
|
454
|
-
|
455
|
-
if @top_items
|
456
|
-
obj[:item_count] = @item_count
|
457
|
-
obj[:item_sum] = @item_sum
|
458
|
-
end
|
459
|
-
|
460
|
-
obj
|
461
|
-
end
|
462
|
-
|
463
|
-
def marshal_load(obj)
|
464
|
-
warn "[disco] Marshal serialization is deprecated - use JSON instead"
|
465
|
-
|
466
|
-
@implicit = obj[:implicit]
|
467
|
-
@user_map = obj[:user_map]
|
468
|
-
@item_map = obj[:item_map]
|
469
|
-
@rated = obj[:rated]
|
470
|
-
@global_mean = obj[:global_mean]
|
471
|
-
@user_factors = obj[:user_factors]
|
472
|
-
@item_factors = obj[:item_factors]
|
473
|
-
@factors = obj[:factors]
|
474
|
-
@epochs = obj[:epochs]
|
475
|
-
@verbose = obj[:verbose]
|
476
|
-
|
477
|
-
unless @implicit
|
478
|
-
@min_rating = obj[:min_rating]
|
479
|
-
@max_rating = obj[:max_rating]
|
480
|
-
end
|
481
|
-
|
482
|
-
@top_items = obj.key?(:item_count)
|
483
|
-
if @top_items
|
484
|
-
@item_count = obj[:item_count]
|
485
|
-
@item_sum = obj[:item_sum]
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
433
|
def json_load(obj)
|
490
|
-
require "base64"
|
491
|
-
|
492
434
|
@implicit = obj["implicit"]
|
493
435
|
@user_map = obj["user_ids"].map.with_index.to_h
|
494
436
|
@item_map = obj["item_ids"].map.with_index.to_h
|
495
437
|
@rated = obj["rated"].map.with_index.to_h { |r, i| [i, r.to_h { |v| [v, true] }] }
|
496
438
|
@global_mean = obj["global_mean"].to_f
|
497
439
|
@factors = obj["factors"].to_i
|
498
|
-
@user_factors = Numo::SFloat.from_binary(
|
499
|
-
@item_factors = Numo::SFloat.from_binary(
|
440
|
+
@user_factors = Numo::SFloat.from_binary(obj["user_factors"].unpack1("m0"), [@user_map.size, @factors])
|
441
|
+
@item_factors = Numo::SFloat.from_binary(obj["item_factors"].unpack1("m0"), [@item_map.size, @factors])
|
500
442
|
@epochs = obj["epochs"].to_i
|
501
443
|
@verbose = obj["verbose"]
|
502
444
|
|
data/lib/disco/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-
|
10
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: libmf
|
@@ -16,29 +15,28 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
18
|
+
version: '0.4'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
25
|
+
version: '0.4'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: numo-narray
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
32
|
+
version: 0.9.2
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
description:
|
39
|
+
version: 0.9.2
|
42
40
|
email: andrew@ankane.org
|
43
41
|
executables: []
|
44
42
|
extensions: []
|
@@ -61,7 +59,6 @@ homepage: https://github.com/ankane/disco
|
|
61
59
|
licenses:
|
62
60
|
- MIT
|
63
61
|
metadata: {}
|
64
|
-
post_install_message:
|
65
62
|
rdoc_options: []
|
66
63
|
require_paths:
|
67
64
|
- lib
|
@@ -69,15 +66,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
66
|
requirements:
|
70
67
|
- - ">="
|
71
68
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
69
|
+
version: '3.1'
|
73
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
72
|
- - ">="
|
76
73
|
- !ruby/object:Gem::Version
|
77
74
|
version: '0'
|
78
75
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
80
|
-
signing_key:
|
76
|
+
rubygems_version: 3.6.2
|
81
77
|
specification_version: 4
|
82
78
|
summary: Recommendations for Ruby and Rails using collaborative filtering
|
83
79
|
test_files: []
|