easystats 0.4.0.rc2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,6 +33,7 @@ array = [4, 8, 15, 16, 23, 42, 42]
33
33
  standard_deviation
34
34
  sum
35
35
  variance
36
+ weighted_moving_average
36
37
  ].each do |method|
37
38
  puts "#{method}: #{array.send(method.to_sym)}"
38
39
  end
@@ -48,4 +49,5 @@ range: 38
48
49
  standard_deviation: 15.295501984321435
49
50
  sum: 150
50
51
  variance: 200.53061224489798
52
+ weighted_moving_average: 30.476190476190474
51
53
  ```
@@ -7,6 +7,20 @@ class Array
7
7
 
8
8
  alias_method :average, :mean unless method_defined? :average
9
9
 
10
+ def weighted_moving_average
11
+ return if empty?
12
+ return first if one?
13
+ weighted_sum = 0
14
+ sum = 0
15
+ index = 0
16
+ each do |element|
17
+ weighted_sum = weighted_sum + (index * element)
18
+ sum += index
19
+ index += 1
20
+ end
21
+ weighted_sum.to_f / sum
22
+ end unless method_defined? :weighted_moving_average
23
+
10
24
  def median
11
25
  return if empty?
12
26
 
@@ -1,3 +1,3 @@
1
1
  module Easystats
2
- VERSION = "0.4.0.rc2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -13,14 +13,16 @@ describe Array do
13
13
  :standard_deviation => nil,
14
14
  :sum => nil,
15
15
  :variance => nil,
16
- :probability_distribution => nil
16
+ :probability_distribution => nil,
17
+ :weighted_moving_average => nil
17
18
  }
18
19
 
19
20
  build_stats_spec [1,1,1,2,2], {
20
21
  :probability_distribution => {
21
22
  1 => 0.6,
22
23
  2 => 0.4
23
- }
24
+ },
25
+ :weighted_moving_average => 1.7
24
26
  }
25
27
 
26
28
  build_stats_spec [0], {
@@ -31,7 +33,8 @@ describe Array do
31
33
  :standard_deviation => 0,
32
34
  :sum => 0,
33
35
  :variance => 0.0,
34
- :probability_distribution => {0 => 1.0}
36
+ :probability_distribution => { 0 => 1.0 },
37
+ :weighted_moving_average => 0.0
35
38
  }
36
39
 
37
40
  build_stats_spec [1], {
@@ -42,7 +45,8 @@ describe Array do
42
45
  :standard_deviation => 0,
43
46
  :sum => 1,
44
47
  :variance => 0.0,
45
- :probability_distribution => {1 => 1.0}
48
+ :probability_distribution => { 1 => 1.0 },
49
+ :weighted_moving_average => 1.0
46
50
  }
47
51
 
48
52
  build_stats_spec [1,2], {
@@ -53,7 +57,8 @@ describe Array do
53
57
  :standard_deviation => 0.707106781186548,
54
58
  :sum => 3,
55
59
  :variance => 0.25,
56
- :probability_distribution => {1 => 0.5, 2 => 0.5}
60
+ :probability_distribution => { 1 => 0.5, 2 => 0.5 },
61
+ :weighted_moving_average => 2.0
57
62
  }
58
63
 
59
64
  build_stats_spec [1,2,3], {
@@ -64,7 +69,8 @@ describe Array do
64
69
  :standard_deviation => 1,
65
70
  :sum => 6,
66
71
  :variance => 2.0 / 3.0,
67
- :probability_distribution => {1 => 0.3333333333333333, 2 => 0.3333333333333333, 3 => 0.3333333333333333}
72
+ :probability_distribution => { 1 => 0.3333333333333333, 2 => 0.3333333333333333, 3 => 0.3333333333333333 },
73
+ :weighted_moving_average => 2.6666666666666665
68
74
  }
69
75
 
70
76
  build_stats_spec [1,2,3,4], {
@@ -75,7 +81,8 @@ describe Array do
75
81
  :standard_deviation => 1.29099444873581,
76
82
  :sum => 10,
77
83
  :variance => 1.25,
78
- :probability_distribution => {1 => 0.25, 2=>0.25, 3=> 0.25, 4=>0.25}
84
+ :probability_distribution => {1 => 0.25, 2 => 0.25, 3 => 0.25, 4 => 0.25 },
85
+ :weighted_moving_average => 3.3333333333333335
79
86
 
80
87
  }
81
88
 
@@ -87,7 +94,8 @@ describe Array do
87
94
  :standard_deviation => 0.5773502691896257,
88
95
  :sum => 6,
89
96
  :variance => 0.25,
90
- :probability_distribution => {1=>0.5, 2=>0.5}
97
+ :probability_distribution => { 1=>0.5, 2=>0.5 },
98
+ :weighted_moving_average => 1.8333333333333333
91
99
  }
92
100
 
93
101
  build_stats_spec [1,2,2,4], {
@@ -98,7 +106,8 @@ describe Array do
98
106
  :standard_deviation => 1.2583057392117916,
99
107
  :sum => 9,
100
108
  :variance => 1.1875,
101
- :probability_distribution => { 1 => 0.25, 2 => 0.5, 4 => 0.25 }
109
+ :probability_distribution => { 1 => 0.25, 2 => 0.5, 4 => 0.25 },
110
+ :weighted_moving_average => 3.0
102
111
  }
103
112
 
104
113
  build_stats_spec [1,3,3,4], {
@@ -109,7 +118,8 @@ describe Array do
109
118
  :standard_deviation => 1.2583057392117916,
110
119
  :sum => 11,
111
120
  :variance => 1.1875,
112
- :probability_distribution => { 1 => 0.25, 3 => 0.5, 4=>0.25 }
121
+ :probability_distribution => { 1 => 0.25, 3 => 0.5, 4 => 0.25 },
122
+ :weighted_moving_average => 3.5
113
123
  }
114
124
 
115
125
  build_stats_spec (0..100).to_a, {
@@ -119,7 +129,8 @@ describe Array do
119
129
  :range => 100,
120
130
  :standard_deviation => 29.300170647967224,
121
131
  :sum => 5050,
122
- :variance => 850.0
132
+ :variance => 850.0,
133
+ :weighted_moving_average => 67
123
134
  }
124
135
 
125
136
  build_stats_spec (1..100).to_a, {
@@ -129,7 +140,8 @@ describe Array do
129
140
  :range => 99,
130
141
  :standard_deviation => 29.011491975882016,
131
142
  :sum => 5050,
132
- :variance => 833.25
143
+ :variance => 833.25,
144
+ :weighted_moving_average => 67.33333333333333
133
145
  }
134
146
 
135
147
  build_stats_spec [-1,0,1], {
@@ -140,7 +152,8 @@ describe Array do
140
152
  :standard_deviation => 1,
141
153
  :sum => 0,
142
154
  :variance => 0.6666666666666666,
143
- :probability_distribution => { -1 => 0.3333333333333333, 0 => 0.3333333333333333, 1 => 0.3333333333333333 }
155
+ :probability_distribution => { -1 => 0.3333333333333333, 0 => 0.3333333333333333, 1 => 0.3333333333333333 },
156
+ :weighted_moving_average => 0.6666666666666666
144
157
  }
145
158
 
146
159
  build_stats_spec [1,2.5], {
@@ -151,7 +164,8 @@ describe Array do
151
164
  :standard_deviation => 1.0606601717798212,
152
165
  :sum => 3.5,
153
166
  :variance =>0.5625,
154
- :probability_distribution => { 1 => 0.5, 2.5=>0.5 }
167
+ :probability_distribution => { 1 => 0.5, 2.5 => 0.5 },
168
+ :weighted_moving_average => 2.5
155
169
  }
156
170
  end
157
171
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easystats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc2
5
- prerelease: 6
4
+ version: 0.5.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthew Grigajtis
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-23 00:00:00.000000000 Z
13
+ date: 2013-04-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: guard-rspec
@@ -114,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  none: false
116
116
  requirements:
117
- - - ! '>'
117
+ - - ! '>='
118
118
  - !ruby/object:Gem::Version
119
- version: 1.3.1
119
+ version: '0'
120
120
  requirements: []
121
121
  rubyforge_project: easystats
122
122
  rubygems_version: 1.8.23