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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbc2c36a98486f496c7c5aed996b3250def9f87ce444dc48e4f8c9164db9e630
4
- data.tar.gz: a862bf6d66484f5dac154586dea0a89d85a4873644ff00f4420ac3dfc0c9a852
3
+ metadata.gz: b1d7b56a9c40088874bbd79ff7fa5bf8783a4406a9e5dadf1dddb04303ca7fee
4
+ data.tar.gz: 0d843da83fc246b5da2aa097eba3534d729b51d9b03c368226b884fe33e61795
5
5
  SHA512:
6
- metadata.gz: 948d564359a61c1ad356c0806e34c57d6dcae354cc55cf1bff4bce5f40ee94b37edd3c5d8fc35e36cb0aeae59ee467acb561c0074bbb7fb8da929b7e548bcf1f
7
- data.tar.gz: f3d98a62dd540957343a29c01624586e853a0f400f8105d2ae67d34e85e408b652befc0d702720e4d7e33852ac738b2a8e276acb6ac143195620386b07e99084
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
- # TODO handle this better
37
- raise "No HOME" unless ENV["HOME"]
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 < 6
5
- raise Disco::Error, "Requires Active Record 6+"
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
@@ -64,8 +64,8 @@ module Disco
64
64
  end
65
65
 
66
66
  if @top_items
67
- @item_count = [0] * @item_map.size
68
- @item_sum = [0.0] * @item_map.size
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: Base64.strict_encode64(@user_factors.to_binary),
274
- item_factors: Base64.strict_encode64(@item_factors.to_binary),
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(Base64.strict_decode64(obj["user_factors"]), [@user_map.size, @factors])
499
- @item_factors = Numo::SFloat.from_binary(Base64.strict_decode64(obj["item_factors"]), [@item_map.size, @factors])
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
@@ -1,3 +1,3 @@
1
1
  module Disco
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.1"
3
3
  end
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.2
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-06-24 00:00:00.000000000 Z
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.2'
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.2'
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: '0'
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: '0'
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: '2.7'
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.5.11
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: []