{"id":22197314,"url":"https://github.com/dpbm/bayesian-networks","last_synced_at":"2025-06-12T08:05:37.029Z","repository":{"id":265941622,"uuid":"896087829","full_name":"Dpbm/bayesian-networks","owner":"Dpbm","description":"Testing Quantum bayesian networks with pennnylane","archived":false,"fork":false,"pushed_at":"2024-12-01T16:49:09.000Z","size":480,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T22:44:18.592Z","etag":null,"topics":["bayesian","bayesian-networks","pennylane","quantum","quantum-computing","quantum-machine-learning"],"latest_commit_sha":null,"homepage":"https://dpbm.github.io/bayesian-networks/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dpbm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T14:17:11.000Z","updated_at":"2024-12-01T16:49:12.000Z","dependencies_parsed_at":"2024-12-01T17:39:32.193Z","dependency_job_id":null,"html_url":"https://github.com/Dpbm/bayesian-networks","commit_stats":null,"previous_names":["dpbm/bayesian-networks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Dpbm/bayesian-networks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fbayesian-networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fbayesian-networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fbayesian-networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fbayesian-networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dpbm","download_url":"https://codeload.github.com/Dpbm/bayesian-networks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fbayesian-networks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259426913,"owners_count":22855550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","bayesian-networks","pennylane","quantum","quantum-computing","quantum-machine-learning"],"created_at":"2024-12-02T14:19:10.580Z","updated_at":"2025-06-12T08:05:37.001Z","avatar_url":"https://github.com/Dpbm.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bayesian Networks\n\nThis project was meant to be an example to be given during my quantum machine learning [mini-course](https://github.com/Dpbm/qml-course).\nHowever, due to the amount of time I was given, I decided to remove these example about Bayesian Networks and focus specially on Quantum Convolutional Neural Networks.\n\nAlthough it was a small snippet of code, I think that it deserved some attention. So, here I am, check out what I did.\n\n## How to Run\n\nAll this code was done using Python and PennyLane, so you may need to have [Python3.10](https://www.python.org/) installed as well as all the dependencies required for this project. I recommend you to use `mamba/conda-lock`, but feel free to use whatever you want.\n\n```bash\n#mamba setup\nmamba env create -f environment.yml\n\n#conda-lock setup\nconda-lock install -n bays conda-lock.yml\n\n#pip setup\npip install -r requirements.txt\n```\n\nWith all configured, you can run:\n\n```bash\njupyter lab bayesian-network.ipynb\n```\n\n## Explanation\n\nIs pretty common to see out there, some explanations about Bayesian Theorem using a disease and a test that can give either the correct or the wrong answer (like false positives and negatives). For this case, it won't be different.\n\nA similar probability case was mapped into a quantum circuit with all probabilities embedded as rotations. This way, each qubit has some probability to be in a certain classical state based on the odds pre-modeled.\n\nThis kind of network can be seen as a graph, where node is a state and every weight on the edges represents the probability to go to a certain state (much like a automaton).\n\n| qubit | Meaning                      |\n|-------|----------------------------------|\n|   0   | positive(1) negative(0) |\n|   1   | false psotive/negative |\n|   2   | chance of having the disease |\n\n\n| odds | to |\n|---------------|-------|\n|  0.2          | false positive |\n|  0.4         | false negative |\n|  0.01         | have the disease given a false positive/negative |\n\n![graph](./assets/probabilities_graph.png)\n\nFollowing this structure, it's very straightforward to create the circuit.\n\n![circuit 1](./assets/first_example.png)\n\nIn this case, the first qubit will act as an input, telling what was the test result (positive/negative), then the probability chain will be in charge to compute the probabilities based on the previous state.\n\nAfter measuring the last two qubits, we have the following distribution:\n\n![probabilities circuit 1](./assets/probs_example_1.png)\n\nThe same can be experienced when the result value is `1`.\n\n![circuit 2](./assets/circuit_example_2.png)\n\n![probabilities circuit 2](./assets/probs_example_2.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbm%2Fbayesian-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpbm%2Fbayesian-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbm%2Fbayesian-networks/lists"}