-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bayesian Networks #5094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bayesian Networks #5094
Conversation
|
@MichaelBroughton |
|
The discussion from Cirq sync was about considering whether or not this should be in Cirq proper. I think someone was going to ask around internally to find out if anyone is interested in Bayesian Networks. |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
@vtomole But I am totally OK with re-considering. I certainly don't want to pollute the repo and could abandon this PR if it is misguided, of course. |
MichaelBroughton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good first pass. I'm wondering if we've got the logic from the paper exactly captured. Are we handling the cases of the root vs child nodes ? Perhaps it might be worth recreating a test to match what is done in figure 10 for corectness sake ?
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
| for param, init_prob in self._init_probs: | ||
| yield self._generate_got_set_for_init_prob(qubit_map[param], init_prob) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we assuming all nodes are root nodes and none follow along with eqn 14 from the paper ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. We just specify the dependent nodes with a None probability. Also the user messes up and specify a node is independent (i.e. with an initial probability) and then assigns it as a dependent variable, the code will run fine (but return absurd results).
The reason I decided to do it this way, was that there are other ways to mess things up. We would have to check the graph is directed acyclic, but that seems like pulling a lot of graph code in. I can do it if you want, of course. For now, I just put a warning in the docstring.
Leaving unresolved. Let me know?
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
| if not isinstance(params, tuple): | ||
| raise ValueError('Conditional prob params must be a tuple.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't need to make type checking part of python APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but I want to distinguish cases like
('q0')
versus
('q0',)
The first version is NOT correct, but without the check, the code will iterate over the characters 'q' and '0'. It's a very common mistake, so this could be a good help.
|
Thanks @MichaelBroughton . Now, the PR is ready for another iteration. I left a few comments unresolved to make sure I understood what you were asking. PTAL when you can? |
|
Friendly ping when you have the time? I understand that v1.0 takes priority, of course. |
dabacon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaelBroughton may want to take another look.
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate.py
Outdated
Show resolved
Hide resolved
|
Thanks. PTAL. |
|
Automerge cancelled: A status check is failing. |
|
@MichaelBroughton |
|
Automerge cancelled: A status check is failing. |
|
@tonybruguier Can't merge due to some checks failing. |
This class implements Quantum Bayesian Networks as described in: https://arxiv.org/abs/2004.14803 In addition, these write ups could be helpful: https://towardsdatascience.com/create-a-quantum-bayesian-network-d26d7c5c4217 https://towardsdatascience.com/how-to-create-a-quantum-bayesian-network-5b011914b03e
This class implements Quantum Bayesian Networks as described in: https://arxiv.org/abs/2004.14803 In addition, these write ups could be helpful: https://towardsdatascience.com/create-a-quantum-bayesian-network-d26d7c5c4217 https://towardsdatascience.com/how-to-create-a-quantum-bayesian-network-5b011914b03e
This class implements Quantum Bayesian Networks as described in:
https://arxiv.org/abs/2004.14803
In addition, these write ups could be helpful:
https://towardsdatascience.com/create-a-quantum-bayesian-network-d26d7c5c4217
https://towardsdatascience.com/how-to-create-a-quantum-bayesian-network-5b011914b03e