least_squares 0.1.0 → 0.1.1

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.
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ CHANGELOG
3
+ LICENSE
data/CHANGELOG ADDED
@@ -0,0 +1,7 @@
1
+ 2010-05-17 Shane Emmons <semmons99@gmail.com>
2
+
3
+ * Use #zip in place of #each in #pearson
4
+
5
+ 2010-05-05 Shane Emmons <semmons99@gmail.com>
6
+
7
+ * initial release
data/README.md CHANGED
@@ -30,7 +30,16 @@ Results:
30
30
 
31
31
  Included methods are `#mean`, `#stdev`, `#pearson` and `#least_squares`.
32
32
 
33
+ CHANGELOG
34
+ ---------
35
+
36
+ - **May.05.17**: 0.1.1 release
37
+ - See {file:CHANGELOG} for changes
38
+
39
+ - **May.05.10**: 0.1.0 release
40
+ - See {file:CHANGELOG} for changes
41
+
33
42
  Copyright
34
43
  ---------
35
44
 
36
- Copyright (c) 2010 Shane Emmons. See LICENSE for details.
45
+ Copyright (c) 2010 Shane Emmons. See {file:LICENSE} for details.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'rake/clean'
4
4
 
5
- CLOBBER.include('.yardoc', 'doc')
5
+ CLOBBER.include('.yardoc', 'doc', 'pkg')
6
6
 
7
7
  begin
8
8
  require 'jeweler'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{least_squares}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Shane Emmons"]
12
+ s.date = %q{2010-05-17}
13
+ s.description = %q{This gem adds methods to the Math module to aid in calculating the Least Squares Regression Line given two arrays.}
14
+ s.email = %q{semmons99@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "CHANGELOG",
17
+ "LICENSE",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ ".yardopts",
23
+ "CHANGELOG",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "least_squares.gemspec",
29
+ "lib/least_squares.rb",
30
+ "spec/least_squares_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/semmons99/least_squares}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Calulate the Least Squares Regression Line}
39
+ s.test_files = [
40
+ "spec/least_squares_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
50
+ s.add_development_dependency(%q<yard>, [">= 0.5.4"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
53
+ s.add_dependency(%q<yard>, [">= 0.5.4"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
57
+ s.add_dependency(%q<yard>, [">= 0.5.4"])
58
+ end
59
+ end
60
+
data/lib/least_squares.rb CHANGED
@@ -39,13 +39,11 @@ module Math
39
39
  # ys = [9, 1, 0, 5, 4, 7, 7, 0, 9, 3]
40
40
  # Math.pearson(xs,ys) #=> 0.0581327470763432
41
41
  def Math.pearson(xs, ys)
42
- numerator = 0
43
42
  xs_mean = Math.mean(xs)
44
43
  ys_mean = Math.mean(ys)
45
- (0...xs.size).each do |i|
46
- numerator += (xs[i] - xs_mean) * (ys[i] - ys_mean)
47
- end
48
- numerator / (Math.sqrt(xs.inject(0){|s,x| s + (x - xs_mean) ** 2}) * Math.sqrt(ys.inject(0){|s,y| s + (y - ys_mean) ** 2}))
44
+ numerator = xs.zip(ys).inject(0){|s,n| s + ((n[0] - xs_mean) * (n[1] - ys_mean))}
45
+ denominator = Math.sqrt(xs.inject(0){|s,x| s + (x - xs_mean) ** 2}) * Math.sqrt(ys.inject(0){|s,y| s + (y - ys_mean) ** 2})
46
+ numerator / denominator
49
47
  end
50
48
 
51
49
  ##
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: least_squares
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Shane Emmons
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-05 00:00:00 -04:00
18
+ date: 2010-05-17 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 27
27
30
  segments:
28
31
  - 1
29
32
  - 3
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: yard
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 3
41
46
  segments:
42
47
  - 0
43
48
  - 5
@@ -52,15 +57,18 @@ executables: []
52
57
  extensions: []
53
58
 
54
59
  extra_rdoc_files:
60
+ - CHANGELOG
55
61
  - LICENSE
56
62
  - README.md
57
63
  files:
58
- - .document
59
64
  - .gitignore
65
+ - .yardopts
66
+ - CHANGELOG
60
67
  - LICENSE
61
68
  - README.md
62
69
  - Rakefile
63
70
  - VERSION
71
+ - least_squares.gemspec
64
72
  - lib/least_squares.rb
65
73
  - spec/least_squares_spec.rb
66
74
  - spec/spec.opts
@@ -75,23 +83,27 @@ rdoc_options:
75
83
  require_paths:
76
84
  - lib
77
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
78
87
  requirements:
79
88
  - - ">="
80
89
  - !ruby/object:Gem::Version
90
+ hash: 3
81
91
  segments:
82
92
  - 0
83
93
  version: "0"
84
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
85
96
  requirements:
86
97
  - - ">="
87
98
  - !ruby/object:Gem::Version
99
+ hash: 3
88
100
  segments:
89
101
  - 0
90
102
  version: "0"
91
103
  requirements: []
92
104
 
93
105
  rubyforge_project:
94
- rubygems_version: 1.3.6
106
+ rubygems_version: 1.3.7
95
107
  signing_key:
96
108
  specification_version: 3
97
109
  summary: Calulate the Least Squares Regression Line
data/.document DELETED
@@ -1,3 +0,0 @@
1
- README.md
2
- lib/**/*.rb
3
- LICENSE