cofi_cost 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. data/lib/cofi_cost.rb +10 -7
  2. metadata +5 -5
data/lib/cofi_cost.rb CHANGED
@@ -6,8 +6,8 @@ include GSL::MultiMin
6
6
 
7
7
  class CofiCost
8
8
 
9
- attr_accessor :ratings, :num_features, :cost, :lambda, :iterations
10
- attr_reader :boolean_rated, :num_tracks, :num_users, :features, :theta, :ratings_mean, :ratings_norm, :predictions
9
+ attr_accessor :ratings, :num_features, :cost, :lambda, :iterations, :features, :theta
10
+ attr_reader :boolean_rated, :num_tracks, :num_users, :ratings_mean, :ratings_norm, :predictions
11
11
 
12
12
  def initialize(ratings, num_features = 2, lambda = 1, iterations = 10, features = nil, theta = nil)
13
13
  @ratings = ratings.to_f # make sure it's a float for correct normalization
@@ -33,7 +33,12 @@ class CofiCost
33
33
  for i in 0..@num_tracks-1 # sadly, @num_tracks.each_index does not work with NArray yet
34
34
  track_rating = @ratings[true,i] # get all user ratings for track i (including unrated)
35
35
  boolean_track_rating = boolean_rated[true,i] # get all user ratings that exist for track i
36
- @ratings_mean[i] = track_rating[boolean_track_rating].mean
36
+ track_rating_boolean = track_rating[boolean_track_rating]
37
+ if track_rating_boolean.size == 0
38
+ @ratings_mean[i] = 0
39
+ else
40
+ @ratings_mean[i] = track_rating_boolean.mean
41
+ end
37
42
 
38
43
  track_norm = @ratings_norm[true,i]
39
44
  track_norm[boolean_track_rating] = track_rating[boolean_track_rating] - @ratings_mean[i]
@@ -154,10 +159,8 @@ class NArray
154
159
  end
155
160
 
156
161
  ##ratings = NArray.float(4,5).indgen(0,2)
157
- #ratings = NArray[[5.0,4.0,0.0,0.0],[3.0,0.0,0.0,0.0],[4.0,0.0,0.0,0.0],[3.0,0.0,0.0,0.0],[3.0,0.0,0.0,0.0]]
158
- #num_features = 2
159
- #lambda = 1
160
- #g = CofiCost.new(ratings, num_features, lambda)
162
+ #ratings = NArray[[1.0,4.0],[4.0,0.0],[0.0,0.0]]
163
+ #g = CofiCost.new(ratings, 5, 1, 10, nil, nil)
161
164
  #puts g.theta.nil?
162
165
  #g.min_cost
163
166
  #puts "new theta"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cofi_cost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gsl
16
- requirement: &84373640 !ruby/object:Gem::Requirement
16
+ requirement: &77565430 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84373640
24
+ version_requirements: *77565430
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: narray
27
- requirement: &84373200 !ruby/object:Gem::Requirement
27
+ requirement: &77565210 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *84373200
35
+ version_requirements: *77565210
36
36
  description: Playground for collaborative filtering in Ruby using NArray and rb-gsl.
37
37
  email: tomwolfe@gmail.com
38
38
  executables: []