# pita.pl -- pita

This module performs reasoning over Logic Programs with Annotated Disjunctions and CP-Logic programs. It reads probabilistic program and computes the probability of queries.

See https://friguzzi.github.io/cplint/ for details.

Reexports cplint_util and bddem

author
- Fabrizio Riguzzi
dt_solve(-Strategy:list, -Cost:float) is det
The predicate computes the best solution for the decision theory problem. It returns the best strategy in Strategy and it cost in Cost. Complete solution without pruning.
prob_meta(:Query:conjunction_of_literals, -Probability:float) is nondet
To be used in place of prob/2 for meta calls (doesn't abolish tables)
abd_prob(:Query:conjunction_of_literals, -Probability:float, -Delta:list) is nondet
The predicate computes the most probable abductive explanation of the ground query Query. It returns the explanation in Delta together with its Probability
bdd_dot_file(:Query:atom, +FileName:string, -LV:list) is det
The predicate builds the BDD for Query and writes its dot representation to file FileName and a list in LV with the association of variables to rules. LV is a list of list, each sublist has three elements: the multivalued variable number, the rule number and the grounding substitution.
bdd_dot_string(:Query:atom, -DotString:string, -LV:list) is det
The predicate builds the BDD for Query and returns its dot representation in DotString and a list in LV with the association of variables to rules. LV is a list of list, each sublist has three elements: the multivalued variable number, the rule number and the grounding substitution.
abd_bdd_dot_string(:Query:atom, -DotString:string, -LV:list, -LAV:list) is det
The predicate builds the BDD for the abductive explanations for Query and returns its dot representation in DotString and lists LV and LAV, the association of variables to rules and to abductive variables to rules respectively. LV and LAV are lists of list, each sublist has three elements: the multivalued variable number, the rule number and the grounding substitution.
abd_bdd_dot_string(:Query:atom, -DotString:string, -LV:list, -LAV:list, -Probability:float, -Delta:list) is det
The predicate builds the BDD for the abductive explanations for Query It returns the explanation in Delta together with its Probability. The predicate builds the BDD for Query and returns its dot representation in DotString and lists LV and LAV, the association of variables to rules and to abductive variables to rules respectively. LV and LAV are lists of list, each sublist has three elements: the multivalued variable number, the rule number and the grounding substitution.
map(:Query:atom, -Probability:float, -Delta:list) is nondet
The predicate computes the explanation of the ground query Query with Maximum A Posteriori (MAP) probability. It returns the explanation in Delta together with its Probability
map_bdd_dot_string(:Query:atom, -DotString:string, -LV:list, -LAV:list, -Probability:float, -Delta:list) is nondet
The predicate computes the explanation of the ground query Query with Maximum A Posteriori (MAP) probability. It returns the explanation in Delta together with its Probability The predicate builds the BDD for Query and returns its dot representation in DotString and lists LV and LAV, the association of variables to rules and of query variables to rules respectively. LV and LAV are lists of list, each sublist has three elements: the multivalued variable number, the rule number and the grounding substitution.
prob(:Query:atom, -Probability:float) is nondet
The predicate computes the probability of Query If Query is not ground, it returns in backtracking all ground instantiations of Query together with their probabilities
prob(:Query:conjunction_of_literals, :Evidence:conjunction_of_literals, -Probability:float) is nondet
Equivalent to prob/4 with an empty option list.
prob_meta(:Query:conjunction_of_literals, :Evidence:conjunction_of_literals, -Probability:float) is nondet
To be used in place of prob/3 for meta calls (doesn't abolish tables)
get_var_n(++M:atomic, ++Environment:int, ++Rule:int, ++Substitution:term, ++Probabilities:list, -Variable:int) is det
Returns the index Variable of the random variable associated to rule with index Rule, grounding substitution Substitution and head distribution Probabilities in environment Environment.
get_dec_var_n(++M:atomic, ++Environment:int, ++Rule:int, ++Substitution:term, -Variable:int) is det
Returns the index Variable of the random variable associated to rule with index Rule in environment Environment.
get_abd_var_n(++M:atomic, ++Environment:int, ++Rule:int, ++Substitution:term, ++Probabilities:list, -Variable:int) is det
Returns the index Variable of the random variable associated to rule with index Rule, grounding substitution Substitution and head distribution Probabilities in environment Environment.
msw(:Var:term, ?Value:term, ++Environment:int, --BDD:int) is det
Returns a BDD representing Var=Value. This is a predicate for programs in the PRISM syntax
msw(:Var:term, ?Value:term, ++Environment:int, --BDD:int, ?DB:int) is det
Returns a BDD representing Var=Value when there is a depth bound on derivations. This is a predicate for programs in the PRISM syntax
set_pita(:Parameter:atom, +Value:term) is det
The predicate sets the value of a parameter For a list of parameters see https://friguzzi.github.io/cplint/
setting_pita(:Parameter:atom, ?Value:term) is det
The predicate returns the value of a parameter For a list of parameters see https://friguzzi.github.io/cplint/

## Re-exported predicates

The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.

argbar(+Values:list, -Chart:dict) is det
Values is a list of pairs V-N where V is the value and N is the number of samples returning that value. The predicate returns a dict for rendering with c3 as a bar chart with a bar for each value V. The size of the bar is given by N.
make_query_var(++Environment:int, +Variable:int, --BDD:int) is det
Makes Variable belonging to Environment a query random variable for MAP inference. Returns in BDD the diagram of the formula encoding the required constraints among the Boolean random variable that represent Variable.
create_dot(++Env:int, ++BDD:int, ++File:string) is det
The predicate writes the BDD in dot format to to file FileName.
ret_probc(++Environment:int, ++EBDD:couple, -Probability:float) is det
EBDD is a couple (Environment,BDD) Returns the Probability of BDD belonging to environment Environment Uses
add_query_var(++Environment:int, ++ProbabilityDistribution:list, ++Rule:int, -Variable:int) is det
Returns in Variable the index of a new random variable to be queried in MAP inference with NumberOHeads values and probability distribution ProbabilityDistribution. The variable belongs to Environment.
andc(++Environment:int, ++A:couple, ++B:couple, --AandB:couple) is semidet
A and B are couples (Environment, BDDA) and (Environment, BDDB) respectively Returns in AandB a couple (Environment, BDDAandB) where BDDAandB is pointer to a BDD belonging to environment Environment representing the conjunction of BDDs BDDA and BDDB. fails if BDDB represents the zero function
std_dev(+Values:list, -Dev:float) is det
Computes the standard deviation of Values. Values can be
• a list of numbers
• a list of pairs number-weight, in which case each number is multiplied by the weight before being considered
• a list of pairs list-weight, in which case list is considered as a matrix of numbers. The matrix in each element of List must have the same dimension and are aggregated element- wise
debug_cudd_var(++Environment:int, -Variable:out) is det
Prints the debug information which is the result of the call of Cudd_ReadDead, Cudd_CheckZeroRef, Cudd_CheckKeys and Cudd_DebugCheck(env->mgr));
variance(+Values:list, -Average:float, -Variance:float) is det
Computes the variance the average of Values. Values can be
• a list of numbers
• a list of pairs number-weight, in which case each number is multiplied by the weight before being considered
• a list of pairs list-weight, in which case list is considered as a matrix of numbers. The matrix in each element of List must have the same dimension and are aggregated element- wise
ret_prob(++Environment:int, ++BDD:int, -Probability:float) is det
Returns the Probability of BDD belonging to environment Environment.
bin(+N:int, +Values:list, +Lower:number, +BinWidth:number, -Couples:list) is det
Given a list of numeric Values, a Lower value and BinWidth, returns in Couples a list of N pairs V-Freq where V is the midpoint of a bin and Freq is the number of values that are inside the bin interval [V-BinWidth/2,V+BinWidth/2) starting with the bin where V-BinWidth/2=Lower
zero(++Environment:int, --Zero:int) is det
Returns in Zero a pointer to a BDD belonging to environment Environment representing the zero Boolean function.
Returns in Variable the index of a new decision variable in Environment
ret_strategy(++Environment:int, ++ADD:int, --Decision:list, --Cost:int) is det
Computes the optimal strategy given a pointer to the ADD belonging to environment Environment. Decision is a list of selected facts, Cost is the total cost.
dirichlet_sample(++Alpha:list, --Value:list) is det
Returns a Value sampled from a Dirichlet distribution with parameters Alpha. Alpha and Value are lists of floating point numbers of the same length.
density2d(+List:list, -Dens:list, +Options:list) is det
Returns a set of 3-dimensional points representing the plot of the density of a sets of 2-dimensional samples. The samples are in List as pairs [X,Y]-W where (X,Y) is a point and W its weigth.

Options is a list of options, the following are recognised by density2d/3:

xmin(+XMin:float)
the minimum value of the X domain, default value the minimum in List
xmax(-XMax:float)
the maximum value of the X domain, default value the maximum in List
ymin(-YMin:float)
the minimum value of the Y domain, default value the minimum in List
ymax(-YMax:float)
the maximum value of the Y domain, default value the maximum in List
nbins(+NBins:int)
the number of bins for dividing the X and Y domains, default value 40
densities(+PriorList:list, +PostList:list, -Chart:dict, +Options:list) is det
Draws a line chart of the density of two sets of samples, usually prior and post observations. The samples from the prior are in PriorList while the samples from the posterior are in PostList. PriorList and PostList must be lists of pairs of the form [V]-W or V-W where V is a sampled value and W is its weight, or lists of values V. Options is a list of options, the following are recognised by histogram/3:
nbins(+NBins:int)
the number of bins for dividing the domain, default value 40 */
init(--Environment:int) is det
Initializes a data structure for storing a single BDD. Returns an integer Environment that is a pointer to a data structure for storing a single BDD to be used for inference only (no learning).
rand_seed(+Seed:int) is det
The pseudo-random number generator is initialized using the argument passed as Seed. It calls the C function srand.
or_listc(++ListOfBDDs:list, ++Environment, --BDD:int) is det
Returns in BDD a couple (Env,B) with B a pointer to a BDD belonging to environment Environment representing the disjunction of all the BDDs in ListOfBDDs (a list of couples (Env,BDD))
bar1(+Probability:float, -Chart:dict) is det
The predicate returns a dict for rendering with c3 as a bar chart with a bar for the probability
orc(++A:couple, ++B:couple, --AorB:couple) is det
A and B are couples (Environment, BDDA) and (Environment, BDDB) respectively Returns in AorB a couple (Environment, BDDAorB) where BDDAorB is pointer to a BDD belonging to environment Environment representing the disjunction of BDDs BDDA and BDDB.
zeroc(++Environment:int, --Zero:couple) is det
Returns in Zero a couple (Environment,BDD) where BDD is pointer to a BDD belonging to environment Environment representing the zero Boolean function
ret_abd_prob(++Environment:int, ++BDD:int, -Probability:float, -Explanation:list) is det
Returns the abductive Explanation of BDD and its Probability. BDD belongs to environment Environment.
std_dev(+Values:list, -Average:float, -Dev:float) is det
Computes the standard deviation and the average of Values. Values can be
• a list of numbers
• a list of pairs number-weight, in which case each number is multiplied by the weight before being considered
• a list of pairs list-weight, in which case list is considered as a matrix of numbers. The matrix in each element of List must have the same dimension and are aggregated element- wise
to_atom(+In:pair, -Out:pair) is det
Given In=A0-N, to_atom/2 returns Out=A-N where A is an atom representing A0
variance(+Values:list, -Variance:float) is det
Computes the variance of Values. Values can be
• a list of numbers
• a list of pairs number-weight, in which case each number is multiplied by the weight before being considered
• a list of pairs list-weight, in which case list is considered as a matrix of numbers. The matrix in each element of List must have the same dimension and are aggregated element- wise
and(++Environment:int, ++A:int, ++B:int, --AandB:int) is det
Returns in AandB a pointer to a BDD belonging to environment Environment representing the conjunction of BDDs A and B.
value_pair(+Pair:pair, -Value:term) is det
Given a pair Key-Vaule, returns its second element Value
initial_values(++Environment:int, ++Alpha:float) is det
Sets the type of parameter initialization for EM on Environment: if Alpha is 0.0, it uses a truncated Dirichlet process if Alpha is a float > 0.0, it uses a symmetric Dirichlet distribution with that value as parameter
equality(++Environment:int, ++Variable:int, ++Value:int, --BDD:int) is det
Returns in BDD the BDD belonging to environment Environment that represents the equation Variable=Value.
em(++Context:int, ++RuleInfo:list, ++ListOfBDDs:list, ++EA:float, ++ER:float, ++Iterations:int, -LL:float, -Parameters:list, -ExampleProbabilities:list) is det
NumberOfHeads is a list of terms, one for each rule. Each term is either an integer, indicating the number of head atoms in the rule, or a list [N] where N is the number of head atoms. In the first case, the parameters of the rule are tunable, in the latter they are fixed.

Performs EM learning. Takes as input the Context, information on the rules, a list of BDDs each representing one example, the minimum absolute difference EA and relative difference ER between the log likelihood of examples in two different iterations and the maximum number of iterations Iterations. RuleInfo is a list of elements, one for each rule, with are either

• an integer, indicating the number of heads, in which case the parameters of the corresponding rule should be randomized,
• a list of floats, in which case the parameters should be set to those indicated in the list and not changed during learning (fixed parameters)
• [a list of floats], in which case the initial values of the parameters should be set to those indicated in the list and changed during learning (initial values of the parameters) Returns the final log likelihood of examples LL, the list of new Parameters and a list with the final probabilities of each example. Parameters is a list whose elements are of the form [N,P] where N is the rule number and P is a list of probabilities, one for each head atom of rule N, in reverse order.
density2d(+List:list, -Dens:list) is det
Equivalent to density2d/3 with an empty option list.
densities(+PriorList:list, +PostList:list, -Chart:dict) is det
Equivalent to densities/4 with an empty option list.
uniform_sample(--Value:float) is det
Returns a Value sampled from a uniform distribution in [0,1]
end_em(++Context:int) is det
Terminates the context data structure for performing parameter learning. Context is a pointer to a context data structure for performing the EM algorithm. Context must have been returned by a call to init_em/1. It frees the memory occupied by Context.
end(++Environment:int) is det
Terminates the environment data structure for storing a single BDD. Environment is a pointer to a data structure returned by a call to init/1.
bar(+Successes:int, +Failures:int, -Chart:dict) is det
The predicate returns a dict for rendering with c3 as a bar chart with a bar for the number of successes and a bar for the number of failures
or_list(++ListOfBDDs:list, ++Environment, --BDD:int) is det
Returns in BDD a pointer to a BDD belonging to environment Environment representing the disjunction of all the BDDs in ListOfBDDs
bdd_notc(++Environment:int, ++EBDD:couple, --NotEBDD:couple) is det
EBDD is a couple (Environment,A) Returns in NotEBDD a couple (Environment,NotA) where NotA is pointer to a BDD belonging to environment Environment representing the negation of BDD A
add_abd_var(++Environment:int, ++ProbabilityDistribution:list, ++Rule:int, -Variable:int) is det
Returns in Variable the index of a new abducible random variable in Environment with NumberOHeads values and probability distribution ProbabilityDistribution.
onec(++Environment:int, --One:couple) is det
Returns in One a couple (Environment,BDD) where BDD is pointer to a BDD belonging to environment Environment representing the one Boolean function
agg_val(+Couple:atom, +PartialSum:number, -Sum:number) is det
Aggregate values by summation. The first argument is a couple _-N with N the new value to sum to PartialSum
average(+Values:list, -Average:float) is det
Computes the average of Values. Values can be
• a list of numbers
• a list of pairs number-weight, in which case each number is multiplied by the weight before being summed
• a list of lists, in which case lists are considered as matrices of numbers and averaged element-wise
• a list of pairs list-weight, in which case the list is considered as a matrix of numbers. The matrix in each element of List must have the same dimension and are aggregated element- wise
end_ex(++Environment:int) is det
Terminates the evnironment data structure for storing a BDD. Environment is a pointer to a data structure returned by init_ex/2. It frees the memory occupied by the BDD.
or(++Environment:int, ++A:int, ++B:int, --AorB:int) is det
Returns in AorB a pointer to a BDD belonging to environment Environment representing the disjunction of BDDs A and B.
key_pair(+Pair:pair, -Key:term) is det
Given a pair Key-Vaule, returns its first element Key
discrete_sample(++Theta:list, --Value:int) is det
Returns a Value sampled from a discrete distribution with parameters Theta. Theta is a list of floating point numbers in [0,1] that sum to 1. Value is in 0..(`length(Theta)`-1)
Multiplies the ADD belonging to environment Environment with the value Utility and stores the result in ADDOut.
init_em(--Context:int) is det
Initializes a data structure for performing parameter learning. It returns an integer in Context that is a pointer to a context data structure for performing the EM algorithm.
density(+List:list, -Chart:dict, +Options:list) is det
Draws a line chart of the density of a sets of samples. The samples are in List as pairs [V]-W or V-W where V is a value and W its weigth.

Options is a list of options, the following are recognised by density/3:

min(+Min:float)
the minimum value of domain, default value the minimum in List
max(+Max:float)
the maximum value of domain, default value the maximum in List
nbins(+NBins:int)
the number of bins for dividing the domain, default value 40
gauss_sample(++Mean:float, ++Variance:float, --Value:float) is det
Returns a Value sampled from a Gaussian distribution with parameters Mean and Variance
histogram(+List:list, -Chart:dict, +Options:list) is det
Draws a histogram of the samples in List. List must be a list of pairs of the form [V]-W or V-W where V is a sampled value and W is its weight, or a list of values.

Options is a list of options, the following are recognised by histogram/3:

min(+Min:float)
the minimum value of domain, default value the minimum in List
max(+Max:float)
the maximum value of domain, default value the maximum in List
nbins(+NBins:int)
the number of bins for dividing the domain, default value 40
create_dot_string(++Env:int, ++BDD:int, -Dot:string) is det
The predicate returns the BDD in dot format.
bar(+Probability:float, -Chart:dict) is det
The predicate returns a dict for rendering with c3 as a bar chart with a bar for the probability and a bar for one minus the probability.
andcnf(++Environment:int, ++A:couple, ++B:couple, --AandB:couple) is semidet
A and B are couples (Environment, BDDA) and (Environment, BDDB) respectively Returns in AandB a couple (Environment, BDDAandB) where BDDAandB is pointer to a BDD belonging to environment Environment representing the conjunction of BDDs BDDA and BDDB.
equalityc(++Environment:int, ++Variable:int, ++Value:int, --EBDD:couple) is det
Returns in EBDD a couple (Environment,BDD) where BDD belongs to environment Environment and represents the equation Variable=Value.
add_var(++Environment:int, ++ProbabilityDistribution:list, ++Rule:int, -Variable:int) is det
Returns in Variable the index of a new random variable in Environment with NumberOHeads values and probability distribution ProbabilityDistribution.
ret_map_prob(++Environment:int, ++BDD:int, -Probability:float, -MAPState:list) is det
Returns the MAP state MPAState of BDD and its Probability. BDD belongs to environment Environment.
swi_builtin(+Goal:atom) is det
Succeeds if Goal is an atom whose predicate is defined in Prolog (either builtin or defined in a standard library).
Converts the BDD belonging to environment Environment into an ADD.
beta(+Alphas:list, -Beta:float) is det
Computes the value of the multivariate beta function for vector Alphas https://en.wikipedia.org/wiki/Beta_function#Multivariate_beta_function Alphas is a list of floats
bdd_not(++Environment:int, ++A:int, --NotA:int) is det
Returns in NotA a pointer to a BDD belonging to environment Environment representing the negation of BDD A.
one(++Environment:int, --One:int) is det
Returns in One a pointer to a BDD belonging to environment Environment representing the one Boolean function.
to_pair(+Pair:pair, -FlattenedPair:pair) is det
Given a pair E-W, returns a pair Ep-W where Ep=EE if E=[EE], otherwise Ep=E
symmetric_dirichlet_sample(++Alpha:float, ++K:int, --Value:list) is det
Returns a Value sampled from a symmetric Dirichlet distribution with parameter Alpha. K is the number of dimensions of the result.
init_ex(++Context:int, --Environment:int) is det
Initializes an enviroment data structure for storing a BDD. Context is an integer that is a pointer to a context data structure created using init_em/1. Returns an integer Environment that is a pointer to a data structure for storing a single BDD to be used for the EM algorithm.
density(+List:list, -Chart:dict) is det
Equivalent to density/3 with an empty option list.
gamma_sample(++Shape:float, ++Scale:float, --Value:float) is det
Returns a Value sampled from a gamma distribution with parameters Shape and Scale
histogram(+List:list, -Chart:dict) is det
Equivalent to histogram/3 with an empty option list.