compiled-knowledge 4.1.0a1__tar.gz → 4.1.0a3__tar.gz
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.
- {compiled_knowledge-4.1.0a1/src/compiled_knowledge.egg-info → compiled_knowledge-4.1.0a3}/PKG-INFO +2 -1
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/pyproject.toml +2 -1
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/cross_table.py +143 -79
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/dataset.py +143 -38
- compiled_knowledge-4.1.0a3/src/ck/dataset/dataset_builder.py +519 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/dataset_from_crosstable.py +21 -2
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/dataset_from_csv.py +5 -1
- compiled_knowledge-4.1.0a3/src/ck/learning/coalesce_cross_tables.py +395 -0
- compiled_knowledge-4.1.0a3/src/ck/learning/model_from_cross_tables.py +242 -0
- compiled_knowledge-4.1.0a3/src/ck/learning/parameters.py +117 -0
- compiled_knowledge-4.1.0a3/src/ck/learning/train_generative_bn.py +198 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm.py +10 -8
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/marginals_program.py +5 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/wmc_program.py +5 -0
- compiled_knowledge-4.1.0a3/src/ck/probability/divergence.py +226 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/probability/probability_space.py +43 -19
- compiled_knowledge-4.1.0a3/src/ck_demos/dataset/demo_dataset_builder.py +37 -0
- compiled_knowledge-4.1.0a3/src/ck_demos/dataset/demo_dataset_from_sampler.py +18 -0
- compiled_knowledge-4.1.0a3/src/ck_demos/learning/demo_bayesian_network_from_cross_tables.py +71 -0
- compiled_knowledge-4.1.0a3/src/ck_demos/learning/demo_simple_learning.py +55 -0
- compiled_knowledge-4.1.0a3/src/ck_demos/sampling/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/sampling/demo_wmc_direct_sampler.py +2 -2
- compiled_knowledge-4.1.0a3/src/ck_demos/utils/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3/src/compiled_knowledge.egg-info}/PKG-INFO +2 -1
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/compiled_knowledge.egg-info/SOURCES.txt +13 -2
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/compiled_knowledge.egg-info/requires.txt +1 -0
- compiled_knowledge-4.1.0a1/src/ck/learning/train_generative.py +0 -149
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/LICENSE.txt +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/MANIFEST.in +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/README.md +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/setup.cfg +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/setup.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/_circuit_cy.c +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/_circuit_cy.pxd +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/_circuit_cy.pyx +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/_circuit_py.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit/tmp_const.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/circuit_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/cython_vm_compiler/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/cython_vm_compiler/_compiler.c +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/cython_vm_compiler/_compiler.pyx +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/cython_vm_compiler/cython_vm_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/interpret_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/llvm_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/llvm_vm_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/named_circuit_compilers.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/circuit_analyser/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.c +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.pyx +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_py.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/input_vars.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/circuit_compiler/support/llvm_ir_function.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/dataset_compute.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/dataset/sampled_dataset.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/alarm.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/asia.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/binary_clique.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/bow_tie.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/cancer.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/chain.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/child.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/clique.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/cnf_pgm.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/diamond_square.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/earthquake.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/empty.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/hailfinder.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/hepar2.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/insurance.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/loop.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/mildew.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/munin.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/pathfinder.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/rain.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/rectangle.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/run.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/sachs.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/sprinkler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/star.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/stress.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/student.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/survey.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/triangle_square.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/example/truss.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/parse_ace_lmap.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/parse_ace_nnf.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/parse_net.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/parser_utils.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/pgm_pickle.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/pgm_python.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/render_bugs.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/render_net.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/in_out/render_pomegranate.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/learning/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/mpe_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/pgm_circuit.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/program_with_slotmap.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/slot_map.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/support/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/support/compile_circuit.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_circuit/target_marginals_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/ace/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/ace/ace.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/factor_elimination.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/named_pgm_compilers.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/pgm_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/recursive_conditioning.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/circuit_table/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/circuit_table/_circuit_table_cy.c +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/circuit_table/_circuit_table_cy.pyx +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/circuit_table/_circuit_table_py.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/clusters.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/factor_tables.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/join_tree.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/support/named_compiler_maker.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/pgm_compiler/variable_elimination.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/probability/__init__.py +0 -0
- /compiled_knowledge-4.1.0a1/src/ck/dataset/cross_table_probabilities.py → /compiled_knowledge-4.1.0a3/src/ck/probability/cross_table_probability_space.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/probability/empirical_probability_space.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/probability/pgm_probability_space.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/program/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/program/program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/program/program_buffer.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/program/raw_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/forward_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/marginals_direct_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/sampler_support.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/uniform_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/wmc_direct_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/wmc_gibbs_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/wmc_metropolis_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/sampling/wmc_rejection_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/iter_extras.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/local_config.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/map_list.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/map_set.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/np_extras.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/random_extras.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck/utils/tmp_dir.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/ace/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/ace/copy_ace_to_ck.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/ace/demo_ace.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/ace/simple_ace_demo.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/all_demos.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit/demo_circuit_dump.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit/demo_derivatives.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit_compiler/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit_compiler/compare_circuit_compilers.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/circuit_compiler/show_llvm_program.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/getting_started → compiled_knowledge-4.1.0a3/src/ck_demos/dataset}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/pgm → compiled_knowledge-4.1.0a3/src/ck_demos/getting_started}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/getting_started/simple_demo.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/pgm_compiler → compiled_knowledge-4.1.0a3/src/ck_demos/learning}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/pgm_inference → compiled_knowledge-4.1.0a3/src/ck_demos/pgm}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm/demo_pgm_dump.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm/demo_pgm_dump_stress.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm/demo_pgm_string_rendering.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm/show_examples.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/programs → compiled_knowledge-4.1.0a3/src/ck_demos/pgm_compiler}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/compare_pgm_compilers.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_compiler_dump.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_factor_elimination.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_join_tree.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_marginals_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_mpe_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_pgm_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_recursive_conditioning.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_variable_elimination.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/demo_wmc_program.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_compiler/time_fe_compiler.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/sampling → compiled_knowledge-4.1.0a3/src/ck_demos/pgm_inference}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_inference/demo_inferencing_basic.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_inference/demo_inferencing_mpe_cancer.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_inference/demo_inferencing_wmc_and_mpe_sprinkler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/pgm_inference/demo_inferencing_wmc_student.py +0 -0
- {compiled_knowledge-4.1.0a1/src/ck_demos/utils → compiled_knowledge-4.1.0a3/src/ck_demos/programs}/__init__.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_program_buffer.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_program_multi.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_program_none.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_program_single.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_raw_program_dump.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_raw_program_interpreted.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/programs/demo_raw_program_llvm.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/sampling/check_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/sampling/demo_marginal_direct_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/sampling/demo_uniform_sampler.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/utils/compare.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/utils/convert_network.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/utils/sample_model.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/ck_demos/utils/stop_watch.py +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/compiled_knowledge.egg-info/dependency_links.txt +0 -0
- {compiled_knowledge-4.1.0a1 → compiled_knowledge-4.1.0a3}/src/compiled_knowledge.egg-info/top_level.txt +0 -0
{compiled_knowledge-4.1.0a1/src/compiled_knowledge.egg-info → compiled_knowledge-4.1.0a3}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compiled-knowledge
|
|
3
|
-
Version: 4.1.
|
|
3
|
+
Version: 4.1.0a3
|
|
4
4
|
Summary: A Python package for compiling and querying discrete probabilistic graphical models.
|
|
5
5
|
Author-email: Barry Drake <barry@compiledknowledge.org>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
|
|
|
13
13
|
License-File: LICENSE.txt
|
|
14
14
|
Requires-Dist: llvmlite
|
|
15
15
|
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: scipy
|
|
16
17
|
Dynamic: license-file
|
|
17
18
|
|
|
18
19
|
Compiled Knowledge
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "compiled-knowledge"
|
|
3
|
-
version = "4.1.
|
|
3
|
+
version = "4.1.0a3"
|
|
4
4
|
description = "A Python package for compiling and querying discrete probabilistic graphical models."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -11,6 +11,7 @@ authors = [
|
|
|
11
11
|
dependencies = [
|
|
12
12
|
"llvmlite",
|
|
13
13
|
"numpy",
|
|
14
|
+
"scipy",
|
|
14
15
|
]
|
|
15
16
|
requires-python = ">= 3.12"
|
|
16
17
|
classifiers = [
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
from
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import List, Tuple, Sequence, Iterator, Iterable, Optional, MutableMapping, Dict, assert_never
|
|
2
4
|
|
|
3
5
|
from ck.dataset import SoftDataset, HardDataset
|
|
4
6
|
from ck.pgm import RandomVariable, rv_instances, Instance
|
|
5
|
-
from ck.utils.np_extras import NDArray
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class CrossTable(MutableMapping[Instance, float]):
|
|
@@ -19,12 +20,14 @@ class CrossTable(MutableMapping[Instance, float]):
|
|
|
19
20
|
and `0 < ct[instance]`.
|
|
20
21
|
|
|
21
22
|
Zero weighted instances are not explicitly represented in a cross-table.
|
|
23
|
+
Given a cross-table `ct` then the following is always true.
|
|
24
|
+
`x in ct.keys()` is true if and only if `ct[x] != 0`.
|
|
22
25
|
"""
|
|
23
26
|
|
|
24
27
|
def __init__(
|
|
25
28
|
self,
|
|
26
29
|
rvs: Sequence[RandomVariable],
|
|
27
|
-
dirichlet_prior: float = 0,
|
|
30
|
+
dirichlet_prior: float | CrossTable = 0,
|
|
28
31
|
update: Iterable[Tuple[Instance, float]] = (),
|
|
29
32
|
):
|
|
30
33
|
"""
|
|
@@ -38,24 +41,46 @@ class CrossTable(MutableMapping[Instance, float]):
|
|
|
38
41
|
Args:
|
|
39
42
|
rvs: the random variables that this cross-table records weights for. Instances
|
|
40
43
|
in this cross-table are tuples of state indexes, co-indexed with `rvs`.
|
|
41
|
-
dirichlet_prior: a
|
|
44
|
+
dirichlet_prior: provides a prior for `rvs`. This can be represented either:
|
|
45
|
+
(a) as a uniform prior, represented as a float value,
|
|
46
|
+
(b) as an arbitrary prior, represented as a cross-table.
|
|
47
|
+
If a cross-table is provided as a prior, then it must have the same random variables as `rvs`.
|
|
48
|
+
The default value for `dirichlet_prior` is 0.
|
|
42
49
|
update: an optional iterable of (instance, weight) tuples to add to
|
|
43
50
|
the cross-table at construction time.
|
|
44
51
|
"""
|
|
45
52
|
self._rvs: Tuple[RandomVariable, ...] = tuple(rvs)
|
|
46
53
|
self._dict: Dict[Instance, float]
|
|
47
54
|
|
|
48
|
-
if dirichlet_prior
|
|
49
|
-
|
|
55
|
+
if isinstance(dirichlet_prior, CrossTable):
|
|
56
|
+
# rv_map[i] is where rvs[i] appears in the dirichlet_prior cross-table
|
|
57
|
+
# It will be used to map instances of the prior to instances of self.
|
|
58
|
+
rv_map: List[int] = [
|
|
59
|
+
dirichlet_prior.rvs.index(rv)
|
|
60
|
+
for rv in rvs
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
# Copy items from the prior to self, mapping the instances as needed
|
|
50
64
|
self._dict = {
|
|
51
|
-
|
|
52
|
-
for
|
|
65
|
+
tuple(prior_instance[select] for select in rv_map): weight
|
|
66
|
+
for prior_instance, weight in dirichlet_prior.items()
|
|
53
67
|
}
|
|
68
|
+
|
|
69
|
+
elif isinstance(dirichlet_prior, (float, int)):
|
|
70
|
+
if dirichlet_prior != 0:
|
|
71
|
+
# Initialise self with every possible combination of rvs states.
|
|
72
|
+
instance: Instance
|
|
73
|
+
self._dict = {
|
|
74
|
+
instance: dirichlet_prior
|
|
75
|
+
for instance in rv_instances(*self._rvs)
|
|
76
|
+
}
|
|
77
|
+
else:
|
|
78
|
+
self._dict = {}
|
|
54
79
|
else:
|
|
55
|
-
|
|
80
|
+
assert_never('not reached')
|
|
56
81
|
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
# Apply any provided updates
|
|
83
|
+
self.add_all(update)
|
|
59
84
|
|
|
60
85
|
def __eq__(self, other) -> bool:
|
|
61
86
|
"""
|
|
@@ -66,7 +91,7 @@ class CrossTable(MutableMapping[Instance, float]):
|
|
|
66
91
|
|
|
67
92
|
def __setitem__(self, key: Instance, value) -> None:
|
|
68
93
|
if value == 0:
|
|
69
|
-
self._dict.pop(key,
|
|
94
|
+
self._dict.pop(key, None)
|
|
70
95
|
else:
|
|
71
96
|
self._dict[key] = value
|
|
72
97
|
|
|
@@ -120,18 +145,87 @@ class CrossTable(MutableMapping[Instance, float]):
|
|
|
120
145
|
"""
|
|
121
146
|
self[instance] = self._dict.get(instance, 0) + weight
|
|
122
147
|
|
|
148
|
+
def add_all(self, to_add: Iterable[Tuple[Instance, float]]) -> None:
|
|
149
|
+
"""
|
|
150
|
+
Add the given weighted instances to the cross-table.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
to_add: an iterable of (instance, weight) tuples to add to the cross-table.
|
|
154
|
+
"""
|
|
155
|
+
for instance, weight in to_add:
|
|
156
|
+
self.add(instance, weight)
|
|
157
|
+
|
|
158
|
+
def mul(self, multiplier: float) -> None:
|
|
159
|
+
"""
|
|
160
|
+
Multiply all weights by the given multiplier.
|
|
161
|
+
"""
|
|
162
|
+
if multiplier == 0:
|
|
163
|
+
self._dict.clear()
|
|
164
|
+
elif multiplier == 1:
|
|
165
|
+
pass
|
|
166
|
+
else:
|
|
167
|
+
for instance in self._dict.keys():
|
|
168
|
+
self._dict[instance] *= multiplier
|
|
169
|
+
|
|
123
170
|
def total_weight(self) -> float:
|
|
124
171
|
"""
|
|
125
172
|
Calculate the total weight of this cross-table.
|
|
126
173
|
"""
|
|
127
174
|
return sum(self.values())
|
|
128
175
|
|
|
176
|
+
def project(self, rvs: Sequence[RandomVariable]) -> CrossTable:
|
|
177
|
+
"""
|
|
178
|
+
Project this cross-table onto the given set of random variables.
|
|
179
|
+
|
|
180
|
+
If successful, this method will always return a new CrossTable object.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
a CrossTable with the given sequence of random variables.
|
|
184
|
+
|
|
185
|
+
Assumes:
|
|
186
|
+
`rvs` is a subset of the cross-table's random variables.
|
|
187
|
+
"""
|
|
188
|
+
# Mapping rv_map[i] is the index into `self.rvs` for `rvs[i]`.
|
|
189
|
+
rv_map: List[int] = [self.rvs.index(rv) for rv in rvs]
|
|
190
|
+
|
|
191
|
+
return CrossTable(
|
|
192
|
+
rvs=rvs,
|
|
193
|
+
update=(
|
|
194
|
+
(tuple(instance[i] for i in rv_map), weight)
|
|
195
|
+
for instance, weight in self._dict.items()
|
|
196
|
+
),
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
def dump(self, *, show_rvs: bool = True, show_weights: bool = True, as_states: bool = False) -> None:
|
|
200
|
+
"""
|
|
201
|
+
Dump the cross-table in a human-readable format.
|
|
202
|
+
If as_states is true, then instance states are dumped instead of just state indexes.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
show_rvs: If `True`, the random variables are dumped.
|
|
206
|
+
show_weights: If `True`, the instance weights are dumped.
|
|
207
|
+
as_states: If `True`, the states are dumped instead of just state indexes.
|
|
208
|
+
"""
|
|
209
|
+
if show_rvs:
|
|
210
|
+
rvs = ', '.join(str(rv) for rv in self.rvs)
|
|
211
|
+
print(f'rvs: [{rvs}]')
|
|
212
|
+
print(f'instances ({len(self)}, with total weight {self.total_weight()}):')
|
|
213
|
+
for instance, weight in self.items():
|
|
214
|
+
if as_states:
|
|
215
|
+
instance_str = ', '.join(repr(rv.states[idx]) for idx, rv in zip(instance, self.rvs))
|
|
216
|
+
else:
|
|
217
|
+
instance_str = ', '.join(str(idx) for idx in instance)
|
|
218
|
+
if show_weights:
|
|
219
|
+
print(f'({instance_str}) * {weight}')
|
|
220
|
+
else:
|
|
221
|
+
print(f'({instance_str})')
|
|
222
|
+
|
|
129
223
|
|
|
130
224
|
def cross_table_from_dataset(
|
|
131
225
|
dataset: HardDataset | SoftDataset,
|
|
132
226
|
rvs: Optional[Sequence[RandomVariable]] = None,
|
|
133
227
|
*,
|
|
134
|
-
dirichlet_prior: float = 0,
|
|
228
|
+
dirichlet_prior: float | CrossTable = 0,
|
|
135
229
|
) -> CrossTable:
|
|
136
230
|
"""
|
|
137
231
|
Generate a cross-table for the given random variables, using the given dataset, represented
|
|
@@ -141,7 +235,12 @@ def cross_table_from_dataset(
|
|
|
141
235
|
dataset: The dataset to use to compute the cross-table.
|
|
142
236
|
rvs: The random variables to compute the cross-table for. If omitted
|
|
143
237
|
then `dataset.rvs` will be used.
|
|
144
|
-
dirichlet_prior: a
|
|
238
|
+
dirichlet_prior: provides a Dirichlet prior for `rvs`. This can be represented either:
|
|
239
|
+
(a) as a uniform prior, represented as a float value,
|
|
240
|
+
(b) as an arbitrary Dirichlet prior, represented as a cross-table.
|
|
241
|
+
If a cross-table is provided as a prior, then it must have the same random variables as `rvs`.
|
|
242
|
+
The default value for `dirichlet_prior` is 0.
|
|
243
|
+
See `CrossTable` for more explanation.
|
|
145
244
|
|
|
146
245
|
Returns:
|
|
147
246
|
The cross-table for the given random variables, using the given dataset,
|
|
@@ -151,18 +250,18 @@ def cross_table_from_dataset(
|
|
|
151
250
|
Raises:
|
|
152
251
|
KeyError: If any random variable in `rvs` does not appear in the dataset.
|
|
153
252
|
"""
|
|
154
|
-
if isinstance(dataset, SoftDataset):
|
|
155
|
-
return cross_table_from_soft_dataset(dataset, rvs, dirichlet_prior=dirichlet_prior)
|
|
156
253
|
if isinstance(dataset, HardDataset):
|
|
157
254
|
return cross_table_from_hard_dataset(dataset, rvs, dirichlet_prior=dirichlet_prior)
|
|
255
|
+
if isinstance(dataset, SoftDataset):
|
|
256
|
+
return cross_table_from_soft_dataset(dataset, rvs, dirichlet_prior=dirichlet_prior)
|
|
158
257
|
raise TypeError('dataset must be either a SoftDataset or HardDataset')
|
|
159
258
|
|
|
160
259
|
|
|
161
|
-
def
|
|
162
|
-
dataset:
|
|
260
|
+
def cross_table_from_hard_dataset(
|
|
261
|
+
dataset: HardDataset,
|
|
163
262
|
rvs: Optional[Sequence[RandomVariable]] = None,
|
|
164
263
|
*,
|
|
165
|
-
dirichlet_prior: float = 0
|
|
264
|
+
dirichlet_prior: float | CrossTable = 0
|
|
166
265
|
) -> CrossTable:
|
|
167
266
|
"""
|
|
168
267
|
Generate a cross-table for the given random variables, using the given dataset, represented
|
|
@@ -172,7 +271,12 @@ def cross_table_from_soft_dataset(
|
|
|
172
271
|
dataset: The dataset to use to compute the cross-table.
|
|
173
272
|
rvs: The random variables to compute the cross-table for. If omitted
|
|
174
273
|
then `dataset.rvs` will be used.
|
|
175
|
-
dirichlet_prior: a
|
|
274
|
+
dirichlet_prior: provides a Dirichlet prior for `rvs`. This can be represented either:
|
|
275
|
+
(a) as a uniform prior, represented as a float value,
|
|
276
|
+
(b) as an arbitrary Dirichlet prior, represented as a cross-table.
|
|
277
|
+
If a cross-table is provided as a prior, then it must have the same random variables as `rvs`.
|
|
278
|
+
The default value for `dirichlet_prior` is 0.
|
|
279
|
+
See `CrossTable` for more explanation.
|
|
176
280
|
|
|
177
281
|
Returns:
|
|
178
282
|
The cross-table for the given random variables, using the given dataset,
|
|
@@ -184,31 +288,18 @@ def cross_table_from_soft_dataset(
|
|
|
184
288
|
"""
|
|
185
289
|
if rvs is None:
|
|
186
290
|
rvs = dataset.rvs
|
|
291
|
+
return CrossTable(
|
|
292
|
+
rvs=rvs,
|
|
293
|
+
dirichlet_prior=dirichlet_prior,
|
|
294
|
+
update=dataset.instances(rvs)
|
|
295
|
+
)
|
|
187
296
|
|
|
188
|
-
# Special case
|
|
189
|
-
if len(rvs) == 0:
|
|
190
|
-
return CrossTable((), 0, [((), dataset.total_weight() + dirichlet_prior)])
|
|
191
297
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
columns: List[NDArray] = [
|
|
195
|
-
dataset.state_weights(rv)
|
|
196
|
-
for rv in rvs
|
|
197
|
-
]
|
|
198
|
-
|
|
199
|
-
for instance_weights, weight in zip(zip(*columns), dataset.weights):
|
|
200
|
-
if weight != 0:
|
|
201
|
-
for instance, instance_weight in _product_instance_weights(instance_weights):
|
|
202
|
-
weights.add(instance, instance_weight * weight)
|
|
203
|
-
|
|
204
|
-
return weights
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
def cross_table_from_hard_dataset(
|
|
208
|
-
dataset: HardDataset,
|
|
298
|
+
def cross_table_from_soft_dataset(
|
|
299
|
+
dataset: SoftDataset,
|
|
209
300
|
rvs: Optional[Sequence[RandomVariable]] = None,
|
|
210
301
|
*,
|
|
211
|
-
dirichlet_prior: float = 0
|
|
302
|
+
dirichlet_prior: float | CrossTable = 0
|
|
212
303
|
) -> CrossTable:
|
|
213
304
|
"""
|
|
214
305
|
Generate a cross-table for the given random variables, using the given dataset, represented
|
|
@@ -218,7 +309,12 @@ def cross_table_from_hard_dataset(
|
|
|
218
309
|
dataset: The dataset to use to compute the cross-table.
|
|
219
310
|
rvs: The random variables to compute the cross-table for. If omitted
|
|
220
311
|
then `dataset.rvs` will be used.
|
|
221
|
-
dirichlet_prior: a
|
|
312
|
+
dirichlet_prior: provides a Dirichlet prior for `rvs`. This can be represented either:
|
|
313
|
+
(a) as a uniform prior, represented as a float value,
|
|
314
|
+
(b) as an arbitrary Dirichlet prior, represented as a cross-table.
|
|
315
|
+
If a cross-table is provided as a prior, then it must have the same random variables as `rvs`.
|
|
316
|
+
The default value for `dirichlet_prior` is 0.
|
|
317
|
+
See `CrossTable` for more explanation.
|
|
222
318
|
|
|
223
319
|
Returns:
|
|
224
320
|
The cross-table for the given random variables, using the given dataset,
|
|
@@ -231,40 +327,8 @@ def cross_table_from_hard_dataset(
|
|
|
231
327
|
if rvs is None:
|
|
232
328
|
rvs = dataset.rvs
|
|
233
329
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
columns: List[NDArray] = [
|
|
241
|
-
dataset.states(rv)
|
|
242
|
-
for rv in rvs
|
|
243
|
-
]
|
|
244
|
-
|
|
245
|
-
for instance, weight in zip(zip(*columns), dataset.weights):
|
|
246
|
-
if weight != 0:
|
|
247
|
-
instance: Tuple[int, ...] = tuple(int(i) for i in instance)
|
|
248
|
-
weights.add(instance, weight)
|
|
249
|
-
|
|
250
|
-
return weights
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def _product_instance_weights(instance_weights: Sequence[NDArray]) -> Iterator[Tuple[Tuple[int, ...], float]]:
|
|
254
|
-
"""
|
|
255
|
-
Iterate over all possible instance for the given instance weights,
|
|
256
|
-
where the weight is not zero.
|
|
257
|
-
"""
|
|
258
|
-
|
|
259
|
-
# Base case
|
|
260
|
-
if len(instance_weights) == 0:
|
|
261
|
-
yield (), 1
|
|
262
|
-
|
|
263
|
-
# Recursive case
|
|
264
|
-
else:
|
|
265
|
-
next_weights: NDArray = instance_weights[-1]
|
|
266
|
-
pre_weights: Sequence[NDArray] = instance_weights[:-1]
|
|
267
|
-
for pre_instance, pre_weight in _product_instance_weights(pre_weights):
|
|
268
|
-
for i, weight in enumerate(next_weights):
|
|
269
|
-
if weight != 0:
|
|
270
|
-
yield pre_instance + (int(i),), pre_weight * weight
|
|
330
|
+
return CrossTable(
|
|
331
|
+
rvs=rvs,
|
|
332
|
+
dirichlet_prior=dirichlet_prior,
|
|
333
|
+
update=dataset.hard_instances(rvs)
|
|
334
|
+
)
|