Rules

The galactic.rules module.

It implements basic classes for dealing with bases of rules:

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
Keyword Arguments
conclusions()Iterator[galactic.descriptions.Predicate]

Get an iterator over the conclusions.

Returns

An iterator over the conclusions.

Return type

Iterator[Predicate]

property confidence

Get the confidence.

Returns

The confidence.

Return type

float

premises()Iterator[galactic.descriptions.Predicate]

Get an iterator over the premises.

Returns

An iterator over the premises.

Return type

Iterator[Predicate]

property support

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[galactic.rules.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[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
Returns

An iterator over the rules.

Return type

Iterator[Rule]

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
Returns

An iterator over the rules.

Return type

Iterator[Rule]

property lattice

Get the concept lattice.

Returns

The concept lattice.

Return type

ConceptLattice

property prefix

Get the prefix.

Returns

The prefix.

Return type

str

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
Returns

An iterator over the rules.

Return type

Iterator[Rule]

property lattice

Get the concept lattice.

Returns

The concept lattice.

Return type

ConceptLattice

property prefix

Get the prefix.

Returns

The prefix.

Return type

str

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
Returns

An iterator over the rules.

Return type

Iterator[Rule]

property lattice

Get the concept lattice.

Returns

The concept lattice.

Return type

ConceptLattice

property prefix

Get the prefix.

Returns

The prefix.

Return type

str

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
Returns

An iterator over the rules.

Return type

Iterator[Rule]

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 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

Get the underlying basis.

Returns

The underlying basis.

Return type

Basis

property conclusion_width

Get the conclusion width.

Returns

The conclusion width.

Return type

int

property confidence

Get the confidence.

Returns

The confidence.

Return type

Optional[float]

property confidence_width

Get the confidence width.

Returns

The confidence width.

Return type

int

property premise_width

Get the premise width.

Returns

The premise width.

Return type

int

property support

Get the support.

Returns

The support.

Return type

Optional[float]

property support_width

Get the support width.

Returns

The support width.

Return type

int

register_classes()None

Register all classes defined in this module.