random_value_sampler 0.1.0 → 0.1.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.
- data/README +14 -14
- metadata +2 -2
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
RandomValueSampler
|
2
2
|
========
|
3
3
|
|
4
4
|
Class to allow sampling from very, very simple probability mass functions
|
@@ -15,7 +15,7 @@ can be:
|
|
15
15
|
probability mass is quantized (e.g. a 1/3, 2/3 distribution). This may
|
16
16
|
prove to be a more efficient implementation in such cases as the non-uniform
|
17
17
|
pmf is more computationally demanding).
|
18
|
-
- a ruby Range object;
|
18
|
+
- a ruby Range object; RandomValueSampler honors the inclusion/exclusion of last/end
|
19
19
|
of the Range (as defined by exclude_end? method). the Range must be of
|
20
20
|
numeric type unless you REALLY know what you're doing (e.g. the Xs class
|
21
21
|
example in the Range rdoc won't work).
|
@@ -36,27 +36,27 @@ will normalize accordingly. The pmf may be specified as a Hash or an Array:
|
|
36
36
|
Examples
|
37
37
|
=========
|
38
38
|
|
39
|
-
require '
|
39
|
+
require 'random_value_sampler'
|
40
40
|
|
41
41
|
uniform
|
42
42
|
-------
|
43
43
|
|
44
44
|
# generate a uniform pmf over [1,5]
|
45
|
-
a =
|
45
|
+
a = RandomValueSampler.new_uniform([1,2,3,4,5])
|
46
46
|
|
47
47
|
# generate a uniform pmf over some words
|
48
|
-
a =
|
48
|
+
a = RandomValueSampler.new_uniform(["one", "two", "buckle", "my", "shoe"])
|
49
49
|
|
50
50
|
# generate a 'quantized' pmf by using duplicate entries
|
51
|
-
a =
|
52
|
-
a =
|
51
|
+
a = RandomValueSampler.new_uniform([1, 2, 2, 3, 3, 3])
|
52
|
+
a = RandomValueSampler.new_uniform(["the", "the", "a", "the", "and", "zyzzyva"])
|
53
53
|
|
54
54
|
# generate a uniform pmf over [1,5] using a Range
|
55
|
-
a =
|
56
|
-
a =
|
55
|
+
a = RandomValueSampler.new_uniform(1..5)
|
56
|
+
a = RandomValueSampler.new_uniform(1...6)
|
57
57
|
|
58
58
|
# generate a uniform pmf over [0,5] by specifying upper limit
|
59
|
-
a =
|
59
|
+
a = RandomValueSampler.new_uniform(5)
|
60
60
|
|
61
61
|
non-uniform
|
62
62
|
-----------
|
@@ -64,16 +64,16 @@ non-uniform
|
|
64
64
|
# generate a non-uniform pmf using the Hash form:
|
65
65
|
|
66
66
|
# values are 5 and 10, with probability 0.4 and 0.6, respectively
|
67
|
-
a =
|
67
|
+
a = RandomValueSampler.new_non_uniform( { 5 => 20, 10 => 30 } )
|
68
68
|
|
69
69
|
# values are "probable", "possible" and "not likely" with probability
|
70
70
|
# 0.75, 0.20 and 0.05, respectively.
|
71
|
-
a =
|
71
|
+
a = RandomValueSampler.new_non_uniform( { "probable" => 75,
|
72
72
|
"possible" => 20,
|
73
73
|
"not likely" => 5 } )
|
74
74
|
|
75
75
|
# generate a non-uniform pmf using the Array form (same examples as above)
|
76
|
-
a =
|
77
|
-
a =
|
76
|
+
a = RandomValueSampler.new_non_uniform( [ [5,20], [10,30] )
|
77
|
+
a = RandomValueSampler.new_non_uniform( [ ["probable",75],
|
78
78
|
["possible" => 20],
|
79
79
|
["not likely" => 5 ] ] )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random_value_sampler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bmpercy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-19 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|