normcore 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62078ad0b3ab7a5cd12a10eafbeddb120117fa38
4
+ data.tar.gz: 2d232fadddaa878ca0899864c1c9db4ff3750e23
5
+ SHA512:
6
+ metadata.gz: bf013bba69a41da90a5ed30d267668e5277892788dd4294165190c7f0a7e8c98566275a45ae591ffb505d2254315636ee9731f4f9b598646991a291af3a07263
7
+ data.tar.gz: c24e7d317730ebdd9f4d843efd327ce6308338942126cef49e2d4ad382e68c37b70bf2e4aa19b17e18643d2d844810c767eb7aef68d0f117d97d81a6e4019084
@@ -0,0 +1,7 @@
1
+ module Normcore
2
+ class Base
3
+ def sample n
4
+ n.times.map { rng }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Normcore
2
+ #
3
+ # The log-normal distribution
4
+ #
5
+ # https://en.wikipedia.org/wiki/Log-normal_distribution
6
+ #
7
+ class LogNormal < Normal
8
+ def rng
9
+ Math.exp(box_muller)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module Normcore
2
+ #
3
+ # The normal a.k.a. Gaussian distribution
4
+ #
5
+ # https://en.wikipedia.org/wiki/Box–μller_transform
6
+ #
7
+ # Usage:
8
+ #
9
+ # normal = Normal.new(0, 1)
10
+ #
11
+ # normal.rng # return one sample
12
+ #
13
+ # normal.sample(10) # return 10 samples
14
+ #
15
+ class Normal < Base
16
+ attr_reader :μ, :σ
17
+
18
+ def initialize μ, σ
19
+ @μ = μ
20
+ @σ = σ
21
+ end
22
+
23
+ #
24
+ # yield samples from gaussian distribution using the Box-μller transform
25
+ #
26
+ def rng
27
+ box_muller
28
+ end
29
+
30
+ private
31
+
32
+ #
33
+ # Use the Box-μller transform to generate pairs of independent, standard,
34
+ # normally distributed random numbers.
35
+ #
36
+ def box_muller
37
+ θ = 2 * Math::PI * rand
38
+ ρ = Math.sqrt(-2 * Math.log(1 - rand))
39
+ scale = σ * ρ
40
+ μ + scale * Math.cos(θ)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ require 'base'
2
+ require 'normal'
3
+ require 'log_normal'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: normcore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Austin Davis-Richardson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generate random numbers from a Normal/Gaussian distribution
14
+ email: harekrishna@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - "./lib/base.rb"
20
+ - "./lib/log_normal.rb"
21
+ - "./lib/normal.rb"
22
+ - "./lib/normcore.rb"
23
+ homepage: https://github.com/pivotbio/normcore
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.8
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Generate numbers from a normal distribution
47
+ test_files: []