compiled-knowledge 4.0.0a20__cp313-cp313-win32.whl

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.

Potentially problematic release.


This version of compiled-knowledge might be problematic. Click here for more details.

Files changed (178) hide show
  1. ck/__init__.py +0 -0
  2. ck/circuit/__init__.py +17 -0
  3. ck/circuit/_circuit_cy.c +37523 -0
  4. ck/circuit/_circuit_cy.cp313-win32.pyd +0 -0
  5. ck/circuit/_circuit_cy.pxd +32 -0
  6. ck/circuit/_circuit_cy.pyx +768 -0
  7. ck/circuit/_circuit_py.py +836 -0
  8. ck/circuit/tmp_const.py +74 -0
  9. ck/circuit_compiler/__init__.py +2 -0
  10. ck/circuit_compiler/circuit_compiler.py +26 -0
  11. ck/circuit_compiler/cython_vm_compiler/__init__.py +1 -0
  12. ck/circuit_compiler/cython_vm_compiler/_compiler.c +19824 -0
  13. ck/circuit_compiler/cython_vm_compiler/_compiler.cp313-win32.pyd +0 -0
  14. ck/circuit_compiler/cython_vm_compiler/_compiler.pyx +380 -0
  15. ck/circuit_compiler/cython_vm_compiler/cython_vm_compiler.py +121 -0
  16. ck/circuit_compiler/interpret_compiler.py +223 -0
  17. ck/circuit_compiler/llvm_compiler.py +388 -0
  18. ck/circuit_compiler/llvm_vm_compiler.py +546 -0
  19. ck/circuit_compiler/named_circuit_compilers.py +57 -0
  20. ck/circuit_compiler/support/__init__.py +0 -0
  21. ck/circuit_compiler/support/circuit_analyser/__init__.py +13 -0
  22. ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.c +10618 -0
  23. ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.cp313-win32.pyd +0 -0
  24. ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.pyx +98 -0
  25. ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_py.py +93 -0
  26. ck/circuit_compiler/support/input_vars.py +148 -0
  27. ck/circuit_compiler/support/llvm_ir_function.py +234 -0
  28. ck/example/__init__.py +53 -0
  29. ck/example/alarm.py +366 -0
  30. ck/example/asia.py +28 -0
  31. ck/example/binary_clique.py +32 -0
  32. ck/example/bow_tie.py +33 -0
  33. ck/example/cancer.py +37 -0
  34. ck/example/chain.py +38 -0
  35. ck/example/child.py +199 -0
  36. ck/example/clique.py +33 -0
  37. ck/example/cnf_pgm.py +39 -0
  38. ck/example/diamond_square.py +68 -0
  39. ck/example/earthquake.py +36 -0
  40. ck/example/empty.py +10 -0
  41. ck/example/hailfinder.py +539 -0
  42. ck/example/hepar2.py +628 -0
  43. ck/example/insurance.py +504 -0
  44. ck/example/loop.py +40 -0
  45. ck/example/mildew.py +38161 -0
  46. ck/example/munin.py +22982 -0
  47. ck/example/pathfinder.py +53747 -0
  48. ck/example/rain.py +39 -0
  49. ck/example/rectangle.py +161 -0
  50. ck/example/run.py +30 -0
  51. ck/example/sachs.py +129 -0
  52. ck/example/sprinkler.py +30 -0
  53. ck/example/star.py +44 -0
  54. ck/example/stress.py +64 -0
  55. ck/example/student.py +43 -0
  56. ck/example/survey.py +46 -0
  57. ck/example/triangle_square.py +54 -0
  58. ck/example/truss.py +49 -0
  59. ck/in_out/__init__.py +3 -0
  60. ck/in_out/parse_ace_lmap.py +216 -0
  61. ck/in_out/parse_ace_nnf.py +322 -0
  62. ck/in_out/parse_net.py +480 -0
  63. ck/in_out/parser_utils.py +185 -0
  64. ck/in_out/pgm_pickle.py +42 -0
  65. ck/in_out/pgm_python.py +268 -0
  66. ck/in_out/render_bugs.py +111 -0
  67. ck/in_out/render_net.py +177 -0
  68. ck/in_out/render_pomegranate.py +184 -0
  69. ck/pgm.py +3475 -0
  70. ck/pgm_circuit/__init__.py +1 -0
  71. ck/pgm_circuit/marginals_program.py +352 -0
  72. ck/pgm_circuit/mpe_program.py +237 -0
  73. ck/pgm_circuit/pgm_circuit.py +79 -0
  74. ck/pgm_circuit/program_with_slotmap.py +236 -0
  75. ck/pgm_circuit/slot_map.py +35 -0
  76. ck/pgm_circuit/support/__init__.py +0 -0
  77. ck/pgm_circuit/support/compile_circuit.py +83 -0
  78. ck/pgm_circuit/target_marginals_program.py +103 -0
  79. ck/pgm_circuit/wmc_program.py +323 -0
  80. ck/pgm_compiler/__init__.py +2 -0
  81. ck/pgm_compiler/ace/__init__.py +1 -0
  82. ck/pgm_compiler/ace/ace.py +299 -0
  83. ck/pgm_compiler/factor_elimination.py +395 -0
  84. ck/pgm_compiler/named_pgm_compilers.py +63 -0
  85. ck/pgm_compiler/pgm_compiler.py +19 -0
  86. ck/pgm_compiler/recursive_conditioning.py +231 -0
  87. ck/pgm_compiler/support/__init__.py +0 -0
  88. ck/pgm_compiler/support/circuit_table/__init__.py +17 -0
  89. ck/pgm_compiler/support/circuit_table/_circuit_table_cy.c +16396 -0
  90. ck/pgm_compiler/support/circuit_table/_circuit_table_cy.cp313-win32.pyd +0 -0
  91. ck/pgm_compiler/support/circuit_table/_circuit_table_cy.pyx +332 -0
  92. ck/pgm_compiler/support/circuit_table/_circuit_table_py.py +304 -0
  93. ck/pgm_compiler/support/clusters.py +568 -0
  94. ck/pgm_compiler/support/factor_tables.py +406 -0
  95. ck/pgm_compiler/support/join_tree.py +332 -0
  96. ck/pgm_compiler/support/named_compiler_maker.py +43 -0
  97. ck/pgm_compiler/variable_elimination.py +91 -0
  98. ck/probability/__init__.py +0 -0
  99. ck/probability/empirical_probability_space.py +50 -0
  100. ck/probability/pgm_probability_space.py +32 -0
  101. ck/probability/probability_space.py +622 -0
  102. ck/program/__init__.py +3 -0
  103. ck/program/program.py +137 -0
  104. ck/program/program_buffer.py +180 -0
  105. ck/program/raw_program.py +67 -0
  106. ck/sampling/__init__.py +0 -0
  107. ck/sampling/forward_sampler.py +211 -0
  108. ck/sampling/marginals_direct_sampler.py +113 -0
  109. ck/sampling/sampler.py +62 -0
  110. ck/sampling/sampler_support.py +232 -0
  111. ck/sampling/uniform_sampler.py +72 -0
  112. ck/sampling/wmc_direct_sampler.py +171 -0
  113. ck/sampling/wmc_gibbs_sampler.py +153 -0
  114. ck/sampling/wmc_metropolis_sampler.py +165 -0
  115. ck/sampling/wmc_rejection_sampler.py +115 -0
  116. ck/utils/__init__.py +0 -0
  117. ck/utils/iter_extras.py +163 -0
  118. ck/utils/local_config.py +270 -0
  119. ck/utils/map_list.py +128 -0
  120. ck/utils/map_set.py +128 -0
  121. ck/utils/np_extras.py +51 -0
  122. ck/utils/random_extras.py +64 -0
  123. ck/utils/tmp_dir.py +94 -0
  124. ck_demos/__init__.py +0 -0
  125. ck_demos/ace/__init__.py +0 -0
  126. ck_demos/ace/copy_ace_to_ck.py +15 -0
  127. ck_demos/ace/demo_ace.py +49 -0
  128. ck_demos/all_demos.py +88 -0
  129. ck_demos/circuit/__init__.py +0 -0
  130. ck_demos/circuit/demo_circuit_dump.py +22 -0
  131. ck_demos/circuit/demo_derivatives.py +43 -0
  132. ck_demos/circuit_compiler/__init__.py +0 -0
  133. ck_demos/circuit_compiler/compare_circuit_compilers.py +32 -0
  134. ck_demos/circuit_compiler/show_llvm_program.py +26 -0
  135. ck_demos/pgm/__init__.py +0 -0
  136. ck_demos/pgm/demo_pgm_dump.py +18 -0
  137. ck_demos/pgm/demo_pgm_dump_stress.py +18 -0
  138. ck_demos/pgm/demo_pgm_string_rendering.py +15 -0
  139. ck_demos/pgm/show_examples.py +25 -0
  140. ck_demos/pgm_compiler/__init__.py +0 -0
  141. ck_demos/pgm_compiler/compare_pgm_compilers.py +63 -0
  142. ck_demos/pgm_compiler/demo_compiler_dump.py +60 -0
  143. ck_demos/pgm_compiler/demo_factor_elimination.py +47 -0
  144. ck_demos/pgm_compiler/demo_join_tree.py +25 -0
  145. ck_demos/pgm_compiler/demo_marginals_program.py +53 -0
  146. ck_demos/pgm_compiler/demo_mpe_program.py +55 -0
  147. ck_demos/pgm_compiler/demo_pgm_compiler.py +38 -0
  148. ck_demos/pgm_compiler/demo_recursive_conditioning.py +33 -0
  149. ck_demos/pgm_compiler/demo_variable_elimination.py +33 -0
  150. ck_demos/pgm_compiler/demo_wmc_program.py +29 -0
  151. ck_demos/pgm_compiler/time_fe_compiler.py +93 -0
  152. ck_demos/pgm_inference/__init__.py +0 -0
  153. ck_demos/pgm_inference/demo_inferencing_basic.py +188 -0
  154. ck_demos/pgm_inference/demo_inferencing_mpe_cancer.py +45 -0
  155. ck_demos/pgm_inference/demo_inferencing_wmc_and_mpe_sprinkler.py +154 -0
  156. ck_demos/pgm_inference/demo_inferencing_wmc_student.py +110 -0
  157. ck_demos/programs/__init__.py +0 -0
  158. ck_demos/programs/demo_program_buffer.py +24 -0
  159. ck_demos/programs/demo_program_multi.py +24 -0
  160. ck_demos/programs/demo_program_none.py +19 -0
  161. ck_demos/programs/demo_program_single.py +23 -0
  162. ck_demos/programs/demo_raw_program_interpreted.py +21 -0
  163. ck_demos/programs/demo_raw_program_llvm.py +21 -0
  164. ck_demos/sampling/__init__.py +0 -0
  165. ck_demos/sampling/check_sampler.py +71 -0
  166. ck_demos/sampling/demo_marginal_direct_sampler.py +40 -0
  167. ck_demos/sampling/demo_uniform_sampler.py +38 -0
  168. ck_demos/sampling/demo_wmc_direct_sampler.py +40 -0
  169. ck_demos/utils/__init__.py +0 -0
  170. ck_demos/utils/compare.py +120 -0
  171. ck_demos/utils/convert_network.py +45 -0
  172. ck_demos/utils/sample_model.py +216 -0
  173. ck_demos/utils/stop_watch.py +384 -0
  174. compiled_knowledge-4.0.0a20.dist-info/METADATA +50 -0
  175. compiled_knowledge-4.0.0a20.dist-info/RECORD +178 -0
  176. compiled_knowledge-4.0.0a20.dist-info/WHEEL +5 -0
  177. compiled_knowledge-4.0.0a20.dist-info/licenses/LICENSE.txt +21 -0
  178. compiled_knowledge-4.0.0a20.dist-info/top_level.txt +2 -0
