cyberpoint / libpgm Goto Github PK
View Code? Open in Web Editor NEWA library for creating and using probabilistic graphical models
License: BSD 3-Clause "New" or "Revised" License
A library for creating and using probabilistic graphical models
License: BSD 3-Clause "New" or "Revised" License
[old comment]
Hi Charles,
I found another bug that might be rather important. When I change the data ordering, I find that the estimatestruct does not give the same PDAG. Since the data points are the same, the PDAG should be unique regardless of the data points ordering (the DAG could be different as you have pointed out).
I have sent a test data (.npz) and a test script (.py) to your email. It would be great to have your opinion on this issue.
Thank you!
Cheers,
Yuan-Sen
Hi,
I've build a Hybrid Bayesian Network, and now I'm trying to use the choose method of a Discrete node, but what happens is that python tells me this:
File "C:\Users\eliam\Miniconda2\lib\site-packages\libpgm\CPDtypes\discrete.py", line 71, in choose
pvalues = [str(outcome[t]) for t in self.Vdataentry["parents"]] # ideally can we pull this from the skeleton so as not to store parent data at all?
NameError: global name 'outcome' is not defined
And actually, looking at the code there's something strange I don't understand going on in that function: basically the parameter pvals is completely ignored, instead it builds it's own pvals using some kind of list named outcome that doesn't exist in the file though..
Was this library abandoned?
I added Python 3 support with this pull request: #19
However, I'm missing some of the most recent changes. So can someone review that my code works with all parts of Python3?
I tested my code against https://github.com/CyberPoint/libpgm/blob/master/examples/examples.py
as such:
python3 examples.py
and got no errors, but that doesn't mean it covers the full suite of possible python 3 compatability issues. But I do think it's a good start! Please give direction on further testing so I may complete full Python 3 compatibility.
How is it possible to deliver a package with so wide use and general naming? It's affecting all other dependencies, above all internal apps which have a utils package. Would you refactor it moving it to libpgm.utils or rename it to something like libpgm_utils? It's not a very good practice to deliver packages with this kind of modules on top level with generic names.
Does libpgm supports integer values ? Even though I gave integer values in json file, those are taken as string. I could see them as string when it is dumped again.
Does libpgm support learning hybrid network parameters from data?
Hi there,
I came across another bug in the dev_struct_finding branch. When libpgm calculates the likelihood, it calls norm(loc=mean, scale=variance). It should be scale=np.sqrt(variance).
Thanks.
Cheers,
Yuan-Sen
I use discrete_constraint_estimatestruct to learn structure, it failed and return
Traceback (most recent call last):
File "fs.py", line 77, in
result = learner.discrete_constraint_estimatestruct(bn_data)
File "/Users/zhuting/Projects/PyWorkspace/BayesianNet/venv/lib/python2.7/site-packages/libpgm/pgmlearner.py", line 590, in discrete_constraint_estimatestruct
pdag.toporder()
File "/Users/zhuting/Projects/PyWorkspace/BayesianNet/venv/lib/python2.7/site-packages/libpgm/graphskeleton.py", line 146, in toporder
assert (not Ecopy), ("Graph contains a cycle", Ecopy)
AssertionError: ('Graph contains a cycle', [[164, 21], [21, 58], [21, 16], [16, 11], [58, 164], [11, 67], [16, 2], [164, 2]])
There is still some issue with python3.4.
The way you use print in bntextutils is not supported in python3.4. I made some small changes and its working fine. Could you please do the change for others.
I can't seem to run multiple specific queries without completely rebuilding my BN and then regenerating a TableCPDFactorization:
learner = PGMLearner()
bn = learner.discrete_mle_estimateparams(graphSkeleton, observations)
query = dict(poisonous='e')
evidence = dict()
factorization = TableCPDFactorization(bn)
print(factorization.specificquery(query, evidence))
factorization.refresh()
query = dict(poisonous='p')
evidence = dict()
print(factorization.specificquery(query, evidence))
This yields a probability for the first call to specificquery()
. The second call, however, gives me:
Traceback (most recent call last):
File "/Users/brennon/Downloads/text-generator/mushrooms/pima/nb-pgm.py", line 109, in <module>
print(factorization.specificquery(query, evidence))
File "/Library/Python/2.7/site-packages/libpgm/tablecpdfactorization.py", line 268, in specificquery
self.condprobve(query, evidence)
File "/Library/Python/2.7/site-packages/libpgm/tablecpdfactorization.py", line 182, in condprobve
eliminate.remove(key)
ValueError: list.remove(x): x not in list
If I persist V
, E
, and Vdata
from my original BN, rebuild my DiscreteBayesianNetwork
, generate a new TableCPDFactorization
, and then call specificquery()
again, all is well. This seems crazy, though. Isn't this the purpose of refresh()
?
The build directory has files that are different than the original source files. Therefore, distutils installs an old version of the files instead of the new version.
Take for instance "utils/bntextutils.py". This file is different than "build/lib/utils/bntextutils.py".
On running:
from libpgm.discretebayesiannetwork import DiscreteBayesianNetwork
I am getting the issue below:
File "/usr/local/lib/python3.6/dist-packages/utils/bntextutils.py", line 22
print "%s --> %s" % (e[0], e[1])
^
SyntaxError: invalid syntax
[old comment]
I believe ' random.seed() ' should be removed in all of the following files. Its use sets the seed to some random value every time the library is used. Because of this, it is impossible to replicate any results exactly. Instead, user should be able to specify the desired seed before the library is used - and package should not override his choice.
List of files:
libpgm/CPDtypes/discrete.py
libpgm/CPDtypes/lg.py
libpgm/CPDtypes/lgandd.py
libpgm/hybayesiannetwork.py
libpgm/lgbayesiannetwork.py
libpgm/discretebayesiannetwork.py
libpgm/dyndiscbayesiannetwork.py
libpgm/tablecpdfactorization.py
Dear authors,
Thank you for writing this useful library.
I have built a discrete Bayesian network using your library. I would like to ask whether it is possible to perform inference using soft evidence, by specifying the individual state probabilites. Something like { x: [0.5, 0.2, 0.3] }
Not sure if this is the right forum to make this request. Apologies if it is not.
Cheers
Zack
I'm using Lgandd with discrete parents only. The documentation says that such nodes must have one or more discrete parents and one or more Lg parents.
As far as I can tell from the source code, it should work correctly exclusively with discrete parents. Is that correct or am I missing something?
The problem is that it works, but I get a warning message each time a sample is drawn:
Did not find LG and discrete type parents.
Using the student Discrete Bayesian Network example provided on the website. I'm not able to query
the distribution
tableCPD.specificquery(dict(Intelligence='high'),dict())
throws the following error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-cf3eec4eb42c> in <module>()
1 tableCPD.refresh()
----> 2 tableCPD.specificquery(dict(Intelligence='high'),dict())
/usr/local/lib/python2.7/dist-packages/libpgm/tablecpdfactorization.pyc in specificquery(self, query, evidence)
279 visited[var] = False
280 for poss in query[var]:
--> 281 rindices[var].append(self.bn.Vdata[var]["vals"].index(poss))
282
283 # define function to help iterate recursively through all combinations of variables
ValueError: 'h' is not in list
The fix I found for this is to pass the value as a list, like so
tableCPD.specificquery(dict(Intelligence=['high']),dict())
poss in line 280 holds individual characters of the string instead of the entire value. Not sure how it worked before. Any ideas? Running python 2.7.6, Ipython 4.0.0
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.