neurolang.probabilistic.cplogic.cplogic_to_gm module

class neurolang.probabilistic.cplogic.cplogic_to_gm.AndPlateNode(node_symbol, expression, relation)

Bases: PlateNode

Object used to produce deterministic conditional probabilities that conjunct the values of boolean parent random variables.

It only makes sense to use this CPD if all the parents are boolean random variables and if the random variable itself is a boolean random variable.

Let X be the random variable for which the CPD is calculated and let Y_1, …, Y_n be n parent boolean random variables.

The AND CPD encodes that

|- 1 if all y_i = T

P(X = T | Y_1 = y_1, … Y_n = y_1) = |

|- 0 otherwise

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.BernoulliPlateNode(node_symbol, expression, relation, probability_column)

Bases: ProbabilisticPlateNode

Object used to produce Bernoulli-distributed random variables.

Although this object is called a “CPD” factory, there is no parent to this distribution. Instead, it represents the marginal distributions of a batch of independent Bernoulli random variables.

An extra column in the relation used to represent the random variables is used to encode the probability of that specific random variable’s Bernoulli distribution:

For example, to represent the program

P(a) : 0.7 <- T P(b) : 0.2 <- T

One would use the following relation

_p_ | x

=====|===

0.7 | a 0.2 | b

where each row represents one random variable P(x) and where the column _p_ encodes the Bernoulli parameter of the distribution of P(x).

Attributes:
relation: Constant[AbstractSet]

A relation that encodes all the variables for which a conditional probability distribution will be produced.

probability_column: Constant[ColumnStr]

The column that contains the Bernoulli parameter associated to each random variable.

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.CPLogicGroundingToGraphicalModelTranslator

Bases: PatternWalker

Attributes:
patterns

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

Methods

extensional_set_grounding(grounding)

Represent a set of ground facts as a Bernoulli node with all probabilities set to 1.0.

intensional_rule_grounding(grounding)

Represent a deterministic intensional rule with an AND node.

match(expression)

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

pattern_match(pattern, expression)

Return True if pattern matches expression.

probabilistic_choice_grounding(grounding)

Represent a probabilistic choice as a n-ary choice node.

probfact_set_grounding(grounding)

Represent a set of probabilistic facts with a Bernoulli node.

type

add_plate_node

block_of_groundings

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

walk

add_plate_node(node_symbol, node, parent_node_symbols=None)
block_of_groundings(block)
extensional_set_grounding(grounding)

Represent a set of ground facts as a Bernoulli node with all probabilities set to 1.0.

intensional_rule_grounding(grounding)

Represent a deterministic intensional rule with an AND node.

probabilistic_choice_grounding(grounding)

Represent a probabilistic choice as a n-ary choice node.

probfact_set_grounding(grounding)

Represent a set of probabilistic facts with a Bernoulli node.

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.GraphicalModel(nodes, edges)

Bases: Definition

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_node

get_parent_node_symbols

get_wrapped_attribute

get_node(node_symbol)
get_parent_node_symbols(node_symbol)
type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.NaryChoicePlateNode(node_symbol, expression, relation, probability_column)

Bases: ProbabilisticPlateNode

Object used to represent the distribution of a single n-ary choice random variable.

The relation does not represent multiple random variables but the different predicates that can be chosen by the rule, alongside their associated probability.

Given a CP-Event of the form

P(a_1) : p_1 v … v P(a_n) : p_n <- T

where p_1, …, p_n are the probability labels attached to each head predicate P(a_1), …, P(a_n) – respectively,

the conditional probability distribution of the choice random variable (which is its marginal because there is no parent) is defined by the relation

_p_ | x ====|==== p_1 | a_1 p_2 | a_2 … | … p_n | a_n

where each row represents a possible value of the random variable with its probability.

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.NaryChoiceResultPlateNode(node_symbol, expression, relation)

Bases: PlateNode

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.PlateNode(node_symbol, expression, relation)

Bases: Definition

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
class neurolang.probabilistic.cplogic.cplogic_to_gm.ProbabilisticPlateNode(node_symbol, expression, relation, probability_column)

Bases: PlateNode

Object used to represent non-deterministic nodes.represent non-deterministic nodes

Although this object is called a “CPD” factory, there is no parent to this distribution. Instead, it represents the marginal distributions of a batch of independent Bernoulli random variables.

An extra column in the relation used to represent the random variables is used to encode the probability of that specific random variable’s Bernoulli distribution:

For example, to represent the program

P(a) : 0.7 <- T P(b) : 0.2 <- T

One would use the following relation

_p_ | x

=====|===

0.7 | a 0.2 | b

where each row represents one random variable P(x) and where the column _p_ encodes the Bernoulli parameter of the distribution of P(x).

Attributes:
relation: Constant[AbstractSet]

A relation that encodes all the variables for which a conditional probability distribution will be produced.

probability_column: Constant[ColumnStr]

The column that contains the Bernoulli parameter associated to each random variable.

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

unapply()

Returns a tuple of parameters used to build the expression.

cast

change_type

get_wrapped_attribute

type = typing.Any
neurolang.probabilistic.cplogic.cplogic_to_gm.is_extensional_grounding(grounding)

TODO: represent extensional grounding with a fact instead?