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 semantics;
  • L-Stable semantics.

Probabilistic semantics

  • Credal semantics;
  • MaxEnt semantics.

There are two uses of the systems: learning and querying. Currently, learning allows only for 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:

import pasp

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

program_str = '''
% DOMAIN
#const n = 5.
vertex(1..n).
% Specifies a random graph
0.5::edge(X, Y) :- vertex(X), vertex(Y), X < Y.
edge(X, Y) :- e(Y, X).
% Disjunctive specify specify candidate solutions 
color(X, red); color(X,blue); color(X,green) :- vertex(X).
% Constraints discard invalid candidate solutions
:- edge(X, Y), color(X, Z), color(Y, Z).
% We use directives to select a semantics (other options are `partial`, `lstable`, `credal`)
#semantics maxent.
% Directive also specify the query, in this case the probability that node 1 is colored red
#query color(1,red).
'''

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

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

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

>>> P()

To run exact (enumerative) inference, do:

pasp.exact(P)

You can also run inference with a specified semantics: To run exact (enumerative) inference, do:

pasp.exact(P, psemantics="credal", semantics="stable")

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://arxiv.org/abs/2308.02944

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-0.0.5.tar.gz (30.6 MB view details)

Uploaded Source

File details

Details for the file pasp_plp-0.0.5.tar.gz.

File metadata

  • Download URL: pasp_plp-0.0.5.tar.gz
  • Upload date:
  • Size: 30.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

File hashes

Hashes for pasp_plp-0.0.5.tar.gz
Algorithm Hash digest
SHA256 94b7b385b5d3c44157a9fc2bb57c71ca30f206dc7d1585dd9d74d34be482bb73
MD5 60ac4dc7380709d9e5185fb4e819ed73
BLAKE2b-256 51d1be0e0be64e15d85dade4f18017a093f312aded8a2bf0264db46482b7207b

See more details on using hashes here.

Supported by

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