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
- copyright
- - 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.
- 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.
- 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.
- 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.
- 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.
- 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).
- 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.
- one(++Environment:int, --One:int) is det
- Returns in One a pointer to a BDD belonging to environment Environment
representing the one Boolean function.
- zero(++Environment:int, --Zero:int) is det
- Returns in Zero a pointer to a BDD belonging to environment Environment
representing the zero Boolean function.
- 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.
- 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.
- ret_prob(++Environment:int, ++BDD:int, -Probability:float) is det
- Returns the Probability of BDD belonging to environment Environment.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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_string(++Env:int, ++BDD:int, -Dot:string) is det
- The predicate returns the BDD in dot format.
- create_dot(++Env:int, ++BDD:int, ++File:string) is det
- The predicate writes the BDD in dot format to
to file FileName.
- 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.
- 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.
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.
- onec(Arg1, Arg2)
- zeroc(Arg1, Arg2)
- andc(Arg1, Arg2, Arg3, Arg4)
- andcnf(Arg1, Arg2, Arg3, Arg4)
- bdd_notc(Arg1, Arg2, Arg3)
- ret_probc(Arg1, Arg2, Arg3)
- equalityc(Arg1, Arg2, Arg3, Arg4)
- or_list(Arg1, Arg2, Arg3)
- or_listc(Arg1, Arg2, Arg3)
- gamma_sample(Arg1, Arg2, Arg3)
- gauss_sample(Arg1, Arg2, Arg3)
- uniform_sample(Arg1)
- dirichlet_sample(Arg1, Arg2)
- symmetric_dirichlet_sample(Arg1, Arg2, Arg3)
- discrete_sample(Arg1, Arg2)
- initial_values(Arg1, Arg2)
- add_decision_var(Arg1, Arg2, Arg3)
- probability_dd(Arg1, Arg2, Arg3)
- add_prod(Arg1, Arg2, Arg3, Arg4)
- add_sum(Arg1, Arg2, Arg3, Arg4)
- ret_strategy(Arg1, Arg2, Arg3, Arg4)
- debug_cudd_var(Arg1, Arg2)