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.2.tar.gz (201.2 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.2-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.2-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pasp_plp_uas-0.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pasp_plp_uas-0.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pasp_plp_uas-0.1.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: pasp_plp_uas-0.1.2.tar.gz
  • Upload date:
  • Size: 201.2 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.2.tar.gz
Algorithm Hash digest
SHA256 27fbedc1a9c5fa6c0a8f2c404228ccdb8bb9329be72a527956f66bf18a72d6f6
MD5 6aba3be3e9fc7251fc760cc6ee69e1f9
BLAKE2b-256 b473338f79aaacc6d80557d74b7ebcd97b0fdaff2ab66355920aab13126982a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2.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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e3f48a4f291d1b7e249cef0ea54a3ed7109d04379bff8d6869c32ba0574a21e
MD5 4ba9819bfc3a38d96b60b7e68df43772
BLAKE2b-256 28f64314ff6e3b91c9a7828b8b013a381e2d0534027292e72e86e5592c8790c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0af82d1c252709cd98fe59dc4a262bf8ead8399991c76efdf7d1e1df48dce5bf
MD5 8a420aaf6566d6e57287e33a1dc64734
BLAKE2b-256 25d7cdd5d1d02bb8e10a55051ebfd9f3b155d4a9f4007cb78b5366bb98826c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecc10e94487f245d5f3a8b5976064127c678db0d19b883c4d975b932fd639c95
MD5 e8199286c180b797c1797752f55eb353
BLAKE2b-256 4fdb166d3a824637f4ddebf98ddd4165706b6f199d6019533e27b82f3686b142

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3807a1b8a507f7dd5a9fa43eb168d31b1df05fcc533685515587bd24530deb7
MD5 a17b3af8d9133ae9040daf6e2e47c7c7
BLAKE2b-256 e49ff7d6d62382f4b23949a59d03af1a299a3134d7a09dfaa2ae63a602a1d227

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b3fe54ee5fb34d89653912938530095648b0b9aaefffe3bd104e5cf29195b2d
MD5 a7a33f7764a3e5cdc8e6b97144c556b4
BLAKE2b-256 cbec2fb689f87be6c2e65d233873403db5a12daef7e092058be0876fb49a0ca3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd64802c807571e57634294b85cf58bba41fab56d562017c51bc4bc5a7ea1430
MD5 e13690643a2daa113b872fb88e5af550
BLAKE2b-256 0518c54967ea7436fa76bfccad628153933fe108720cc24016ccd31239e8d1cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a847129658586cf282539eda9a307b424ec86b72a5100140cf538616f64bdd4b
MD5 62d617ab1040524901040a36f431ef04
BLAKE2b-256 d20ab6e3a94a48df187dc4bdae8238c7bcdc316d7333d8176a6f02675c1303e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6525db194101a462d61d00b03abd31f6898546c4fbf436338fb467bb8e2532c
MD5 b3e69d6b9112d773c3c8f846f7e42d59
BLAKE2b-256 de1dc781be792dfdb7734cae602996d74b2d8c55f408fa699137e6b2507eed11

See more details on using hashes here.

Provenance

The following attestation bundles were made for pasp_plp_uas-0.1.2-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