BayesForge 0.0.46__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.
- bayesforge-0.0.46/BF/BNN/__init__.py +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/activations.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/activations.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/activations.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/bnn.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/bnn.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/__pycache__/bnn.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/BNN/activations.py +249 -0
- bayesforge-0.0.46/BF/BNN/bnn.py +272 -0
- bayesforge-0.0.46/BF/Build/Build api reference.ipynb +580 -0
- bayesforge-0.0.46/BF/Build/Build_NP_light.py +221 -0
- bayesforge-0.0.46/BF/Build/Build_R_documentation.py +112 -0
- bayesforge-0.0.46/BF/Build/Build_TFP_light.py +120 -0
- bayesforge-0.0.46/BF/Build/Build_test_file.py +84 -0
- bayesforge-0.0.46/BF/Build/Doc_R.json +1 -0
- bayesforge-0.0.46/BF/Build/Doc_python.json +1 -0
- bayesforge-0.0.46/BF/Data/__pycache__/manip.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Data/__pycache__/manip.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Data/__pycache__/manip.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Data/manip.py +263 -0
- bayesforge-0.0.46/BF/Diagnostic/Diag.py +584 -0
- bayesforge-0.0.46/BF/Diagnostic/Diag2.py +1341 -0
- bayesforge-0.0.46/BF/Diagnostic/__init__.py +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/Diag2.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/Diag2.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/Diag2.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/jax_diagnostics.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/patch_diag.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/ppc.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/regression_plot.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/__pycache__/sensitivity.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Diagnostic/jax_diagnostics.py +1251 -0
- bayesforge-0.0.46/BF/Diagnostic/jax_summary.py +113 -0
- bayesforge-0.0.46/BF/Diagnostic/patch_diag.py +651 -0
- bayesforge-0.0.46/BF/Diagnostic/ppc.py +669 -0
- bayesforge-0.0.46/BF/Diagnostic/regression_plot.py +200 -0
- bayesforge-0.0.46/BF/Diagnostic/sensitivity.py +417 -0
- bayesforge-0.0.46/BF/Distributions/__init__.py +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/np_dists.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/np_dists.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/__pycache__/np_dists.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Distributions/np_dists.py +7743 -0
- bayesforge-0.0.46/BF/Distributions/np_dists_old.py +6771 -0
- bayesforge-0.0.46/BF/Distributions/tfp_dists.py +4729 -0
- bayesforge-0.0.46/BF/ML/KMeans.py +253 -0
- bayesforge-0.0.46/BF/ML/__init__.py +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/KMeans.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/KMeans.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/KMeans.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/ml.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/ml.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/ML/__pycache__/ml.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/ML/ml.py +105 -0
- bayesforge-0.0.46/BF/Main/__init__.py +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/main.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/main.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Main/__pycache__/main.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Main/main.py +776 -0
- bayesforge-0.0.46/BF/Models/BNNC.py +155 -0
- bayesforge-0.0.46/BF/Models/DPMM.py +349 -0
- bayesforge-0.0.46/BF/Models/GMM.py +218 -0
- bayesforge-0.0.46/BF/Models/PCA.py +759 -0
- bayesforge-0.0.46/BF/Models/SRM.py +516 -0
- bayesforge-0.0.46/BF/Models/__init__.py +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/BNNC.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/BNNC.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/BNNC.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/DPMM.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/DPMM.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/DPMM.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/GMM.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/GMM.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/GMM.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/PCA.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/PCA.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/PCA.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/models.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/models.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/models.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/surv.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/surv.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Models/__pycache__/surv.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Models/models.py +35 -0
- bayesforge-0.0.46/BF/Models/surv.py +909 -0
- bayesforge-0.0.46/BF/NBDA/NBDA.py +725 -0
- bayesforge-0.0.46/BF/NBDA/__init__.py +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/NBDA.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/NBDA.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/NBDA.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/NBDA/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/Net.py +17 -0
- bayesforge-0.0.46/BF/Network/__init__.py +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/Net.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/Net.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/Net.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/metrics.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/metrics.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/metrics.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/model_effects.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/model_effects.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/model_effects.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/util.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/util.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Network/__pycache__/util.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Network/metrics.py +564 -0
- bayesforge-0.0.46/BF/Network/model_effects.py +427 -0
- bayesforge-0.0.46/BF/Network/util.py +331 -0
- bayesforge-0.0.46/BF/PostModel/__init__.py +0 -0
- bayesforge-0.0.46/BF/PostModel/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/PostModel/__pycache__/to_latex.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/PostModel/to_latex.py +173 -0
- bayesforge-0.0.46/BF/R/BF doc.py +65 -0
- bayesforge-0.0.46/BF/R/R warpper.R +169 -0
- bayesforge-0.0.46/BF/R/RDoc.json +101 -0
- bayesforge-0.0.46/BF/Resources/Howell1.csv +545 -0
- bayesforge-0.0.46/BF/Resources/Howell2.csv +847 -0
- bayesforge-0.0.46/BF/Resources/Kline.csv +11 -0
- bayesforge-0.0.46/BF/Resources/Kline2.csv +11 -0
- bayesforge-0.0.46/BF/Resources/KosterLeckie copy.rda +0 -0
- bayesforge-0.0.46/BF/Resources/KosterLeckie.rda +0 -0
- bayesforge-0.0.46/BF/Resources/NBDA_data.json +1 -0
- bayesforge-0.0.46/BF/Resources/NBDA_edge_list.csv +101 -0
- bayesforge-0.0.46/BF/Resources/NBDA_event_data.csv +51 -0
- bayesforge-0.0.46/BF/Resources/Sim dat Gamma poisson.csv +3401 -0
- bayesforge-0.0.46/BF/Resources/Sim data multinomial.csv +13 -0
- bayesforge-0.0.46/BF/Resources/Sim data multivariatenormal.csv +201 -0
- bayesforge-0.0.46/BF/Resources/UCBadmit.csv +13 -0
- bayesforge-0.0.46/BF/Resources/WaffleDivorce.csv +51 -0
- bayesforge-0.0.46/BF/Resources/__init__.py +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/datasets.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/datasets.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/__pycache__/datasets.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Resources/chimpanzees.csv +505 -0
- bayesforge-0.0.46/BF/Resources/datasets.py +663 -0
- bayesforge-0.0.46/BF/Resources/elephants.csv +42 -0
- bayesforge-0.0.46/BF/Resources/islandsDistMatrix.csv +11 -0
- bayesforge-0.0.46/BF/Resources/mastectomy.csv +45 -0
- bayesforge-0.0.46/BF/Resources/milk.csv +30 -0
- bayesforge-0.0.46/BF/Resources/panama_ewa.csv +1442 -0
- bayesforge-0.0.46/BF/Resources/phylo_L_meta.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_L_poisson.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_L_repeated.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_L_simple.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_L_slopes.csv +51 -0
- bayesforge-0.0.46/BF/Resources/phylo_data_meta.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_data_poisson.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_data_repeated.csv +1001 -0
- bayesforge-0.0.46/BF/Resources/phylo_data_simple.csv +201 -0
- bayesforge-0.0.46/BF/Resources/phylo_data_slopes.csv +51 -0
- bayesforge-0.0.46/BF/Resources/reedfrogs.csv +49 -0
- bayesforge-0.0.46/BF/Resources/sim_nested_effects.csv +401 -0
- bayesforge-0.0.46/BF/Resources/tulips.csv +28 -0
- bayesforge-0.0.46/BF/Samplers/Model_handler.py +125 -0
- bayesforge-0.0.46/BF/Samplers/SVI/__init__.py +0 -0
- bayesforge-0.0.46/BF/Samplers/SVI/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/SVI/__pycache__/svi_numpyro.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/SVI/svi_numpyro.py +71 -0
- bayesforge-0.0.46/BF/Samplers/__init__.py +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/mcmc_numpyro.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/mcmc_numpyro.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/__pycache__/mcmc_numpyro.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Samplers/mcmc_numpyro.py +62 -0
- bayesforge-0.0.46/BF/Samplers/mcmc_tfp.py +182 -0
- bayesforge-0.0.46/BF/SetDevice/__init__.py +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/set.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/set.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/__pycache__/set.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/SetDevice/set.py +73 -0
- bayesforge-0.0.46/BF/Utils/Effects.py +638 -0
- bayesforge-0.0.46/BF/Utils/Gaussian.py +276 -0
- bayesforge-0.0.46/BF/Utils/ImportManager.py +35 -0
- bayesforge-0.0.46/BF/Utils/R/asymmetric_laplace.R +36 -0
- bayesforge-0.0.46/BF/Utils/SampledData.py +740 -0
- bayesforge-0.0.46/BF/Utils/__init__.py +1 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Effects.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Effects.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Effects.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Gaussian.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Gaussian.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/Gaussian.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/ImportManager.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/ImportManager.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/ImportManager.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/SampledData.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/SampledData.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/SampledData.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/link.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/link.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/__pycache__/link.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BF/Utils/link.py +254 -0
- bayesforge-0.0.46/BF/__init__.py +12 -0
- bayesforge-0.0.46/BF/__pycache__/__init__.cpython-310.pyc +0 -0
- bayesforge-0.0.46/BF/__pycache__/__init__.cpython-312.pyc +0 -0
- bayesforge-0.0.46/BF/__pycache__/__init__.cpython-313.pyc +0 -0
- bayesforge-0.0.46/BayesForge.egg-info/PKG-INFO +339 -0
- bayesforge-0.0.46/BayesForge.egg-info/SOURCES.txt +361 -0
- bayesforge-0.0.46/BayesForge.egg-info/dependency_links.txt +1 -0
- bayesforge-0.0.46/BayesForge.egg-info/requires.txt +17 -0
- bayesforge-0.0.46/BayesForge.egg-info/top_level.txt +4 -0
- bayesforge-0.0.46/Documentation/__init__.py +0 -0
- bayesforge-0.0.46/Documentation/_setup.py +21 -0
- bayesforge-0.0.46/LICENSE +674 -0
- bayesforge-0.0.46/MANIFEST.in +1 -0
- bayesforge-0.0.46/PKG-INFO +339 -0
- bayesforge-0.0.46/README.md +304 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/check_parity.py +28 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/compare_cjs_ms.py +74 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/model_BF.py +195 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/plot_comparison.py +42 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/prepare_data.py +33 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/run_phase3_scalability.py +42 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/run_stan_benchmark.py +114 -0
- bayesforge-0.0.46/Test/Capture-Recapture (WIP)/verify_data.py +34 -0
- bayesforge-0.0.46/Test/Copula (WIP)/gaussian_copula_approaches.py +320 -0
- bayesforge-0.0.46/Test/Copula (WIP)/test_icdf_patch.py +77 -0
- bayesforge-0.0.46/Test/Copula (WIP)/test_inference.py +86 -0
- bayesforge-0.0.46/Test/Copula (WIP)/test_mock.py +29 -0
- bayesforge-0.0.46/Test/DP-VAE (WIP)/perfect_dp_mixture.py +266 -0
- bayesforge-0.0.46/Test/Diagnostic/diagnose sampling/__init__.py +1 -0
- bayesforge-0.0.46/Test/Diagnostic/diagnose sampling/diagnose.py +322 -0
- bayesforge-0.0.46/Test/Diagnostic/personality_traits/traits.py +87 -0
- bayesforge-0.0.46/Test/Diagnostic/ppc/test_ppc.py +138 -0
- bayesforge-0.0.46/Test/Diagnostic/regression/test_regression.py +78 -0
- bayesforge-0.0.46/Test/Diagnostic/sensitivity/test_sensitivity.py +111 -0
- bayesforge-0.0.46/Test/Diagnostic/summary/diag test.py +48 -0
- bayesforge-0.0.46/Test/Diagnostic/summary/jax_diagnostics.py +13 -0
- bayesforge-0.0.46/Test/Diagnostic/summary/patch_diag.py +8 -0
- bayesforge-0.0.46/Test/Distributions/distribution_numpyro.py +602 -0
- bayesforge-0.0.46/Test/Distributions/distribution_tfp.py +70 -0
- bayesforge-0.0.46/Test/EWA/BI_backend/model.py +145 -0
- bayesforge-0.0.46/Test/EWA/run_comparison.py +206 -0
- bayesforge-0.0.46/Test/GMM (WIP)/compare.py +150 -0
- bayesforge-0.0.46/Test/GMM (WIP)/ggmm_BF.py +287 -0
- bayesforge-0.0.46/Test/HGAM (WIP)/benchmark_hgam_BF.py +89 -0
- bayesforge-0.0.46/Test/HGAM (WIP)/gam_utils.py +184 -0
- bayesforge-0.0.46/Test/HGAM (WIP)/plot_hgam_comparison.py +63 -0
- bayesforge-0.0.46/Test/HGAM (WIP)/test_native_gam.py +105 -0
- bayesforge-0.0.46/Test/MGM and DPMM/7.MGM_DPM_Similarity_Test.py +109 -0
- bayesforge-0.0.46/Test/MGM and DPMM/Similarity_Test.py +109 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/fit_BF_gamma.py +127 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/fit_BF_gamma_fixed.py +127 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/fit_BF_gamma_fixed2.py +127 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/fit_BF_gamma_fixed3.py +22 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/fit_BF_gamma_vec.py +104 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_1_Spatial_Heterogeneity/parse_trees.py +57 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_2_Temporal_Heterogeneity/fit_BF_ucln.py +129 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_2_Temporal_Heterogeneity/fit_BF_ucln_vec.py +110 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_3_Spatial_BLMarg/fit_BF_gamma_blmarg.py +137 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/Model_4_Temporal_BLMarg/fit_BF_ucln_blmarg.py +150 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_3way_beast.py +86 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_beast_BF.py +99 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_bl_beast_equivalence.py +73 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_estimations.py +45 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_posteriors.py +123 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/compare_posteriors_blmarg.py +154 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/create_xmls.py +90 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/scripts/check_vectorization_logic.py +78 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/scripts/generate_xtx_log.py +66 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/scripts/load_data.py +72 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/scripts/tree_6.py +48 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/scripts/tree_data.py +58 -0
- bayesforge-0.0.46/Test/Modeling Evolutionary Heterogeneity (WIP)/tree_data.py +58 -0
- bayesforge-0.0.46/Test/Models.py +321 -0
- bayesforge-0.0.46/Test/Nested effect/builtin_function.py +533 -0
- bayesforge-0.0.46/Test/Network/Multiplex (WIP)/SIM.py +469 -0
- bayesforge-0.0.46/Test/Network/Network metrics/network_metrics.py +233 -0
- bayesforge-0.0.46/Test/Network/SRM/SIM.py +728 -0
- bayesforge-0.0.46/Test/Network/SRM/benchmark_stan2.py +463 -0
- bayesforge-0.0.46/Test/Network/SRM/benchmark_suite/benchmark_stan2.py +463 -0
- bayesforge-0.0.46/Test/Network/SRM/fit_comparison.py +469 -0
- bayesforge-0.0.46/Test/PCA/PCA.py +124 -0
- bayesforge-0.0.46/Test/Phylogenic analysis/Model_1_Simple/fit_BF_simple.py +69 -0
- bayesforge-0.0.46/Test/Phylogenic analysis/Model_2_Poisson/fit_BF_pois.py +76 -0
- bayesforge-0.0.46/Test/Phylogenic analysis/Model_3_Repeated/fit_BF_repeat.py +126 -0
- bayesforge-0.0.46/Test/Phylogenic analysis/Model_4_Meta/fit_BF_meta.py +80 -0
- bayesforge-0.0.46/Test/Phylogenic analysis/Model_5_Slopes/fit_BF_slopes.py +107 -0
- bayesforge-0.0.46/Test/Repertoire/BF_only.py +79 -0
- bayesforge-0.0.46/Test/Repertoire/benchmark.py +116 -0
- bayesforge-0.0.46/Test/Repertoire/check_stan.py +5 -0
- bayesforge-0.0.46/Test/Repertoire/compare_moments_p.py +61 -0
- bayesforge-0.0.46/Test/Repertoire/compare_summary.py +48 -0
- bayesforge-0.0.46/Test/Repertoire/save_stan_samples.py +25 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/1.Continuous variable.py +110 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/10.Zero inflated.py +115 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/11.Varying intercepts.py +132 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/12.Varying effects.py +183 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/13.Gaussian processes.py +212 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/2.Categorical variable.py +116 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/3.Continuous interactions.py +136 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/4.Binomial.py +86 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/5.Binomial with indices.py +124 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/6.Poisson.py +119 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/7.Negative binomial.py +111 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/8.Multinomial.py +154 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/9.Beta binomial.py +132 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/Utils.py +249 -0
- bayesforge-0.0.46/Test/Rethinking/Numpyro backend/run_all.py +67 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/1.Continuous variable.py +112 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/10.Zero inflated.py +117 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/11.Varying intercepts.py +132 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/12.Varying effects.py +212 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/13.Gaussian processes.py +214 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/2.Categorical variable.py +118 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/3.Continuous interactions.py +140 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/4.Binomial.py +87 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/5.Binomial with indices.py +125 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/6.Poisson.py +119 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/7.Negative binomial.py +113 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/8.Multinomial.py +157 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/9.Beta binomial.py +130 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/Utils.py +249 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/run_all.py +66 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/scratch/check_summary.py +16 -0
- bayesforge-0.0.46/Test/Rethinking/TFP backend/scratch/test_df.py +12 -0
- bayesforge-0.0.46/Test/Survival analysis/Survival analysis.py +144 -0
- bayesforge-0.0.46/Test/Survival analysis/Survival_analysis_verify.py +117 -0
- bayesforge-0.0.46/Test/VINE (WIP)/__init__.py +59 -0
- bayesforge-0.0.46/Test/VINE (WIP)/data_parser.py +136 -0
- bayesforge-0.0.46/Test/VINE (WIP)/decoder.py +566 -0
- bayesforge-0.0.46/Test/VINE (WIP)/embeddings.py +180 -0
- bayesforge-0.0.46/Test/VINE (WIP)/likelihood.py +350 -0
- bayesforge-0.0.46/Test/VINE (WIP)/optimizer.py +312 -0
- bayesforge-0.0.46/Test/VINE (WIP)/validation.py +578 -0
- bayesforge-0.0.46/Test/Workflow/workflow.py +1458 -0
- bayesforge-0.0.46/Test/test_BF_simple.py +18 -0
- bayesforge-0.0.46/Test/test_save_load.py +69 -0
- bayesforge-0.0.46/pyproject.toml +57 -0
- bayesforge-0.0.46/setup.cfg +4 -0
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import jax
|
|
2
|
+
import jax.numpy as jnp
|
|
3
|
+
from jax.scipy.special import erf
|
|
4
|
+
|
|
5
|
+
class activation:
|
|
6
|
+
"""
|
|
7
|
+
A collection of common neural network activation functions implemented in JAX.
|
|
8
|
+
|
|
9
|
+
This class serves as a namespace for activation functions, which can be
|
|
10
|
+
called directly as static methods (e.g., `activation.relu(x)`).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# --- Original Functions (with improved docstrings) ---
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def tanh(x: jnp.ndarray) -> jnp.ndarray:
|
|
17
|
+
"""
|
|
18
|
+
Computes the hyperbolic tangent activation function.
|
|
19
|
+
|
|
20
|
+
This function squashes its input values into the range [-1, 1]. It is
|
|
21
|
+
zero-centered, which can help with optimization by making the mean of
|
|
22
|
+
the activations closer to zero. However, it can suffer from the
|
|
23
|
+
vanishing gradient problem for very large or very small inputs.
|
|
24
|
+
|
|
25
|
+
Parameters:
|
|
26
|
+
- x (jnp.ndarray): The input array.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
- jnp.ndarray: The array with tanh applied element-wise.
|
|
30
|
+
"""
|
|
31
|
+
return jnp.tanh(x)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def relu(x: jnp.ndarray) -> jnp.ndarray:
|
|
35
|
+
"""
|
|
36
|
+
Computes the Rectified Linear Unit (ReLU) activation function.
|
|
37
|
+
|
|
38
|
+
ReLU is one of the most widely used activation functions. It computes
|
|
39
|
+
f(x) = max(0, x), effectively "turning off" neurons with negative
|
|
40
|
+
outputs. This makes the network sparse and computationally efficient.
|
|
41
|
+
Its main drawback is the "dying ReLU" problem, where neurons can get
|
|
42
|
+
stuck in a state where they always output zero if their weights are
|
|
43
|
+
updated such that their input is always negative.
|
|
44
|
+
|
|
45
|
+
Parameters:
|
|
46
|
+
- x (jnp.ndarray): The input array.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
- jnp.ndarray: The array with ReLU applied element-wise.
|
|
50
|
+
"""
|
|
51
|
+
return jnp.maximum(0, x)
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def sigmoid(x: jnp.ndarray) -> jnp.ndarray:
|
|
55
|
+
"""
|
|
56
|
+
Computes the sigmoid (or logistic) activation function.
|
|
57
|
+
|
|
58
|
+
This function squashes its input values into the range [0, 1]. It is
|
|
59
|
+
commonly used in the output layer of binary classification models to
|
|
60
|
+
represent a probability. It is less favored for hidden layers due to
|
|
61
|
+
its non-zero-centered output and strong saturation, which leads to
|
|
62
|
+
vanishing gradients.
|
|
63
|
+
|
|
64
|
+
Parameters:
|
|
65
|
+
- x (jnp.ndarray): The input array.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
- jnp.ndarray: The array with sigmoid applied element-wise.
|
|
69
|
+
"""
|
|
70
|
+
return jax.nn.sigmoid(x)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def softmax(x: jnp.ndarray, axis: int = -1) -> jnp.ndarray:
|
|
74
|
+
"""
|
|
75
|
+
Computes the softmax activation function.
|
|
76
|
+
|
|
77
|
+
Softmax transforms a vector of real numbers into a probability
|
|
78
|
+
distribution. Each output value is in the range [0, 1], and all
|
|
79
|
+
output values sum to 1. It is almost exclusively used as the output
|
|
80
|
+
activation function for multi-class classification problems.
|
|
81
|
+
|
|
82
|
+
Parameters:
|
|
83
|
+
- x (jnp.ndarray): The input array.
|
|
84
|
+
- axis (int): The axis along which the softmax should be computed.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
- jnp.ndarray: The array with softmax applied along the specified axis.
|
|
88
|
+
"""
|
|
89
|
+
return jax.nn.softmax(x, axis=axis)
|
|
90
|
+
|
|
91
|
+
# --- New and Important Activation Functions ---
|
|
92
|
+
|
|
93
|
+
@staticmethod
|
|
94
|
+
def leaky_relu(x: jnp.ndarray, negative_slope: float = 0.01) -> jnp.ndarray:
|
|
95
|
+
"""
|
|
96
|
+
Computes the Leaky Rectified Linear Unit (Leaky ReLU).
|
|
97
|
+
|
|
98
|
+
Leaky ReLU is a variant of ReLU designed to solve the "dying ReLU"
|
|
99
|
+
problem. Instead of being zero for negative inputs, it allows a small,
|
|
100
|
+
non-zero gradient (controlled by `negative_slope`). This ensures that
|
|
101
|
+
neurons do not become completely inactive.
|
|
102
|
+
|
|
103
|
+
f(x) = x if x > 0, else negative_slope * x.
|
|
104
|
+
|
|
105
|
+
Usage:
|
|
106
|
+
A common drop-in replacement for ReLU, especially if you suspect
|
|
107
|
+
dying neurons are an issue.
|
|
108
|
+
|
|
109
|
+
Parameters:
|
|
110
|
+
- x (jnp.ndarray): The input array.
|
|
111
|
+
- negative_slope (float): The small slope for negative inputs. Default is 0.01.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
- jnp.ndarray: The array with Leaky ReLU applied element-wise.
|
|
115
|
+
"""
|
|
116
|
+
return jnp.where(x >= 0, x, negative_slope * x)
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def elu(x: jnp.ndarray, alpha: float = 1.0) -> jnp.ndarray:
|
|
120
|
+
"""
|
|
121
|
+
Computes the Exponential Linear Unit (ELU).
|
|
122
|
+
|
|
123
|
+
ELU is another alternative to ReLU that also aims to solve the dying
|
|
124
|
+
neuron problem and can lead to faster learning. For negative inputs,
|
|
125
|
+
it becomes a smooth, saturating function that pushes the mean
|
|
126
|
+
activation closer to zero, which can speed up convergence.
|
|
127
|
+
|
|
128
|
+
f(x) = x if x > 0, else alpha * (exp(x) - 1).
|
|
129
|
+
|
|
130
|
+
Usage:
|
|
131
|
+
Often provides better performance than ReLU or Leaky ReLU but is
|
|
132
|
+
slightly more computationally expensive due to the exponential function.
|
|
133
|
+
|
|
134
|
+
Parameters:
|
|
135
|
+
- x (jnp.ndarray): The input array.
|
|
136
|
+
- alpha (float): The saturation parameter for negative inputs. Default is 1.0.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
- jnp.ndarray: The array with ELU applied element-wise.
|
|
140
|
+
"""
|
|
141
|
+
return jnp.where(x >= 0, x, alpha * (jnp.exp(x) - 1))
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def gelu(x: jnp.ndarray) -> jnp.ndarray:
|
|
145
|
+
"""
|
|
146
|
+
Computes the Gaussian Error Linear Unit (GELU).
|
|
147
|
+
|
|
148
|
+
GELU is a smooth, high-performing activation function that is the
|
|
149
|
+
standard in modern Transformer models like BERT and GPT. It weights
|
|
150
|
+
its input by its value, but this weighting is stochastic and depends
|
|
151
|
+
on the standard Gaussian cumulative distribution function (CDF).
|
|
152
|
+
Intuitively, it's more likely to "drop" (zero-out) inputs that are
|
|
153
|
+
closer to zero.
|
|
154
|
+
|
|
155
|
+
f(x) = x * Φ(x), where Φ(x) is the standard normal CDF.
|
|
156
|
+
|
|
157
|
+
Usage:
|
|
158
|
+
The state-of-the-art choice for Transformer-based architectures. A
|
|
159
|
+
strong general-purpose choice for many deep networks.
|
|
160
|
+
|
|
161
|
+
Parameters:
|
|
162
|
+
- x (jnp.ndarray): The input array.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
- jnp.ndarray: The array with GELU applied element-wise.
|
|
166
|
+
"""
|
|
167
|
+
return x * 0.5 * (1.0 + erf(x / jnp.sqrt(2.0)))
|
|
168
|
+
|
|
169
|
+
@staticmethod
|
|
170
|
+
def silu(x: jnp.ndarray) -> jnp.ndarray:
|
|
171
|
+
"""
|
|
172
|
+
Computes the Sigmoid Linear Unit (SiLU), also known as Swish.
|
|
173
|
+
|
|
174
|
+
SiLU is a self-gated activation function, defined as f(x) = x * sigmoid(x).
|
|
175
|
+
The sigmoid part acts as a soft "gate" that modulates the input. This
|
|
176
|
+
function is smooth, non-monotonic, and has been shown to perform as
|
|
177
|
+
well or better than ReLU on many challenging tasks without adding any
|
|
178
|
+
extra parameters.
|
|
179
|
+
|
|
180
|
+
Usage:
|
|
181
|
+
An excellent, modern, general-purpose replacement for ReLU that often
|
|
182
|
+
improves performance.
|
|
183
|
+
|
|
184
|
+
Parameters:
|
|
185
|
+
- x (jnp.ndarray): The input array.
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
- jnp.ndarray: The array with SiLU applied element-wise.
|
|
189
|
+
"""
|
|
190
|
+
return x * jax.nn.sigmoid(x)
|
|
191
|
+
|
|
192
|
+
@staticmethod
|
|
193
|
+
def softplus(x: jnp.ndarray) -> jnp.ndarray:
|
|
194
|
+
"""
|
|
195
|
+
Computes the Softplus activation function.
|
|
196
|
+
|
|
197
|
+
Softplus is a smooth approximation of the ReLU function, defined as
|
|
198
|
+
f(x) = log(1 + exp(x)). Its output is always strictly positive.
|
|
199
|
+
|
|
200
|
+
Usage:
|
|
201
|
+
While less common as a hidden layer activation, it is very useful in
|
|
202
|
+
the output layer of a model when a strictly positive output is
|
|
203
|
+
required, for example, when predicting the variance (scale) parameter
|
|
204
|
+
of a distribution.
|
|
205
|
+
|
|
206
|
+
Parameters:
|
|
207
|
+
- x (jnp.ndarray): The input array.
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
- jnp.ndarray: The array with Softplus applied element-wise.
|
|
211
|
+
"""
|
|
212
|
+
return jnp.log(1.0 + jnp.exp(x))
|
|
213
|
+
# A more numerically stable version is: jax.nn.softplus(x)
|
|
214
|
+
|
|
215
|
+
@staticmethod
|
|
216
|
+
def linear(x: jnp.ndarray) -> jnp.ndarray:
|
|
217
|
+
"""
|
|
218
|
+
Computes the linear (or identity) activation function.
|
|
219
|
+
|
|
220
|
+
This function simply returns the input without any modification, i.e.,
|
|
221
|
+
f(x) = x.
|
|
222
|
+
|
|
223
|
+
Usage:
|
|
224
|
+
This is a critical component. It is the default choice for the output
|
|
225
|
+
layer of any regression model, where the output is an unbounded,
|
|
226
|
+
continuous value.
|
|
227
|
+
|
|
228
|
+
Parameters:
|
|
229
|
+
- x (jnp.ndarray): The input array.
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
- jnp.ndarray: The identical input array.
|
|
233
|
+
"""
|
|
234
|
+
return x
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def exp(x: jnp.ndarray) -> jnp.ndarray:
|
|
238
|
+
"""
|
|
239
|
+
Computes the exponential activation function.
|
|
240
|
+
|
|
241
|
+
f(x) = exp(x). Output is always positive.
|
|
242
|
+
|
|
243
|
+
Parameters:
|
|
244
|
+
- x (jnp.ndarray): The input array.
|
|
245
|
+
|
|
246
|
+
Returns:
|
|
247
|
+
- jnp.ndarray: The array with exponential applied element-wise.
|
|
248
|
+
"""
|
|
249
|
+
return jnp.exp(x)
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
from BF.Distributions.np_dists import UnifiedDist as dist
|
|
2
|
+
from BF.BNN.activations import activation
|
|
3
|
+
|
|
4
|
+
from numpyro import deterministic
|
|
5
|
+
import jax.numpy as jnp
|
|
6
|
+
import jax
|
|
7
|
+
|
|
8
|
+
class bnn(activation):
|
|
9
|
+
"""
|
|
10
|
+
The bnn class is designed to build Bayesian Neural Networks (BNNs). It provides methods for creating network layers with specified prior distributions and activation functions. Additionally, it includes a specific two-layer BNN model for covariance estimation and a utility function to compute a correlation matrix from posterior samples.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, rand_seed = True):
|
|
13
|
+
super().__init__()
|
|
14
|
+
|
|
15
|
+
self.dist = dist(rand_seed)
|
|
16
|
+
# Create the mapping in the constructor
|
|
17
|
+
self._activation_map = {
|
|
18
|
+
# Standard functions
|
|
19
|
+
"relu": self.relu,
|
|
20
|
+
"tanh": self.tanh,
|
|
21
|
+
"sigmoid": self.sigmoid,
|
|
22
|
+
"softmax": self.softmax,
|
|
23
|
+
"linear": self.linear,
|
|
24
|
+
|
|
25
|
+
# Advanced/Modern functions
|
|
26
|
+
"leaky_relu": self.leaky_relu,
|
|
27
|
+
"elu": self.elu,
|
|
28
|
+
"gelu": self.gelu,
|
|
29
|
+
"silu": self.silu,
|
|
30
|
+
"swish": self.silu, # Common alias for SiLU
|
|
31
|
+
|
|
32
|
+
# Specialty functions
|
|
33
|
+
"softplus": self.softplus,
|
|
34
|
+
"exp": self.exp,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def available_activations(self):
|
|
38
|
+
"""
|
|
39
|
+
Returns a list of available activation functions.
|
|
40
|
+
|
|
41
|
+
This method retrieves the names of all activation functions defined in the class.
|
|
42
|
+
"""
|
|
43
|
+
return list(self._activation_map.keys())
|
|
44
|
+
|
|
45
|
+
def layer_linear(self, X, dist, activation=None, bias=False):
|
|
46
|
+
"""
|
|
47
|
+
Adds a layer to the BNN with the specified prior distribution and activation function.
|
|
48
|
+
|
|
49
|
+
Parameters:
|
|
50
|
+
- prior_dist (BF.dist): The prior distribution for the weights of the layer. The shape of the distribution defines the layer's input/output dimensions.
|
|
51
|
+
- activation (str): The name of the activation function to use after this layer ('relu', 'tanh', 'sigmoid', 'softmax').
|
|
52
|
+
"""
|
|
53
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
54
|
+
if bias is not False:
|
|
55
|
+
prod = jnp.matmul(X, dist) + bias
|
|
56
|
+
else:
|
|
57
|
+
prod = jnp.matmul(X, dist)
|
|
58
|
+
|
|
59
|
+
# 2. Get and store the activation function object.
|
|
60
|
+
if activation is None:
|
|
61
|
+
return prod
|
|
62
|
+
else:
|
|
63
|
+
try:
|
|
64
|
+
activation_func = getattr(self, activation)
|
|
65
|
+
except AttributeError:
|
|
66
|
+
raise ValueError(f"Unknown activation function: '{activation}'")
|
|
67
|
+
return activation_func(prod)
|
|
68
|
+
|
|
69
|
+
def layer_attention(self, b_kv, b_q, d_model=32, sample=True, name = '', seed = None):
|
|
70
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
71
|
+
# Layers
|
|
72
|
+
### Dimensions
|
|
73
|
+
self.b_q, self.b_kv, self.d_model = b_q, b_kv, d_model
|
|
74
|
+
### Create learnable vector embeddings for each feature in the Query block a
|
|
75
|
+
self.emb_q = self.dist.normal(0,1,shape=(self.b_q,self.d_model), sample=sample, name=f'attention_q_{name}', seed = seed)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Create learnable vector embeddings for each feature in the Key/ Value block
|
|
79
|
+
self.emb_kv= self.dist.normal(0,1,shape=(self.b_kv,d_model),sample=sample, name=f'attention_kv_{name}', seed = seed)
|
|
80
|
+
|
|
81
|
+
### Define linear layers to project embeddings into Query, Key, and Value spaces
|
|
82
|
+
self.q_k_v_proj = self.dist.normal(0,1,shape=(self.d_model,self.d_model,3),sample=sample, name=f'attention_q_k_v_{name}', seed = seed)
|
|
83
|
+
|
|
84
|
+
### Define a final output layer to map the attention context to the desired matrix shape.
|
|
85
|
+
self.out = self.dist.normal(0,1,shape=(self.d_model * self.b_q, self.b_q * self.b_kv), sample=sample, name=f'attention_out_{name}', seed = seed)
|
|
86
|
+
|
|
87
|
+
# Performs the attention mechanism
|
|
88
|
+
## three dense (linear) layers : Q = X W_Q, K = X W_K, V = X W_V
|
|
89
|
+
## the three projection layers in attention do not have activation functions. They are purely linear transformations.
|
|
90
|
+
Q = self.layer_linear(X = self.emb_q, dist = self.q_k_v_proj[:,:,0])
|
|
91
|
+
K = self.layer_linear(X = self.emb_kv, dist = self.q_k_v_proj[:,:,1])
|
|
92
|
+
V = self.layer_linear(X = self.emb_kv, dist = self.q_k_v_proj[:,:,2])
|
|
93
|
+
|
|
94
|
+
## Attention mechanism:
|
|
95
|
+
### Calculate dot-product similarity scores between all Queries and Keys. Scale for stability.
|
|
96
|
+
scores =jnp.matmul(Q, K.T) / jnp.sqrt(self.d_model ** 0.5)
|
|
97
|
+
|
|
98
|
+
#### Convert raw scores into attention weights (probabilities) using softmax.
|
|
99
|
+
attn = jax.nn.softmax(scores, axis=-1)
|
|
100
|
+
|
|
101
|
+
####Compute the context vector as a weighted average of the Value vectors. Now we normalize the similarity scores across all possible `j` for each `i`
|
|
102
|
+
context = jnp.matmul(attn, V)
|
|
103
|
+
|
|
104
|
+
# Reshape and pass through the final output layer to get the L_ij block.
|
|
105
|
+
return self.layer_linear(context.reshape(1, -1), self.out).reshape(self.b_q, self.b_kv)
|
|
106
|
+
|
|
107
|
+
def layer_toeplitz(self, block_size = 32, sample = False, name = '', seed = None):
|
|
108
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
109
|
+
"""
|
|
110
|
+
Models a diagonal covariance block C_ii with a diagonal structure.
|
|
111
|
+
|
|
112
|
+
This is the simplest structure, assuming all variables in the block are
|
|
113
|
+
uncorrelated with each other. It only learns their individual variances.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
block_size (int): The dimension of this square block.
|
|
117
|
+
"""
|
|
118
|
+
self.b = block_size
|
|
119
|
+
# Learnable parameter for the base variance (stored in log space for unconstrained optimization).
|
|
120
|
+
self.log_sigma = self.dist.log_normal(1,sample=sample, name = f'toeplitz_log_sigma_{name}', seed = seed)
|
|
121
|
+
# Learnable parameter controlling correlation decay.
|
|
122
|
+
self.raw_alpha = self.dist.normal(0.5,1,sample=sample, name = f'toeplitz_raw_alpha_{name}', seed = seed)
|
|
123
|
+
# Learnable parameter for the diagonal adjustment.
|
|
124
|
+
self.log_diag = self.dist.normal(0,1,sample=sample, name = f'toeplitz_log_diag_{name}', seed = seed)
|
|
125
|
+
|
|
126
|
+
## Constructs the Toeplitz matrix from the learned parameters.
|
|
127
|
+
sigma, alpha = jax.nn.softplus(self.log_sigma) + 1e-6, jax.nn.sigmoid(self.raw_alpha)
|
|
128
|
+
idx = jnp.arange(self.b)
|
|
129
|
+
|
|
130
|
+
# Create the first row of the Toeplitz matrix: [sigma, sigma*alpha, sigma*alpha^2, ...].
|
|
131
|
+
toeplitz_row = sigma * (alpha ** idx)
|
|
132
|
+
indices = jnp.abs(idx[:, None] - idx[None, :])
|
|
133
|
+
# Build the full Toeplitz matrix by indexing the first row with the lag matrix.
|
|
134
|
+
toeplitz = toeplitz_row[indices]
|
|
135
|
+
diag = jax.nn.softplus(self.log_diag) + 1e-5
|
|
136
|
+
result = toeplitz + diag * jnp.eye(self.b)
|
|
137
|
+
return result
|
|
138
|
+
|
|
139
|
+
def layer_compound_symmetry(self, block_size, sample= True, name='', seed = None):
|
|
140
|
+
"""
|
|
141
|
+
Build a Compound Symmetry covariance block.
|
|
142
|
+
|
|
143
|
+
All variables share a common variance (sigma^2) and correlation (rho).
|
|
144
|
+
C = sigma^2 * [(1 - rho) I + rho 11^T]
|
|
145
|
+
|
|
146
|
+
Returns a (size, size) SPD matrix.
|
|
147
|
+
"""
|
|
148
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
149
|
+
# Store the block size.
|
|
150
|
+
self.b = block_size
|
|
151
|
+
|
|
152
|
+
# Learnable parameter for the common variance (log space).
|
|
153
|
+
self.log_sigma = self.dist.log_normal(1, sample = sample, seed = seed, name = f'compound_symmetry_log_sigma_{name}')
|
|
154
|
+
|
|
155
|
+
# Learnable parameter for the common correlation (raw, to be mapped to valid range).
|
|
156
|
+
self.raw_rho = self.dist.normal(0, 1, sample = sample, seed = seed, name = f'compound_symmetry_raw_rho_{name}')
|
|
157
|
+
|
|
158
|
+
# Learnable diagonal offsets.
|
|
159
|
+
self.log_diag = self.dist.normal(0, 1, shape = (self.b,), sample = sample, seed = seed, name = f'compound_symmetry_log_diag_{name}')
|
|
160
|
+
|
|
161
|
+
# Constructs the compound symmetry matrix from the learned parameters.
|
|
162
|
+
# Convert log_sigma to positive sigma.
|
|
163
|
+
sigma = jax.nn.softplus(self.log_sigma) + 1e-6
|
|
164
|
+
# Define the mathematically valid range for rho to ensure the matrix is PD.
|
|
165
|
+
low = -1.0 / (self.b - 1.0) + 1e-6 if self.b > 1 else 0.0
|
|
166
|
+
high = 0.999
|
|
167
|
+
|
|
168
|
+
# Map the output of sigmoid (0, 1) to the valid range (low, high).
|
|
169
|
+
rho = low + jax.nn.sigmoid(self.raw_rho) * (high - low)
|
|
170
|
+
# Create identity and all-ones matrices as building blocks.
|
|
171
|
+
I = jnp.eye(self.b)
|
|
172
|
+
ones = jnp.ones((self.b, self.b))
|
|
173
|
+
|
|
174
|
+
# Construct the matrix using its mathematical formula.
|
|
175
|
+
comp_sym = sigma * ((1.0 - rho) * I + rho * ones)
|
|
176
|
+
# Convert log_diag to positive offsets.
|
|
177
|
+
diag = jax.nn.softplus(self.log_diag) + 1e-5
|
|
178
|
+
|
|
179
|
+
# Add the diagonal offsets.
|
|
180
|
+
return comp_sym + diag * jnp.eye(self.b)
|
|
181
|
+
|
|
182
|
+
def layer_diagonal(self, block_size, sample= True, name='', seed = None):
|
|
183
|
+
"""
|
|
184
|
+
Build a Diagonal covariance block.
|
|
185
|
+
|
|
186
|
+
Variables are assumed independent; only individual variances are learned.
|
|
187
|
+
|
|
188
|
+
Returns a (size, size) SPD diagonal matrix.
|
|
189
|
+
"""
|
|
190
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
191
|
+
# Store the block size.
|
|
192
|
+
self.b = block_size
|
|
193
|
+
# Learnable vector of per-variable variances (stored in log space).
|
|
194
|
+
self.log_variances = self.dist.normal(0, 1, sample = sample, shape = (block_size,), name = f"log_variances_{name}",seed=seed)
|
|
195
|
+
|
|
196
|
+
#Constructs the diagonal matrix from the learned variances
|
|
197
|
+
# Convert log-variances to positive variances.
|
|
198
|
+
variances = jax.nn.softplus(self.log_variances) + 1e-6
|
|
199
|
+
# Create a diagonal matrix from the variances vector.
|
|
200
|
+
return jnp.diag(variances)
|
|
201
|
+
|
|
202
|
+
def scaled_dot_product_attention(self, Q, K, V):
|
|
203
|
+
"""Compute scaled dot-product attention."""
|
|
204
|
+
d_k = Q.shape[-1]
|
|
205
|
+
scores = jnp.matmul(Q, K.T) / jnp.sqrt(d_k)
|
|
206
|
+
attn_weights = jax.nn.softmax(scores, axis=-1)
|
|
207
|
+
return jnp.matmul(attn_weights, V), attn_weights
|
|
208
|
+
|
|
209
|
+
def __call__(self, X):
|
|
210
|
+
"""Forward pass through the Bayesian attention mechanism."""
|
|
211
|
+
Q = self.layer(X, self.q_proj)
|
|
212
|
+
K = self.layer(X, self.k_proj)
|
|
213
|
+
V = self.layer(X, self.v_proj)
|
|
214
|
+
|
|
215
|
+
attn_output, attn_weights = self.scaled_dot_product_attention(Q, K, V)
|
|
216
|
+
return attn_output, attn_weights
|
|
217
|
+
|
|
218
|
+
def cov(self,hidden_dim,N,a, b, sample = False):
|
|
219
|
+
"""
|
|
220
|
+
Creates a Bayesian Neural Network (BNN) with two layers for covariance estimation.
|
|
221
|
+
The first layer maps the input to a hidden dimension using a normal distribution,
|
|
222
|
+
and the second layer outputs two values per N (offsets for a and b).
|
|
223
|
+
Parameters:
|
|
224
|
+
- hidden_dim (int): The number of hidden units in the first layer.
|
|
225
|
+
- N (int): The number of data points, which determines the size of the input and output.
|
|
226
|
+
- a (jnp.ndarray): The first set of offsets for the covariance matrix.
|
|
227
|
+
- b (jnp.ndarray): The second set of offsets for the covariance matrix.
|
|
228
|
+
"""
|
|
229
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
230
|
+
# First layer weights/biases: note these are treated as latent parameters
|
|
231
|
+
W1 = self.dist.normal(0, 1, shape=(N, hidden_dim), name='W1', sample=sample)
|
|
232
|
+
|
|
233
|
+
# Second layer weights/biases
|
|
234
|
+
W2 = self.dist.normal(0, 1, shape=(hidden_dim, 2), name='W2', sample=sample)
|
|
235
|
+
|
|
236
|
+
# Create one-hot encoding for each N (each row is a one–hot vector)
|
|
237
|
+
X = jnp.eye(N)
|
|
238
|
+
|
|
239
|
+
hidden = jnp.tanh(jnp.dot(X, W1)) # shape: (N, hidden_dim)
|
|
240
|
+
|
|
241
|
+
# Second layer: output two values per cafe (offsets for a and b)
|
|
242
|
+
delta = jnp.dot(hidden, W2) # shape: (N, 2)
|
|
243
|
+
|
|
244
|
+
return deterministic('rf', jnp.stack([a, b]) + delta)
|
|
245
|
+
|
|
246
|
+
def get_rho(self, posterior):
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
"""
|
|
250
|
+
print("⚠️This function is still in development. Use it with caution. ⚠️")
|
|
251
|
+
a_b = jnp.mean(posterior, axis=0)
|
|
252
|
+
N= a_b.shape[0]
|
|
253
|
+
|
|
254
|
+
# 1. Compute sample covariance matrix
|
|
255
|
+
mean_a_b = jnp.mean(a_b, axis=0) # Mean of [a_cafe, b_cafe]
|
|
256
|
+
|
|
257
|
+
centered_data = a_b - mean_a_b # Center data by subtracting the mean
|
|
258
|
+
|
|
259
|
+
cov_sample = jnp.dot(centered_data.T, centered_data) / (N - 1) # Covariance matrix
|
|
260
|
+
|
|
261
|
+
# 2. Extract sigma (standard deviations) from the diagonal of the covariance matrix
|
|
262
|
+
sigma = jnp.sqrt(jnp.diagonal(cov_sample)) # Extract standard deviations (sqrt of variance)
|
|
263
|
+
|
|
264
|
+
# 3. Compute Rho (correlation matrix)
|
|
265
|
+
rho = cov_sample / (sigma[:, None] * sigma[None, :]) # Normalize covariance to obtain correlation matrix
|
|
266
|
+
return rho
|
|
267
|
+
|
|
268
|
+
def make_pd_and_cholesky_jax(self, A):
|
|
269
|
+
A = 0.5 * (A + A.T)
|
|
270
|
+
jitter = 1e-6
|
|
271
|
+
A += jitter * jnp.eye(A.shape[-1])
|
|
272
|
+
return jnp.linalg.cholesky(A)
|