srlearn
.Background¶
- class srlearn.Background(*, modes=None, ok_if_unknown=None, bridgers=None, ranges=None, number_of_clauses=100, number_of_cycles=100, recursion=False, line_search=False, use_std_logic_variables=False, use_prolog_variables=True, load_all_libraries=False, load_all_basic_modes=False)[source]¶
Background Knowledge for a database.
Background knowledge expressed in the form of modes.
- __init__(*, modes=None, ok_if_unknown=None, bridgers=None, ranges=None, number_of_clauses=100, number_of_cycles=100, recursion=False, line_search=False, use_std_logic_variables=False, use_prolog_variables=True, load_all_libraries=False, load_all_basic_modes=False)[source]¶
Initialize a set of background knowledge
- Parameters
- modeslist of str (default: None)
Modes constrain the search space for hypotheses.
- ok_if_unknownlist of str (default: None)
Okay if not known.
- bridgerslist of str (default: None)
List of bridger predicates.
- rangesdict of str (default: None)
Dict mapping object types to discrete categories
- number_of_clausesint, optional (default: 100)
Maximum number of clauses in the tree (i.e. maximum number of leaves)
- number_of_cyclesint, optional (default: 100)
Maximum number of times the code will loop to learn clauses, increments even if no new clauses are learned.
- line_searchbool, optional (default: False)
Use lineSearch
- recursionbool, optional (default: False)
Use recursion
- use_std_logic_variablesbool, optional (default: False)
Set the stdLogicVariables parameter to True
- use_prolog_variablesbool, optional (default: True)
Set the usePrologVariables parameter to True
- load_all_librariesbool, optional (default: False)
Load libraries:
arithmeticInLogic
,comparisonInLogic
,differentInLogic
,listsInLogic
- load_all_basic_modesbool, optional (default: False)
Load
modes_arithmeticInLogic
,modes_comparisonInLogic
,modes_differentInLogic
,modes_listsInLogic
These may require many cycles while proving.
Notes
Descriptions of these parameters are lifted almost word-for-word from the BoostSRL-Wiki “Advanced Parameters” page [1].
Some of these parameters are defined in multiple places. This is mostly to follow the sklearn-style requirement for all tune-able parameters to be part of the object while still being relatively similar to the style where BoostSRL has parameters defined in a modes file.
Examples
This demonstrates how to add parameters to the Background object. The main thing to take note of is the
modes
parameter, where background knowledge of the Toy-Cancer domain is specified.>>> from srlearn import Background >>> bk = Background( ... modes=[ ... "cancer(+Person).", ... "smokes(+Person).", ... "friends(+Person,-Person).", ... "friends(-Person,+Person).", ... ], ... ) >>> print(bk) setParam: numOfClauses=100. setParam: numOfCycles=100. usePrologVariables: true. setParam: nodeSize=2. setParam: maxTreeDepth=3. mode: cancer(+Person). mode: smokes(+Person). mode: friends(+Person,-Person). mode: friends(-Person,+Person).
This Background object is used by the
srlearn.rdn.BoostedRDN
class to write the parameters to abackground.txt
file before running BoostSRL.>>> from srlearn import Background >>> from srlearn.datasets import load_toy_cancer >>> train, _ = load_toy_cancer() >>> bk = Background(modes=train.modes) >>> bk.write("training/")