Skip to main content

Probabilistic Answer Set Programming

Project description

dPASP: A Flexible Framework For Neuro-Probabilistic Answer Set Programming

Tests Docs GitHub

The dPASP framework provides a high-level declarative language for describing sophisticated probabilistic reasoning tasks that can combine perception and logical reasoning. dPASP programs are made of probabilistic choices and logic rules (think of if-then rules), allowing easy specification of uncertain and logic knowledge. Notably, the probabilities in the program can arise as outputs of neural network classifiers, and both the statistical model and logic program can be jointly optimized by making use of efficient gradient-based learning libraries (e.g. PyTorch).

Getting Started

dPASP has both a domain-specific language (DSL) and command-line interpreter (parser) for that language, which can be used as a standalone tool. Alternatively, dPASP can be accessed as Python library or more directly through its C backend.

The easiest way to get started is by reading the tutorial Learning dPASP Through Examples

Features

dPASP allows for several semantics by combining logic programming semantics and probabilistic semantics:

Logic semantics

  • Stable semantics;
  • Partial Stable semantics;
  • L-Stable semantics;
  • smProbLog semantics.

Probabilistic semantics

  • Credal semantics;
  • MaxEnt semantics.

There are two uses of the systems: learning and querying. Currently, learning is only available for the MaxEnt-Stable semantics.

Learning and querying can either be made by (highly inneficient) enumerative algorithms and (more efficient) approximate inference. Enumerative algorithms are available to all possible (logic and probabilistic) semantics, while currently only MaxEnt-Stable semantics implements all approximate algorithms. Developing more efficient and accurate approximate algorithms is a current active line of research.

Example

Here's a simple example of dPASP for inference in probabilistic logic programs (no neural networks and no learning).

Assuming you have dPASP installed and configured (see the tutorial if not), open a Python Shell and load the Python library by:

pasp examples/earthquake.plp

One may need to manipulate output probabilities, in which case the Python API can be used instead.

import pasp

To parse the program into dPASP internal's data struct we use

P = pasp.parse("examples/earthquake.plp")

We can also specify a probabilistic logic program string using the dPASP DSL. Here we have a program enconding graph 3-coloring (lines starting with % are comments):

program_str = '''
% Build a random graph with n vertices.
#const n = 5.
v(1..n).
% The choice of p reflects the sparsity/density of the random graph.
% A small p produces sparser graphs, while a large p prefers denser graphs.
0.5::e(X, Y) :- v(X), v(Y), X < Y.
e(X, Y) :- e(Y, X).
% A color (here the predicate c/2) defines a coloring of a vertex.
% The next three lines define the uniqueness of a vertex's color.
c(X, r) :- not c(X, g), not c(X, b), v(X).
c(X, g) :- not c(X, r), not c(X, b), v(X).
c(X, b) :- not c(X, r), not c(X, g), v(X).
% Produce a contradiction if two neighbors have the same color.
f :- not f, e(X, Y), c(X, Z), c(Y, Z).

#semantics lstable.

% Query the probability of vertex a being red.
#query(c(1, r)).
% Query the probability of the edge e(1, 2) existing given that the graph is not 3-colorable.
#query(e(1, 2) | undef f).
% Query the probability of the graph not being 3-colorable.
#query(undef f).'''

We may then pass program_str to dPASP as a string by using the from_str=True keyword.

P = pasp.parse(program_str, from_str=True)

You can check that the program was correctly parsed by inspecting the object P

>>> P
<Logic Program:
#const n = 5.
v(1..n).
e(X, Y) :- e(Y, X).
_e(X, Y) :- _e(Y, X).
c(X, r) :- not _c(X, g), not _c(X, b), v(X).
_c(X, r) :- not c(X, g), not c(X, b), _v(X).
c(X, g) :- not _c(X, r), not _c(X, b), v(X).
_c(X, g) :- not c(X, r), not c(X, b), _v(X).
c(X, b) :- not _c(X, r), not _c(X, g), v(X).
_c(X, b) :- not c(X, r), not c(X, g), _v(X).
f :- not _f, e(X, Y), c(X, Z), c(Y, Z).
_f :- not f, _e(X, Y), _c(X, Z), _c(Y, Z).
_c(X, g) :- c(X, g).
_e(X, Y) :- e(X, Y).
_c(X, b) :- c(X, b).
_f :- f.
_c(X, r) :- c(X, r).
_v(1..n) :- v(1..n).,
Probabilistic Rules:
[0.5::e(X, Y) :- v(X), v(Y), X < Y],
Queries:
[(c(1,r)), (e(1,2) | undef f), (undef f)]>

