sixarm_ruby_math_statistics 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/README.md +88 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/lib/sixarm_ruby_math_statistics.rb +88 -0
- data/test/sixarm_ruby_math_statistics_test.rb +129 -0
- metadata +79 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/.gemtest
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# SixArm.com » Ruby » <br> Math Statistics
|
2
|
+
|
3
|
+
* Docs: <http://sixarm.com/sixarm_ruby_math_statistics/doc>
|
4
|
+
* Repo: <http://github.com/sixarm/sixarm_ruby_math_statistics>
|
5
|
+
* Email: Joel Parker Henderson, <joel@sixarm.com>
|
6
|
+
|
7
|
+
|
8
|
+
## Introduction
|
9
|
+
|
10
|
+
Math statistics methods.
|
11
|
+
|
12
|
+
See http://pallas.telperion.info/ruby-stats/
|
13
|
+
|
14
|
+
For docs go to <http://sixarm.com/sixarm_ruby_math_statistics/doc>
|
15
|
+
|
16
|
+
Want to help? We're happy to get pull requests.
|
17
|
+
|
18
|
+
|
19
|
+
## Quickstart
|
20
|
+
|
21
|
+
Install:
|
22
|
+
|
23
|
+
gem install sixarm_ruby_math_statistics
|
24
|
+
|
25
|
+
Bundler:
|
26
|
+
|
27
|
+
gem "sixarm_ruby_math_statistics", "=1.2.0"
|
28
|
+
|
29
|
+
Require:
|
30
|
+
|
31
|
+
require "sixarm_ruby_math_statistics"
|
32
|
+
|
33
|
+
|
34
|
+
## High Security (Optional)
|
35
|
+
|
36
|
+
To enable high security for all our gems:
|
37
|
+
|
38
|
+
wget http://sixarm.com/sixarm.pem
|
39
|
+
gem cert --add sixarm.pem
|
40
|
+
gem sources --add http://sixarm.com
|
41
|
+
|
42
|
+
To install with high security:
|
43
|
+
|
44
|
+
gem install sixarm_ruby_ --test --trust-policy HighSecurity
|
45
|
+
|
46
|
+
|
47
|
+
## Examples
|
48
|
+
|
49
|
+
require "sixarm_ruby_math_statistics"
|
50
|
+
[1,2].sum => 3
|
51
|
+
[1,2].mean => 1.5
|
52
|
+
[1,2].mean => 1.5
|
53
|
+
[1,2].variance => 0.25
|
54
|
+
[1,2].deviation => 0.5
|
55
|
+
|
56
|
+
|
57
|
+
## Changes
|
58
|
+
|
59
|
+
* 2012-03-14 1.1.0 Update docs, tests
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
You may choose any of these open source licenses:
|
65
|
+
|
66
|
+
* Apache License
|
67
|
+
* BSD License
|
68
|
+
* CreativeCommons License, Non-commercial Share Alike
|
69
|
+
* GNU General Public License Version 2 (GPL 2)
|
70
|
+
* GNU Lesser General Public License (LGPL)
|
71
|
+
* MIT License
|
72
|
+
* Perl Artistic License
|
73
|
+
* Ruby License
|
74
|
+
|
75
|
+
The software is provided "as is", without warranty of any kind,
|
76
|
+
express or implied, including but not limited to the warranties of
|
77
|
+
merchantability, fitness for a particular purpose and noninfringement.
|
78
|
+
|
79
|
+
In no event shall the authors or copyright holders be liable for any
|
80
|
+
claim, damages or other liability, whether in an action of contract,
|
81
|
+
tort or otherwise, arising from, out of or in connection with the
|
82
|
+
software or the use or other dealings in the software.
|
83
|
+
|
84
|
+
This license is for the included software that is created by SixArm;
|
85
|
+
some of the included software may have its own licenses, copyrights,
|
86
|
+
authors, etc. and these do take precedence over the SixArm license.
|
87
|
+
|
88
|
+
Copyright (c) 2005-2013 Joel Parker Henderson
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.8
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin rdoc
|
3
|
+
Please see README
|
4
|
+
=end
|
5
|
+
|
6
|
+
|
7
|
+
module Enumerable
|
8
|
+
|
9
|
+
|
10
|
+
# Examples
|
11
|
+
# [].sum => 0
|
12
|
+
# [1].sum => 1
|
13
|
+
# [1,2,3].sum => 5
|
14
|
+
#
|
15
|
+
# Example with default for empty
|
16
|
+
# [].sum(99) => 99
|
17
|
+
#
|
18
|
+
# Example with block
|
19
|
+
# [1,2,3].sum{|x| x*2} => 10
|
20
|
+
#
|
21
|
+
# This method is copied from rails to ensure compatibility.
|
22
|
+
|
23
|
+
def sum(identity = 0, &block)
|
24
|
+
return identity unless size > 0
|
25
|
+
if block_given?
|
26
|
+
map(&block).sum
|
27
|
+
else
|
28
|
+
inject { |sum, element| sum + element }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Examples
|
34
|
+
# [].mean => nil
|
35
|
+
# [1].mean => 1.0
|
36
|
+
# [1,2].mean => 1.5
|
37
|
+
# [1,2,9].mean => 4.0
|
38
|
+
|
39
|
+
def mean
|
40
|
+
size==0 ? nil : sum.to_f / size
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Examples
|
45
|
+
# [].median => nil
|
46
|
+
# [1].median => 1.0
|
47
|
+
# [1,2].median => 1.5
|
48
|
+
# [1,2,9].mean => 2.0
|
49
|
+
|
50
|
+
def median
|
51
|
+
size==0 ? nil : ((0==self.size%2) ? sort[size/2-1,2].mean : sort[self.size/2].to_f)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Examples
|
56
|
+
# [].sum_of_squares => 0
|
57
|
+
# [1].sum_of_squares => 1.0
|
58
|
+
# [1,2].sum_of_squares => 5.0
|
59
|
+
# [1,2,3].sum_of_squares => 14.0
|
60
|
+
|
61
|
+
def sum_of_squares
|
62
|
+
size==0 ? 0 : inject(0){|sum,x|sum+(x*x)}
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# Examples
|
67
|
+
# [].variance => nil
|
68
|
+
# [1].variance => 0.0
|
69
|
+
# [1,2].variance => 0.25
|
70
|
+
# [1,2,3,4].variance => 1.25
|
71
|
+
|
72
|
+
def variance
|
73
|
+
size==0 ? nil : ( m=mean and sum_of_squares.to_f/size - m*m )
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Examples
|
78
|
+
# [].deviation => nil
|
79
|
+
# [1].deviation => 0.0
|
80
|
+
# [1,2].deviation => 0.5
|
81
|
+
# [2,2,4,2,2].deviation => 0.8
|
82
|
+
|
83
|
+
def deviation
|
84
|
+
size==0 ? nil : Math::sqrt(variance)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'sixarm_ruby_math_statistics'
|
6
|
+
|
7
|
+
describe Enumerable do
|
8
|
+
|
9
|
+
describe "#sum" do
|
10
|
+
|
11
|
+
it "[] => 0, which tests edge case" do
|
12
|
+
[].sum.must_equal 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "[1] => 1, which tests minimal case" do
|
16
|
+
[1].sum.must_equal 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "[1, 2] => 3, which tests a couple args" do
|
20
|
+
[1, 2].sum.must_equal 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it "[1, 2, 3] => 6, which tests a few args" do
|
24
|
+
[1,2,3].sum.must_equal 6
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#mean" do
|
30
|
+
|
31
|
+
it "[] => nil, which tests edge case" do
|
32
|
+
[].mean.must_equal nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "[1] => 1.0, which tests minimal case" do
|
36
|
+
[1].mean.must_equal 1.0
|
37
|
+
end
|
38
|
+
|
39
|
+
it "[1, 2] => 1.5, which tests a couple args" do
|
40
|
+
[1,2].mean.must_equal 1.5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "[1, 2, 9] => 4.0, which tests a few args and distinguishes mean and median" do
|
44
|
+
[1,2,9].mean.must_equal 4.0
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#median" do
|
50
|
+
|
51
|
+
it "[] => nil, which tests edge case" do
|
52
|
+
[].median.must_equal nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it "[1] => 1.0, which tests minimal case" do
|
56
|
+
[1].median.must_equal 1.0
|
57
|
+
end
|
58
|
+
|
59
|
+
it "[1, 2] => 1.5, which tests a couple args" do
|
60
|
+
[1,2].median.must_equal 1.5
|
61
|
+
end
|
62
|
+
|
63
|
+
it "[1, 2, 9] => 2.0, which tests a few args and distiguishes mean from median" do
|
64
|
+
[1,2,9].median.must_equal 2.0
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#sum_of_squares" do
|
70
|
+
|
71
|
+
it "[] => 0, which tests edge case" do
|
72
|
+
[].sum_of_squares.must_equal []
|
73
|
+
end
|
74
|
+
|
75
|
+
it "[1] => 1.0, which tests minimal case" do
|
76
|
+
[1].sum_of_squares.must_equal 1.0
|
77
|
+
end
|
78
|
+
|
79
|
+
it "[1, 2] => 5.0, which tests a couple args" do
|
80
|
+
[1,2].sum_of_squares.must_equal 5.0
|
81
|
+
end
|
82
|
+
|
83
|
+
it "[1,2,3] => 14.0, which tests few args" do
|
84
|
+
[1,2,3].sum_of_squares.must_equal 14.0
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#variance" do
|
90
|
+
|
91
|
+
it "[] => 0, which tests edge case" do
|
92
|
+
[].variance.must_equal nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it "[1] => 0, which tests minimal case" do
|
96
|
+
[1].variance.must_equal 0.0
|
97
|
+
end
|
98
|
+
|
99
|
+
it "[1, 2] => 0.25, which tests a couple args" do
|
100
|
+
[1,2].variance.must_equal 0.25
|
101
|
+
end
|
102
|
+
|
103
|
+
it "[1,2,3,4] => 1.25, which tests a few args" do
|
104
|
+
[1,2,3,4].variance.must_equal 1.25
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#deviation" do
|
110
|
+
|
111
|
+
it "[] => 0, which tests edge case" do
|
112
|
+
[].deviation.must_equal 0
|
113
|
+
end
|
114
|
+
|
115
|
+
it "[1] => 0, which tests minimal case" do
|
116
|
+
[1].deviation.must_equal 0.0
|
117
|
+
end
|
118
|
+
|
119
|
+
it "[1, 2] => 0.25, which tests a couple args" do
|
120
|
+
[1,2].deviation.must_equal 0.5
|
121
|
+
end
|
122
|
+
|
123
|
+
it "[2, 2, 4, 2, 2] => 0.8 with delta 0.001, which tests a small delta" do
|
124
|
+
[2,2,4,2,2].deviation.must_equal 0.8 # TODO delta 0.001
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_math_statistics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SixArm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
|
14
|
+
Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
|
15
|
+
TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
|
16
|
+
WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
|
17
|
+
aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
|
18
|
+
RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlF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
+
d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
|
35
|
+
L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
|
36
|
+
dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
|
37
|
+
Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
38
|
+
date: 2012-03-17 00:00:00.000000000 Z
|
39
|
+
dependencies: []
|
40
|
+
description:
|
41
|
+
email: sixarm@sixarm.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gemtest
|
47
|
+
- Rakefile
|
48
|
+
- README.md
|
49
|
+
- VERSION
|
50
|
+
- lib/sixarm_ruby_math_statistics.rb
|
51
|
+
- test/sixarm_ruby_math_statistics_test.rb
|
52
|
+
homepage: http://sixarm.com/
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: ! 'SixArm Ruby Gem: Math statitics methods for sum, mean, median, mode, variance,
|
76
|
+
deviation, etc.'
|
77
|
+
test_files:
|
78
|
+
- test/sixarm_ruby_math_statistics_test.rb
|
79
|
+
has_rdoc: true
|
metadata.gz.sig
ADDED
Binary file
|