slipcover.pl -- slipcover

This module performs learning over Logic Programs with Annotated Disjunctions and CP-Logic programs. It performs both parameter and structure learning.

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

Reexports bddem

author
- Fabrizio Riguzzi, Elena Bellodi
license
- Artistic License 2.0
 induce(:TrainFolds:list_of_atoms, -P:probabilistic_program) is det
The predicate performs structure learning using the folds indicated in TrainFolds for training. It returns in P the learned probabilistic program.
 test(:P:probabilistic_program, +TestFolds:list_of_atoms, -LL:float, -AUCROC:float, -ROC:dict, -AUCPR:float, -PR:dict) is det
The predicate takes as input in P a probabilistic program, tests P on the folds indicated in TestFolds and returns the log likelihood of the test examples in LL, the area under the Receiver Operating Characteristic curve in AUCROC, a dict containing the points of the ROC curve in ROC, the area under the Precision Recall curve in AUCPR and a dict containing the points of the PR curve in PR
 test_prob(:P:probabilistic_program, +TestFolds:list_of_atoms, -NPos:int, -NNeg:int, -LL:float, -Results:list) is det
The predicate takes as input in P a probabilistic program, tests P on the folds indicated in TestFolds and returns the number of positive examples in NPos, the number of negative examples in NNeg, the log likelihood in LL and in Results a list containing the probabilistic result for each query contained in TestFolds.
 make_dynamic(+Module:atom) is det
Makes the predicates required for learning dynamic.
 induce_par(:TrainFolds:list_of_atoms, -P:probabilistic_program) is det
The predicate learns the parameters of the program stored in the in/1 fact of the input file using the folds indicated in TrainFolds for training. It returns in P the input program with the updated parameters.
 learn_params(+DB:list_of_atoms, +M:atom, +R0:probabilistic_program, -P:probabilistic_program, -Score:float) is det
The predicate learns the parameters of the program R0 and returns the updated program in R and the score in Score. DB contains the list of interpretations ids and M the module where the data is stored.
 rules2terms(:R:list_of_rules, -T:tern) is det
The predicate translates a list of rules from the internal representation format (rule/4 and def_rule/3) to the LPAD syntax.
 list2or(+List:list, -Or:term) is det
list2or(-List:list, +Or:term) is det
The predicate succeeds when Or is a disjunction (using the ; operator) of the terms in List
 list2and(+List:list, -And:term) is det
list2and(-List:list, +And:term) is det
The predicate succeeds when And is a conjunction (using the , operator) of the terms in List
 sample(+N, List:list, -Sampled:list, -Rest:list) is det
Samples N elements from List and returns them in Sampled. The rest of List is returned in Rest If List contains less than N elements, Sampled is List and Rest is [].
 generate_body(+ModeDecs:list, +Module:atom, -BottomClauses:list) is det
Generates the body of bottom clauses and returns the bottom clauses in BottomClauses.
 remove_duplicates(+List1:list, -List2:list) is det
Removes duplicates from List1. Equality is checked with ==.
 banned_clause(+Module:atom, -Head:term, -Body:term) is nondet
The predicate checks whether Head:-Body is a banned clause, as specified by the user in the input file. Module is the module of the input file.
 linked_clause(+Literals:list, +Module:atom, +PrevLits:list) is det
The predicate checks whether Literals form a linked list of literals given that PrevLits are the previous literals. In a linked list of literals input variables of a literal are output variables in a previous literal.
 extract_type_vars(+Literals:list, +Module:atom, +Types:term) is det
The predicate extracts the type of variables from the list of literals Literals. Types is a list of elements of the form Variable=Type
 take_var_args(+ArgSpec:list, +TypeVars:list, -Vars:list) is det
The predicate returns in Vars the list of vars corresponding to variables arguments in ArgSpec (those with argument specification +type or -type). TypeVars is a list of terns of the form Variable=Types as returnd by extract_type_vars/3.
 extract_fancy_vars(+Term:term, -Vars:list) is nondet
Given Term, it returns the list of all of its variables in the form 'VN'=Var where VN is an atom with N an increasing integer starting from 1 and Var a variable in Term.
 delete_one(+List:list, -Rest:list, +Element:term) is nondet
As the library predicate delete(+List1, @Elem, -List2) but Element is unified with the deleted element (so it can be instantiated by the call).
 assert_all(+Terms:list, +Module:atom, -Refs:list) is det
The predicate asserts all terms in Terms in module Module using assertz(M:Term,Ref) and returns the list of references in Refs
 retract_all(+Refs:list) is det
The predicate erases all references in Refs (using erase/1).
 process_clauses(+InputClauses:list, +Module:atom, +Rules:list, -RulesOut:list, +Clauses:list, -ClausesOut:list) is det
