fathom 0.3.4 → 0.3.6
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/VERSION +1 -1
- data/lib/fathom.rb +31 -33
- data/lib/fathom/node/mc_node.rb +2 -1
- data/spec/fathom/distributions/gaussian_spec.rb +5 -5
- data/spec/fathom/import/import_node_spec.rb +1 -1
- data/spec/fathom/node/cpm_node_spec.rb +34 -34
- data/spec/fathom/node/plausible_range_spec.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
data/lib/fathom.rb
CHANGED
@@ -19,39 +19,6 @@ module Fathom
|
|
19
19
|
lib = File.expand_path(File.dirname(__FILE__))
|
20
20
|
$LOAD_PATH.unshift(lib)
|
21
21
|
|
22
|
-
Fathom.autoload :Node, "node"
|
23
|
-
Fathom.autoload :BeliefNode, "node/belief_node"
|
24
|
-
Fathom.autoload :DataCollection, "node/data_collection"
|
25
|
-
Fathom.autoload :DataNode, "node/data_node"
|
26
|
-
Fathom.autoload :DiscreteNode, "node/discrete_node"
|
27
|
-
Fathom.autoload :MCNode, "node/mc_node"
|
28
|
-
Fathom.autoload :PlausibleRange, "node/plausible_range"
|
29
|
-
Fathom.autoload :Fact, "node/fact"
|
30
|
-
Fathom.autoload :Decision, "node/decision"
|
31
|
-
Fathom.autoload :CPMNode, 'node/cpm_node'
|
32
|
-
|
33
|
-
Fathom.autoload :ValueDescription, "value_description"
|
34
|
-
Fathom.autoload :MonteCarloSet, "monte_carlo_set"
|
35
|
-
Fathom.autoload :KnowledgeBase, "knowledge_base"
|
36
|
-
|
37
|
-
Fathom.autoload :Import, "import"
|
38
|
-
Fathom.autoload :ImportNode, "import/import_node"
|
39
|
-
Fathom.autoload :YAMLImport, 'import/yaml_import'
|
40
|
-
Fathom.autoload :CSVImport, 'import/csv_import'
|
41
|
-
|
42
|
-
Fathom.autoload :Simulation, 'simulation'
|
43
|
-
Fathom.autoload :TickMethods, 'simulation/tick_methods'
|
44
|
-
Fathom.autoload :TickSimulation, 'simulation/tick_simulation'
|
45
|
-
|
46
|
-
Fathom.autoload :Agent, 'agent'
|
47
|
-
Fathom.autoload :Properties, 'agent/properties'
|
48
|
-
Fathom.autoload :AgentCluster, 'agent/agent_cluster'
|
49
|
-
|
50
|
-
Fathom.autoload :EnforcedName, 'node/node_extensions/enforced_name'
|
51
|
-
Fathom.autoload :NumericMethods, 'node/node_extensions/numeric_methods'
|
52
|
-
|
53
|
-
|
54
|
-
|
55
22
|
# Autoload classes and modules so that we only load as much of the library as we're using.
|
56
23
|
# This allows us to have a fairly large library without taking up a lot of memory unless we need it.
|
57
24
|
# autoload :Node, "node"
|
@@ -103,3 +70,34 @@ end
|
|
103
70
|
|
104
71
|
# Temporary
|
105
72
|
# include Fathom
|
73
|
+
|
74
|
+
Fathom.autoload :Node, "node"
|
75
|
+
Fathom.autoload :BeliefNode, "node/belief_node"
|
76
|
+
Fathom.autoload :DataCollection, "node/data_collection"
|
77
|
+
Fathom.autoload :DataNode, "node/data_node"
|
78
|
+
Fathom.autoload :DiscreteNode, "node/discrete_node"
|
79
|
+
Fathom.autoload :MCNode, "node/mc_node"
|
80
|
+
Fathom.autoload :PlausibleRange, "node/plausible_range"
|
81
|
+
Fathom.autoload :Fact, "node/fact"
|
82
|
+
Fathom.autoload :Decision, "node/decision"
|
83
|
+
Fathom.autoload :CPMNode, 'node/cpm_node'
|
84
|
+
|
85
|
+
Fathom.autoload :ValueDescription, "value_description"
|
86
|
+
Fathom.autoload :MonteCarloSet, "monte_carlo_set"
|
87
|
+
Fathom.autoload :KnowledgeBase, "knowledge_base"
|
88
|
+
|
89
|
+
Fathom.autoload :Import, "import"
|
90
|
+
Fathom.autoload :ImportNode, "import/import_node"
|
91
|
+
Fathom.autoload :YAMLImport, 'import/yaml_import'
|
92
|
+
Fathom.autoload :CSVImport, 'import/csv_import'
|
93
|
+
|
94
|
+
Fathom.autoload :Simulation, 'simulation'
|
95
|
+
Fathom.autoload :TickMethods, 'simulation/tick_methods'
|
96
|
+
Fathom.autoload :TickSimulation, 'simulation/tick_simulation'
|
97
|
+
|
98
|
+
Fathom.autoload :Agent, 'agent'
|
99
|
+
Fathom.autoload :Properties, 'agent/properties'
|
100
|
+
Fathom.autoload :AgentCluster, 'agent/agent_cluster'
|
101
|
+
|
102
|
+
Fathom.autoload :EnforcedName, 'node/node_extensions/enforced_name'
|
103
|
+
Fathom.autoload :NumericMethods, 'node/node_extensions/numeric_methods'
|
data/lib/fathom/node/mc_node.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom'))
|
2
2
|
class Fathom::MCNode < Fathom::Node
|
3
3
|
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :samples_taken
|
5
|
+
attr_accessor :value_description
|
5
6
|
|
6
7
|
def initialize(opts={}, &block)
|
7
8
|
super(opts)
|
@@ -18,7 +18,7 @@ describe Gaussian do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be able to generate an inverse CDF" do
|
21
|
-
Gaussian.inverse_cdf(@opts).should
|
21
|
+
Gaussian.inverse_cdf(@opts).should be_within(0.00001).of(-0.16448)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should require mean as an option for an inverse CDF" do
|
@@ -33,20 +33,20 @@ describe Gaussian do
|
|
33
33
|
|
34
34
|
it "should take std as an alias for sd when creating an inverse CDF" do
|
35
35
|
@opts.delete(:sd)
|
36
|
-
Gaussian.inverse_cdf(@opts.merge(:std => 0.1)).should
|
36
|
+
Gaussian.inverse_cdf(@opts.merge(:std => 0.1)).should be_within(0.00001).of(-0.16448)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should take standard_deviation as an alias for sd when creating an inverse CDF" do
|
40
40
|
@opts.delete(:sd)
|
41
|
-
Gaussian.inverse_cdf(@opts.merge(:standard_deviation => 0.1)).should
|
41
|
+
Gaussian.inverse_cdf(@opts.merge(:standard_deviation => 0.1)).should be_within(0.00001).of(-0.16448)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should be able to set upper to true and get Q instead of P" do
|
45
|
-
Gaussian.inverse_cdf(@opts.merge(:upper =>true)).should
|
45
|
+
Gaussian.inverse_cdf(@opts.merge(:upper =>true)).should be_within(0.00001).of(0.16448)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should be able to take a different confidence interval" do
|
49
|
-
Gaussian.inverse_cdf(@opts.merge(:confidence_interval => 0.1)).should
|
49
|
+
Gaussian.inverse_cdf(@opts.merge(:confidence_interval => 0.1)).should be_within(0.00001).of(-0.12815)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should have a lower_bound alias for inverse_cdf" do
|
@@ -46,24 +46,24 @@ describe CPMNode do
|
|
46
46
|
# GSL::Matrix
|
47
47
|
# [ 8.000e-02 1.200e-01
|
48
48
|
# 3.200e-01 4.800e-01 ]
|
49
|
-
@cpm.probability(:color => :red, :child => :asher).should
|
50
|
-
@cpm.probability(:color => :red, :child => :stella).should
|
51
|
-
@cpm.probability(:color => :green, :child => :asher).should
|
52
|
-
@cpm.probability(:color => :green, :child => :stella).should
|
49
|
+
@cpm.probability(:color => :red, :child => :asher).should be_within(1e-10).of(0.08)
|
50
|
+
@cpm.probability(:color => :red, :child => :stella).should be_within(1e-10).of(0.32)
|
51
|
+
@cpm.probability(:color => :green, :child => :asher).should be_within(1e-10).of(0.12)
|
52
|
+
@cpm.probability(:color => :green, :child => :stella).should be_within(1e-10).of(0.48)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should look for all children values, if no child is provided" do
|
56
|
-
@cpm.probability(:child => :asher).should
|
57
|
-
@cpm.probability(:child => :stella).should
|
56
|
+
@cpm.probability(:child => :asher).should be_within(1e-10).of(0.2)
|
57
|
+
@cpm.probability(:child => :stella).should be_within(1e-10).of(0.8)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should look for all parent values, if no parent is provided" do
|
61
|
-
@cpm.probability(:color => :red).should
|
62
|
-
@cpm.probability(:color => :green).should
|
61
|
+
@cpm.probability(:color => :red).should be_within(1e-10).of(0.4)
|
62
|
+
@cpm.probability(:color => :green).should be_within(1e-10).of(0.6)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should provide a probability of 1 if no filter is set" do
|
66
|
-
@cpm.probability.should
|
66
|
+
@cpm.probability.should be_within(1e-10).of(1.0)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should give a description in a hash, if description is turned on" do
|
@@ -79,38 +79,38 @@ describe CPMNode do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should alias p for probability" do
|
82
|
-
@cpm.p(:color => :red, :child => :asher).should
|
83
|
-
@cpm.p(:color => :red, :child => :stella).should
|
84
|
-
@cpm.p(:color => :green, :child => :asher).should
|
85
|
-
@cpm.p(:color => :green, :child => :stella).should
|
86
|
-
@cpm.p(:child => :asher).should
|
87
|
-
@cpm.p(:child => :stella).should
|
88
|
-
@cpm.p(:color => :red).should
|
89
|
-
@cpm.p(:color => :green).should
|
90
|
-
@cpm.p.should
|
82
|
+
@cpm.p(:color => :red, :child => :asher).should be_within(1e-10).of(0.08)
|
83
|
+
@cpm.p(:color => :red, :child => :stella).should be_within(1e-10).of(0.32)
|
84
|
+
@cpm.p(:color => :green, :child => :asher).should be_within(1e-10).of(0.12)
|
85
|
+
@cpm.p(:color => :green, :child => :stella).should be_within(1e-10).of(0.48)
|
86
|
+
@cpm.p(:child => :asher).should be_within(1e-10).of(0.2)
|
87
|
+
@cpm.p(:child => :stella).should be_within(1e-10).of(0.8)
|
88
|
+
@cpm.p(:color => :red).should be_within(1e-10).of(0.4)
|
89
|
+
@cpm.p(:color => :green).should be_within(1e-10).of(0.6)
|
90
|
+
@cpm.p.should be_within(1e-10).of(1.0)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should have odds for any query" do
|
94
|
-
@cpm.odds(:color => :red, :child => :asher).should
|
95
|
-
@cpm.odds(:color => :red, :child => :stella).should
|
96
|
-
@cpm.odds(:color => :green, :child => :asher).should
|
97
|
-
@cpm.odds(:color => :green, :child => :stella).should
|
98
|
-
@cpm.odds(:child => :asher).should
|
99
|
-
@cpm.odds(:child => :stella).should
|
100
|
-
@cpm.odds(:color => :red).should
|
101
|
-
@cpm.odds(:color => :green).should
|
94
|
+
@cpm.odds(:color => :red, :child => :asher).should be_within(1e-3).of(0.087)
|
95
|
+
@cpm.odds(:color => :red, :child => :stella).should be_within(1e-3).of(0.471)
|
96
|
+
@cpm.odds(:color => :green, :child => :asher).should be_within(1e-3).of(0.136)
|
97
|
+
@cpm.odds(:color => :green, :child => :stella).should be_within(1e-3).of(0.923)
|
98
|
+
@cpm.odds(:child => :asher).should be_within(1e-3).of(0.25)
|
99
|
+
@cpm.odds(:child => :stella).should be_within(1e-3).of(4.0)
|
100
|
+
@cpm.odds(:color => :red).should be_within(1e-3).of(0.666)
|
101
|
+
@cpm.odds(:color => :green).should be_within(1e-3).of(1.5)
|
102
102
|
@cpm.odds.should eql(1 / 0.0)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should alias o for odds" do
|
106
|
-
@cpm.o(:color => :red, :child => :asher).should
|
107
|
-
@cpm.o(:color => :red, :child => :stella).should
|
108
|
-
@cpm.o(:color => :green, :child => :asher).should
|
109
|
-
@cpm.o(:color => :green, :child => :stella).should
|
110
|
-
@cpm.o(:child => :asher).should
|
111
|
-
@cpm.o(:child => :stella).should
|
112
|
-
@cpm.o(:color => :red).should
|
113
|
-
@cpm.o(:color => :green).should
|
106
|
+
@cpm.o(:color => :red, :child => :asher).should be_within(1e-3).of(0.087)
|
107
|
+
@cpm.o(:color => :red, :child => :stella).should be_within(1e-3).of(0.471)
|
108
|
+
@cpm.o(:color => :green, :child => :asher).should be_within(1e-3).of(0.136)
|
109
|
+
@cpm.o(:color => :green, :child => :stella).should be_within(1e-3).of(0.923)
|
110
|
+
@cpm.o(:child => :asher).should be_within(1e-3).of(0.25)
|
111
|
+
@cpm.o(:child => :stella).should be_within(1e-3).of(4.0)
|
112
|
+
@cpm.o(:color => :red).should be_within(1e-3).of(0.666)
|
113
|
+
@cpm.o(:color => :green).should be_within(1e-3).of(1.5)
|
114
114
|
@cpm.o.should eql(1 / 0.0)
|
115
115
|
end
|
116
116
|
|
@@ -68,7 +68,7 @@ describe PlausibleRange do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should be able to calculate the standard deviation" do
|
71
|
-
@pr.standard_deviation.should
|
71
|
+
@pr.standard_deviation.should be_within(0.0001).of( 2.7358)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should be able to use std instead of standard_deviation" do
|
metadata
CHANGED