ck/example/alarm.py ADDED
@@ -0,0 +1,366 @@
1
+ from ck.pgm import PGM
2
+
3
+
4
+ class Alarm(PGM):
5
+ """
6
+ This PGM is the well known, pedagogical 'Alarm' Bayesian network.
7
+ """
8
+
9
+ def __init__(self):
10
+ super().__init__(self.__class__.__name__)
11
+
12
+ MinVol = self.new_rv('MinVol', ('Zero', 'Low', 'Normal', 'High'))
13
+ Press = self.new_rv('Press', ('Zero', 'Low', 'Normal', 'High'))
14
+ PAP = self.new_rv('PAP', ('Low', 'Normal', 'High'))
15
+ ExpCO2 = self.new_rv('ExpCO2', ('Zero', 'Low', 'Normal', 'High'))
16
+ HRBP = self.new_rv('HRBP', ('Low', 'Normal', 'High'))
17
+ ErrLowOutput = self.new_rv('ErrLowOutput', ('True', 'False'))
18
+ HRSat = self.new_rv('HRSat', ('Low', 'Normal', 'High'))
19
+ HREKG = self.new_rv('HREKG', ('Low', 'Normal', 'High'))
20
+ ErrCauter = self.new_rv('ErrCauter', ('True', 'False'))
21
+ BP = self.new_rv('BP', ('Low', 'Normal', 'High'))
22
+ History = self.new_rv('History', ('True', 'False'))
23
+ CO = self.new_rv('CO', ('Low', 'Normal', 'High'))
24
+ HR = self.new_rv('HR', ('Low', 'Normal', 'High'))
25
+ Catechol = self.new_rv('Catechol', ('Normal', 'High'))
26
+ ArtCO2 = self.new_rv('ArtCO2', ('Low', 'Normal', 'High'))
27
+ TPR = self.new_rv('TPR', ('Low', 'Normal', 'High'))
28
+ Anaphylaxis = self.new_rv('Anaphylaxis', ('True', 'False'))
29
+ SaO2 = self.new_rv('SaO2', ('Low', 'Normal', 'High'))
30
+ PVSat = self.new_rv('PVSat', ('Low', 'Normal', 'High'))
31
+ FiO2 = self.new_rv('FiO2', ('Low', 'Normal'))
32
+ VentAlv = self.new_rv('VentAlv', ('Zero', 'Low', 'Normal', 'High'))
33
+ VentLung = self.new_rv('VentLung', ('Zero', 'Low', 'Normal', 'High'))
34
+ VentTube = self.new_rv('VentTube', ('Zero', 'Low', 'Normal', 'High'))
35
+ Disconnect = self.new_rv('Disconnect', ('True', 'False'))
36
+ VentMach = self.new_rv('VentMach', ('Zero', 'Low', 'Normal', 'High'))
37
+ MinVolSet = self.new_rv('MinVolSet', ('Low', 'Normal', 'High'))
38
+ KinkedTube = self.new_rv('KinkedTube', ('True', 'False'))
39
+ Shunt = self.new_rv('Shunt', ('Normal', 'High'))
40
+ Intubation = self.new_rv('Intubation', ('Normal', 'Esophageal', 'OneSided'))
41
+ PulmEmbolus = self.new_rv('PulmEmbolus', ('True', 'False'))
42
+ InsuffAnesth = self.new_rv('InsuffAnesth', ('True', 'False'))
43
+ PCWP = self.new_rv('PCWP', ('Low', 'Normal', 'High'))
44
+ CVP = self.new_rv('CVP', ('Low', 'Normal', 'High'))
45
+ StrokeVolume = self.new_rv('StrokeVolume', ('Low', 'Normal', 'High'))
46
+ LVEDVolume = self.new_rv('LVEDVolume', ('Low', 'Normal', 'High'))
47
+ LVFailure = self.new_rv('LVFailure', ('True', 'False'))
48
+ Hypovolemia = self.new_rv('Hypovolemia', ('True', 'False'))
49
+
50
+ pgm_factor0 = self.new_factor(MinVol, VentLung, Intubation)
51
+ pgm_function_2759353723488 = pgm_factor0.set_cpt()
52
+ pgm_function_2759353723488.set_cpd((0, 0), (0.97, 0.01, 0.01, 0.01))
53
+ pgm_function_2759353723488.set_cpd((1, 0), (0.01, 0.97, 0.01, 0.01))
54
+ pgm_function_2759353723488.set_cpd((2, 0), (0.01, 0.01, 0.97, 0.01))
55
+ pgm_function_2759353723488.set_cpd((3, 0), (0.01, 0.01, 0.01, 0.97))
56
+ pgm_function_2759353723488.set_cpd((0, 1), (0.97, 0.01, 0.01, 0.01))
57
+ pgm_function_2759353723488.set_cpd((1, 1), (0.6, 0.38, 0.01, 0.01))
58
+ pgm_function_2759353723488.set_cpd((2, 1), (0.5, 0.48, 0.01, 0.01))
59
+ pgm_function_2759353723488.set_cpd((3, 1), (0.5, 0.48, 0.01, 0.01))
60
+ pgm_function_2759353723488.set_cpd((0, 2), (0.97, 0.01, 0.01, 0.01))
61
+ pgm_function_2759353723488.set_cpd((1, 2), (0.01, 0.97, 0.01, 0.01))
62
+ pgm_function_2759353723488.set_cpd((2, 2), (0.01, 0.01, 0.97, 0.01))
63
+ pgm_function_2759353723488.set_cpd((3, 2), (0.01, 0.01, 0.01, 0.97))
64
+ pgm_factor1 = self.new_factor(Press, KinkedTube, Intubation, VentTube)
65
+ pgm_function_2759353724528 = pgm_factor1.set_cpt()
66
+ pgm_function_2759353724528.set_cpd((0, 0, 0), (0.97, 0.01, 0.01, 0.01))
67
+ pgm_function_2759353724528.set_cpd((1, 0, 0), (0.97, 0.01, 0.01, 0.01))
68
+ pgm_function_2759353724528.set_cpd((0, 1, 0), (0.97, 0.01, 0.01, 0.01))
69
+ pgm_function_2759353724528.set_cpd((1, 1, 0), (0.97, 0.01, 0.01, 0.01))
70
+ pgm_function_2759353724528.set_cpd((0, 2, 0), (0.97, 0.01, 0.01, 0.01))
71
+ pgm_function_2759353724528.set_cpd((1, 2, 0), (0.97, 0.01, 0.01, 0.01))
72
+ pgm_function_2759353724528.set_cpd((0, 0, 1), (0.01, 0.49, 0.3, 0.2))
73
+ pgm_function_2759353724528.set_cpd((1, 0, 1), (0.01, 0.97, 0.01, 0.01))
74
+ pgm_function_2759353724528.set_cpd((0, 1, 1), (0.1, 0.84, 0.05, 0.01))
75
+ pgm_function_2759353724528.set_cpd((1, 1, 1), (0.4, 0.58, 0.01, 0.01))
76
+ pgm_function_2759353724528.set_cpd((0, 2, 1), (0.01, 0.29, 0.3, 0.4))
77
+ pgm_function_2759353724528.set_cpd((1, 2, 1), (0.01, 0.9, 0.08, 0.01))
78
+ pgm_function_2759353724528.set_cpd((0, 0, 2), (0.01, 0.01, 0.08, 0.9))
79
+ pgm_function_2759353724528.set_cpd((1, 0, 2), (0.01, 0.01, 0.97, 0.01))
80
+ pgm_function_2759353724528.set_cpd((0, 1, 2), (0.05, 0.25, 0.25, 0.45))
81
+ pgm_function_2759353724528.set_cpd((1, 1, 2), (0.2, 0.75, 0.04, 0.01))
82
+ pgm_function_2759353724528.set_cpd((0, 2, 2), (0.01, 0.01, 0.08, 0.9))
83
+ pgm_function_2759353724528.set_cpd((1, 2, 2), (0.01, 0.01, 0.38, 0.6))
84
+ pgm_function_2759353724528.set_cpd((0, 0, 3), (0.01, 0.01, 0.01, 0.97))
85
+ pgm_function_2759353724528.set_cpd((1, 0, 3), (0.01, 0.01, 0.01, 0.97))
86
+ pgm_function_2759353724528.set_cpd((0, 1, 3), (0.01, 0.15, 0.25, 0.59))
87
+ pgm_function_2759353724528.set_cpd((1, 1, 3), (0.2, 0.7, 0.09, 0.01))
88
+ pgm_function_2759353724528.set_cpd((0, 2, 3), (0.01, 0.01, 0.01, 0.97))
89
+ pgm_function_2759353724528.set_cpd((1, 2, 3), (0.01, 0.01, 0.01, 0.97))
90
+ pgm_factor2 = self.new_factor(PAP, PulmEmbolus)
91
+ pgm_function_2759353723904 = pgm_factor2.set_cpt()
92
+ pgm_function_2759353723904.set_cpd((0,), (0.01, 0.19, 0.8))
93
+ pgm_function_2759353723904.set_cpd((1,), (0.05, 0.9, 0.05))
94
+ pgm_factor3 = self.new_factor(ExpCO2, ArtCO2, VentLung)
95
+ pgm_function_2759353724112 = pgm_factor3.set_cpt()
96
+ pgm_function_2759353724112.set_cpd((0, 0), (0.97, 0.01, 0.01, 0.01))
97
+ pgm_function_2759353724112.set_cpd((1, 0), (0.97, 0.01, 0.01, 0.01))
98
+ pgm_function_2759353724112.set_cpd((2, 0), (0.97, 0.01, 0.01, 0.01))
99
+ pgm_function_2759353724112.set_cpd((0, 1), (0.01, 0.97, 0.01, 0.01))
100
+ pgm_function_2759353724112.set_cpd((1, 1), (0.01, 0.01, 0.97, 0.01))
101
+ pgm_function_2759353724112.set_cpd((2, 1), (0.01, 0.01, 0.01, 0.97))
102
+ pgm_function_2759353724112.set_cpd((0, 2), (0.01, 0.97, 0.01, 0.01))
103
+ pgm_function_2759353724112.set_cpd((1, 2), (0.01, 0.01, 0.97, 0.01))
104
+ pgm_function_2759353724112.set_cpd((2, 2), (0.01, 0.01, 0.01, 0.97))
105
+ pgm_function_2759353724112.set_cpd((0, 3), (0.01, 0.97, 0.01, 0.01))
106
+ pgm_function_2759353724112.set_cpd((1, 3), (0.01, 0.01, 0.97, 0.01))
107
+ pgm_function_2759353724112.set_cpd((2, 3), (0.01, 0.01, 0.01, 0.97))
108
+ pgm_factor4 = self.new_factor(HRBP, ErrLowOutput, HR)
109
+ pgm_function_2759353721200 = pgm_factor4.set_cpt()
110
+ pgm_function_2759353721200.set_cpd((0, 0), (0.98, 0.01, 0.01))
111
+ pgm_function_2759353721200.set_cpd((1, 0), (0.98, 0.01, 0.01))
112
+ pgm_function_2759353721200.set_cpd((0, 1), (0.4, 0.59, 0.01))
113
+ pgm_function_2759353721200.set_cpd((1, 1), (0.01, 0.98, 0.01))
114
+ pgm_function_2759353721200.set_cpd((0, 2), (0.3, 0.4, 0.3))
115
+ pgm_function_2759353721200.set_cpd((1, 2), (0.01, 0.01, 0.98))
116
+ pgm_factor5 = self.new_factor(ErrLowOutput)
117
+ pgm_function_2759353722448 = pgm_factor5.set_cpt()
118
+ pgm_function_2759353722448.set_cpd((), (0.05, 0.95))
119
+ pgm_factor6 = self.new_factor(HRSat, HR, ErrCauter)
120
+ pgm_function_2759353722656 = pgm_factor6.set_cpt()
121
+ pgm_function_2759353722656.set_cpd((0, 0), (0.33333333, 0.33333333, 0.33333333))
122
+ pgm_function_2759353722656.set_cpd((1, 0), (0.33333333, 0.33333333, 0.33333333))
123
+ pgm_function_2759353722656.set_cpd((2, 0), (0.33333333, 0.33333333, 0.33333333))
124
+ pgm_function_2759353722656.set_cpd((0, 1), (0.98, 0.01, 0.01))
125
+ pgm_function_2759353722656.set_cpd((1, 1), (0.01, 0.98, 0.01))
126
+ pgm_function_2759353722656.set_cpd((2, 1), (0.01, 0.01, 0.98))
127
+ pgm_factor7 = self.new_factor(HREKG, HR, ErrCauter)
128
+ pgm_function_2759353722032 = pgm_factor7.set_cpt()
129
+ pgm_function_2759353722032.set_cpd((0, 0), (0.33333333, 0.33333333, 0.33333333))
130
+ pgm_function_2759353722032.set_cpd((1, 0), (0.33333333, 0.33333333, 0.33333333))
131
+ pgm_function_2759353722032.set_cpd((2, 0), (0.33333333, 0.33333333, 0.33333333))
132
+ pgm_function_2759353722032.set_cpd((0, 1), (0.98, 0.01, 0.01))
133
+ pgm_function_2759353722032.set_cpd((1, 1), (0.01, 0.98, 0.01))
134
+ pgm_function_2759353722032.set_cpd((2, 1), (0.01, 0.01, 0.98))
135
+ pgm_factor8 = self.new_factor(ErrCauter)
136
+ pgm_function_2759353722864 = pgm_factor8.set_cpt()
137
+ pgm_function_2759353722864.set_cpd((), (0.1, 0.9))
138
+ pgm_factor9 = self.new_factor(BP, CO, TPR)
139
+ pgm_function_2759353721408 = pgm_factor9.set_cpt()
140
+ pgm_function_2759353721408.set_cpd((0, 0), (0.98, 0.01, 0.01))
141
+ pgm_function_2759353721408.set_cpd((1, 0), (0.98, 0.01, 0.01))
142
+ pgm_function_2759353721408.set_cpd((2, 0), (0.9, 0.09, 0.01))
143
+ pgm_function_2759353721408.set_cpd((0, 1), (0.98, 0.01, 0.01))
144
+ pgm_function_2759353721408.set_cpd((1, 1), (0.1, 0.85, 0.05))
145
+ pgm_function_2759353721408.set_cpd((2, 1), (0.05, 0.2, 0.75))
146
+ pgm_function_2759353721408.set_cpd((0, 2), (0.3, 0.6, 0.1))
147
+ pgm_function_2759353721408.set_cpd((1, 2), (0.05, 0.4, 0.55))
148
+ pgm_function_2759353721408.set_cpd((2, 2), (0.01, 0.09, 0.9))
149
+ pgm_factor10 = self.new_factor(History, LVFailure)
150
+ pgm_function_2759353720992 = pgm_factor10.set_cpt()
151
+ pgm_function_2759353720992.set_cpd((0,), (0.9, 0.1))
152
+ pgm_function_2759353720992.set_cpd((1,), (0.01, 0.99))
153
+ pgm_factor11 = self.new_factor(CO, HR, StrokeVolume)
154
+ pgm_function_2759353723280 = pgm_factor11.set_cpt()
155
+ pgm_function_2759353723280.set_cpd((0, 0), (0.98, 0.01, 0.01))
156
+ pgm_function_2759353723280.set_cpd((1, 0), (0.95, 0.04, 0.01))
157
+ pgm_function_2759353723280.set_cpd((2, 0), (0.8, 0.19, 0.01))
158
+ pgm_function_2759353723280.set_cpd((0, 1), (0.95, 0.04, 0.01))
159
+ pgm_function_2759353723280.set_cpd((1, 1), (0.04, 0.95, 0.01))
160
+ pgm_function_2759353723280.set_cpd((2, 1), (0.01, 0.04, 0.95))
161
+ pgm_function_2759353723280.set_cpd((0, 2), (0.3, 0.69, 0.01))
162
+ pgm_function_2759353723280.set_cpd((1, 2), (0.01, 0.3, 0.69))
163
+ pgm_function_2759353723280.set_cpd((2, 2), (0.01, 0.01, 0.98))
164
+ pgm_factor12 = self.new_factor(HR, Catechol)
165
+ pgm_function_2759353723072 = pgm_factor12.set_cpt()
166
+ pgm_function_2759353723072.set_cpd((0,), (0.1, 0.89, 0.01))
167
+ pgm_function_2759353723072.set_cpd((1,), (0.01, 0.09, 0.9))
168
+ pgm_factor13 = self.new_factor(Catechol, InsuffAnesth, SaO2, TPR, ArtCO2)
169
+ pgm_function_2759353724320 = pgm_factor13.set_cpt()
170
+ pgm_function_2759353724320.set_cpd((0, 0, 0, 0), (0.01, 0.99))
171
+ pgm_function_2759353724320.set_cpd((1, 0, 0, 0), (0.05, 0.95))
172
+ pgm_function_2759353724320.set_cpd((0, 1, 0, 0), (0.01, 0.99))
173
+ pgm_function_2759353724320.set_cpd((1, 1, 0, 0), (0.1, 0.9))
174
+ pgm_function_2759353724320.set_cpd((0, 2, 0, 0), (0.01, 0.99))
175
+ pgm_function_2759353724320.set_cpd((1, 2, 0, 0), (0.95, 0.05))
176
+ pgm_function_2759353724320.set_cpd((0, 0, 1, 0), (0.01, 0.99))
177
+ pgm_function_2759353724320.set_cpd((1, 0, 1, 0), (0.05, 0.95))
178
+ pgm_function_2759353724320.set_cpd((0, 1, 1, 0), (0.01, 0.99))
179
+ pgm_function_2759353724320.set_cpd((1, 1, 1, 0), (0.95, 0.05))
180
+ pgm_function_2759353724320.set_cpd((0, 2, 1, 0), (0.05, 0.95))
181
+ pgm_function_2759353724320.set_cpd((1, 2, 1, 0), (0.99, 0.01))
182
+ pgm_function_2759353724320.set_cpd((0, 0, 2, 0), (0.01, 0.99))
183
+ pgm_function_2759353724320.set_cpd((1, 0, 2, 0), (0.05, 0.95))
184
+ pgm_function_2759353724320.set_cpd((0, 1, 2, 0), (0.05, 0.95))
185
+ pgm_function_2759353724320.set_cpd((1, 1, 2, 0), (0.95, 0.05))
186
+ pgm_function_2759353724320.set_cpd((0, 2, 2, 0), (0.05, 0.95))
187
+ pgm_function_2759353724320.set_cpd((1, 2, 2, 0), (0.95, 0.05))
188
+ pgm_function_2759353724320.set_cpd((0, 0, 0, 1), (0.01, 0.99))
189
+ pgm_function_2759353724320.set_cpd((1, 0, 0, 1), (0.05, 0.95))
190
+ pgm_function_2759353724320.set_cpd((0, 1, 0, 1), (0.01, 0.99))
191
+ pgm_function_2759353724320.set_cpd((1, 1, 0, 1), (0.1, 0.9))
192
+ pgm_function_2759353724320.set_cpd((0, 2, 0, 1), (0.01, 0.99))
193
+ pgm_function_2759353724320.set_cpd((1, 2, 0, 1), (0.95, 0.05))
194
+ pgm_function_2759353724320.set_cpd((0, 0, 1, 1), (0.01, 0.99))
195
+ pgm_function_2759353724320.set_cpd((1, 0, 1, 1), (0.05, 0.95))
196
+ pgm_function_2759353724320.set_cpd((0, 1, 1, 1), (0.01, 0.99))
197
+ pgm_function_2759353724320.set_cpd((1, 1, 1, 1), (0.95, 0.05))
198
+ pgm_function_2759353724320.set_cpd((0, 2, 1, 1), (0.05, 0.95))
199
+ pgm_function_2759353724320.set_cpd((1, 2, 1, 1), (0.99, 0.01))
200
+ pgm_function_2759353724320.set_cpd((0, 0, 2, 1), (0.01, 0.99))
201
+ pgm_function_2759353724320.set_cpd((1, 0, 2, 1), (0.05, 0.95))
202
+ pgm_function_2759353724320.set_cpd((0, 1, 2, 1), (0.05, 0.95))
203
+ pgm_function_2759353724320.set_cpd((1, 1, 2, 1), (0.95, 0.05))
204
+ pgm_function_2759353724320.set_cpd((0, 2, 2, 1), (0.05, 0.95))
205
+ pgm_function_2759353724320.set_cpd((1, 2, 2, 1), (0.99, 0.01))
206
+ pgm_function_2759353724320.set_cpd((0, 0, 0, 2), (0.01, 0.99))
207
+ pgm_function_2759353724320.set_cpd((1, 0, 0, 2), (0.01, 0.99))
208
+ pgm_function_2759353724320.set_cpd((0, 1, 0, 2), (0.01, 0.99))
209
+ pgm_function_2759353724320.set_cpd((1, 1, 0, 2), (0.1, 0.9))
210
+ pgm_function_2759353724320.set_cpd((0, 2, 0, 2), (0.01, 0.99))
211
+ pgm_function_2759353724320.set_cpd((1, 2, 0, 2), (0.3, 0.7))
212
+ pgm_function_2759353724320.set_cpd((0, 0, 1, 2), (0.01, 0.99))
213
+ pgm_function_2759353724320.set_cpd((1, 0, 1, 2), (0.01, 0.99))
214
+ pgm_function_2759353724320.set_cpd((0, 1, 1, 2), (0.01, 0.99))
215
+ pgm_function_2759353724320.set_cpd((1, 1, 1, 2), (0.3, 0.7))
216
+ pgm_function_2759353724320.set_cpd((0, 2, 1, 2), (0.01, 0.99))
217
+ pgm_function_2759353724320.set_cpd((1, 2, 1, 2), (0.99, 0.01))
218
+ pgm_function_2759353724320.set_cpd((0, 0, 2, 2), (0.01, 0.99))
219
+ pgm_function_2759353724320.set_cpd((1, 0, 2, 2), (0.01, 0.99))
220
+ pgm_function_2759353724320.set_cpd((0, 1, 2, 2), (0.01, 0.99))
221
+ pgm_function_2759353724320.set_cpd((1, 1, 2, 2), (0.3, 0.7))
222
+ pgm_function_2759353724320.set_cpd((0, 2, 2, 2), (0.01, 0.99))
223
+ pgm_function_2759353724320.set_cpd((1, 2, 2, 2), (0.3, 0.7))
224
+ pgm_factor14 = self.new_factor(ArtCO2, VentAlv)
225
+ pgm_function_2759353720784 = pgm_factor14.set_cpt()
226
+ pgm_function_2759353720784.set_cpd((0,), (0.01, 0.01, 0.98))
227
+ pgm_function_2759353720784.set_cpd((1,), (0.01, 0.01, 0.98))
228
+ pgm_function_2759353720784.set_cpd((2,), (0.04, 0.92, 0.04))
229
+ pgm_function_2759353720784.set_cpd((3,), (0.9, 0.09, 0.01))
230
+ pgm_factor15 = self.new_factor(TPR, Anaphylaxis)
231
+ pgm_function_2759353721616 = pgm_factor15.set_cpt()
232
+ pgm_function_2759353721616.set_cpd((0,), (0.98, 0.01, 0.01))
233
+ pgm_function_2759353721616.set_cpd((1,), (0.3, 0.4, 0.3))
234
+ pgm_factor16 = self.new_factor(Anaphylaxis)
235
+ pgm_function_2759353721824 = pgm_factor16.set_cpt()
236
+ pgm_function_2759353721824.set_cpd((), (0.01, 0.99))
237
+ pgm_factor17 = self.new_factor(SaO2, Shunt, PVSat)
238
+ pgm_function_2759353722240 = pgm_factor17.set_cpt()
239
+ pgm_function_2759353722240.set_cpd((0, 0), (0.98, 0.01, 0.01))
240
+ pgm_function_2759353722240.set_cpd((1, 0), (0.98, 0.01, 0.01))
241
+ pgm_function_2759353722240.set_cpd((0, 1), (0.01, 0.98, 0.01))
242
+ pgm_function_2759353722240.set_cpd((1, 1), (0.98, 0.01, 0.01))
243
+ pgm_function_2759353722240.set_cpd((0, 2), (0.01, 0.01, 0.98))
244
+ pgm_function_2759353722240.set_cpd((1, 2), (0.69, 0.3, 0.01))
245
+ pgm_factor18 = self.new_factor(PVSat, VentAlv, FiO2)
246
+ pgm_function_2759355657712 = pgm_factor18.set_cpt()
247
+ pgm_function_2759355657712.set_cpd((0, 0), (0.98, 0.01, 0.01))
248
+ pgm_function_2759355657712.set_cpd((1, 0), (0.98, 0.01, 0.01))
249
+ pgm_function_2759355657712.set_cpd((2, 0), (0.95, 0.04, 0.01))
250
+ pgm_function_2759355657712.set_cpd((3, 0), (0.95, 0.04, 0.01))
251
+ pgm_function_2759355657712.set_cpd((0, 1), (0.98, 0.01, 0.01))
252
+ pgm_function_2759355657712.set_cpd((1, 1), (0.98, 0.01, 0.01))
253
+ pgm_function_2759355657712.set_cpd((2, 1), (0.01, 0.95, 0.04))
254
+ pgm_function_2759355657712.set_cpd((3, 1), (0.01, 0.01, 0.98))
255
+ pgm_factor19 = self.new_factor(FiO2)
256
+ pgm_function_2759355653760 = pgm_factor19.set_cpt()
257
+ pgm_function_2759355653760.set_cpd((), (0.01, 0.99))
258
+ pgm_factor20 = self.new_factor(VentAlv, Intubation, VentLung)
259
+ pgm_function_2759355654384 = pgm_factor20.set_cpt()
260
+ pgm_function_2759355654384.set_cpd((0, 0), (0.97, 0.01, 0.01, 0.01))
261
+ pgm_function_2759355654384.set_cpd((1, 0), (0.97, 0.01, 0.01, 0.01))
262
+ pgm_function_2759355654384.set_cpd((2, 0), (0.97, 0.01, 0.01, 0.01))
263
+ pgm_function_2759355654384.set_cpd((0, 1), (0.01, 0.97, 0.01, 0.01))
264
+ pgm_function_2759355654384.set_cpd((1, 1), (0.01, 0.97, 0.01, 0.01))
265
+ pgm_function_2759355654384.set_cpd((2, 1), (0.03, 0.95, 0.01, 0.01))
266
+ pgm_function_2759355654384.set_cpd((0, 2), (0.01, 0.01, 0.97, 0.01))
267
+ pgm_function_2759355654384.set_cpd((1, 2), (0.01, 0.01, 0.97, 0.01))
268
+ pgm_function_2759355654384.set_cpd((2, 2), (0.01, 0.94, 0.04, 0.01))
269
+ pgm_function_2759355654384.set_cpd((0, 3), (0.01, 0.01, 0.01, 0.97))
270
+ pgm_function_2759355654384.set_cpd((1, 3), (0.01, 0.01, 0.01, 0.97))
271
+ pgm_function_2759355654384.set_cpd((2, 3), (0.01, 0.88, 0.1, 0.01))
272
+ pgm_factor21 = self.new_factor(VentLung, KinkedTube, VentTube, Intubation)
273
+ pgm_function_2759355650848 = pgm_factor21.set_cpt()
274
+ pgm_function_2759355650848.set_cpd((0, 0, 0), (0.97, 0.01, 0.01, 0.01))
275
+ pgm_function_2759355650848.set_cpd((1, 0, 0), (0.97, 0.01, 0.01, 0.01))
276
+ pgm_function_2759355650848.set_cpd((0, 1, 0), (0.95, 0.03, 0.01, 0.01))
277
+ pgm_function_2759355650848.set_cpd((1, 1, 0), (0.01, 0.97, 0.01, 0.01))
278
+ pgm_function_2759355650848.set_cpd((0, 2, 0), (0.4, 0.58, 0.01, 0.01))
279
+ pgm_function_2759355650848.set_cpd((1, 2, 0), (0.01, 0.01, 0.97, 0.01))
280
+ pgm_function_2759355650848.set_cpd((0, 3, 0), (0.3, 0.68, 0.01, 0.01))
281
+ pgm_function_2759355650848.set_cpd((1, 3, 0), (0.01, 0.01, 0.01, 0.97))
282
+ pgm_function_2759355650848.set_cpd((0, 0, 1), (0.97, 0.01, 0.01, 0.01))
283
+ pgm_function_2759355650848.set_cpd((1, 0, 1), (0.97, 0.01, 0.01, 0.01))
284
+ pgm_function_2759355650848.set_cpd((0, 1, 1), (0.97, 0.01, 0.01, 0.01))
285
+ pgm_function_2759355650848.set_cpd((1, 1, 1), (0.97, 0.01, 0.01, 0.01))
286
+ pgm_function_2759355650848.set_cpd((0, 2, 1), (0.97, 0.01, 0.01, 0.01))
287
+ pgm_function_2759355650848.set_cpd((1, 2, 1), (0.97, 0.01, 0.01, 0.01))
288
+ pgm_function_2759355650848.set_cpd((0, 3, 1), (0.97, 0.01, 0.01, 0.01))
289
+ pgm_function_2759355650848.set_cpd((1, 3, 1), (0.97, 0.01, 0.01, 0.01))
290
+ pgm_function_2759355650848.set_cpd((0, 0, 2), (0.97, 0.01, 0.01, 0.01))
291
+ pgm_function_2759355650848.set_cpd((1, 0, 2), (0.97, 0.01, 0.01, 0.01))
292
+ pgm_function_2759355650848.set_cpd((0, 1, 2), (0.95, 0.03, 0.01, 0.01))
293
+ pgm_function_2759355650848.set_cpd((1, 1, 2), (0.01, 0.97, 0.01, 0.01))
294
+ pgm_function_2759355650848.set_cpd((0, 2, 2), (0.5, 0.48, 0.01, 0.01))
295
+ pgm_function_2759355650848.set_cpd((1, 2, 2), (0.01, 0.01, 0.97, 0.01))
296
+ pgm_function_2759355650848.set_cpd((0, 3, 2), (0.3, 0.68, 0.01, 0.01))
297
+ pgm_function_2759355650848.set_cpd((1, 3, 2), (0.01, 0.01, 0.01, 0.97))
298
+ pgm_factor22 = self.new_factor(VentTube, VentMach, Disconnect)
299
+ pgm_function_2759355653968 = pgm_factor22.set_cpt()
300
+ pgm_function_2759355653968.set_cpd((0, 0), (0.97, 0.01, 0.01, 0.01))
301
+ pgm_function_2759355653968.set_cpd((1, 0), (0.97, 0.01, 0.01, 0.01))
302
+ pgm_function_2759355653968.set_cpd((2, 0), (0.97, 0.01, 0.01, 0.01))
303
+ pgm_function_2759355653968.set_cpd((3, 0), (0.97, 0.01, 0.01, 0.01))
304
+ pgm_function_2759355653968.set_cpd((0, 1), (0.97, 0.01, 0.01, 0.01))
305
+ pgm_function_2759355653968.set_cpd((1, 1), (0.01, 0.97, 0.01, 0.01))
306
+ pgm_function_2759355653968.set_cpd((2, 1), (0.01, 0.01, 0.97, 0.01))
307
+ pgm_function_2759355653968.set_cpd((3, 1), (0.01, 0.01, 0.01, 0.97))
308
+ pgm_factor23 = self.new_factor(Disconnect)
309
+ pgm_function_2759355654592 = pgm_factor23.set_cpt()
310
+ pgm_function_2759355654592.set_cpd((), (0.05, 0.95))
311
+ pgm_factor24 = self.new_factor(VentMach, MinVolSet)
312
+ pgm_function_2759355652720 = pgm_factor24.set_cpt()
313
+ pgm_function_2759355652720.set_cpd((0,), (0.01, 0.97, 0.01, 0.01))
314
+ pgm_function_2759355652720.set_cpd((1,), (0.01, 0.01, 0.97, 0.01))
315
+ pgm_function_2759355652720.set_cpd((2,), (0.01, 0.01, 0.01, 0.97))
316
+ pgm_factor25 = self.new_factor(MinVolSet)
317
+ pgm_function_2759355654800 = pgm_factor25.set_cpt()
318
+ pgm_function_2759355654800.set_cpd((), (0.01, 0.98, 0.01))
319
+ pgm_factor26 = self.new_factor(KinkedTube)
320
+ pgm_function_2759355651056 = pgm_factor26.set_cpt()
321
+ pgm_function_2759355651056.set_cpd((), (0.04, 0.96))
322
+ pgm_factor27 = self.new_factor(Shunt, PulmEmbolus, Intubation)
323
+ pgm_function_2759355656464 = pgm_factor27.set_cpt()
324
+ pgm_function_2759355656464.set_cpd((0, 0), (0.1, 0.9))
325
+ pgm_function_2759355656464.set_cpd((1, 0), (0.95, 0.05))
326
+ pgm_function_2759355656464.set_cpd((0, 1), (0.1, 0.9))
327
+ pgm_function_2759355656464.set_cpd((1, 1), (0.95, 0.05))
328
+ pgm_function_2759355656464.set_cpd((0, 2), (0.01, 0.99))
329
+ pgm_function_2759355656464.set_cpd((1, 2), (0.05, 0.95))
330
+ pgm_factor28 = self.new_factor(Intubation)
331
+ pgm_function_2759355657920 = pgm_factor28.set_cpt()
332
+ pgm_function_2759355657920.set_cpd((), (0.92, 0.03, 0.05))
333
+ pgm_factor29 = self.new_factor(PulmEmbolus)
334
+ pgm_function_2759355652304 = pgm_factor29.set_cpt()
335
+ pgm_function_2759355652304.set_cpd((), (0.01, 0.99))
336
+ pgm_factor30 = self.new_factor(InsuffAnesth)
337
+ pgm_function_2759355650224 = pgm_factor30.set_cpt()
338
+ pgm_function_2759355650224.set_cpd((), (0.2, 0.8))
339
+ pgm_factor31 = self.new_factor(PCWP, LVEDVolume)
340
+ pgm_function_2759355658128 = pgm_factor31.set_cpt()
341
+ pgm_function_2759355658128.set_cpd((0,), (0.95, 0.04, 0.01))
342
+ pgm_function_2759355658128.set_cpd((1,), (0.04, 0.95, 0.01))
343
+ pgm_function_2759355658128.set_cpd((2,), (0.01, 0.04, 0.95))
344
+ pgm_factor32 = self.new_factor(CVP, LVEDVolume)
345
+ pgm_function_2759355656256 = pgm_factor32.set_cpt()
346
+ pgm_function_2759355656256.set_cpd((0,), (0.95, 0.04, 0.01))
347
+ pgm_function_2759355656256.set_cpd((1,), (0.04, 0.95, 0.01))
348
+ pgm_function_2759355656256.set_cpd((2,), (0.01, 0.29, 0.7))
349
+ pgm_factor33 = self.new_factor(StrokeVolume, LVFailure, Hypovolemia)
350
+ pgm_function_2759355650432 = pgm_factor33.set_cpt()
351
+ pgm_function_2759355650432.set_cpd((0, 0), (0.98, 0.01, 0.01))
352
+ pgm_function_2759355650432.set_cpd((1, 0), (0.95, 0.04, 0.01))
353
+ pgm_function_2759355650432.set_cpd((0, 1), (0.5, 0.49, 0.01))
354
+ pgm_function_2759355650432.set_cpd((1, 1), (0.05, 0.9, 0.05))
355
+ pgm_factor34 = self.new_factor(LVEDVolume, Hypovolemia, LVFailure)
356
+ pgm_function_2759355652512 = pgm_factor34.set_cpt()
357
+ pgm_function_2759355652512.set_cpd((0, 0), (0.95, 0.04, 0.01))
358
+ pgm_function_2759355652512.set_cpd((1, 0), (0.01, 0.09, 0.9))
359
+ pgm_function_2759355652512.set_cpd((0, 1), (0.98, 0.01, 0.01))
360
+ pgm_function_2759355652512.set_cpd((1, 1), (0.05, 0.9, 0.05))
361
+ pgm_factor35 = self.new_factor(LVFailure)
362
+ pgm_function_2759355655216 = pgm_factor35.set_cpt()
363
+ pgm_function_2759355655216.set_cpd((), (0.05, 0.95))
364
+ pgm_factor36 = self.new_factor(Hypovolemia)
365
+ pgm_function_2759355656672 = pgm_factor36.set_cpt()
366
+ pgm_function_2759355656672.set_cpd((), (0.2, 0.8))
ck/example/asia.py ADDED
@@ -0,0 +1,28 @@
1
+ from ck.pgm import PGM
2
+
3
+
4
+ class Asia(PGM):
5
+ """
6
+ This PGM is the well known, pedagogical 'Asia' Bayesian network.
7
+ """
8
+
9
+ def __init__(self):
10
+ super().__init__(self.__class__.__name__)
11
+
12
+ asia = self.new_rv('asia', ('yes', 'no'))
13
+ tub = self.new_rv('tub', ('yes', 'no'))
14
+ smoke = self.new_rv('smoke', ('yes', 'no'))
15
+ lung = self.new_rv('lung', ('yes', 'no'))
16
+ bronc = self.new_rv('bronc', ('yes', 'no'))
17
+ either = self.new_rv('either', ('yes', 'no'))
18
+ xray = self.new_rv('xray', ('yes', 'no'))
19
+ dysp = self.new_rv('dysp', ('yes', 'no'))
20
+
21
+ self.new_factor(asia).set_dense().set_flat(0.01, 0.99)
22
+ self.new_factor(tub, asia).set_dense().set_flat(0.05, 0.01, 0.95, 0.99)
23
+ self.new_factor(smoke).set_dense().set_flat(0.5, 0.5)
24
+ self.new_factor(lung, smoke).set_dense().set_flat(0.1, 0.01, 0.9, 0.99)
25
+ self.new_factor(bronc, smoke).set_dense().set_flat(0.6, 0.3, 0.4, 0.7)
26
+ self.new_factor(either, lung, tub).set_dense().set_flat(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)
27
+ self.new_factor(xray, either).set_dense().set_flat(0.98, 0.05, 0.02, 0.95)
28
+ self.new_factor(dysp, bronc, either).set_dense().set_flat(0.9, 0.8, 0.7, 0.1, 0.1, 0.2, 0.3, 0.9)
@@ -0,0 +1,32 @@
1
+ import random as _random
2
+
3
+ from ck.pgm import PGM
4
+ from ck.utils.iter_extras import pairs as _pairs
5
+
6
+
7
+ class BinaryClique(PGM):
8
+ """
9
+ This PGM is a factor graph with binary factors and a fully connected set of variables
10
+ """
11
+
12
+ def __init__(
13
+ self,
14
+ vars_per_clique: int = 5,
15
+ states_per_var: int = 2,
16
+ include_unaries: bool = False,
17
+ random_seed: int = 123456,
18
+ ):
19
+ params = (vars_per_clique, states_per_var, include_unaries)
20
+ super().__init__(f'{self.__class__.__name__}({",".join(str(param) for param in params)})')
21
+
22
+ random_stream = _random.Random(random_seed).random
23
+
24
+ rvs = [self.new_rv(f'x{i}', states_per_var) for i in range(vars_per_clique)]
25
+
26
+ for x_i, x_j in _pairs(rvs):
27
+ self.new_factor(x_i, x_j).set_dense().set_stream(random_stream)
28
+
29
+ if include_unaries:
30
+ if include_unaries:
31
+ for rv in rvs:
32
+ self.new_factor(rv).set_dense().set_stream(random_stream)
ck/example/bow_tie.py ADDED
@@ -0,0 +1,33 @@
1
+ import random as _random
2
+
3
+ from ck.pgm import PGM
4
+
5
+
6
+ class BowTie(PGM):
7
+ """
8
+ This PGM is the 'BowTie' factor graph.
9
+
10
+ A BowTie is a factor graph with five random variables (x1, ..., x5).
11
+ One factor connects: x1, x2, x3.
12
+ Another factor connects: x1, x4, x5.
13
+ """
14
+
15
+ def __init__(
16
+ self,
17
+ states_per_var: int = 2,
18
+ random_seed: int = 123456,
19
+ ):
20
+ params = (states_per_var,)
21
+ super().__init__(f'{self.__class__.__name__}({",".join(str(param) for param in params)})')
22
+
23
+ random_stream = _random.Random(random_seed).random
24
+ rand_iter = iter(random_stream, None)
25
+
26
+ x1 = self.new_rv('x1', states_per_var)
27
+ x2 = self.new_rv('x2', states_per_var)
28
+ x3 = self.new_rv('x3', states_per_var)
29
+ x4 = self.new_rv('x4', states_per_var)
30
+ x5 = self.new_rv('x5', states_per_var)
31
+
32
+ self.new_factor(x1, x2, x3).set_dense().set_iter(rand_iter)
33
+ self.new_factor(x1, x4, x5).set_dense().set_iter(rand_iter)
ck/example/cancer.py ADDED
@@ -0,0 +1,37 @@
1
+ from ck.pgm import PGM
2
+
3
+
4
+ class Cancer(PGM):
5
+ """
6
+ This PGM is the well known, pedagogical 'Cancer' Bayesian network.
7
+ """
8
+
9
+ def __init__(self):
10
+ super().__init__(self.__class__.__name__)
11
+
12
+ pollution = self.new_rv('pollution', ('low', 'high'))
13
+ smoker = self.new_rv('smoker', ('True', 'False'))
14
+ cancer = self.new_rv('cancer', ('True', 'False'))
15
+ xray = self.new_rv('xray', ('positive', 'negative'))
16
+ dyspnoea = self.new_rv('dyspnoea', ('True', 'False'))
17
+
18
+ pgm_factor0 = self.new_factor(pollution)
19
+ pgm_function_2511325233376 = pgm_factor0.set_cpt()
20
+ pgm_function_2511325233376.set_cpd((), (0.9, 0.1))
21
+ pgm_factor1 = self.new_factor(smoker)
22
+ pgm_function_2511322114176 = pgm_factor1.set_cpt()
23
+ pgm_function_2511322114176.set_cpd((), (0.3, 0.7))
24
+ pgm_factor2 = self.new_factor(cancer, pollution, smoker)
25
+ pgm_function_2511324995136 = pgm_factor2.set_cpt()
26
+ pgm_function_2511324995136.set_cpd((0, 0), (0.03, 0.97))
27
+ pgm_function_2511324995136.set_cpd((1, 0), (0.05, 0.95))
28
+ pgm_function_2511324995136.set_cpd((0, 1), (0.001, 0.999))
29
+ pgm_function_2511324995136.set_cpd((1, 1), (0.02, 0.98))
30
+ pgm_factor3 = self.new_factor(xray, cancer)
31
+ pgm_function_2511331552432 = pgm_factor3.set_cpt()
32
+ pgm_function_2511331552432.set_cpd((0,), (0.9, 0.1))
33
+ pgm_function_2511331552432.set_cpd((1,), (0.2, 0.8))
34
+ pgm_factor4 = self.new_factor(dyspnoea, cancer)
35
+ pgm_function_2511325139344 = pgm_factor4.set_cpt()
36
+ pgm_function_2511325139344.set_cpd((0,), (0.65, 0.35))
37
+ pgm_function_2511325139344.set_cpd((1,), (0.3, 0.7))
ck/example/chain.py ADDED
@@ -0,0 +1,38 @@
1
+ import math
2
+ import random as _random
3
+
4
+ from ck.pgm import PGM
5
+
6
+
7
+ class Chain(PGM):
8
+ """
9
+ This PGM is the 'Chain' factor graph.
10
+
11
+ The Chain factor graph consists of a chain of random variables, x0, x1, x2, ...
12
+ where adjacent random variables in the chain are connected by a binary factor.
13
+ If include_unaries then, also includes one unary factor per random variable.
14
+ """
15
+
16
+ def __init__(
17
+ self,
18
+ vars_per_chain: int = 240,
19
+ states_per_var: int = 35,
20
+ include_unaries: bool = True,
21
+ random_seed: int = 123456,
22
+ ):
23
+ params = (vars_per_chain, states_per_var, include_unaries)
24
+ super().__init__(f'{self.__class__.__name__}({",".join(str(param) for param in params)})')
25
+
26
+ scale = 1 + math.log2(vars_per_chain)
27
+ random_stream = _random.Random(random_seed).random
28
+ binary_iter = map(lambda x: x / scale, iter(random_stream, None))
29
+ unary_iter = iter(random_stream, None)
30
+
31
+ rvs = [self.new_rv(f'x{i}', states_per_var) for i in range(vars_per_chain)]
32
+
33
+ for i in range(1, len(rvs)):
34
+ self.new_factor(rvs[i], rvs[i - 1]).set_dense().set_iter(binary_iter)
35
+
36
+ if include_unaries:
37
+ for rv in rvs:
38
+ self.new_factor(rv).set_dense().set_iter(unary_iter)