fathom 0.3.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.autotest +7 -5
  2. data/.document +2 -2
  3. data/Gemfile +9 -10
  4. data/{LICENSE → LICENSE.txt} +1 -1
  5. data/README.md +29 -90
  6. data/Rakefile +34 -32
  7. data/VERSION +1 -1
  8. data/fathom.gemspec +105 -0
  9. data/features/fathom.feature +26 -0
  10. data/features/step_definitions/fathom_steps.rb +23 -0
  11. data/features/support/env.rb +13 -0
  12. data/lib/ext/array.rb +6 -2
  13. data/lib/ext/string.rb +86 -7
  14. data/lib/fathom.rb +51 -88
  15. data/lib/fathom/behaviors/attribute_system.rb +91 -0
  16. data/lib/fathom/behaviors/context_behavior.rb +28 -0
  17. data/lib/fathom/behaviors/plugins.rb +16 -0
  18. data/lib/fathom/contexts/network_population.rb +47 -0
  19. data/lib/fathom/contexts/network_traversal.rb +4 -0
  20. data/lib/fathom/data/adjacency_matrix.rb +27 -0
  21. data/lib/fathom/data/definition.rb +22 -0
  22. data/lib/fathom/data/edge.rb +58 -0
  23. data/lib/fathom/data/network.rb +35 -0
  24. data/lib/fathom/data/outcome.rb +30 -0
  25. data/lib/fathom/data/property.rb +31 -0
  26. data/lib/fathom/data/variable.rb +59 -0
  27. data/lib/fathom/roles/general_graph_tools.rb +87 -0
  28. data/lib/fathom/roles/network_builder.rb +61 -0
  29. data/spec/fathom/behaviors/attribute_system_spec.rb +141 -0
  30. data/spec/fathom/behaviors/context_behavior_spec.rb +15 -0
  31. data/spec/fathom/behaviors/plugins_spec.rb +80 -0
  32. data/spec/fathom/contexts/network_population_spec.rb +55 -0
  33. data/spec/fathom/contexts/network_traversal_spec.rb +11 -0
  34. data/spec/fathom/data/adjacency_matrix_spec.rb +42 -0
  35. data/spec/fathom/data/definition_spec.rb +19 -0
  36. data/spec/fathom/data/edge_spec.rb +77 -0
  37. data/spec/fathom/data/network_spec.rb +72 -0
  38. data/spec/fathom/data/outcome_spec.rb +17 -0
  39. data/spec/fathom/data/property_spec.rb +17 -0
  40. data/spec/fathom/data/variable_spec.rb +101 -0
  41. data/spec/fathom/ext/array_spec.rb +17 -0
  42. data/spec/fathom/ext/string_spec.rb +90 -0
  43. data/spec/fathom/roles/general_graph_tools_spec.rb +95 -0
  44. data/spec/fathom/roles/network_builder_spec.rb +90 -0
  45. data/spec/fathom_spec.rb +28 -49
  46. data/spec/spec_helper.rb +7 -11
  47. data/spec/support/context_behavior.rb +14 -0
  48. data/spec/support/custom_matchers.rb +12 -0
  49. data/spec/support/files.rb +8 -0
  50. data/spec/support/network.yml +42 -0
  51. metadata +133 -174
  52. data/.bundle/config +0 -2
  53. data/.gitignore +0 -6
  54. data/Gemfile.lock +0 -42
  55. data/TODO.md +0 -127
  56. data/autotest/discover.rb +0 -1
  57. data/lib/ext/faster_csv.rb +0 -1
  58. data/lib/ext/open_struct.rb +0 -17
  59. data/lib/fathom/agent.rb +0 -48
  60. data/lib/fathom/agent/agent_cluster.rb +0 -23
  61. data/lib/fathom/agent/properties.rb +0 -48
  62. data/lib/fathom/archive/causal_graph.rb +0 -12
  63. data/lib/fathom/archive/concept.rb +0 -83
  64. data/lib/fathom/archive/conditional_probability_matrix.rb +0 -119
  65. data/lib/fathom/archive/inverter.rb +0 -20
  66. data/lib/fathom/archive/n2.rb +0 -198
  67. data/lib/fathom/archive/n3.rb +0 -119
  68. data/lib/fathom/archive/node.rb +0 -97
  69. data/lib/fathom/archive/noodle.rb +0 -136
  70. data/lib/fathom/archive/scratch.rb +0 -45
  71. data/lib/fathom/distributions.rb +0 -8
  72. data/lib/fathom/distributions/discrete_gaussian.rb +0 -44
  73. data/lib/fathom/distributions/discrete_uniform.rb +0 -25
  74. data/lib/fathom/distributions/gaussian.rb +0 -46
  75. data/lib/fathom/distributions/uniform.rb +0 -35
  76. data/lib/fathom/import.rb +0 -85
  77. data/lib/fathom/import/csv_import.rb +0 -59
  78. data/lib/fathom/import/import_node.rb +0 -17
  79. data/lib/fathom/import/yaml_import.rb +0 -74
  80. data/lib/fathom/knowledge_base.rb +0 -46
  81. data/lib/fathom/knowledge_base/search.rb +0 -19
  82. data/lib/fathom/monte_carlo_set.rb +0 -152
  83. data/lib/fathom/node.rb +0 -139
  84. data/lib/fathom/node/belief_node.rb +0 -121
  85. data/lib/fathom/node/cpm_node.rb +0 -100
  86. data/lib/fathom/node/data_collection.rb +0 -97
  87. data/lib/fathom/node/data_node.rb +0 -22
  88. data/lib/fathom/node/decision.rb +0 -11
  89. data/lib/fathom/node/discrete_node.rb +0 -41
  90. data/lib/fathom/node/fact.rb +0 -24
  91. data/lib/fathom/node/mc_node.rb +0 -70
  92. data/lib/fathom/node/node_extensions/enforced_name.rb +0 -12
  93. data/lib/fathom/node/node_extensions/numeric_methods.rb +0 -68
  94. data/lib/fathom/node/plausible_range.rb +0 -98
  95. data/lib/fathom/simulation.rb +0 -59
  96. data/lib/fathom/simulation/tick_methods.rb +0 -25
  97. data/lib/fathom/simulation/tick_simulation.rb +0 -12
  98. data/lib/fathom/value_description.rb +0 -79
  99. data/lib/options_hash.rb +0 -186
  100. data/spec/ext/array_spec.rb +0 -10
  101. data/spec/ext/faster_csv_spec.rb +0 -10
  102. data/spec/ext/open_struct_spec.rb +0 -20
  103. data/spec/ext/string_spec.rb +0 -7
  104. data/spec/fathom/agent/agent_cluster_spec.rb +0 -17
  105. data/spec/fathom/agent_spec.rb +0 -51
  106. data/spec/fathom/distributions/discrete_gaussian_spec.rb +0 -64
  107. data/spec/fathom/distributions/discrete_uniform_spec.rb +0 -0
  108. data/spec/fathom/distributions/gaussian_spec.rb +0 -64
  109. data/spec/fathom/distributions/uniform_spec.rb +0 -0
  110. data/spec/fathom/import/csv_import_spec.rb +0 -52
  111. data/spec/fathom/import/import_node_spec.rb +0 -10
  112. data/spec/fathom/import/yaml_import_spec.rb +0 -73
  113. data/spec/fathom/import_spec.rb +0 -36
  114. data/spec/fathom/knowledge_base_spec.rb +0 -20
  115. data/spec/fathom/monte_carlo_set_spec.rb +0 -149
  116. data/spec/fathom/node/belief_node_spec.rb +0 -180
  117. data/spec/fathom/node/cpm_node_spec.rb +0 -144
  118. data/spec/fathom/node/data_collection_spec.rb +0 -26
  119. data/spec/fathom/node/data_node_spec.rb +0 -102
  120. data/spec/fathom/node/decision_spec.rb +0 -15
  121. data/spec/fathom/node/discrete_node_spec.rb +0 -56
  122. data/spec/fathom/node/fact_spec.rb +0 -33
  123. data/spec/fathom/node/mc_node_spec.rb +0 -66
  124. data/spec/fathom/node/node_extensions/enforced_name_spec.rb +0 -15
  125. data/spec/fathom/node/node_extensions/numeric_methods_spec.rb +0 -124
  126. data/spec/fathom/node/plausible_range_spec.rb +0 -151
  127. data/spec/fathom/node_spec.rb +0 -172
  128. data/spec/fathom/simulation/tick_simulation_spec.rb +0 -32
  129. data/spec/fathom/simulation_spec.rb +0 -24
  130. data/spec/fathom/value_description_spec.rb +0 -70
  131. data/spec/support/demo.yml +0 -17
  132. data/spec/support/demo_agent.rb +0 -8
  133. data/spec/support/dummy_numeric_node.rb +0 -8
  134. data/spec/support/fact.yml +0 -11
