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: - modes : list of str (default: None)
Modes constrain the search space for hypotheses.
- ok_if_unknown : list of str (default: None)
Okay if not known.
- bridgers : list of str (default: None)
List of bridger predicates.
- ranges : dict of str (default: None)
Dict mapping object types to discrete categories
- number_of_clauses : int, optional (default: 100)
Maximum number of clauses in the tree (i.e. maximum number of leaves)
- number_of_cycles : int, optional (default: 100)
Maximum number of times the code will loop to learn clauses, increments even if no new clauses are learned.
- line_search : bool, optional (default: False)
Use lineSearch
- recursion : bool, optional (default: False)
Use recursion
- use_std_logic_variables : bool, optional (default: False)
Set the stdLogicVariables parameter to True
- use_prolog_variables : bool, optional (default: True)
Set the usePrologVariables parameter to True
- load_all_libraries : bool, optional (default: False)
Load libraries:
arithmeticInLogic
,comparisonInLogic
,differentInLogic
,listsInLogic
- load_all_basic_modes : bool, 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.
[1] https://starling.utdallas.edu/software/boostsrl/wiki/advanced-parameters/ 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). <BLANKLINE>
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/") # doctest: +SKIP
-
write
(filename='train', location=PosixPath('train')) → None[source]¶ Write the background to disk for learning.
Parameters: - filename : str
Name of the file to write to: âtrain_bk.txtâ or âtest_bk.txtâ
- location :
pathlib.Path
This should be handled by a manager to ensure locations do not overlap.
-