fathom 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -0
- data/TODO.md +140 -0
- data/VERSION +1 -1
- data/lib/fathom.rb +13 -12
- data/lib/fathom/data_node.rb +3 -32
- data/lib/fathom/distributions.rb +8 -0
- data/lib/fathom/distributions/discrete_gaussian.rb +44 -0
- data/lib/fathom/distributions/discrete_uniform.rb +46 -0
- data/lib/fathom/distributions/gaussian.rb +46 -0
- data/lib/fathom/distributions/uniform.rb +35 -0
- data/lib/fathom/{basic_node.rb → enforced_name.rb} +5 -1
- data/lib/fathom/ext/string.rb +27 -0
- data/lib/fathom/inverter.rb +1 -2
- data/lib/fathom/monte_carlo_set.rb +26 -3
- data/lib/fathom/node.rb +90 -0
- data/lib/fathom/numeric_methods.rb +50 -0
- data/lib/fathom/plausible_range.rb +11 -15
- data/spec/fathom/data_node_spec.rb +45 -4
- data/spec/fathom/distributions/discrete_gaussian_spec.rb +64 -0
- data/spec/fathom/distributions/discrete_uniform_spec.rb +0 -0
- data/spec/fathom/distributions/gaussian_spec.rb +64 -0
- data/spec/fathom/distributions/uniform_spec.rb +0 -0
- data/spec/fathom/enforced_name_spec.rb +15 -0
- data/spec/fathom/monte_carlo_set_spec.rb +12 -1
- data/spec/fathom/node_spec.rb +129 -0
- data/spec/fathom/numeric_methods_spec.rb +82 -0
- data/spec/fathom/plausible_range_spec.rb +1 -2
- data/spec/support/dummy_numeric_node.rb +8 -0
- metadata +30 -7
- data/lib/fathom/combined_plausibilities.rb +0 -12
- data/lib/fathom/node_utilities.rb +0 -8
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include Fathom::Distributions
|
4
|
+
|
5
|
+
class DemoEnforcedNameNode < Node
|
6
|
+
include EnforcedName
|
7
|
+
end
|
8
|
+
|
9
|
+
describe EnforcedName do
|
10
|
+
|
11
|
+
it "should ensure that we have a name as a UID if one is not provided" do
|
12
|
+
n = DemoEnforcedNameNode.new
|
13
|
+
n.name.should_not be_nil
|
14
|
+
end
|
15
|
+
end
|
@@ -17,7 +17,7 @@ describe MonteCarloSet do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
@fields = [:commissions_paid, :gross_margins, :revenue]
|
20
|
-
@summary_fields = [:coefficient_of_variation, :max, :mean, :min, :sd]
|
20
|
+
@summary_fields = [:coefficient_of_variation, :lower_bound, :max, :mean, :min, :sd, :upper_bound]
|
21
21
|
end
|
22
22
|
|
23
23
|
before do
|
@@ -90,6 +90,17 @@ describe MonteCarloSet do
|
|
90
90
|
@mcs.process(2)
|
91
91
|
@mcs.revenue_summary.should eql(@mcs.summary(:revenue))
|
92
92
|
end
|
93
|
+
|
94
|
+
it "should allow the model to be able to produce non-array values" do
|
95
|
+
margin_description = ValueDescription.new(@q1_sales) do |s|
|
96
|
+
{
|
97
|
+
:description => {:first_quarter_sales => s.first_quarter_sales, :first_quarter_prices => s.first_quarter_prices}
|
98
|
+
}
|
99
|
+
end
|
100
|
+
mcs = MonteCarloSet.new(margin_description)
|
101
|
+
lambda{mcs.process(2)}.should_not raise_error
|
102
|
+
lambda{mcs.summary}.should_not raise_error
|
103
|
+
end
|
93
104
|
end
|
94
105
|
|
95
106
|
def sort_array_of_symbols(array)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include Fathom
|
4
|
+
|
5
|
+
describe Node do
|
6
|
+
it "should take an options hash to instantiate" do
|
7
|
+
lambda{Node.new(:any_value => true)}.should_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should take an optional name parameter" do
|
11
|
+
node = Node.new(:name => "My Name")
|
12
|
+
node.name.should eql("My Name")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should take an optional distribution parameter" do
|
16
|
+
node = Node.new(:distribution => Fathom::Distributions::Gaussian)
|
17
|
+
node.distribution.should eql(Fathom::Distributions::Gaussian)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should default to the standard distribution" do
|
21
|
+
node = Node.new
|
22
|
+
node.distribution.should eql(Fathom::Distributions::Gaussian)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to take a symbol and find the appropriate distribution" do
|
26
|
+
node = Node.new(:distribution => :gaussian)
|
27
|
+
node.distribution.should eql(Fathom::Distributions::Gaussian)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should take an optional description" do
|
31
|
+
node = Node.new(:description => "some description")
|
32
|
+
node.description.should eql('some description')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should take an optional values parameter" do
|
36
|
+
node = Node.new(:values => [1,2,3])
|
37
|
+
node.values.should eql([1,2,3])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should provide name_sym, if a name is defined" do
|
41
|
+
node = Node.new(:name => "Some name")
|
42
|
+
node.name_sym.should eql(:some_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should change dashes to underscores for name_sym" do
|
46
|
+
node = Node.new(:name => "Some-name")
|
47
|
+
node.name_sym.should eql(:some_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should take an optional parents list" do
|
51
|
+
n1 = Node.new
|
52
|
+
n2 = Node.new(:parents => [n1])
|
53
|
+
n2.parents.should eql([n1])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow a single node as a parent or parents and turn it into an array" do
|
57
|
+
n1 = Node.new
|
58
|
+
n2 = Node.new(:parents => n1)
|
59
|
+
n2.parents.should eql([n1])
|
60
|
+
n2 = Node.new(:parent => n1)
|
61
|
+
n2.parents.should eql([n1])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create an empty list of parents by default" do
|
65
|
+
n1 = Node.new
|
66
|
+
n1.parents.should eql([])
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be able to add a parent" do
|
70
|
+
n1, n2 = Node.new, Node.new
|
71
|
+
n3 = Node.new(:parent => n2)
|
72
|
+
n3.add_parent(n1)
|
73
|
+
n3.parents.should eql([n2, n1])
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should register the receiving node when adding a parent" do
|
77
|
+
n1 = Node.new
|
78
|
+
n1.should_receive(:register_child).and_return(true)
|
79
|
+
n2 = Node.new(:parent => n1)
|
80
|
+
|
81
|
+
n1 = Node.new
|
82
|
+
n1.should_receive(:register_child).and_return(true)
|
83
|
+
n2 = Node.new
|
84
|
+
n2.add_parent(n1)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not allow a parent to be registered if it is not a child of the other node" do
|
88
|
+
n1 = Node.new
|
89
|
+
n2 = Node.new
|
90
|
+
lambda{n2.register_parent(n1)}.should raise_error
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should take an optional children list" do
|
94
|
+
n1 = Node.new
|
95
|
+
n2 = Node.new(:children => [n1])
|
96
|
+
n2.children.should eql([n1])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should allow a single node as a child or children and turn it into an array" do
|
100
|
+
n1 = Node.new
|
101
|
+
n2 = Node.new(:children => n1)
|
102
|
+
n2.children.should eql([n1])
|
103
|
+
n2 = Node.new(:child => n1)
|
104
|
+
n2.children.should eql([n1])
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should create an empty list of children by default" do
|
108
|
+
n1 = Node.new
|
109
|
+
n1.children.should eql([])
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should register the receiving node when adding a child" do
|
113
|
+
n1 = Node.new
|
114
|
+
n1.should_receive(:register_parent).and_return(true)
|
115
|
+
n2 = Node.new(:child => n1)
|
116
|
+
|
117
|
+
n1 = Node.new
|
118
|
+
n1.should_receive(:register_parent).and_return(true)
|
119
|
+
n2 = Node.new
|
120
|
+
n2.add_child(n1)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not allow a child to be registered if it is not a parent of the other node" do
|
124
|
+
n1 = Node.new
|
125
|
+
n2 = Node.new
|
126
|
+
lambda{n2.register_child(n1)}.should raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include Fathom
|
4
|
+
|
5
|
+
describe NumericMethods do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@values = [1,2,3]
|
9
|
+
@vector = GSL::Vector.ary_to_gv(@values)
|
10
|
+
@opts = {:values => @values}
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
@n = DummyNumericNode.new(@opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should respond to a rand method" do
|
18
|
+
@n = DummyNumericNode.new
|
19
|
+
@n.should be_respond_to(:rand)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be able to construct a vector from the values" do
|
23
|
+
@n.vector.should ==(@vector)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have a standard deviation if it has a vector" do
|
27
|
+
@n.standard_deviation.should eql(@vector.sd)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have std and sd aliases for standard deviation" do
|
31
|
+
@n.sd.should eql(@n.standard_deviation)
|
32
|
+
@n.std.should eql(@n.standard_deviation)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not raise an error when looking for a standard deviation and there is no vector" do
|
36
|
+
@n = DummyNumericNode.new
|
37
|
+
@n.vector.should be_nil
|
38
|
+
@n.sd.should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a mean if it has a vector" do
|
42
|
+
@n.mean.should eql(@vector.mean)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return nil for mean if it doesn't have a vector" do
|
46
|
+
@n = DummyNumericNode.new
|
47
|
+
@n.mean.should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should provide rand, if it has a vector" do
|
51
|
+
Gaussian.should_receive(:rand).and_return(0.5)
|
52
|
+
@n.rand
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return nil for rand if it doesn't have a vector" do
|
56
|
+
@n = DummyNumericNode.new
|
57
|
+
@n.mean.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to calculate the inverse_cdf, lower_bound, upper_bound and interval_values" do
|
61
|
+
lambda{@n.inverse_cdf}.should_not raise_error
|
62
|
+
lambda{@n.lower_bound}.should_not raise_error
|
63
|
+
lambda{@n.upper_bound}.should_not raise_error
|
64
|
+
lambda{@n.interval_values}.should_not raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should pass the mean and standard deviation to the distribution when calculating an inverse_cdf" do
|
68
|
+
@n.inverse_cdf.should eql(Gaussian.inverse_cdf(:mean => @n.mean, :sd => @n.sd))
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should pass the mean and standard deviation to the distribution when calculating an lower_bound" do
|
72
|
+
@n.lower_bound.should eql(Gaussian.lower_bound(:mean => @n.mean, :sd => @n.sd))
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should pass the mean and standard deviation to the distribution when calculating an upper_bound" do
|
76
|
+
@n.upper_bound.should eql(Gaussian.upper_bound(:mean => @n.mean, :sd => @n.sd))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should pass the mean and standard deviation to the distribution when calculating an interval_values" do
|
80
|
+
@n.interval_values.should eql(Gaussian.interval_values(:mean => @n.mean, :sd => @n.sd))
|
81
|
+
end
|
82
|
+
end
|
@@ -67,9 +67,8 @@ describe PlausibleRange do
|
|
67
67
|
@pr.midpoint.should eql(5.5)
|
68
68
|
end
|
69
69
|
|
70
|
-
# TODO: Make this more accurate when we start using the GSL stuff more
|
71
70
|
it "should be able to calculate the standard deviation" do
|
72
|
-
@pr.standard_deviation.should be_close(2.
|
71
|
+
@pr.standard_deviation.should be_close( 2.7358, 0.0001)
|
73
72
|
end
|
74
73
|
|
75
74
|
it "should be able to use std instead of standard_deviation" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fathom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-10 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- LICENSE
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
|
+
- TODO.md
|
54
55
|
- VERSION
|
55
56
|
- autotest/discover.rb
|
56
57
|
- lib/fathom.rb
|
@@ -63,21 +64,27 @@ files:
|
|
63
64
|
- lib/fathom/archive/node.rb
|
64
65
|
- lib/fathom/archive/noodle.rb
|
65
66
|
- lib/fathom/archive/scratch.rb
|
66
|
-
- lib/fathom/basic_node.rb
|
67
67
|
- lib/fathom/causal_graph.rb
|
68
|
-
- lib/fathom/combined_plausibilities.rb
|
69
68
|
- lib/fathom/concept.rb
|
70
69
|
- lib/fathom/data_node.rb
|
70
|
+
- lib/fathom/distributions.rb
|
71
|
+
- lib/fathom/distributions/discrete_gaussian.rb
|
72
|
+
- lib/fathom/distributions/discrete_uniform.rb
|
73
|
+
- lib/fathom/distributions/gaussian.rb
|
74
|
+
- lib/fathom/distributions/uniform.rb
|
75
|
+
- lib/fathom/enforced_name.rb
|
71
76
|
- lib/fathom/ext/array.rb
|
72
77
|
- lib/fathom/ext/faster_csv.rb
|
73
78
|
- lib/fathom/ext/open_struct.rb
|
79
|
+
- lib/fathom/ext/string.rb
|
74
80
|
- lib/fathom/import.rb
|
75
81
|
- lib/fathom/import/csv_import.rb
|
76
82
|
- lib/fathom/import/yaml_import.rb
|
77
83
|
- lib/fathom/inverter.rb
|
78
84
|
- lib/fathom/knowledge_base.rb
|
79
85
|
- lib/fathom/monte_carlo_set.rb
|
80
|
-
- lib/fathom/
|
86
|
+
- lib/fathom/node.rb
|
87
|
+
- lib/fathom/numeric_methods.rb
|
81
88
|
- lib/fathom/plausible_range.rb
|
82
89
|
- lib/fathom/simulation.rb
|
83
90
|
- lib/fathom/simulation/tick_methods.rb
|
@@ -89,11 +96,18 @@ files:
|
|
89
96
|
- spec/fathom/agent/agent_cluster_spec.rb
|
90
97
|
- spec/fathom/agent_spec.rb
|
91
98
|
- spec/fathom/data_node_spec.rb
|
99
|
+
- spec/fathom/distributions/discrete_gaussian_spec.rb
|
100
|
+
- spec/fathom/distributions/discrete_uniform_spec.rb
|
101
|
+
- spec/fathom/distributions/gaussian_spec.rb
|
102
|
+
- spec/fathom/distributions/uniform_spec.rb
|
103
|
+
- spec/fathom/enforced_name_spec.rb
|
92
104
|
- spec/fathom/import/csv_import_spec.rb
|
93
105
|
- spec/fathom/import/yaml_import_spec.rb
|
94
106
|
- spec/fathom/import_spec.rb
|
95
107
|
- spec/fathom/knowledge_base_spec.rb
|
96
108
|
- spec/fathom/monte_carlo_set_spec.rb
|
109
|
+
- spec/fathom/node_spec.rb
|
110
|
+
- spec/fathom/numeric_methods_spec.rb
|
97
111
|
- spec/fathom/plausible_range_spec.rb
|
98
112
|
- spec/fathom/simulation/tick_simulation_spec.rb
|
99
113
|
- spec/fathom/simulation_spec.rb
|
@@ -102,6 +116,7 @@ files:
|
|
102
116
|
- spec/spec_helper.rb
|
103
117
|
- spec/support/demo.yml
|
104
118
|
- spec/support/demo_agent.rb
|
119
|
+
- spec/support/dummy_numeric_node.rb
|
105
120
|
has_rdoc: true
|
106
121
|
homepage: http://github.com/davidrichards/fathom
|
107
122
|
licenses: []
|
@@ -140,11 +155,18 @@ test_files:
|
|
140
155
|
- spec/fathom/agent/agent_cluster_spec.rb
|
141
156
|
- spec/fathom/agent_spec.rb
|
142
157
|
- spec/fathom/data_node_spec.rb
|
158
|
+
- spec/fathom/distributions/discrete_gaussian_spec.rb
|
159
|
+
- spec/fathom/distributions/discrete_uniform_spec.rb
|
160
|
+
- spec/fathom/distributions/gaussian_spec.rb
|
161
|
+
- spec/fathom/distributions/uniform_spec.rb
|
162
|
+
- spec/fathom/enforced_name_spec.rb
|
143
163
|
- spec/fathom/import/csv_import_spec.rb
|
144
164
|
- spec/fathom/import/yaml_import_spec.rb
|
145
165
|
- spec/fathom/import_spec.rb
|
146
166
|
- spec/fathom/knowledge_base_spec.rb
|
147
167
|
- spec/fathom/monte_carlo_set_spec.rb
|
168
|
+
- spec/fathom/node_spec.rb
|
169
|
+
- spec/fathom/numeric_methods_spec.rb
|
148
170
|
- spec/fathom/plausible_range_spec.rb
|
149
171
|
- spec/fathom/simulation/tick_simulation_spec.rb
|
150
172
|
- spec/fathom/simulation_spec.rb
|
@@ -152,3 +174,4 @@ test_files:
|
|
152
174
|
- spec/fathom_spec.rb
|
153
175
|
- spec/spec_helper.rb
|
154
176
|
- spec/support/demo_agent.rb
|
177
|
+
- spec/support/dummy_numeric_node.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'fathom'))
|
2
|
-
module Fathom
|
3
|
-
class CombinedPlausibilities
|
4
|
-
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
if __FILE__ == $0
|
9
|
-
include Fathom
|
10
|
-
# TODO: Is there anything you want to do to run this file on its own?
|
11
|
-
# CombinedPlausibilities.new
|
12
|
-
end
|