Skip to content

Commit

Permalink
changed how to run enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
bkbilly committed Nov 16, 2019
1 parent dbf2603 commit a2030e7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.egg-info/
dist/
__pycache__/
*.pyc
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ Implementation for bayesian network with
- Enumeration
- Rejection Sampling
- Likelihood Weighting

```python
{
'netid': "burglary",
'query': ('B', 'j,m'),
'result': {True: 0.28, False: 0.72},
'samples': 10000,
}
RejectionSampling().run(testcase)
LikelihoodWeighting().run(testcase)
Enumeration().run(testcase)
```
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@ def calc_query(self, node, query, graph):

class Enumeration(BayesianClass):

def __init__(self, graph):
def __init__(self, graph=None):
self.graph = graph

def run(self, testcase):
# Initialize graph
parser = ParseInputs()
known_data = parser.get_test_data(testcase['netid'])
self.graph = parser.get_graph(known_data)

node, query = parser.get_query('|'.join(testcase['query']))
for key, value in self.graph.items():
print(key, value)
print('---------------')

# enum = Enumeration(graph)
enum_results = self.enum_ask(node, query)
parser.print_results(node, query, enum_results)

def enum_ask(self, node, query):
sorted_nodes = self.graph.keys()
prob_results = []
Expand Down Expand Up @@ -76,16 +91,9 @@ def enum_all(self, sorted_nodes, query):


if __name__ == '__main__':
parser = ParseInputs()
known_data = parser.get_test_data('burglary')
graph = parser.get_graph(known_data)
node, query = parser.get_query('P(B|j,m)')
print(node, query)

for key, value in graph.items():
print(key, value)
print('---------------')

enum = Enumeration(graph)
enum_results = enum.enum_ask(node, query)
parser.print_results(node, query, enum_results)
testcase = {
'netid': "burglary",
'query': ('B', 'j,m'),
'result': {True: 0.28, False: 0.72},
}
Enumeration().run(testcase)
File renamed without changes.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
long_description = fh.read()

setuptools.setup(
name='bayesian-networks',
name='bayesian_networks',
version='0.5',
author="bkbilly",
author_email="[email protected]",
description="Implementation for bayesian network with Enumeration, Rejection Sampling and Likelihood Weighting",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/bkbilly/bayesian-networks",
url="https://github.com/bkbilly/bayesian_networks",
packages=setuptools.find_packages(),
install_requires=[
'pytz>=2019.2',
'matplotlib>=3.1.1',
'matplotlib==3.1.1',
'networkx>=2.4',
],
classifiers=[
Expand Down

0 comments on commit a2030e7

Please sign in to comment.