InputClauses is a list of probabilistic clauses in input syntax. The predicate translates them into the internal format. RulesOut/Rules is a difference list of term of the form rule(R,HeadList,BodyList,Lit,Tun). ClausesOut/Clauses is a difference list of clauses to be asserted.
 get_next_rule_number(+Module:atom, -R:integer) is det
The predicate returns the next rule number. Module is used to access local data.
 set_sc(: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_sc(: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/
 member_eq(+List:list, +Element:term) is det
Checks the presence of Element in List. Equality is checked with ==.
 generate_clauses(+Rules0:list, +Module:atom, +StartingIndex:integer, -Rules:list, +Clauses:list, -ClausesOut:list) is det
The predicate generate the internal representation of rules to produce clauses to be asserted in the database. Rules0 is a list of term of the form rule(R,HeadList,BodyList,Lit,Tun). Rules is a list of terms of the form rule(N,HeadList,BodyList,Lit,Tun) where N is an increasing index starting from StartingIndex. ClausesOut/Clauses is a difference list of clauses to be asserted.
 generate_clauses_bg(+Rules:list, -Clauses:list) is det
The predicate generate clauses to be asserted in the database for the rules from the background. Rules is a list of term of the form def_rule(H,BodyList,_Lit). Clauses is a list of clauses to be asserted.
 get_sc_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, grouding substitution Substitution and head distribution Probabilities in environment Environment. Differs from get_var_n/6 of pita because R can be ng(RN,Vals), indicating a rule for which different instantiations get different parameters.
 write2(+Module:atom, +Message:term) is det
The predicate calls write(Message) if the verbosity is at least 2. Module is used to get the verbosity setting
 write3(+Module:atom, +Message:term) is det
The predicate calls write(Message) if the verbosity is at least 3. Module is used to get the verbosity setting.
 nl2(+Module:atom) is det
The predicate prints a newline if the verbosity is at least 2. Module is used to get the verbosity setting.
 nl3(+Module:atom) is det
The predicate prints a newline if the verbosity is at least 3. Module is used to get the verbosity setting.
 format2(+Module:atom, +Format, :Arguments) is det
The predicate calls format(Format,Arguments) if the verbosity is at least 2. Module is used to get the verbosity setting.
 format3(+Module:atom, +Format, :Arguments) is det
The predicate calls format(Format,Arguments) if the verbosity is at least 3. Module is used to get the verbosity setting.
 write_rules2(+Module:atom, +Rules:list, +Stream:atom) is det
The predicate write the rules in Rules on stream Stream if the verbosity is at least 2. Module is used to get the verbosity setting.
 write_rules3(+Module:atom, +Rules:list, +Stream:atom) is det
The predicate write the rules in Rules on stream Stream if the verbosity is at least 3. Module is used to get the verbosity setting.
 tab(+Module:atom, +PredSpec:pred_spec, -TableSpec:term) is det
Records the fact that predicate PredSpec must be tabled and returns the necessary term for the tabling directive in TableSpec. Module is used to store the information in the correct module
 zero_clause(+Module:atom, +PredSpec:pred_spec, -ZeroClause:term) is det
Generates the zero clause for predicate PredSpec. Module is the module of the input file.

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.

 create_dot(++Env:int, ++BDD:int, ++File:string) is det
The predicate writes the BDD in dot format to to file FileName.
 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.
 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
 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));
 ret_prob(++Environment:int, ++BDD:int, -Probability:float) is det
Returns the Probability of BDD belonging to environment Environment.
 zero(++Environment:int, --Zero:int) is det
Returns in Zero a pointer to a BDD belonging to environment Environment representing the zero Boolean function.
 add_decision_var(++Environment:int, ++Rule:int, -Variable:int) is det
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.
 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))
 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.
 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.
 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

 add_sum(++Environment:int, ++ADD1:int, ++ADD2:int, --ADDOut:int) is det
Computes the sum of the two ADDs ADD1 ADD2 belonging to environment Environment. The result in saved in ADDOut.
 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.
 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
 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.
 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)
 add_prod(++Environment:int, ++ADDIn:int, ++Utility:float, --ADDOut:int) is det
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.
 gauss_sample(++Mean:float, ++Variance:float, --Value:float) is det
Returns a Value sampled from a Gaussian distribution with parameters Mean and Variance
 create_dot_string(++Env:int, ++BDD:int, -Dot:string) is det
The predicate returns the BDD in dot format.
 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.
 probability_dd(++Environment:int, ++BDD:int, --ADD:int) is det
Converts the BDD belonging to environment Environment into an ADD.
 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.
 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.
 gamma_sample(++Shape:float, ++Scale:float, --Value:float) is det
Returns a Value sampled from a gamma distribution with parameters Shape and Scale