histogram 0.2.1.3 → 0.2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7328c3ca0000e0400eb3f755153170bcc02d017
4
- data.tar.gz: 4df8b91ec124fddbca08099ab7ac7302bde3a682
3
+ metadata.gz: deecc5f583bc853f2e7dccdb1e4cb8311acb45c0
4
+ data.tar.gz: 879bdf4508f55f29a1c560328d11b48ef2acc48d
5
5
  SHA512:
6
- metadata.gz: db2f21ceb25dcc0558923e385f07147b1a16aa824ef3119fc3097a2e26bfdb9f6b30c6d7677577c0ab88d53fb22a14f4848a7ccf7162c48ec78242c467b10cc3
7
- data.tar.gz: a6ceb91a51ba4da871e9f00635fd1277e3046e9ac24d0a95e12cb39ad8fc4f7119c9076ac30d96efbde679f44fa6fbee2f6e1a98c7c8d23ad18ebb61473a9878
6
+ metadata.gz: c29c405ec579ac016526801f7845767aae155ee186f63dd8610d3d1596e1542126c2749623d84ae64c11e68a95b9b6d446d4b5a34bbecdfe11a20cd7d2d8fdaf
7
+ data.tar.gz: 81fc3b7306f61085b57cf103d6815f894841af07549421647ff343179b521f794e6ac4237cf49d6158587ab79c3aebf0b47e908ceeb26c8daaa3995feb333abe
data/README.md CHANGED
@@ -4,7 +4,10 @@
4
4
 
5
5
  Generates histograms similar to R's hist and numpy's histogram functions.
