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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pasp_plp_uas-0.1.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: pasp_plp_uas-0.1.1.tar.gz
  • Upload date:
  • Size: 200.8 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.1.tar.gz
Algorithm Hash digest
SHA256 10a536e161fd82ea3952d4928042afcfff9b7a74e20ccb7dd5f84e5b629768d7
MD5 40b409cf21d50f34ec890a6e6aa19fa4
BLAKE2b-256 6c89fdefa93ce2484bc6ce166c9562bc1b7b9395a2d7bae62c659bfea6c6666f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99f1ffa97933eb1a9511bf4fa51e5e50f9b8ff6b78a52610557ef400e90a347b
MD5 a2dd535310dd1e6a3f7b468e6d45a67c
BLAKE2b-256 4d37797a9427a7c9652e29ad48107a210b9a19ddf913e2c485020ce00ad66809

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eddbf6bee72d93856d3e1f8cb5064f8f69fa747f1257c87e470790465ba5b0ce
MD5 7ff14a391d3d852eddf9d4ae27f3f82a
BLAKE2b-256 549e83f2d3f92fd43ec59e5b8760d1110911f5d191d154ae74d971cd17ec029b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ad09b8a8389765105587d1cd0bd24dccaa01e3097a5a11fdced869ca8ddfc28
MD5 760425adcc6020991de8d880597bc002
BLAKE2b-256 436cabcc3ed6d397617076adb68cc3ca64fd0642434faf6af8168a12ad202c17

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3f4aa75004867f092646a2ad0b776921d3b36d11b7d5b01a7249c71271111a2
MD5 581a10c99c0258eab8eb19c1e27d09b0
BLAKE2b-256 d93ca94bfca0dbb40f64bb50b280c9205b0ae3e9c4f943e1fe4f80d84b6e74ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94ef77ada2f7d078eee9f7fa48c8abcb570e7e2dd084296dfacdc9081e97a92c
MD5 40f8fd38c705f0c63c6b931ad21c6cda
BLAKE2b-256 5d28ece38f066598c1590ceb891e8c240df9722298dcbd52106a89335e76dfaf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b28429a7fcabeb6e9688bc0803b022b65c515b4eaf2fb7bd618c9d3afb9c7111
MD5 2b12e803dd5e2c97d126c2db57aebf79
BLAKE2b-256 1d999397e839690ba3ab4c297b0ff5383e8605bca6df655025ab3cf42861e24b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7cd47839b3dbc9db453d34f2e1e7c1030e71295c643e1d08c13a3367da7b682
MD5 24c3f56f038fe93dd607fdafef212bf3
BLAKE2b-256 681c986f65bcb252eb945155d86c85c5701a229f5f9cc95dae52c4e83ae29dd4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pasp_plp_uas-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ca8ebc5d71a06fafa9e153fc4064b34514a25002b0aa7366078ac5b7ce0b810
MD5 946d0e8f73977b304d0ab31a00bf2525
BLAKE2b-256 87c621dee2258d5aa52ab8e2f195926d45a031dca28c795c5c0c744e3f7fd3ff

See more details on using hashes here.

Provenance

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