simpack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/simpack.rb +48 -0
- data/lib/simpack/version.rb +3 -0
- data/simpack.gemspec +25 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 675c709efae46cf72cbc281ee4e020759e6ac43b
|
4
|
+
data.tar.gz: 7facb2c0311aea090cdabfaecf2f6e22d9431c66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a86ff1f5a58a486c3e533f8bdd1ed95c603c66aea7d37e423561c5bad693a59ccd6961e72fed477c5e38edcac90bcb31913e52b0b2e2382b0bca6abf304f42e5
|
7
|
+
data.tar.gz: d3e4f9ed611cd3997506a9a5093cb855a0370cb7a8bb789edb6dfc9a4ff43239c7f0ac8e01f159b529b27c490383dcfce5f91798fb241273d2dd944795fc1886
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 John Ochs
|
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,83 @@
|
|
1
|
+
# Simpack
|
2
|
+
[![Code Climate](https://codeclimate.com/github/johnochs/simpack/badges/gpa.svg)](https://codeclimate.com/github/johnochs/simpack)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/johnochs/simpack/badges/coverage.svg)](https://codeclimate.com/github/johnochs/simpack)
|
4
|
+
|
5
|
+
Simpack is your go-to gem for your simulation needs in Ruby. At its heart, Simpack is a linear congruential generator (LCG) which can then be used to generate random samples from a number of statistical distributions.
|
6
|
+
|
7
|
+
Use it for simulation, modeling, or games!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'simpack'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install simpack
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Simpack::LCG
|
28
|
+
|
29
|
+
#### \#initialize
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
lcg = Simpack::LCG.new
|
33
|
+
```
|
34
|
+
|
35
|
+
Optionally, you may wish to configure your LCG to suit your preferences with an options hash:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
lcg = Simpack::LCG.new({modulus: 8, multiplier: 5})
|
39
|
+
```
|
40
|
+
Keys for the options hash include the following:
|
41
|
+
* `:modulus`
|
42
|
+
* `:multiplier`
|
43
|
+
* `:increment`
|
44
|
+
* `:seed`
|
45
|
+
|
46
|
+
If you do decide to specify your own constants, all bets are off. Simpack (as of now) does not test for constraints of the Hull-Dobell Theorem, or any other tests of period or uniformity. This allows you to create a crappy LCG if you desire, but it will not alert you if you do.
|
47
|
+
|
48
|
+
See the __Technical Specs__ section for details of the standard configuration.
|
49
|
+
|
50
|
+
#### \#uniform
|
51
|
+
|
52
|
+
\#uniform can be called with an optional argument specifying the number of random numbers to return.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
> lcg.uniform
|
56
|
+
> 0.27662859533103207
|
57
|
+
|
58
|
+
> lcg.uniform(3)
|
59
|
+
> [0.9518568231847053, 0.7968659172399516, 0.15733885122680413]
|
60
|
+
```
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Want to add a new distribution? Have ideas for a feature? Spotted a bug? Contribute! I am especially looking for people who have a bit more statistical knowledge than I do to spot any potential problems with the code.
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/johnochs/simpack/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
71
|
+
|
72
|
+
##Technical Specs
|
73
|
+
|
74
|
+
### Simpack::LCG
|
75
|
+
|
76
|
+
Table of standard parameters:
|
77
|
+
|
78
|
+
|Parameter |Value |
|
79
|
+
|----------|-------------------|
|
80
|
+
|Modulus | 2<sup>64 |
|
81
|
+
|Multiplier|6364136223846793005|
|
82
|
+
|Increment |1442695040888963407|
|
83
|
+
|Seed |`Time.now.to_i` |
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simpack"
|
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
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/bin/setup
ADDED
data/lib/simpack.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "simpack/version"
|
2
|
+
|
3
|
+
module Simpack
|
4
|
+
|
5
|
+
class LCG
|
6
|
+
|
7
|
+
attr_reader :multiplier, :modulus, :increment, :seed
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
default_options = {multiplier: 6364136223846793005,
|
11
|
+
modulus: 2 ** 64,
|
12
|
+
increment: 1442695040888963407,
|
13
|
+
seed: Time.now.to_i}
|
14
|
+
|
15
|
+
options = default_options.merge(options)
|
16
|
+
check_options(options)
|
17
|
+
|
18
|
+
@multiplier = options[:multiplier]
|
19
|
+
@modulus = options[:modulus]
|
20
|
+
@increment = options[:increment]
|
21
|
+
@seed = @x = options[:seed]
|
22
|
+
end
|
23
|
+
|
24
|
+
def uniform(n = 1)
|
25
|
+
return generate_number if n == 1
|
26
|
+
|
27
|
+
results = Array.new(n)
|
28
|
+
(0...n).each do |i|
|
29
|
+
results[i] = generate_number
|
30
|
+
end
|
31
|
+
results
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def check_options(options)
|
37
|
+
raise "Invalid Modulus" if options[:modulus] == 0
|
38
|
+
raise "Invalid Multiplier" if options[:multiplier] == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_number
|
42
|
+
@x = (@multiplier * @x + @increment) % @modulus
|
43
|
+
@x / @modulus.to_f
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/simpack.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simpack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simpack"
|
8
|
+
spec.version = Simpack::VERSION
|
9
|
+
spec.authors = ["John Ochs"]
|
10
|
+
spec.email = ["johnochs@me.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simpack is your go-to gem for your simulation needs in Ruby. At its heart, Simpack is a linear congruential generator (LCG) which can then be used to generate random samples from a number of statistical distributions.}
|
13
|
+
spec.description = %q{A solution for all your simulation needs!}
|
14
|
+
spec.homepage = "https://github.com/johnochs/simpack"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simpack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Ochs
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-05 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
description: A solution for all your simulation needs!
|
56
|
+
email:
|
57
|
+
- johnochs@me.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/simpack.rb
|
73
|
+
- lib/simpack/version.rb
|
74
|
+
- simpack.gemspec
|
75
|
+
homepage: https://github.com/johnochs/simpack
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Simpack is your go-to gem for your simulation needs in Ruby. At its heart,
|
99
|
+
Simpack is a linear congruential generator (LCG) which can then be used to generate
|
100
|
+
random samples from a number of statistical distributions.
|
101
|
+
test_files: []
|