6
6
  Inspired somewhat by [Richard Cottons's matlab implementation](http://www.mathworks.com/matlabcentral/fileexchange/21033-calculate-number-of-bins-for-histogram)
7
- and the wikipedia [histogram article](http://en.wikipedia.org/wiki/Histogram).
7
+ and the wikipedia [histogram
8
+ article](http://en.wikipedia.org/wiki/Histogram).
9
+
10
+ Tested on latest MRI 1.9.x, 2.x, and jruby (no NArray support for jruby). Known to work on MRI 1.8.7.
8
11
 
9
12
  ### Typical usage:
10
13
 
@@ -12,13 +15,13 @@ and the wikipedia [histogram article](http://en.wikipedia.org/wiki/Histogram).
12
15
 
13
16
  data = [0,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,5,5,9,9,10]
14
17
  # by default, uses Scott's method to calculate optimal number of bins
15
- # and the bin values are midpoints between the bin edges
16
- (bins, freqs) = data.histogram
17
- # equivalent to: data.histogram(:scott, :bin_boundary => :avg)
18
+ # and the bin values are midpoints between the bin edges
19
+ (bins, freqs) = data.histogram
20
+ # equivalent to: data.histogram(:scott, :bin_boundary => :avg)
18
21
 
19
22
  ### Multiple types of binning behavior:
20
23
 
21
- # :scott, :fd, :sturges, or :middle
24
+ # :scott, :fd, :sturges, or :middle
22
25
  data.histogram(:fd) # use Freedman-Diaconis method to calc num bins
23
26
  data.histogram(:middle) # (median value between the three methods)
24
27
  (bins, freqs) = data.histogram(20) # use 20 bins
@@ -33,7 +36,7 @@ and the wikipedia [histogram article](http://en.wikipedia.org/wiki/Histogram).
33
36
  (bins, freqs) = data.histogram(:bin_width => 0.5)
34
37
 
35
38
  ### Multiple Datasets:
36
-
39
+
37
40
  Sometimes, we want to create histograms where the bins are calculated based on
38
41
  all the data sets. That way, the resulting frequencies will all line up:
39
42
 
@@ -41,12 +44,12 @@ all the data sets. That way, the resulting frequencies will all line up:
41
44
  (bins, *freqs) = set1.histogram(30, :other_sets => [[3,3,4,4,5], [-1,0,0,3,3,6]])
42
45
 
43
46
  ### Histograms with weights/fractions:
44
-
47
+
45
48
  # histogramming with weights
46
49
  data.histogram(20, :weights => [3,3,8,8,9,9,3,3,3,3])
47
50
 
48
51
  ### Works with NArray objects
49
-
52
+
50
53
  require 'histogram/narray' # enables NArray#histogram
51
54
  # if the calling object is an NArray, the output is two NArrays:
52
55
  (bins, freqs) = NArray.float(20).random!(3).histogram(20)
@@ -56,6 +59,13 @@ all the data sets. That way, the resulting frequencies will all line up:
56
59
 
57
60
  gem install histogram
58
61
 
62
+ ## Acknowledgements
63
+
64
+ Big thanks to those who have made contributions!
65
+
66
+ * deal with zero std ([Greg Dean](https://github.com/gsdean))
67
+ * support for 1.8.7 and jruby ([Kiera Radman](https://github.com/kierarad))
68
+
59
69
  ## See Also
60
70
 
61
71
  [aggregate](http://github.com/josephruscio/aggregate), [rserve-client](http://rubygems.org/gems/rserve-client), [rsruby](http://github.com/alexgutteridge/rsruby)
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
- require_relative "lib/histogram/version"
3
2
 
4
3
  require 'rspec/core'
5
4
  require 'rspec/core/rake_task'
data/histogram.gemspec CHANGED
@@ -19,12 +19,16 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
 
22
- [ "bundler ~> 1.3",
22
+ [ "bundler ~> 1.3",
23
23
  "rake ~> 10.1.0",
24
24
  "simplecov ~> 0.7.1",
25
25
  "rspec ~> 2.13.0",
26
- "narray",
26
+ "rdoc"
27
27
  ].each do |argline|
28
28
  spec.add_development_dependency *argline.split(' ', 2).compact
29
29
  end
30
+
31
+ unless RUBY_PLATFORM =~ /java/
32
+ spec.add_development_dependency "narray"
33
+ end
30
34
  end
data/lib/histogram.rb CHANGED
@@ -1,5 +1,11 @@
1
1
 
2
- class NArray
2
+ class NArray
3
+ end
4
+
5
+ unless Math.respond_to?(:log2)
6
+ def Math.log2(num)
7
+ Math.log(num, 2)
8
+ end
3
9
  end
4
10
 
5
11
  module Histogram
@@ -44,8 +50,8 @@ module Histogram
44
50
  # :sorted => false
45
51
  #
46
52
  def iqrange(obj, opts={})
47
- opt = {method: DEFAULT_QUARTILE_METHOD, sorted: false}.merge( opts )
48
- srted = opt[:sorted] ? obj : obj.sort
53
+ opt = {:method => DEFAULT_QUARTILE_METHOD, :sorted => false}.merge( opts )
54
+ srted = opt[:sorted] ? obj : obj.sort
49
55
  sz = srted.size
50
56
  answer =
51
57
  case opt[:method]
@@ -89,9 +95,9 @@ module Histogram
89
95
  (mean, stddev) = Histogram.sample_stats(self)
90
96
  range / ( 3.5*stddev*(self.size**(-1.0/3)) )
91
97
  when :sturges
92
- 1 + Math::log(self.size, 2)
98
+ 1 + Math::log2(self.size)
93
99
  when :fd
94
- 2 * Histogram.iqrange(self, method: quartile_method) * (self.size**(-1.0/3))
100
+ 2 * Histogram.iqrange(self, :method => quartile_method) * (self.size**(-1.0/3))
95
101
  end
96
102
  nbins = 1 if nbins <= 0
97
103
  nbins = 1 if nbins.nan?
@@ -1,3 +1,3 @@
1
1
  module Histogram
2
- VERSION = "0.2.1.3"
2
+ VERSION = "0.2.1.4"
3
3
  end
@@ -2,6 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  require 'histogram'
4
4
 
5
+ class Float
6
+ def round(n=nil)
7
+ if n
8
+ ((n**10) * self).to_i/(10**n)
9
+ else
10
+ super()
11
+ end
12
+ end
13
+ end
14
+
5
15
  RSpec::Matchers.define :be_within_rounding_error_of do |expected|
6
16
  match do |actual|
7
17
  (act, exp) = [actual, expected].map {|ar| ar.collect {|v| v.to_f.round(8) } }
@@ -91,14 +101,14 @@ shared_examples 'something that can histogram' do
91
101
  end
92
102
 
93
103
  describe Histogram do
94
- tmp = {
95
- obj0: (0..10).to_a,
96
- obj1: [0, 1, 1.5, 2.0, 5.0, 6.0, 7, 8, 9, 9],
97
- obj2: [-1, 0, 1, 1.5, 2.0, 5.0, 6.0, 7, 8, 9, 9, 10],
98
- obj3: [1, 1, 2, 2, 3, 3, 4, 4, 4],
99
- obj4: [2, 2, 2, 2, 2, 4],
100
- obj5: [1,2,3,3,3,4,5,6,7,8],
101
- obj6: [0,0,0,0,0]
104
+ tmp = {
105
+ :obj0 => (0..10).to_a,
106
+ :obj1 => [0, 1, 1.5, 2.0, 5.0, 6.0, 7, 8, 9, 9],
107
+ :obj2 => [-1, 0, 1, 1.5, 2.0, 5.0, 6.0, 7, 8, 9, 9, 10],
108
+ :obj3 => [1, 1, 2, 2, 3, 3, 4, 4, 4],
109
+ :obj4 => [2, 2, 2, 2, 2, 4],
110
+ :obj5 => [1,2,3,3,3,4,5,6,7,8],
111
+ :obj6 => [0,0,0,0,0]
102
112
  }
103
113
  data = tmp.each {|k,v| [k, v.map(&:to_f).extend(Histogram)] }
104
114
 
@@ -112,12 +122,12 @@ describe Histogram do
112
122
  it_behaves_like 'something that can histogram'
113
123
  end
114
124
 
115
- have_narray =
125
+ have_narray =
116
126
  begin
117
127
  require 'narray'
118
128
  NArray.respond_to?(:to_na)
119
129
  true
120
- rescue
130
+ rescue LoadError
121
131
  false
122
132
  end
123
133
 
@@ -152,16 +162,15 @@ describe Histogram do
152
162
  end
153
163
 
154
164
  it 'calculates the interquartile range via moore_mccabe' do
155
- Histogram.iqrange(even, method: :moore_mccabe).should == 4.0
156
- Histogram.iqrange(odd, method: :moore_mccabe).should == 4.0
165
+ Histogram.iqrange(even, :method => :moore_mccabe).should == 4.0
166
+ Histogram.iqrange(odd, :method => :moore_mccabe).should == 4.0
157
167
  end
158
168
 
159
169
  it 'calculates the interquartile range via tukey' do
160
- Histogram.iqrange(even, method: :tukey).should == 4.0
161
- Histogram.iqrange(odd, method: :tukey).should == 3.0
170
+ Histogram.iqrange(even, :method => :tukey).should == 4.0
171
+ Histogram.iqrange(odd, :method => :tukey).should == 3.0
162
172
  end
163
173
 
164
174
 
165
175
  end
166
176
  end
167
-
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: histogram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.3
4
+ version: 0.2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John T. Prince
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- requirement: !ruby/object:Gem::Requirement
15
+ version_requirements: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
- - - "~>"
22
+ - - ~>
25
23
  - !ruby/object:Gem::Version
26
24
  version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- requirement: !ruby/object:Gem::Requirement
29
+ version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 10.1.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
37
35
  requirements:
38
- - - "~>"
36
+ - - ~>
39
37
  - !ruby/object:Gem::Version
40
38
  version: 10.1.0
39
+ prerelease: false
40
+ type: :development
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
- requirement: !ruby/object:Gem::Requirement
43
+ version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.7.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
51
49
  requirements:
52
- - - "~>"
50
+ - - ~>
53
51
  - !ruby/object:Gem::Version
54
52
  version: 0.7.1
53
+ prerelease: false
54
+ type: :development
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
- requirement: !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.13.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
62
+ requirement: !ruby/object:Gem::Requirement
65
63
  requirements:
66
- - - "~>"
64
+ - - ~>
67
65
  - !ruby/object:Gem::Version
68
66
  version: 2.13.0
67
+ prerelease: false
68
+ type: :development
69
69
  - !ruby/object:Gem::Dependency
70
- name: narray
71
- requirement: !ruby/object:Gem::Requirement
70
+ name: rdoc
71
+ version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
76
+ requirement: !ruby/object:Gem::Requirement
79
77
  requirements:
80
- - - ">="
78
+ - - '>='
81
79
  - !ruby/object:Gem::Version
82
80
  version: '0'
81
+ prerelease: false
82
+ type: :development
83
83
  description: gives objects the ability to 'histogram' in several useful ways
84
84
  email:
85
85
  - jtprince@gmail.com
@@ -88,7 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - ".gitignore"
91
+ - .gitignore
92
92
  - Gemfile
93
93
  - LICENSE
94
94
  - README.md
@@ -106,24 +106,24 @@ homepage: https://github.com/jtprince/histogram
106
106
  licenses:
107
107
  - MIT
108
108
  metadata: {}
109
- post_install_message:
109
+ post_install_message:
110
110
  rdoc_options: []
111
111
  require_paths:
112
112
  - lib
113
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ">="
120
+ - - '>='
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.2.2
126
- signing_key:
124
+ rubyforge_project:
125
+ rubygems_version: 2.1.9
126
+ signing_key:
127
127
  specification_version: 4
128
128
  summary: histograms data in different ways
129
129
  test_files: