neurolang.probabilistic.cplogic.program module

class neurolang.probabilistic.cplogic.program.CPLogicMixin(*args, **kwargs)

Bases: PatternWalker

Datalog extended with probabilistic facts semantics from ProbLog.

It adds a probabilistic database which is a set of probabilistic facts.

Probabilistic facts are stored in the symbol table of the program such that the key in the symbol table is the symbol of the predicate of the probabilsitic fact and the value is the probabilistic fact itself.

Attributes:
patterns

Property holding an iterator of triplets (pattern, guard, action).

pchoice_pred_symbs
pfact_pred_symbs
predicate_symbols
probabilistic_predicate_symbols

Methods

add_probabilistic_choice_from_tuples(symbol, ...)

Add a probabilistic choice from a predicate symbol and a set of tuples where the first element is the probability label attached to a head predicate and the other elements are the constant terms of the head predicate.

add_probabilistic_facts_from_tuples(symbol, ...)

Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple.

match(expression)

Find the action for a given expression by going through the patterns.

pattern_match(pattern, expression)

Return True if pattern matches expression.

pchoice_pred_symb_set_symb

pfact_pred_symb_set_symb

probabilistic_choices()

Return probabilistic choices of the symbol table.

probabilistic_facts()

Return probabilistic facts of the symbol table.

query_based_probabilistic_choice(implication)

Construct probabilistic choices from deterministic queries.

query_based_probabilistic_fact(implication)

Construct probabilistic facts from deterministic queries.

query_based_probabilistic_predicate(implication)

Left for backward compatibility.

type

extensional_database

marg_implication

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

probabilistic_fact

union_with_probabilistic_facts

walk

within_language_marg_query

within_language_prob_queries

within_language_succ_query

add_probabilistic_choice_from_tuples(symbol, iterable)

Add a probabilistic choice from a predicate symbol and a set of tuples where the first element is the probability label attached to a head predicate and the other elements are the constant terms of the head predicate.

Examples

The following

>>> P = Symbol('P')
>>> tuples = {(0.2, 'a'), (0.8, 'b')}
>>> program.add_probabilistic_choice_from_tuples(P, tuples)

adds the probabilistic choice

P(a) : 0.2 v P(b) : 0.8 <- T

to the program.

add_probabilistic_facts_from_tuples(symbol, iterable)

Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple.

Examples

The following

>>> P = Symbol('P')
>>> tuples = {(0.9, 'a'), (0.8, 'b')}
>>> program.add_probabilistic_facts_from_tuples(P, tuples)

adds the probabilistic facts

P(a) : 0.9 <- T P(b) : 0.8 <- T

to the program.

extensional_database()
marg_implication(implication)
pchoice_pred_symb_set_symb = S{__pchoice_pred_symb_set_symb__: Unknown}
property pchoice_pred_symbs
pfact_pred_symb_set_symb = S{__pfact_pred_symb_set_symb__: Unknown}
property pfact_pred_symbs
property predicate_symbols
probabilistic_choices()

Return probabilistic choices of the symbol table.

probabilistic_fact(expression)
probabilistic_facts()

Return probabilistic facts of the symbol table.

property probabilistic_predicate_symbols
protected_keywords = {'PROB'}
query_based_probabilistic_choice(implication)

Construct probabilistic choices from deterministic queries.

This extends the syntax with rules such as

Or_x P(x) : f(x) :- Q(x)

where x is a set of variables, f(x) is an arithmetic expression yielding a probability between [0, 1] that may use built-ins, and where Q(x) is a conjunction of predicates. The sum of f(x) for all x must be lower than 1.

Only deterministic antecedents are allowed. Declarativity makes it impossible to enforce that at declaration time. Thus, if a query-based probabilistic fact has a dependency on a probabilistic predicate, this will be discovered at query-resolution time, after the program has been fully declared.

query_based_probabilistic_fact(implication)

Construct probabilistic facts from deterministic queries.

This extends the syntax with rules such as

P(x) : f(x) :- Q(x)

where x is a set of variables, f(x) is an arithmetic expression yielding a probability between [0, 1] that may use built-ins, and where Q(x) is a conjunction of predicates.

Only deterministic antecedents are allowed. Declarativity makes it impossible to enforce that at declaration time. Thus, if a query-based probabilistic fact has a dependency on a probabilistic predicate, this will be discovered at query-resolution time, after the program has been fully declared.

query_based_probabilistic_predicate(implication)

Left for backward compatibility. Should be referred to the ProbabilisticFact case

type = typing.Any
union_with_probabilistic_facts(code)
within_language_marg_query(implication)
within_language_prob_queries()
within_language_succ_query(implication)
class neurolang.probabilistic.cplogic.program.CPLogicProgram(*args, **kwargs)

Bases: CPLogicMixin, DatalogProgramNegationMixin, DatalogProgram, ExpressionWalker

Attributes:
included_constants
included_functions
patterns

Property holding an iterator of triplets (pattern, guard, action).

pchoice_pred_symbs
pfact_pred_symbs
predicate_symbols
probabilistic_predicate_symbols

Methods

add_probabilistic_choice_from_tuples(symbol, ...)

Add a probabilistic choice from a predicate symbol and a set of tuples where the first element is the probability label attached to a head predicate and the other elements are the constant terms of the head predicate.

add_probabilistic_facts_from_tuples(symbol, ...)

Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple.

constant_equals

infer_iterable_type(iterable)

Infer the type of iterable elements without modifying the iterable.

match(expression)

Find the action for a given expression by going through the patterns.

pattern_match(pattern, expression)

Return True if pattern matches expression.

pchoice_pred_symb_set_symb

pfact_pred_symb_set_symb

probabilistic_choices()

Return probabilistic choices of the symbol table.

probabilistic_facts()

Return probabilistic facts of the symbol table.

query_based_probabilistic_choice(implication)

Construct probabilistic choices from deterministic queries.

query_based_probabilistic_fact(implication)

Construct probabilistic facts from deterministic queries.

query_based_probabilistic_predicate(implication)

Left for backward compatibility.

type

union_of_cq(expression)

This pattern is here to avoid processing the full program when one rule is rewritten.

add_extensional_predicate_from_tuples

add_included_constants_and_functions_to_symbol_table

builtins

extensional_database

fact

intensional_database

marg_implication

negation_constant

negative_fact

new_set

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

pop_scope

predicate_terms

probabilistic_fact

process_expression

process_iterable_argument

push_scope

statement_intensional

symbol

union_with_probabilistic_facts

walk

within_language_marg_query

within_language_prob_queries

within_language_succ_query

protected_keywords = {'PROB', '__pchoice_pred_symb_set_symb__', '__pfact_pred_symb_set_symb__'}
type = typing.Any