Rules
The galactic.rules
module.
It implements basic classes for dealing with bases of rules:
Rule
basic class for representing implications.Basis
represents all rule bases;BasicBasis
represents bases storing their rules;GeneratedBasis
represents bases generating their rules;CanonicalDirectBasis
represents canonical direct bases;HasseDiagramOrderedBasis
represents Hasse diagram ordered bases;SimplifiedBasis
represents simplified bases.RuleTable
for displaying rule bases in jupyter notebook.
- class Rule(premises: Iterable[galactic.descriptions.Predicate], conclusions: Iterable[galactic.descriptions.Predicate], support: SupportsFloat = 1.0, confidence: SupportsFloat = 1.0)
The
Rule
class.It is used to implement an implication between premises and conclusions.
The
support
of a rule \(A \rightarrow B\) is equal to the number of objects that match the rule divided by the total number of objects.The
confidence
of a rule \(A \rightarrow B\) is equal to the support of \(A \cup B\) divided by the support of \(A\).- __init__(premises: Iterable[galactic.descriptions.Predicate], conclusions: Iterable[galactic.descriptions.Predicate], support: SupportsFloat = 1.0, confidence: SupportsFloat = 1.0)
Initialise a
Rule
instance.- Parameters:
premises (
Iterable[Predicate]
) – An iterable of premises.conclusions (
Iterable[Predicate]
) – An iterable of conclusions.
- Keyword Arguments:
support (
SupportsFloat
) – The rule support.confidence (
SupportsFloat
) – The rule confidence.
- conclusions() Iterator[galactic.descriptions.Predicate]
Get an iterator over the conclusions.
- Returns:
An iterator over the conclusions.
- Return type:
- premises() Iterator[galactic.descriptions.Predicate]
Get an iterator over the premises.
- Returns:
An iterator over the premises.
- Return type:
- class Basis
The
Basis
class is the root of all implicational basis.- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- class BasicBasis(rules: Iterable[galactic.rules.Rule])
The
BasicBasis
class is used to construct implicational basis.- __init__(rules: Iterable[galactic.rules.Rule])
Initialise a
BasicBasis
instance.- Parameters:
rules (
Iterable[Rule]
) – Iterable of rules.
- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- class GeneratedBasis(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
The
GeneratedBasis
is the super class of all generated basis.- __init__(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
Initialise a
GeneratedBasis
instance.- Parameters:
lattice (
ConceptLattice
) – The concept lattice.- Keyword Arguments:
prefix (str) – The prefix used for identifiers.
- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- property lattice: galactic.concepts.ConceptLattice
Get the concept lattice.
- Returns:
The concept lattice.
- Return type:
- class CanonicalDirectBasis(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
The
CanonicalDirectBasis
is used to manage the canonical direct basis.- __init__(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
Initialise a
GeneratedBasis
instance.- Parameters:
lattice (
ConceptLattice
) – The concept lattice.- Keyword Arguments:
prefix (str) – The prefix used for identifiers.
- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- property lattice: galactic.concepts.ConceptLattice
Get the concept lattice.
- Returns:
The concept lattice.
- Return type:
- class HasseDiagramOrderedBasis(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
The
HasseDiagramOrderedBasis
class.It is used to construct implicational basis from a concept lattice using the links from the Hasse diagram.
- __init__(lattice: galactic.concepts.ConceptLattice, prefix: str = '$')
Initialise a
GeneratedBasis
instance.- Parameters:
lattice (
ConceptLattice
) – The concept lattice.- Keyword Arguments:
prefix (str) – The prefix used for identifiers.
- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- property lattice: galactic.concepts.ConceptLattice
Get the concept lattice.
- Returns:
The concept lattice.
- Return type:
- class SimplifiedBasis(rules: Iterable[galactic.rules.Rule], reduction: bool = False, generalization: bool = False, composition: bool = False)
The
SimplifiedBasis
class is used to manage simplified basis of rules.It uses axioms from Malaga’s team.
- __init__(rules: Iterable[galactic.rules.Rule], reduction: bool = False, generalization: bool = False, composition: bool = False)
Initialise a
Simplified
instance.- Parameters:
rules (
Iterable[Rule]
) – An iterable of rules.reduction (bool) – The reduction flag.
generalization (bool) – The generalization flag.
composition (bool) – The composition flag.
- filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[galactic.rules.Rule]
Get the rules with a minimum support and minimum confidence.
- Keyword Arguments:
support (
SupportsFloat
, optional) – The minimum supportconfidence (
SupportsFloat
, optional) – The minimum confidence
- Returns:
An iterator over the rules.
- Return type:
- class RuleTable(basis: galactic.rules.Basis, premise_width: int = 1, conclusion_width: int = 1, support_width: int = 1, confidence_width: int = 1, support: Optional[float] = None, confidence: Optional[float] = None)
The
Table
class is used to represent lattice in jupyter notebooks.- __init__(basis: galactic.rules.Basis, premise_width: int = 1, conclusion_width: int = 1, support_width: int = 1, confidence_width: int = 1, support: Optional[float] = None, confidence: Optional[float] = None) None
Initialise a
Table
class.- Parameters:
basis (
Basis
) – The implicational basis whose table representation is requested- Keyword Arguments:
premise_width (int) – The premise width.
conclusion_width (int) – The conclusion width.
support_width (int) – The support width.
confidence_width (int) – The confidence width.
support (
Optional[float]
) – The minimal supportconfidence (
Optional[float]
) – The minimal confidence.
The values of the given widths are compared with each other to allocate relative column sizes.
- property basis: galactic.rules.Basis
Get the underlying basis.
- Returns:
The underlying basis.
- Return type:
- property conclusion_width: int
Get the conclusion width.
- Returns:
The conclusion width.
- Return type:
- property confidence_width: int
Get the confidence width.
- Returns:
The confidence width.
- Return type: