Rules

The galactic.rules module.

It implements basic classes for dealing with bases of rules:

class Rule(premises: Iterable[Predicate], conclusions: Iterable[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[Predicate], conclusions: Iterable[Predicate], support: SupportsFloat = 1.0, confidence: SupportsFloat = 1.0)

Initialise a Rule instance.

Parameters:
Keyword Arguments:
classmethod __init_subclass__(**kwargs: Any)

Add a sub-class hook.

conclusions() Iterator[Predicate]

Get an iterator over the conclusions.

Returns:

An iterator over the conclusions.

Return type:

Iterator[Predicate]

property confidence: float

Get the confidence.

Returns:

The confidence.

Return type:

float

premises() Iterator[Predicate]

Get an iterator over the premises.

Returns:

An iterator over the premises.

Return type:

Iterator[Predicate]

property support: float

Get the support.

Returns:

The support.

Return type:

float

class Basis

The Basis class is the root of all implicational basis.

filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

class BasicBasis(rules: Iterable[Rule])

The BasicBasis class is used to construct implicational basis.

__init__(rules: Iterable[Rule])

Initialise a BasicBasis instance.

Parameters:

rules (Iterable[Rule]) – Iterable of rules.

filter(support: Optional[SupportsFloat] = None, confidence: Optional[SupportsFloat] = None) Iterator[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

class GeneratedBasis(lattice: ConceptLattice, prefix: str = '$')

The GeneratedBasis is the super class of all generated basis.

__init__(lattice: 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[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

property lattice: ConceptLattice

Get the concept lattice.

Returns:

The concept lattice.

Return type:

ConceptLattice

property prefix: str

Get the prefix.

Returns:

The prefix.

Return type:

str

class CanonicalDirectBasis(lattice: ConceptLattice, prefix: str = '$')

The CanonicalDirectBasis is used to manage the canonical direct basis.

__init__(lattice: 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[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

property lattice: ConceptLattice

Get the concept lattice.

Returns:

The concept lattice.

Return type:

ConceptLattice

property prefix: str

Get the prefix.

Returns:

The prefix.

Return type:

str

class HasseDiagramOrderedBasis(lattice: 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: 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[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

property lattice: ConceptLattice

Get the concept lattice.

Returns:

The concept lattice.

Return type:

ConceptLattice

property prefix: str

Get the prefix.

Returns:

The prefix.

Return type:

str

class SimplifiedBasis(rules: Iterable[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[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[Rule]

Get the rules with a minimum support and minimum confidence.

Keyword Arguments:
Returns:

An iterator over the rules.

Return type:

Iterator[Rule]

class RuleTable(basis: 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: 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 support

  • confidence (Optional[float]) – The minimal confidence.

The values of the given widths are compared with each other to allocate relative column sizes.

property basis: Basis

Get the underlying basis.

Returns:

The underlying basis.

Return type:

Basis

property conclusion_width: int

Get the conclusion width.

Returns:

The conclusion width.

Return type:

int

property confidence: Optional[float]

Get the confidence.

Returns:

The confidence.

Return type:

Optional[float]

property confidence_width: int

Get the confidence width.

Returns:

The confidence width.

Return type:

int

property premise_width: int

Get the premise width.

Returns:

The premise width.

Return type:

int

property support: Optional[float]

Get the support.

Returns:

The support.

Return type:

Optional[float]

property support_width: int

Get the support width.

Returns:

The support width.

Return type:

int

register_classes() None

Register all classes defined in this module.