Giter Site home page Giter Site logo

libpgm's Introduction

libpgm

A library for creating and using probabilistic graphical models Developed by James Ulrich and Charlie Cabot at Cyberpoint LLC (www.cyberpointllc.com).

Copyright 2013 CyberPoint International LLC.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) Neither the name of the CyberPoint International, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CYBERPOINT INTERNATIONAL, LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

libpgm's People

Contributors

benavente avatar cccabot avatar dov avatar ericschles avatar irwincong avatar mikewestcp avatar raugasm avatar schaeferpp avatar yegortk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libpgm's Issues

dev_struct_finding : typo + bug

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

Soft evidence in libpgm

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

Problematic 'utils' module at top level root in site-packages

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.

TableCPDFactorization.specificquery() for Discrete BN throws Value Error

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

Issue with setting the seed for experiment replication

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

discrete_constraint_estimatestruct assert Graph contains a cycle

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]])

compatablity with python3.4

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.

Compatability with Python 3

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.

Lgandd with discrete parents only

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.

Method choose from Discrete node not working

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

Integer values

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.

lg_constraint_estimatestruct does not give the same ordering

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

Error while importing DiscreteBayesianNetwork on Colaboratory

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

Multiple specific queries?

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 should probably be empty

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

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.