@@ -1,32 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
-
3
- include Fathom
4
-
5
- describe TickSimulation do
6
-
7
- before do
8
- @da = DemoAgent.new
9
- end
10
-
11
- it "should process with n ticks" do
12
- @da.should_receive(:on_tick).exactly(3).times.and_return(true)
13
- s = TickSimulation.new(@da)
14
- s.process(3)
15
- end
16
-
17
- it "should expose the number of ticks designed and executed after processing" do
18
- s = TickSimulation.new(@da)
19
- s.process(4)
20
- s.ticks_designed.should eql(4)
21
- s.ticks_executed.should eql(4)
22
- end
23
-
24
- # Any calls coming top down (from the simulator or the agent cluster), will need a standard signature to
25
- # make things interchangeable. We use the simulator itself, which is a bit fat, but will work for the short
26
- # term.
27
- it "should pass the simulator on tick" do
28
- s = TickSimulation.new(@da)
29
- @da.should_receive(:on_tick).with(s)
30
- s.process(1)
31
- end
32
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- include Fathom
4
-
5
- describe Simulation do
6
- before do
7
- @da = DemoAgent.new
8
- @s = Simulation.new(@da)
9
- end
10
-
11
- it "should initialize with a list of agents" do
12
- s = Simulation.new(1,2,3)
13
- s.agents.should eql([1,2,3])
14
- end
15
-
16
- it "should register agent callbacks for simpler execution" do
17
- @da.should_receive(:on_tick).and_return(true)
18
- @s.tick
19
- end
20
-
21
- it "should publish agent subscription to various callbacks to facilitate agent-to-agent communication" do
22
- @s.agents_using_tick.should eql([@da])
23
- end
24
- end
@@ -1,70 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- include Fathom
4
-
5
- describe ValueDescription do
6
-
7
- before(:all) do
8
- @r1 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r1')
9
- @r2 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r2')
10
- @r3 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r3')
11
- @r4 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r4')
12
- end
13
-
14
- before do
15
- @vd = ValueDescription.new
16
- end
17
-
18
- it "should be able to initialize with no nodes" do
19
- @vd.nodes.should be_empty
20
- end
21
-
22
- it "should be able to take a set of nodes to work with" do
23
- vd = ValueDescription.new @r1, @r2, @r3, @r4
24
- vd.nodes.should eql([@r1, @r2, @r3, @r4])
25
- end
26
-
27
- it "should respond to the names of the nodes being added" do
28
- vd = ValueDescription.new @r1, @r2
29
- vd.r1.should be_a(Float)
30
- vd.r2.should be_a(Float)
31
- end
32
-
33
- it "should be able to add a node with add_node" do
34
- @vd.add_node(@r3)
35
- @vd.r3.should be_a(Float)
36
- end
37
-
38
- it "should be able to add a node with an alternative value method" do
39
- @vd.add_node(@r3, :name)
40
- @vd.r3.should eql('r3')
41
- end
42
-
43
- it "should be able to initialize with a hash, to define the value methods" do
44
- vd = ValueDescription.new @r1 => :rand, @r2 => :name
45
- vd.r1.should be_a(Float)
46
- vd.r2.should eql('r2')
47
- end
48
-
49
- it "should convert node names to lower case, underscore values" do
50
- pr = PlausibleRange.new(:min => 1, :max => 3, :name => 'Test Node')
51
- vd = ValueDescription.new pr => :name
52
- vd.test_node.should eql('Test Node')
53
- end
54
-
55
- it "should respond to process, which by default just adds up the values of the nodes" do
56
- vd = ValueDescription.new @r1, @r2
57
- output = vd.process
58
- sum = vd.last_process.values.inject(0.0) {|s, e| s += e}
59
- output.should eql(sum)
60
- end
61
-
62
- it "should be able to take an optional block at initialization" do
63
- vd = ValueDescription.new(@r1 => :name) {|obj|
64
- obj.r1
65
- }
66
- output = vd.process
67
- output.should eql('r1')
68
- end
69
-
70
- end
@@ -1,17 +0,0 @@
1
- CO2 Emissions:
2
- min: 1000000
3
- max: 1000000000
4
-
5
- Invalid Hash:
6
- different: signature
7
-
8
- CO2 Readings:
9
- - 10
10
- - 20
11
- - 30
12
-
13
- More Complete Range:
14
- min: 10
15
- max: 100
16
- confidence_interval: 0.6
17
- description: Some good description
@@ -1,8 +0,0 @@
1
- class DemoAgent < Agent
2
- property :field1
3
- property :field2
4
-
5
- def on_tick(simulation)
6
- end
7
-
8
- end
@@ -1,8 +0,0 @@
1
- module Fathom
2
- module Distributions
3
- class DummyNumericNode < Fathom::Node
4
- include NumericMethods
5
- end
6
- end
7
- end
8
-
@@ -1,11 +0,0 @@
1
- Fact:
2
- name: One
3
- value: 1
4
-
5
- fact:
6
- name: Two
7
- value: 2
8
-
9
- :fact:
10
- name: Three
11
- value: 3