gbnnetwork


Namegbnnetwork JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryImplementation of Bayesian network.
upload_time2023-02-09 20:39:43
maintainer
docs_urlNone
authorGuillermo
requires_python
license
keywords python probability bayes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# BNNetwork Library
Esta librería permite crear redes Bayesianas a partir de la probabilidad condicional de cada nodo.

 ## Instalar
`pip install gbnnetwork`

## Uso
Para crear una Red de Inferencia, se deben de seguir los siguientes pasos:
1. Crear una instancia de la clase BNNetwork `network = BNetwork()`
2. Agregar variables a la red `network.add_variable("A")`
3. Asignar los padres de cada variable (en caso la variable no tenga padres este paso se puede omitir) `network.set_parents_to_variable("A", ["B", "E"])`
4. Agregar las probabilidades a las variables para definir la red totalmente. **Toda la red debe de estar definida si se desea responder cualquier consulta** `network.add_probability("A|BE", 0.001)`
5. Hacer una query `p = network.inference({'B': False}, {'A': False})`

## Funciones De Utilidad
1. Obtener la representación compacta `network.compact_string()` (string)
2. Obtener los factores de la red `network.factor_string()` (string)
3. Saber si la red esta totalmente definida `network.validate_defined_state()` (boolean)

## Ejemplo
Tomando como referencia el siguiente documento: https://people.cs.pitt.edu/~milos/courses/cs2740/Lectures/class19.pdf

La red que se propone tiene la siguiente topología:
![Example Network](example_network.png)

Se procede de la siguiente manera:

```python
from gbnnetwork import BNetwork
network = BNetwork()    # Paso 1

# Paso 2
network.add_variable("B")
network.add_variable("E")
network.add_variable("A")
network.add_variable("J")
network.add_variable("M")

# Paso 3
network.set_parents_to_variable("A", ["B", "E"])
network.set_parents_to_variable("J", ["A"])
network.set_parents_to_variable("M", ["A"])

# Paso 4
network.add_probability("B", 0.001)
network.add_probability("E", 0.002)
network.add_probability("A|BE", 0.95)
network.add_probability("A|-BE", 0.29)
network.add_probability("A|B-E", 0.94)
network.add_probability("A|-B-E", 0.001)
network.add_probability("M|A", 0.7)
network.add_probability("M|-A", 0.01)
network.add_probability("J|A", 0.9)
network.add_probability("J|-A", 0.05)

# Hacer la query P(B=True|J=True,M=True)
p = network.inference({'B': True}, {'J': True, 'M': True})  # 0.2841718353643929 = 28%

```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "gbnnetwork",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,probability,bayes",
    "author": "Guillermo",
    "author_email": "san191517@uvg.edu.gt",
    "download_url": "https://files.pythonhosted.org/packages/b9/7c/30a99dda3ab6f335e6461d8ebc2f4ccfbc1475c18dc15248c9973f869979/gbnnetwork-1.0.0.tar.gz",
    "platform": null,
    "description": "\n# BNNetwork Library\nEsta librer\u00eda permite crear redes Bayesianas a partir de la probabilidad condicional de cada nodo.\n\n ## Instalar\n`pip install gbnnetwork`\n\n## Uso\nPara crear una Red de Inferencia, se deben de seguir los siguientes pasos:\n1. Crear una instancia de la clase BNNetwork `network = BNetwork()`\n2. Agregar variables a la red `network.add_variable(\"A\")`\n3. Asignar los padres de cada variable (en caso la variable no tenga padres este paso se puede omitir) `network.set_parents_to_variable(\"A\", [\"B\", \"E\"])`\n4. Agregar las probabilidades a las variables para definir la red totalmente. **Toda la red debe de estar definida si se desea responder cualquier consulta** `network.add_probability(\"A|BE\", 0.001)`\n5. Hacer una query `p = network.inference({'B': False}, {'A': False})`\n\n## Funciones De Utilidad\n1. Obtener la representaci\u00f3n compacta `network.compact_string()` (string)\n2. Obtener los factores de la red `network.factor_string()` (string)\n3. Saber si la red esta totalmente definida `network.validate_defined_state()` (boolean)\n\n## Ejemplo\nTomando como referencia el siguiente documento: https://people.cs.pitt.edu/~milos/courses/cs2740/Lectures/class19.pdf\n\nLa red que se propone tiene la siguiente topolog\u00eda:\n![Example Network](example_network.png)\n\nSe procede de la siguiente manera:\n\n```python\nfrom gbnnetwork import BNetwork\nnetwork = BNetwork()    # Paso 1\n\n# Paso 2\nnetwork.add_variable(\"B\")\nnetwork.add_variable(\"E\")\nnetwork.add_variable(\"A\")\nnetwork.add_variable(\"J\")\nnetwork.add_variable(\"M\")\n\n# Paso 3\nnetwork.set_parents_to_variable(\"A\", [\"B\", \"E\"])\nnetwork.set_parents_to_variable(\"J\", [\"A\"])\nnetwork.set_parents_to_variable(\"M\", [\"A\"])\n\n# Paso 4\nnetwork.add_probability(\"B\", 0.001)\nnetwork.add_probability(\"E\", 0.002)\nnetwork.add_probability(\"A|BE\", 0.95)\nnetwork.add_probability(\"A|-BE\", 0.29)\nnetwork.add_probability(\"A|B-E\", 0.94)\nnetwork.add_probability(\"A|-B-E\", 0.001)\nnetwork.add_probability(\"M|A\", 0.7)\nnetwork.add_probability(\"M|-A\", 0.01)\nnetwork.add_probability(\"J|A\", 0.9)\nnetwork.add_probability(\"J|-A\", 0.05)\n\n# Hacer la query P(B=True|J=True,M=True)\np = network.inference({'B': True}, {'J': True, 'M': True})  # 0.2841718353643929 = 28%\n\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Implementation of Bayesian network.",
    "version": "1.0.0",
    "split_keywords": [
        "python",
        "probability",
        "bayes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "67d5ecdef467ff5d38b2155802122a8fa8d78cb4792f8e3331a72ccc3ae8c3dd",
                "md5": "479749dd63fc69ed5bf5a91023626008",
                "sha256": "b24d65ba8092b8a516eff8ade79d8a2b9b681b1ec71e5a4bdf3a8584a672ec27"
            },
            "downloads": -1,
            "filename": "gbnnetwork-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "479749dd63fc69ed5bf5a91023626008",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3915,
            "upload_time": "2023-02-09T20:39:41",
            "upload_time_iso_8601": "2023-02-09T20:39:41.349072Z",
            "url": "https://files.pythonhosted.org/packages/67/d5/ecdef467ff5d38b2155802122a8fa8d78cb4792f8e3331a72ccc3ae8c3dd/gbnnetwork-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b97c30a99dda3ab6f335e6461d8ebc2f4ccfbc1475c18dc15248c9973f869979",
                "md5": "bf0ce10760394396c38fefe14d03226f",
                "sha256": "7fe79ecf591cf15855e7420bd380c8cd9a148de34f92f522403e4ee6c729f204"
            },
            "downloads": -1,
            "filename": "gbnnetwork-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bf0ce10760394396c38fefe14d03226f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3667,
            "upload_time": "2023-02-09T20:39:43",
            "upload_time_iso_8601": "2023-02-09T20:39:43.017146Z",
            "url": "https://files.pythonhosted.org/packages/b9/7c/30a99dda3ab6f335e6461d8ebc2f4ccfbc1475c18dc15248c9973f869979/gbnnetwork-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-09 20:39:43",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "gbnnetwork"
}
        
Elapsed time: 0.43242s