cofi_cost 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,41 @@
1
+ h2. About
2
+
3
+ Playground for collaborative filtering in Ruby using NArray and rb-gsl.
4
+
5
+ h2. Usage
6
+
7
+ Create a variable to store the ratings as an NArray (number of users x number of tracks).
8
+
9
+ Set the number of features to learn, lambda (regularization parameter), and the number of iterations of gradient descent.
10
+
11
+ Call min_cost
12
+
13
+ <pre>
14
+ 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]]
15
+ num_features = 2
16
+ lambda = 1
17
+ iterations = 10
18
+ cofi = CofiCost.new(ratings, num_features, lambda, iterations, nil, nil)
19
+ cofi.min_cost
20
+ </pre>
21
+
22
+ The cost and predictions (an NArray of the original size of ratings) can then be
23
+ returned after running min_cost:
24
+
25
+ <pre>
26
+ cofi.cost
27
+ cofi.predictions
28
+ </pre>
29
+
30
+ h2. Installation
31
+
32
+ h3. gem
33
+
34
+ rails 3.2
35
+ # gem 'cofi_cost'
36
+ in your Gemfile
37
+ # <pre>bundle install</pre> from the command line
38
+
39
+ h2. License
40
+
41
+ MIT License 2012 Thomas Wolfe
data/lib/cofi_cost.rb CHANGED
@@ -6,10 +6,10 @@ include GSL::MultiMin
6
6
 
7
7
  class CofiCost
8
8
 
9
- attr_accessor :ratings, :num_features, :cost, :lambda
9
+ attr_accessor :ratings, :num_features, :cost, :lambda, :iterations
10
10
  attr_reader :boolean_rated, :num_tracks, :num_users, :features, :theta, :ratings_mean, :ratings_norm, :predictions
11
11
 
12
- def initialize(ratings, num_features, lambda, features = nil, theta = nil)
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
14
14
  @num_features = num_features
15
15
  @cost = 0
@@ -26,6 +26,7 @@ class CofiCost
26
26
  @ratings_mean, @ratings_norm = normalize_ratings
27
27
  @lambda = lambda
28
28
  @predictions = nil
29
+ @iterations = iterations
29
30
  end
30
31
 
31
32
  def normalize_ratings
@@ -114,7 +115,7 @@ class CofiCost
114
115
  x = minimizer.x
115
116
  f = minimizer.f
116
117
  printf("%5d %.5f %.5f %10.5f\n", iter, x[0], x[1], f)
117
- end while status == GSL::CONTINUE and iter < 10
118
+ end while status == GSL::CONTINUE and iter < @iterations
118
119
 
119
120
  unroll_params_init_shape(x)
120
121
  @cost = f
@@ -10,9 +10,10 @@ class CofiCostTest < Test::Unit::TestCase
10
10
  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]]
11
11
  num_features = 2
12
12
  lambda = 1
13
+ iterations = 10
13
14
  features = NArray[[0.139489,1.804804],[-0.501808,1.050885],[0.354079,-0.518884],[-0.015370,0.096253],[1.147623,-0.745562]]
14
15
  theta = NArray[[-0.079641,1.211386],[-0.130688,0.444762],[-0.789258,1.222232],[0.212132,-1.174545]]
15
- @c = CofiCost.new(ratings, num_features, lambda, features, theta)
16
+ @c = CofiCost.new(ratings, num_features, lambda, iterations, features, theta)
16
17
  end
17
18
 
18
19
  def teardown
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gsl
16
- requirement: &83060750 !ruby/object:Gem::Requirement
16
+ requirement: &84373640 !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: *83060750
24
+ version_requirements: *84373640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: narray
27
- requirement: &83060170 !ruby/object:Gem::Requirement
27
+ requirement: &84373200 !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: *83060170
35
+ version_requirements: *84373200
36
36
  description: Playground for collaborative filtering in Ruby using NArray and rb-gsl.
37
37
  email: tomwolfe@gmail.com
38
38
  executables: []
@@ -40,7 +40,7 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
  files:
42
42
  - lib/cofi_cost.rb
43
- - README
43
+ - README.textile
44
44
  - test/unit/test_cofi_cost.rb
45
45
  homepage: http://github.com/tomwolfe/cofi_cost
46
46
  licenses:
data/README DELETED
@@ -1,10 +0,0 @@
1
- Playground for collaborative filtering in Ruby using NArray and rb-gsl.
2
-
3
- “Snowflakes, like people, are all different and beautiful,
4
- but they can be a nuisance when they lose their identity in a mob”
5
-
6
- Roadmap:
7
- First release name: Graupel
8
- Release Date: TBD
9
- From http://en.wikipedia.org/wiki/Graupel Jan 1, 2012
10
- "Graupel refers to precipitation that forms when supercooled droplets of water are collected and freeze on a falling snowflake, forming a 2–5 mm (0.079–0.197 in) ball of rime. The term graupel is the German word for this meteorological phenomenon. Graupel is sometimes referred to as small hail, although the World Meteorological Organization defines small hail as snow pellets encapsulated by ice, a precipitation halfway between graupel and hail."