Giter Site home page Giter Site logo

pybn's Issues

topsort() is wrong

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.

Chow Liu Tree code wrong

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.

model merging

Code to merge BNs based on parameters (assuming identical structure).. and maybe structure eventually.

edge orientation for structure learning

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)

Newer versions of numpy (>= 1.12.0) does not accept float as array index

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.

fileio

make sure fileio works.

unable to install pyBN

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,

major bn.data design change

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..

hill_climbing

In the hill_climbing function, I have to insert ''data''. How is made this array?

Installing the software

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.

Plotting BNs

Functionality for drawing BNs -- perhaps using networkx?

networkx reliance

get networkx out of the package. Currently mostly used for topological sort - write my own in numba

Plotting Issues

Drawing/Plotting is having some issues due to graphviz/dot engine..

MLE Estimator

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?

BDe score

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)

Error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.