To run the program:

>>> P()
(c(1,r)) = [0.000000, 1.000000]
(e(1,2) | undef f) = [0.772727, 0.772727]
(undef f) = [0.064453, 0.064453]
---
Querying:                                                               0h00m01s
array([[0.        , 1.        ],
       [0.77272727, 0.77272727],
       [0.06445312, 0.06445312]])

Acknowledgments

This software is being developed by the KAMeL group and the Center for Artificial Intelligence of the University of São Paulo. If you use this software, please acknowledge by citing the paper below:

https://proceedings.kr.org/2024/69/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pasp_plp_uas-0.1.3.tar.gz (203.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pasp_plp_uas-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pasp_plp_uas-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pasp_plp_uas-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pasp_plp_uas-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pasp_plp_uas-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pasp_plp_uas-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pasp_plp_uas-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pasp_plp_uas-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pasp_plp_uas-0.1.3.tar.gz.

File metadata

  • Download URL: pasp_plp_uas-0.1.3.tar.gz
  • Upload date:
  • Size: 203.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pasp_plp_uas-0.1.3.tar.gz
Algorithm Hash digest
SHA256 77597ce782471c20ca40b534e039a5af599ce84551afce8afc9156de3829e296
MD5 74221d879780759a8b6f8e1c0b1b75f1
BLAKE2b-256 123617fd16ef3fef48f768d58563ccbfeac1eb25dfe440da5012aca93c7289b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3.tar.gz:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5242c520020aee361e321e2848c7860c4e0e45d6ce0302025c6e9aeee9e08c4a
MD5 25234afae8898a86757b78f8b47dc20f
BLAKE2b-256 526131ebb8b0eb8fcc88304a35c7c4c50d868e3b333483376a77c8ded3ae2e1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9eae7c1160f5755b6618c59036a2f9a08ca34a6f85c447a7cc3d3f99e219d831
MD5 3f15f8b749d9a16d53eab7a00d709123
BLAKE2b-256 96a885485e3d6c8d071dc4b48be52b9d749c48f642915acd2293c0feea599743

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47e6c788d0fc1fc2b94799fc27d744b0c52e29ff00d48e1b5bb9cf7e06c3bbf6
MD5 70350664b19d4f31ffcebf7ef3c71b76
BLAKE2b-256 373b83d4c733378a5f80d4813c83603625c07cea179c777044b311cf591fb7b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aeea34539abd082880f4e907b8c82b6d140f877cbc381d2ae2e3aa9ed466ac70
MD5 8e1cec467cdd7cb531dadf0ebb6f04a0
BLAKE2b-256 83443be068f3fbe2e0383a335c2bdc4c8622b38a63e050a549107916a8cddfdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7059073bd0c5fc8c1612404147176661cf8cdba57bb199863e39f8c27ea96bb4
MD5 89d55a0600430b773bc4f8268097bbcd
BLAKE2b-256 760d36eee644b36337d19e11892d6cdcba06b90729afa72b1a2fcb57867cc424

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f2d1c4fe57c2482a520b63aa5e9746142f01719aa776fd67f244fb0deeac66b
MD5 68aebc9c1d8296e49c308bc182264afd
BLAKE2b-256 b313b07b6e2ab9dd55ac7654bf61226e44e5646d2bf4829255409e3bae376d4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 144c3bd5c98c66fed8793da728f84efffc39aa68bdb5a30d5541d8108d5fbb75
MD5 6f3773a71bee668777db5e9f66437e83
BLAKE2b-256 a62fc98128ce0459a6890bbc95e21503318bf9db59bb0d0c76fd92ed262d1712

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pasp_plp_uas-0.1.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 320fd7d07b58d011f2fc2f750aa92ce057ed360da71c51db326dc14b9ae2791c
MD5 e279950d662ff6701f9b507790d66c7a
BLAKE2b-256 f3d94da5079b11f5b7c8358d933204d7219d14722a366c443ee76b09c09ec5a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.3-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on stedonnelly/dpasp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page