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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 386aaee4684c8ee33471467a97cb425c193d11a4
4
+ data.tar.gz: 3dd98e635eba8c3aa81d180e269d09676343333f
5
+ SHA512:
6
+ metadata.gz: 2f0fbbb0170e4602d9a4aec6239afd7cc881c7cd8840fe640d8d5a989ac9b2e3bc5de9bc3dd2d35c0c59ba399c88c7f2f16e163a751bbd018190420a48f3e33c
7
+ data.tar.gz: e0c1d634ea53c89194efdfc3dc271b003f098311619d6a08aa1aca96dd615a0779cfac8880efd16944ba0deb63df298e64dbc72bde07786a4344b7fa08aec073
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /1000/**
11
+ /codacy-coverage/**
12
+ /coverage/**
13
+ *.so
14
+ *.o
15
+ .gitmsg
data/.rubocop.yml ADDED
@@ -0,0 +1,111 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-02-11 17:16:01 +0000 using RuboCop version 0.37.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 80
14
+ Exclude:
15
+ - 'spec/**/*'
16
+ - 'test/**/*'
17
+ - 'statistical.gemspec'
18
+ - 'bin/distribution'
19
+
20
+ # 10 lines won't be enough for math oriented code
21
+ # 25 decided upon arbitrarily
22
+ Metrics/MethodLength:
23
+ Max: 25
24
+
25
+ Style/Documentation:
26
+ Exclude:
27
+ - 'spec/**/*'
28
+ - 'test/**/*'
29
+ - 'bin/**/*'
30
+
31
+ # Indentation width must be 2 spaces
32
+ Style/IndentationWidth:
33
+ Enabled: true
34
+ Exclude:
35
+ - 'spec/**/*'
36
+ - 'test/**/*'
37
+
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
40
+ # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
41
+ Style/HashSyntax:
42
+ Enabled: true
43
+ UseHashRocketsWithSymbolValues: true
44
+ Exclude:
45
+ - 'statistical.gemspec'
46
+ - 'spec/**/*'
47
+ - 'test/**/*'
48
+
49
+ # Cop supports --auto-correct.
50
+ Style/MutableConstant:
51
+ Enabled: true
52
+
53
+ # Cop supports --auto-correct.
54
+ # Configuration parameters: PreferredDelimiters.
55
+ Style/PercentLiteralDelimiters:
56
+ Exclude:
57
+ - 'statistical.gemspec'
58
+ Exclude:
59
+ - 'statistical.gemspec'
60
+ - 'spec/**/*'
61
+ - 'test/**/*'
62
+
63
+ # Cop supports --auto-correct.
64
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
65
+ # SupportedStyles: space, no_space
66
+ Style/SpaceInsideBlockBraces:
67
+ Enabled: true
68
+ EnforcedStyle: no_space
69
+ Exclude:
70
+ - 'statistical.gemspec'
71
+ - 'spec/**/*'
72
+ - 'test/**/*'
73
+
74
+ # Cop supports --auto-correct.
75
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
76
+ # SupportedStyles: single_quotes, double_quotes
77
+ Style/StringLiterals:
78
+ Enabled: true
79
+ Exclude:
80
+ - 'statistical.gemspec'
81
+ - 'bin/*'
82
+ - 'spec/**/*'
83
+
84
+ # Cop supports --auto-correct.
85
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
86
+ # SupportedStyles: final_newline, final_blank_line
87
+ Style/TrailingBlankLines:
88
+ Enabled: true
89
+ EnforcedStyle: final_newline
90
+
91
+ # Cop supports --auto-correct.
92
+ Style/TrailingWhitespace:
93
+ Enabled: true
94
+
95
+ # Cop supports --auto-correct.
96
+ Style/UnneededPercentQ:
97
+ Exclude:
98
+ - 'spec/**/*'
99
+ - 'test/**/*'
100
+ - 'statistical.gemspec'
101
+
102
+ # I'm fine with either
103
+ Style/RedundantReturn:
104
+ Enabled: false
105
+
106
+ # Allow non-ascii characters in comments
107
+ Style/AsciiComments:
108
+ Enabled: false
109
+
110
+ Style/Alias:
111
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.3
6
+ - 2.3.0
7
+ before_install: gem install bundler -v 1.11.2
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,73 @@
1
+ # Adding a new distribution
2
+ run `bundle exec bin/distribution -n <dist_name>` from the project root to add boilerplate code for the distribution class, rng class and specs.
3
+
4
+ ## Structure
5
+ The gem is split into random number generators and the abstract probabilty distributions that these generators draw from.
6
+
7
+ To add an RNG for a distribution in `statistical/lib/rng` a class with the same name must be defined under `statistical/lib/distribution` under the `Distribution` module
8
+
9
+ `rng.rb` and `distribution.rb` provide useful constants to list all the subclassed distributions, and act as a factory layer on top of all distributions in
10
+
11
+ All abstractions of distributions must be under the module `Statistical::Distribution`
12
+
13
+ All random number generators must be under the module `Statistical::Rng`
14
+
15
+ ## Useful rake tasks
16
+ The default `rake` task is to run the tests
17
+ * `bundle exec rake spec` - Run rspec tests
18
+ * `bundle exec rake cop` - Run rubocop
19
+ * `bundle exec rake doc` - Run yard to generate documentation
20
+
21
+ ## Workflow / General Guidelines
22
+ 1. Fork this repository and create your feature branch
23
+ 2. All new code addition must be through the feature branch only. Changes to master will be rejected.
24
+ 3. Test your on code atleast 3 continuous major releases of ruby (you can setup travis-CI for this). Usually CURRENT_RUBY_VERSION and two major predecessors should be fine (2.3.X, 2.2.Y 2.1.W)
25
+ 4. Try to keep one commit per change (Optional, but better to be organized)
26
+ 5. If possible write a test case which confirms your change
27
+ 6. When submitting a change that chooses a specific algorithm over others available write your rationale behind the choice. Benchmarks comparing different algorithms would be highly appreciated.
28
+ 7. Yes, it's OK to pick an algorithm for simplicity of expression.
29
+ 8. Your pull request should attempt to explain the change you want to introduce
30
+
31
+ ## Coding conventions
32
+
33
+ How to style your C and Ruby code which you want to submit.
34
+
35
+ ### C code
36
+
37
+ Please note the following hints for your C code:
38
+
39
+ #### Comply with C99 (ISO/IEC 9899:1999)
40
+
41
+ This library should be portable to other systems and compilers. For this it is
42
+ recommended to keep your code as close as possible to the C99 standard
43
+ (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf).
44
+
45
+ As some of us may also be using Visual C++ as a build target. For this reason a
46
+ declaration of a local variable has to be at the beginning of a scope block.
47
+
48
+ #### Reduce library dependencies to a minimum
49
+
50
+ The dependencies to libraries should be kept to an absolute minimum. If this is
51
+ not possible immediately, consider authoring a secondary gem for this that lives
52
+ under statistical-<feature_name>. This can also be added as a plugin.
53
+
54
+ #### Don't use C++ style comments
55
+
56
+ /* This is the preferred comment style */
57
+
58
+ Use C++ style comments only for temporary comments e.g. commenting out some code lines.
59
+
60
+ #### Insert a break after the method return value:
61
+
62
+ int
63
+ main(void)
64
+ {
65
+ ...
66
+ }
67
+
68
+ ### Ruby code
69
+
70
+ `bundle exec rake cop` is your best friend.
71
+
72
+ ## Notes
73
+ Feel free to open a "question" issue if you have any questions or want to discuss about better ways to go about this.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'codeclimate-test-reporter', :group => :test, :require => nil
4
+ gem 'yard', require: false
5
+
6
+ # Other dependencies go in statistical.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Vaibhav Yenamandra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Statistical
2
+ [![Code Climate](https://codeclimate.com/github/vaibhav-y/statistical/badges/gpa.svg)](https://codeclimate.com/github/vaibhav-y/statistical)
3
+ [![Test Coverage](https://codeclimate.com/github/vaibhav-y/statistical/badges/coverage.svg)](https://codeclimate.com/github/vaibhav-y/statistical/coverage)
4
+ [![Issue Count](https://codeclimate.com/github/vaibhav-y/statistical/badges/issue_count.svg)](https://codeclimate.com/github/vaibhav-y/statistical)
5
+
6
+ Statistical distributions in ruby. This library aims to provide and enhance an API that maintains familiarity with ruby's core and stdlib.
7
+
8
+ ## Usage
9
+
10
+ TODO: Write usage instructions here, see docs
11
+
12
+ ### Documentation
13
+ Available [here](http://www.rubydoc.info/github/vaibhav-y/statistical/master).
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
18
+
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
24
+
25
+
26
+ ## Roadmap
27
+ ### Immediate focus
28
+ * Implementations of all common distributions mentioned in the NIST [engineering and statistics handbook](http://www.itl.nist.gov/div898/handbook/eda/section3/eda366.htm)
29
+ * Parity with Sciruby/distrbution (The inspiration for this project)
30
+
31
+ ### Long term
32
+ * Add a module `Statistical::Hypothesis` which allows for statistical hypothesis testing
33
+ * Explore creating a symbolic DSL using this library that involves manipulating random variates
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'bundler'
2
+
3
+ Bundler.setup
4
+
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
+ require 'rubocop/rake_task'
8
+ require 'yard'
9
+ require 'statistical/version'
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.verbose = false
13
+ end
14
+
15
+ # Add a cop task for code linting
16
+ RuboCop::RakeTask.new(:cop) do |t|
17
+ t.options = ['--format', 'simple']
18
+ end
19
+
20
+ YARD::Rake::YardocTask.new(:doc) do |t|
21
+ t.files = ['lib/**/*.rb']
22
+ end
23
+
24
+ # Build the gem
25
+ task :build do
26
+ system "gem build statistical.gemspec"
27
+ end
28
+
29
+ # Install gem locally
30
+ task :install => :build do
31
+ system "gem install statistical-#{Statistical::VERSION}.gem"
32
+ end
33
+
34
+ # Release gem to github
35
+ task :release => :build do
36
+ system "git tag -a v#{Statistical::VERSION} -m 'Version #{Statistical::VERSION}'"
37
+ system "git push --tags"
38
+ system "gem push statistical-#{Statistical::VERSION}.gem"
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ task :gem => :build
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "statistical"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
data/bin/distribution ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+ require 'erb'
6
+ gem_base = File.expand_path(File.dirname(__FILE__) + '/..')
7
+ require gem_base + '/lib/statistical'
8
+
9
+ class String
10
+ def camelcase
11
+ split('_').map(&:capitalize).join
12
+ end
13
+ end
14
+
15
+ needs_new = false
16
+ parameters = ''
17
+ OptionParser.new do |opts|
18
+ opts.banner = 'Usage: distribution [--new] [--params parameters] distribution_name'
19
+ opts.on('-n', '--new', 'Create a new template for distribution') do
20
+ needs_new = true
21
+ end
22
+ opts.on('-PMANDATORY', '--params MANDATORY', String, 'Parameters for distribution') do |n_param|
23
+ parameters = ", #{n_param}"
24
+ end
25
+
26
+ opts.on('-h', '--help', 'Show this message') do
27
+ puts opts
28
+ exit
29
+ end
30
+
31
+ begin
32
+ ARGV << '-h' if ARGV.empty?
33
+ opts.parse!(ARGV)
34
+ rescue OptionParser::ParseError => e
35
+ STDERR.puts e.message, "\n", opts
36
+ exit(-1)
37
+ end
38
+ end
39
+
40
+ ARGV.each do |distribution|
41
+ next unless needs_new
42
+ basename = distribution.downcase
43
+ raise 'You should be inside distribution lib directory' unless File.exist? 'statistical.gemspec'
44
+ raise 'Distribution already created' if File.exist?("#{gem_base}/lib/statistical/distribution/#{basename}.rb") && File.exist?("#{gem_base}/lib/statistical/rng/#{basename}.rb")
45
+
46
+ dist = ERB.new(File.read(gem_base + '/data/template/distribution.erb'))
47
+ rng = ERB.new(File.read(gem_base + '/data/template/rng.erb'))
48
+ spec = ERB.new(File.read(gem_base + '/data/template/spec.erb'))
49
+
50
+ File.open("#{gem_base}/lib/statistical/distribution/#{basename}.rb", 'w') { |fp| fp.write(dist.result(binding))}
51
+ File.open("#{gem_base}/lib/statistical/rng/#{basename}.rb", 'w') { |fp| fp.write(rng.result(binding))}
52
+ File.open("#{gem_base}/spec/#{basename}_spec.rb", 'w') { |fp| fp.write(spec.result(binding))}
53
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,84 @@
1
+ require 'statistical/exceptions'
2
+
3
+ module Statistical
4
+ module Distribution
5
+ # Say something useful about this class.
6
+ #
7
+ # @note Any caveats you want to talk about go here...
8
+ #
9
+ # @author Full Name
10
+ # @attr [Types] attribute_name a full description of the attribute
11
+ # @attr_writer [Types] attribute_name a full description of the attribute
12
+ # @attr_reader [Types] attribute_name a full description of the attribute
13
+ # @deprecated warn if the class is deprecated and provide and alternative
14
+ class <%= distribution.capitalize.camelcase %>
15
+ attr_reader # params go here
16
+
17
+ # Returns a new `Statistical::Distribution::<%= distribution.capitalize.camelcase %>` instance
18
+ #
19
+ # @param [Types] param_name Description
20
+ # @return `Statistical::Distribution::<%= distribution.capitalize.camelcase %>` instance
21
+ def initialize(<% parameters %>)
22
+ end
23
+
24
+ # Returns value of probability density function at a point. Calculated
25
+ # using some technique that you might want to name
26
+ #
27
+ # @param [Numeric] x A real valued point
28
+ # @return Probability density function evaluated at `x`
29
+ def pdf(x)
30
+ end
31
+
32
+ # Returns value of cumulative density function at a point. Calculated
33
+ # using some technique that you might want to name
34
+ #
35
+ # @param [Numeric] x A real valued point
36
+ # @return Cumulative density function evaluated for F(u <= x)
37
+ def cdf(x)
38
+ end
39
+
40
+ # Returns value of inverse CDF for a given probability
41
+ #
42
+ # @see #p_value
43
+ #
44
+ # @param [Numeric] p a value within [0, 1]
45
+ # @return Inverse CDF for valid p
46
+ # @raise [RangeError] if p > 1 or p < 0
47
+ def quantile(p)
48
+ raise RangeError, "`p` must be in [0, 1], found: #{p}" if p < 0 || p > 1
49
+ end
50
+
51
+ # Returns the mean value for the calling instance. Calculated mean, and
52
+ # not inferred from simulations
53
+ #
54
+ # @return Mean of the distribution
55
+ def mean
56
+ end
57
+
58
+ # Returns the expected value of variance for the calling instance.
59
+ #
60
+ # @return Variance of the distribution
61
+ def variance
62
+ end
63
+
64
+ # Compares two distribution instances and returns a boolean outcome
65
+ # Available publicly as #==
66
+ #
67
+ # @private
68
+ #
69
+ # @param other A distribution object (preferred)
70
+ # @return [Boolean] true if-and-only-if two instances are of the same
71
+ # class and have the same parameters.
72
+ def eql?(other)
73
+ return false unless other.is_a?(self.class)
74
+ # Compare parameters and other stuff here
75
+ return true
76
+ end
77
+
78
+ alias :== :eql?
79
+ alias :p_value :quantile
80
+
81
+ private :eql?
82
+ end
83
+ end
84
+ end