ncullen93 / pybn Goto Github PK
View Code? Open in Web Editor NEWBayesian Networks in Python
License: MIT License
Bayesian Networks in Python
License: MIT License
Encountered this problem on pyBN/pyBN/classes/factor.py
, method reduce_factor
` 585 """
586 exp_len = len(self.cpt)/float(self.card[rv])
--> 587 new_cpt = np.zeros((exp_len,))
588
589 val_idx = self.bn.F[rv]['values'].index(val)
TypeError: 'float' object cannot be interpreted as an index`
In line 587, the exp_len will be type float and the newer version of numpy does not accept it.
From numpy release note:
DeprecationWarning to error
Indexing with floats raises IndexError, e.g., a[0, 0.0].
Indexing with non-integer array_like raises IndexError, e.g., a['1', '2']
Indexing with multiple ellipsis raises IndexError, e.g., a[..., ...].
Non-integers used as index values raise TypeError, e.g., in reshape, take, and specifying reduce axis.
I reinstall the numpy==1.11.3 and that fixed the problem. But I suggest that the type should be cast to int, and there might be other places that has the same problem, too.
In the hill_climbing function, I have to insert ''data''. How is made this array?
make sure fileio works.
Code to merge BNs based on parameters (assuming identical structure).. and maybe structure eventually.
Loopy Belief Propagation and Message Passing don't currently work.
I created BN from a BIF file (asia.bif) . But when I try to find the score using BDe with 'lizards.csv' it is failing.
Code -
from pyBN import *
import numpy as np
import os
from os.path import dirname
file = 'data/asia.bif'
bn = read_bn(file)
dpath = os.path.join(dirname(dirname(dirname(dirname(file)))),'data')
path = (os.path.join(dpath,'lizards.csv'))
data = np.loadtxt(path, dtype='int32',skiprows=1,delimiter=',')
print BDe(bn,data)
Traceback (most recent call last):
File "test.py", line 12, in
print BDe(bn,data)
File "/home/sonu/Documents/pyBN/pyBN-master/pyBN/learning/structure/score/bayes_scores.py", line 61, in BDe
counts_dict = mle_fast(bn, data, counts=True, np=True)
File "/home/sonu/Documents/pyBN/pyBN-master/pyBN/learning/parameter/mle.py", line 41, in mle_fast
F[n]['values'] = list(nmp.unique(data[:,i]))
IndexError: index 3 is out of bounds for axis 1 with size 3
The algorithm in topsort() is slightly different from the one in wiki. When there is a triangle like A->B->C and A->C, the function could return a wrong result [A, C, B], depending on the order of the input edge_dict.
There is a note in the MLE estimator code that says:
Notes
-----
- Currently doesn't return correct solution
Is this still true? can it return the correct solution?
populate those and make decisions on their design/use
Remove bn.data structure and replace it with a numpy list of "Factor" objects.. they both hold the same information but the Factor object is much faster..
mle and bayesian methods
Drawing/Plotting is having some issues due to graphviz/dot engine..
Currently doesn't work.
Write code for edge orientation after structure learning - for instance, PC algorithm only gives an undirected graph right now. Perhaps make "orient=True" as an argument so users don't have to orient them (ala bnlearn)
test and rewrite factor code
delete/add as necessary
In pyBN.learning.structure.tree.chow_liu
for i,j,w in edge_list:
if i in vertex_cache and j not in vertex_cache:
mst[i].append(j)
vertex_cache.add(j)
elif i not in vertex_cache and j in vertex_cache:
mst[j].append(i)
vertex_cache.add(i)
This code is wrong. Since once an edge i->j both not in vertex_cache, It will not be considerred any longer. Even later, when one of them, say i, is added to vertex_cache, apparently i->j would be a safe link, but won't be considerred, leading to worse spanning tree.
If you are implementing the Kruskal's algorithm, then you should consider the isolated components in current forest, and include the edge when FIND-SET(i) ~= FIND-SET(j).
If you are implementing the Prim's algorithm, then you probably should use a while loop. And inside it, use priority queue (max heap) to add max weight node into the mst.
Make sure marginal inference works after moving the main drivers away from the respective classes and into the inference folder.
get networkx out of the package. Currently mostly used for topological sort - write my own in numba
check algorithm
Functionality for drawing BNs -- perhaps using networkx?
I would like to try your code. Do you have an installer that works with newer versions of Python? Currently, I cannot get the code to execute. Ideally, setup.py should be run with
pip install setup.py
but the code does not appear to work in that way. Any help is appreciated. Thanks.
Hi,
I am trying to use this package, but I cannot install it on my system. I could download and unziped the pyBN-master correctly. Then I opened my anaconda prompt and changed the directory to cd /d D:......\pyBN-master. After that I typed python and then typed "from pyBN import" as mentioned in the "Usage" section, but I faced the SyntaxError: invalid syntax
It would be appreciated if anyone could help me.
Best,
there is a erroe: ModuleNotFoundError: No module named 'pyBN.structure_learn'
I want using another scoring function to learn the structure, I wonder if there is a example for structure_learn using bic, bde or LL.
thanks a lot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.