statistical 0.1.0

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.
@@ -0,0 +1,78 @@
1
+ require 'statistical/distribution/uniform_discrete'
2
+
3
+ module Statistical
4
+ module Rng
5
+ # Companion RNG class for the continuous uniform distribution. Requires a
6
+ # distrbution object of the corresponding distribution
7
+ #
8
+ # @author Vaibhav Yenamandra
9
+ #
10
+ # @attr_reader [Numeric] lower The lower bound of the uniform distribution
11
+ # @attr_reader [Numeric] upper The upper bound of the uniform distribution
12
+ # @attr_reader [Numeric] generator The prng created with `seed` for usage
13
+ # as a source of randomness to base the current RNG on
14
+ class UniformDiscrete
15
+ attr_reader :generator, :lower, :upper
16
+ # Companion RNG class for the continuous uniform distribution. Requires a
17
+ # distrbution object of the corresponding distribution
18
+ #
19
+ # @author Vaibhav Yenamandra
20
+ #
21
+ # @param [Statistical::Distribution::UniformDiscrete] dobj The
22
+ # distribution object to be used to create the RNG
23
+ # @param [Random] seed Seed to set the PRNG initial state
24
+ def initialize(dobj, seed = Random.new_seed)
25
+ unless dobj.nil? || dobj.is_a?(Statistical::Distribution::UniformDiscrete)
26
+ raise TypeError,
27
+ "Expected Distribution object or nil, found #{dobj.class}"
28
+ end
29
+ @generator = Random.new(seed)
30
+ @lower = dobj.lower
31
+ @upper = dobj.upper
32
+ @sdist = dobj
33
+ end
34
+
35
+ # Return the next random number from the sequence using Ruby's `rand`
36
+ #
37
+ # @author Vaibhav Yenamandra
38
+ #
39
+ # @return next random number in the sequence
40
+ def rand
41
+ n = members.count
42
+ return members[@generator.rand(n)]
43
+ end
44
+
45
+ # Compare against another rng. Compares distribution parameters and
46
+ # initial state of rngs to assert equality
47
+ #
48
+ # @private
49
+ # @author Vaibhav Yenamandra
50
+ # @return true if and only if, source distributions are the same and the
51
+ # prng has the same initial state
52
+ def eql?(other)
53
+ return other.is_a?(self.class) &&
54
+ members == other.members &&
55
+ @generator == other.generator
56
+ end
57
+
58
+ # Return the type of the source distribution
59
+ #
60
+ # @author Vaibhav Yenamandra
61
+ #
62
+ # @return source distribution's type
63
+ def type
64
+ @sdist.class
65
+ end
66
+
67
+ # A call to expose the underlying distribution's support set
68
+ #
69
+ # @return The elements over which the distribution exists
70
+ def members
71
+ return @sdist.support
72
+ end
73
+
74
+ alias :== :eql?
75
+ private :eql?
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,58 @@
1
+ require 'statistical/distribution/weibull'
2
+
3
+ module Statistical
4
+ module Rng
5
+ # Companion RNG class for the continuous uniform distribution. Requires a
6
+ # distrbution object of the corresponding distribution
7
+ #
8
+ # @author Vaibhav Yenamandra
9
+ #
10
+ # @attr_reader [Numeric] scale The scale parameter of the Weibull
11
+ # distribution
12
+ # @attr_reader [Numeric] shape The shape parameter of the Weibull
13
+ # distribution
14
+ class Weibull
15
+ attr_reader :generator, :scale, :shape
16
+
17
+ def initialize(dobj = nil, seed = Random.new_seed)
18
+ unless dobj.nil? || dobj.is_a?(Statistical::Distribution::Weibull)
19
+ raise TypeError,
20
+ "Expected Distribution object or nil, found #{dobj.class}"
21
+ end
22
+ dobj = Statistical::Distribution::Weibull.new if dobj.nil?
23
+ @generator = Rng::Uniform.new(Distribution::Uniform.new, seed)
24
+ @scale = dobj.scale
25
+ @shape = dobj.shape
26
+ @sdist = dobj
27
+ end
28
+
29
+ # Return the next random number from the sequence
30
+ #
31
+ # @return next random number in the sequence
32
+ def rand
33
+ return @sdist.quantile(@generator.rand)
34
+ end
35
+
36
+ # Compare against another rng to see if they are the same
37
+ #
38
+ # @return true if and only if, source distributions are the same and the
39
+ # prng has the same initial state
40
+ def eql?(other)
41
+ return other.is_a?(self.class) &&
42
+ @generator == other.generator &&
43
+ @scale == other.scale &&
44
+ @shape == other.shape
45
+ end
46
+
47
+ # Return the type of the source distribution
48
+ #
49
+ # @return source distribution's class
50
+ def type
51
+ @sdist.class
52
+ end
53
+
54
+ alias_method :==, :eql?
55
+ private :eql?
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Statistical
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statistical/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statistical'
8
+ spec.version = Statistical::VERSION
9
+ spec.authors = ['Vaibhav Yenamandra']
10
+ spec.email = ['yvvaibhav@gmail.com']
11
+
12
+ spec.summary = %q{Statistical distributions in ruby. }
13
+ spec.description = %q{Statistical distributions in ruby. This library aims to provide and enhance an API that maintains familiarity with rubys core and stdlib.}
14
+ spec.homepage = "https://github.com/vaibhav-y/statistical"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/})}
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f)}
19
+ spec.extensions = []
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'pry', '~> 0'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rubocop', '~> 0'
28
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statistical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vaibhav Yenamandra
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Statistical distributions in ruby. This library aims to provide and enhance
98
+ an API that maintains familiarity with rubys core and stdlib.
99
+ email:
100
+ - yvvaibhav@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CONTRIBUTING.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/distribution
115
+ - bin/setup
116
+ - data/template/distribution.erb
117
+ - data/template/rng.erb
118
+ - data/template/spec.erb
119
+ - lib/core_extensions.rb
120
+ - lib/statistical.rb
121
+ - lib/statistical/distribution.rb
122
+ - lib/statistical/distribution/bernoulli.rb
123
+ - lib/statistical/distribution/exponential.rb
124
+ - lib/statistical/distribution/laplace.rb
125
+ - lib/statistical/distribution/two_point.rb
126
+ - lib/statistical/distribution/uniform.rb
127
+ - lib/statistical/distribution/uniform_discrete.rb
128
+ - lib/statistical/distribution/weibull.rb
129
+ - lib/statistical/helpers.rb
130
+ - lib/statistical/rng.rb
131
+ - lib/statistical/rng/bernoulli.rb
132
+ - lib/statistical/rng/exponential.rb
133
+ - lib/statistical/rng/laplace.rb
134
+ - lib/statistical/rng/two_point.rb
135
+ - lib/statistical/rng/uniform.rb
136
+ - lib/statistical/rng/uniform_discrete.rb
137
+ - lib/statistical/rng/weibull.rb
138
+ - lib/statistical/version.rb
139
+ - statistical.gemspec
140
+ homepage: https://github.com/vaibhav-y/statistical
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.5.1
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Statistical distributions in ruby.
164
+ test_files: []
165
+ has_rdoc: