galactic.algebras.convex.measures.core#

galactic.algebras.convex.measures.core module

Defines core measures in convex algebras.


class Measure(**data)#

Bases: Resource, ABC

Measure the quality of the concept relatively to its super-concept.

abstractmethod __call__(pred, succ)#

Measure the quality of the concept pred relative to succ.

Parameters:
  • pred (Concept) – Concept to be measured

  • succ (Concept) – A super-concept of pred

Returns:

The measure of the quality of pred relative to succ

Return type:

float

Notes

The measure should be negative when the concept cannot be retained, and should be zero when pred is a very poor concept.

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class Support(**data)#

Bases: Measure

Measure the support of a concept.

The support of a concept is the cardinality of its extent. It measures how many items are described by the concept.

ALIAS#

The alias of the type in the resource registry.

Type:

ClassVar[str] = “core.measure.Support”

Examples

>>> from galactic.algebras.concept.core import ItemUniverse
>>> from galactic.algebras.convex.characteristics.core import Integer, Component
>>> from galactic.algebras.convex.descriptions.core import (
...     PredicateUniverse,
...     Context,
...     GaloisConnection,
...     Concept,
... )
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
...     DivisorDescription,
...     MultipleDescription,
... )
>>> from galactic.algebras.convex.measures.core import Support
>>> from galactic.algebras.convex.strategies.core import NaiveStrategy
>>> characteristic = Integer(components=(Component(),))
>>> descriptions = (
...     DivisorDescription(space=(characteristic,)),
...     MultipleDescription(space=(characteristic,)),
... )
>>> dataset = [36, 48, 16, 32]
>>> domain = ItemUniverse(dataset)
>>> co_domain = PredicateUniverse(descriptions=descriptions)
>>> context = Context(domain, co_domain)
>>> connection = GaloisConnection(context)
>>> top = Concept(connection)
>>> strategy = NaiveStrategy(descriptions=descriptions)
>>> concepts = list(strategy(top))
>>> support = Support()
>>> [support(sub, top) for sub in concepts]
[3.0, 3.0]

Configuration

If you want to specify a support measure in a TOML file, you can use the following syntax:

[measures.my_measure]
"$type" = "core.measure.Support"

Notes

In this measure, the succ argument is not used.

__call__(pred, succ)#

Measure the support of a concept.

The support of a concept is the cardinality of its extent.

Parameters:
  • pred (Concept) – Concept to be measured

  • succ (Concept) – A super-concept of pred

Returns:

The support of pred

Return type:

float

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class NormalisedSupport(**data)#

Bases: Measure

Measure the normalised support of the concept pred.

ALIAS#

The alias of the type in the resource registry.

Type:

ClassVar[str] = “core.measure.NormalisedSupport”

Examples

>>> from galactic.algebras.concept.core import ItemUniverse
>>> from galactic.algebras.convex.characteristics.core import Integer, Component
>>> from galactic.algebras.convex.descriptions.core import (
...     PredicateUniverse,
...     Context,
...     GaloisConnection,
...     Concept,
... )
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
...     DivisorDescription,
...     MultipleDescription,
... )
>>> from galactic.algebras.convex.measures.core import NormalisedSupport
>>> from galactic.algebras.convex.strategies.core import NaiveStrategy
>>> characteristic = Integer(components=(Component(),))
>>> descriptions = (
...     DivisorDescription(space=(characteristic,)),
...     MultipleDescription(space=(characteristic,)),
... )
>>> dataset = [36, 48, 16, 32]
>>> domain = ItemUniverse(dataset)
>>> co_domain = PredicateUniverse(descriptions=descriptions)
>>> context = Context(domain, co_domain)
>>> connection = GaloisConnection(context)
>>> top = Concept(connection)
>>> strategy = NaiveStrategy(descriptions=descriptions)
>>> concepts = list(strategy(top))
>>> support = NormalisedSupport()
>>> [support(sub, top) for sub in concepts]
[0.75, 0.75]

Configuration

If you want to specify a normalised support measure in a TOML file, you can use the following syntax:

[measures.my_measure]
"$type" = "core.measure.NormalisedSupport"

Notes

In this measure, the succ argument is not used.

__call__(pred, succ)#

Measure the normalised support of the concept pred.

Parameters:
  • pred (Concept) – Concept to be measured

  • succ (Concept) – A super-concept of pred

Returns:

The normalised support of pred

Return type:

float

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class RelativeSupport(**data)#

Bases: Measure

Measure the relative support of the concept pred relatively to succ.

ALIAS#

The alias of the type in the resource registry.

Type:

ClassVar[str] = “core.measure.RelativeSupport”

Examples

>>> from galactic.algebras.concept.core import ItemUniverse
>>> from galactic.algebras.convex.characteristics.core import Integer, Component
>>> from galactic.algebras.convex.descriptions.core import (
...     PredicateUniverse,
...     Context,
...     GaloisConnection,
...     Concept,
... )
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
...     DivisorDescription,
...     MultipleDescription,
... )
>>> from galactic.algebras.convex.measures.core import NormalisedSupport
>>> from galactic.algebras.convex.strategies.core import NaiveStrategy
>>> characteristic = Integer(components=(Component(),))
>>> descriptions = (
...     DivisorDescription(space=(characteristic,)),
...     MultipleDescription(space=(characteristic,)),
... )
>>> dataset = [36, 48, 16, 32]
>>> domain = ItemUniverse(dataset)
>>> co_domain = PredicateUniverse(descriptions=descriptions)
>>> context = Context(domain, co_domain)
>>> connection = GaloisConnection(context)
>>> top = Concept(connection)
>>> strategy = NaiveStrategy(descriptions=descriptions)
>>> concepts = list(strategy(top))
>>> support = RelativeSupport()
>>> [support(sub, top) for sub in concepts]
[0.75, 0.75]

Configuration

If you want to specify a relative support measure in a TOML file, you can use the following syntax:

[measures.my_measure]
"$type" = "core.measure.RelativeSupport"

Notes

In this measure, the succ argument is not used.

__call__(pred, succ)#

Measure the relative support of the concept pred relatively to succ.

Parameters:
  • pred (Concept) – Concept to be measured

  • succ (Concept) – A super-concept of pred

Returns:

The relative support of pred relatively to succ

Return type:

float

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].