galactic.algebras.convex.descriptions.core#
galactic.algebras.convex.descriptions.core module
Defines core components for descriptions in convex algebras.
Description
Description: Base class for descriptions in convex algebrasBooleanDescription: Represents the boolean description
Galois connection
Concept: Represents a concept in a Galois connectionExtent: Represents the extent of a concept in a Galois connectionIntent: Represents the intent of a concept in a Galois connectionConvex: Represents a closed set of predicates for a description spaceItemPolarity: Represents item polarity in a Galois connectionPredicatePolarity: Represents predicate polarity in a Galois connectionGaloisConnection: Implements the Galois connection
Context
Context: Represents the context of a Galois connectionPredicateUniverse: Represents the universe of predicates in a context
- class Description(**data)#
Bases:
Resource,ABCRepresents description spaces.
A description space must have a
_call()method able to compute the minimal descriptors for a collection of values; i.e. the borders. It is used to compute the description for a collection of items. It is an abstract class that should be subclassed to implement specific description spaces.- Parameters:
space – A tuple of characteristics
- Raises:
TypeError – If any element in the space is not an instance of Characteristic
Notes
The __call__ method is designed to be used as a callable description, allowing instances of this class to be used directly in contexts where a description is required. It takes a collection of items and computes the description based on the characteristics defined in the space.
The __call__ method iterates over the items, applying the characteristics to each item’s value. If any characteristic returns None, the method returns an empty iterator, indicating that no valid descriptions can be computed. Otherwise, it calls the _call method to compute the actual descriptions based on the values returned by the characteristics.
The space property returns the collection of characteristics that define the description space. This allows access to the characteristics used in the description, which can be useful for understanding or modifying the description’s behavior.
When subclassing this class, ensure to implement the _call method to provide the specific logic for computing descriptions based on the values of the characteristics.
- __call__(items)#
Compute the description of the items.
- __contains__(attr)#
Check if the predicate is in the description space.
- Parameters:
attr (
object) – The predicate to check for membership in the description space- Returns:
True if the predicate is in the description space, False otherwise
- Return type:
Notes
The attr parameter is expected to be an instance of Predicate.
The method should return True if the predicate is part of the description space defined by the characteristics in the description, and False otherwise.
The method checks if the predicate’s characteristics match the description space and if the predicate is contained within the description space using the _contains method. The _contains method should return True when the predicate is an instance of yielded predicates of the _call method.
- class BooleanDescription(**data)#
Bases:
DescriptionA description of a boolean characteristic.
This class represents a description of a boolean characteristic. It validates that the space contains exactly one boolean characteristic and describes a collection of values by yielding boolean predicates.
- ALIAS#
The alias of the type in the resource registry.
- Type:
ClassVar[str] = “core.description.Boolean”
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Boolean, Component >>> from galactic.algebras.convex.descriptions.core import BooleanDescription >>> data = [ ... [1, 0, 0, 0], ... [0, 1, 0, 0], ... [0, 1, 1, 0], ... [0, 0, 1, 0], ... [0, 0, 1, 1], ... ] >>> universe = ItemUniverse(data) >>> component = Component(expr="[2]") >>> characteristic = Boolean(components=(component,), name="attribute") >>> description = BooleanDescription(space=(characteristic,)) >>> [str(attr) for attr in description(universe)] [] >>> [str(attr) for attr in description(universe[2:])] ['attribute']
Configuration
If you want to specify a boolean desription in a TOML file, you can use the following syntax:
[components.my_component] "$type" = "core.Component" expr = "value" [characteristics.my_characteristic] "$type" = "core.characteristic.Boolean" components = [ {"$ref" = "components.my_component"} ] name = "my_name" [descriptions.my_description] "$type" = "core.description.Boolean" space = [ {"$ref" = "characteristics.my_characteristic"} ]
- class Concept(connection, items=None, attrs=None)#
Bases:
ConceptRepresents a convex concept in Formal Concept Analysis (FCA).
- Parameters:
Notes
The Concept class represents a convex concept in Formal Concept Analysis (FCA), which is a mathematical framework for analyzing the relationships between objects and their attributes.
It is built upon a Galois connection, which is a pair of monotone functions that establish a relationship between two partially ordered sets.
The class allows for the creation of concepts based on a set of items and predicates, where items represent objects and predicates represent properties of those objects.
The concept can be constructed either by providing a set of items or by specifying a set of predicates that define the concept.
Providing both items and attrs is ambiguous and raises a ValueError.
The extent property returns the set of items that belong to the concept, while the intent property returns the set of predicates that define the concept.
The borders property provides a collection of predicates that describe the borders of the concept in the description space.
The __lt__, __le__, __gt__, and __ge__ methods allow comparison between concepts based on their extents, enabling the establishment of a partial order among concepts.
The __and__ and __or__ methods allow computing the meet and join of concepts, respectively, enabling the creation of new concepts from existing ones.
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.core import Concept >>> from galactic.algebras.convex.predicates.examples.arithmetic.core import ( ... Multiple, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=(description,)), ... ) >>> connection = GaloisConnection(context) >>> top = Concept(connection) >>> top.extent <galactic.algebras.convex.descriptions.core.Extent object at 0x...> >>> [item.value for item in top.extent] [36, 48, 16, 32] >>> top.intent <galactic.algebras.convex.descriptions.core.Intent object at 0x...> >>> [str(attr) for attr in top.intent] ['M(int(@),4)'] >>> concept1 = Concept( ... connection, ... items=[context.domain[1], context.domain[2]], ... ) >>> [item.value for item in concept1.extent] [48, 16, 32] >>> [str(attr) for attr in concept1.intent] ['M(int(@),16)'] >>> multiple_12 = Multiple(space=description.space, number=12) >>> concept2 = Concept(connection, attrs=[multiple_12]) >>> [item.value for item in concept2.extent] [36, 48] >>> [str(attr) for attr in concept2.intent] ['M(int(@),4)', 'M(int(@),3)'] >>> meet = concept1 & concept2 >>> [item.value for item in meet.extent] [48] >>> [str(attr) for attr in meet.intent] ['M(int(@),16)', 'M(int(@),3)'] >>> meet <= concept1 True >>> meet <= concept2 True >>> join = concept1 | concept2 >>> [item.value for item in join.extent] [36, 48, 16, 32] >>> [str(attr) for attr in join.intent] ['M(int(@),4)'] >>> join >= concept1 True >>> join >= concept2 True
- __hash__()#
Compute the hash value of the concept.
- Returns:
The hash value of the concept
- Return type:
- __eq__(other)#
Check whether this concept is equal to another object.
- __lt__(other)#
Check if this concept is less than another concept.
- __le__(other)#
Check if this concept is less than or equal to another concept.
- __gt__(other)#
Check if this concept is greater than another concept.
- __ge__(other)#
Check if this concept is greater than or equal to another concept.
- __or__(other)#
Compute the join of two concepts.
- Parameters:
other (
object) – Another concept to join with- Returns:
The join of the two concepts
- Return type:
Self
- join(*others)#
Compute the join of multiple concepts.
- Parameters:
*others (
Self) – Other concepts to join with- Returns:
The join of the concepts
- Return type:
Self- Raises:
TypeError – If any of the other concepts is not of the same type as self
ValueError – If any of the other concepts does not share the same connection as self
- __and__(other)#
Compute the meet of two concepts.
- Parameters:
other (
object) – Another concept to meet with- Returns:
The meet of the two concepts
- Return type:
Self
- meet(*others)#
Compute the meet of multiple concepts.
- Parameters:
*others (
Self) – Other concepts to meet with- Returns:
The meet of the concepts
- Return type:
Self- Raises:
TypeError – If any of the other concepts is not of the same type as self
ValueError – If any of the other concepts does not share the same connection as self
- property connection: GaloisConnection#
Get the underlying antitone Galois connection.
- Returns:
The antitone Galois connection
- Return type:
- property intent: Intent#
Get the intent of the concept.
- Returns:
The intent of the concept
- Return type:
- class Extent(connection, attrs=None)#
Bases:
ExtentRepresents a finite closed set of items.
- Parameters:
connection (
GaloisConnection) – The Galois connectionattrs (
Iterable[Predicate] |None, default:None) – The predicates shared by the items in the closed set
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription, ... ) >>> from galactic.algebras.convex.predicates.examples.arithmetic.core import ( ... Multiple, ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=(description,)), ... ) >>> connection = GaloisConnection(context) >>> extent = Extent( ... connection, ... [ ... Multiple(space=description.space, number=4), ... Multiple(space=description.space, number=3), ... ], ... ) >>> extent <galactic.algebras.convex.descriptions.core.Extent object at 0x...> >>> [item.value for item in extent] [36, 48] >>> len(extent) 2
Notes
The Extent class represents a finite closed set of items that share a common set of predicates.
The attrs parameter is used to define the common predicates that characterize the items in the extent. The extent will include all items that satisfy all the specified predicates.
The connection parameter is used to link the extent to the Galois connection, which allows for the computation of the corresponding intent and for checking membership of items in the extent.
Hint
The Extent class is typically used in conjunction with the Intent class to define the Galois connection between items and predicates, where the extent represents the set of items that share a common set of predicates, and the intent represents the set of predicates that are shared by a common set of items.
- static __new__(cls, connection=None, attrs=None)#
Create a new extent object.
- Parameters:
connection (
GaloisConnection|None, default:None) – The Galois connectionattrs (
Iterable[Predicate] |None, default:None) – The predicates shared by the items in the closed set
- Return type:
Self
Notes
If the extent is created with only one intent with known extent, it returns that extent, otherwise it returns a new one.
- __or__(other)#
Compute the join with another extent.
- Parameters:
other (
object) – The other extent- Returns:
The join of the two extents
- Return type:
Self- Raises:
ValueError – If the extents belong to different connections
- join(*others)#
Compute the join with multiple extents.
- Parameters:
*others (
Self) – The other extents- Returns:
The join of the extents
- Return type:
Self- Raises:
TypeError – If any of the others is not an Extent
ValueError – If any of the extents belong to different connections
- __and__(other)#
Compute the meet with another extent.
- Parameters:
other (
object) – The other extent- Returns:
The meet of the two extents
- Return type:
Self- Raises:
ValueError – If the extents belong to different connections
- meet(*others)#
Compute the meet with multiple extents.
- Parameters:
*others (
Extent) – The other extents- Returns:
The meet of the extents
- Return type:
Self- Raises:
TypeError – If any of the others is not an Extent
ValueError – If any of the extents belong to different connections
- property connection: GaloisConnection#
Get the connection.
- Returns:
The connection
- Return type:
- class Intent(connection, items=None)#
Bases:
Closed[Predicate]Represents a closed set of attributes.
- Parameters:
connection (
GaloisConnection) – The Galois connectionitems (
Iterable[Item] |None, default:None) – The items sharing the attributes in the closed set
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... DivisorDescription, ... MultipleDescription, ... ) >>> characteristic = Integer(components=(Component(),)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse( ... descriptions=( ... DivisorDescription(space=(characteristic,)), ... MultipleDescription(space=(characteristic,)), ... ), ... ) ... ) >>> connection = GaloisConnection(context) >>> intent = Intent(connection, [context.domain[0], context.domain[1]]) >>> intent <galactic.algebras.convex.descriptions.core.Intent object at 0x...> >>> [str(attr) for attr in intent] ['D(int(@),144)', 'M(int(@),4)', 'M(int(@),3)'] >>> # Display the predicates for the description space #0 >>> [str(attr) for attr in intent.convexes[0]] ['D(int(@),144)'] >>> # Display the predicates for the description space #1 >>> [str(attr) for attr in intent.convexes[1]] ['M(int(@),4)', 'M(int(@),3)']
- static __new__(cls, connection=None, items=None)#
Create a new intent object.
Notes
If the intent is created with only one extent with known intent, it returns that intent, otherwise it returns a new one.
- Return type:
Self
- __hash__()#
Compute the hash value of the intent.
- Returns:
The hash value of the intent
- Return type:
- __eq__(other)#
Check if self is equal to other.
- Parameters:
other (
object) – The other intent to compare with- Returns:
True if self is equal to other.
- Return type:
Notes
Equality is determined by comparing the bitmaps of the corresponding extents, i.e., two intents are equal if their corresponding extents contain the same elements.
- __lt__(other)#
Check if self is less than other.
- Parameters:
other (
object) – The other intent to compare with- Returns:
True if self is less than other.
- Return type:
Notes
An intent is considered less than another if it is a proper subset of the other.
- __le__(other)#
Check if self is less than or equal to other.
- Parameters:
other (
object) – The other intent to compare with- Returns:
True if self is less than or equal to other.
- Return type:
Notes
An intent is considered less than or equal to another if it is a subset of the other.
- __gt__(other)#
Check if self is greater than other.
- Parameters:
other (
object) – The other intent to compare with- Returns:
True if self is greater than other.
- Return type:
Notes
An intent is considered greater than another if it is a proper superset of the other.
- __ge__(other)#
Check if self is greater than or equal to other.
- Parameters:
other (
object) – The other intent to compare with- Returns:
True if self is greater than or equal to other.
- Return type:
Notes
An intent is considered greater than or equal to another if it is a superset of the other.
- __contains__(attr)#
Check if the predicate is in the intent.
- __iter__()#
Iterate over the borders in the intent.
- __len__()#
Get the number of borders in the intent.
- Returns:
The number of borders in the intent
- Return type:
- __or__(other)#
Compute the join with another intent.
- Parameters:
other (
object) – The other intent- Returns:
The join of the two intents
- Return type:
Self
- join(*others)#
Compute the join with multiple intents.
- Parameters:
*others (
Self) – The other intents- Returns:
The join of the intents
- Return type:
Self- Raises:
TypeError – If any of the others is not an Intent
ValueError – If any of the intents belong to different connections
- __and__(other)#
Compute the meet with another intent.
- Parameters:
other (
object) – The other intent- Returns:
The meet of the two intents
- Return type:
Self
- meet(*others)#
Compute the meet with multiple intents.
- Parameters:
*others (
Self) – The other intents- Returns:
The meet of the intents
- Return type:
Self- Raises:
TypeError – If any of the others is not an Intent
ValueError – If any of the intents belong to different connections
- property connection: GaloisConnection#
Get the connection.
- Returns:
The connection
- Return type:
- class Convex(connection, index, *items)#
Bases:
Closed[Predicate]A convex is a closed set of predicates in a description space.
- Parameters:
connection (
GaloisConnection) – The Galois connectionindex (
int) – The index of the description spaceitems (
Iterable[Item]) – The items sharing the predicates in the closed set
- __eq__(other)#
Check if self is equal to other.
- Parameters:
other (
object) – The other convex to compare with- Returns:
True if self is equal to other.
- Return type:
Notes
Equality is determined by comparing the sets of items in both convexes, i.e., two convexes are equal if their corresponding item sets are identical.
- __lt__(other)#
Check if self is less than other.
- Parameters:
other (
object) – The other convex to compare with- Returns:
True if self is less than other.
- Return type:
Notes
A convex is considered less than another if it is a proper subset of the other.
- __le__(other)#
Check if self is less than or equal to other.
- Parameters:
other (
object) – The other convex to compare with- Returns:
True if self is less than or equal to other.
- Return type:
Notes
A convex is considered less than or equal to another if it is a subset of the other.
- __gt__(other)#
Check if self is greater than other.
- Parameters:
other (
object) – The other convex to compare with- Returns:
True if self is greater than other.
- Return type:
Notes
A convex is considered greater than another if it is a proper superset of the other.
- __ge__(other)#
Check if self is greater than or equal to other.
- Parameters:
other (
object) – The other convex to compare with- Returns:
True if self is greater than or equal to other.
- Return type:
Notes
A convex is considered greater than or equal to another if it is a superset of the other.
- __or__(other)#
Compute the join with another convex.
- Parameters:
other (
object) – The other convex- Returns:
The join of the two convexes
- Return type:
Self
- join(*others)#
Compute the join with multiple convexes.
- Parameters:
*others (
Self) – The other convexes- Returns:
The join of the convexes
- Return type:
Self- Raises:
TypeError – If any of the others is not a Convex
ValueError – If any of the extents belong to different connections
- __and__(other)#
Compute the meet with another convex.
- Parameters:
other (
object) – The other convex- Returns:
The meet of the two convexes
- Return type:
Self
- meet(*others)#
Compute the meet with multiple convexes.
- Parameters:
*others (
Self) – The other convexes- Returns:
The meet of the convexes
- Return type:
Self- Raises:
TypeError – If any of the others is not a Convex
ValueError – If any of the extents belong to different connections
- __iter__()#
Iterate over the borders in the convex.
- __contains__(attr)#
Check if the predicate is in the convex.
- property connection: GaloisConnection#
Get the connection.
- Returns:
The connection
- Return type:
- class ItemPolarity(connection)#
Bases:
Polarity[Predicate,Item]Represents the polarity of items.
- Parameters:
connection (
GaloisConnection) – A Galois connection
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription ... ) >>> from galactic.algebras.convex.predicates.examples.arithmetic.core import ( ... Multiple, ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=(description,)) ... ) >>> connection = GaloisConnection(context) >>> extent = connection.polarities[1]( ... [ ... Multiple(space=description.space, number=4), ... Multiple(space=description.space, number=3), ... ], ... ) >>> extent <galactic.algebras.convex.descriptions.core.Extent object at 0x...> >>> [item.value for item in extent] [36, 48]
- __call__(*elements)#
Compute the correspondence of elements.
- Parameters:
- Returns:
The correspondence of the elements
- Return type:
- Raises:
ValueError – If an element is not in the context co-domain
- property connection: GaloisConnection#
Get the connection.
- Returns:
The connection
- Return type:
- class PredicatePolarity(connection)#
Bases:
objectRepresents the polarity of predicates.
- Parameters:
connection (
GaloisConnection) – A Galois connection
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=(description,)), ... ) >>> connection = GaloisConnection(context) >>> intent = connection.polarities[0]( ... [ ... context.domain[0], ... context.domain[1], ... ], ... ) >>> [str(border) for border in intent] ['M(int(@),4)', 'M(int(@),3)']
- __call__(*elements)#
Compute the correspondence of elements.
- Parameters:
*elements (
Iterable[Item]) – Iterable of items- Returns:
The correspondence of the elements
- Return type:
- Raises:
ValueError – If an element is not in the context domain
- property connection: GaloisConnection#
Get the connection.
- Returns:
The connection
- Return type:
- class GaloisConnection(context)#
Bases:
GaloisConnection[Item,Predicate]Represents an antitone Galois connection.
It is obtained using an item universe and a description.
- Parameters:
context (
Context) – The context of the Galois connection, which includes the item universe and the predicate universe, as well as the binary relation between them.
Examples
>>> from galactic.algebras.concept.core import ItemUniverse >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import ( ... Context, ... GaloisConnection, ... PredicateUniverse, ... ) >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription, ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=(description,)), ... ) >>> connection = GaloisConnection(context) >>> connection <galactic.algebras.convex.descriptions.core.GaloisConnection object at 0x...>
- property polarities: tuple[PredicatePolarity, ItemPolarity]#
Get the polarities.
- Returns:
The polarities
- Return type:
- class Context(domain, co_domain)#
Bases:
BinaryRelation[Item,Predicate]Represents contexts in generalized convex hull FCA.
- Parameters:
domain (
ItemUniverse) – The item universeco_domain (
PredicateUniverse) – The predicate universe
Examples
>>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.descriptions.core import Context >>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... DivisorDescription, ... MultipleDescription, ... ) >>> from galactic.algebras.convex.predicates.examples.arithmetic.core import ( ... Multiple, ... ) >>> characteristic = Integer(components=(Component(),)) >>> descriptions = ( ... DivisorDescription(space=(characteristic,)), ... MultipleDescription(space=(characteristic,)), ... ) >>> dataset = [36, 48, 16, 32] >>> context = Context( ... ItemUniverse(dataset), ... PredicateUniverse(descriptions=descriptions), ... ) >>> context <galactic.algebras.convex.descriptions.core.Context object at 0x...> >>> [item.value for item in context.domain] [36, 48, 16, 32] >>> multiple_3 = Multiple(space=descriptions[1].space, number=3) >>> successors = context.successors(context.domain[0]) # 36 >>> successors <galactic...Successors object at 0x...> >>> multiple_3 in successors True >>> [item.value for item in context.predecessors(multiple_3)] [36, 48] >>> (context.domain[0], multiple_3) in context True >>> (context.domain[1], multiple_3) in context True >>> (context.domain[2], None) in context False
- __bool__()#
Check if the context is non-empty.
- Returns:
True if the context has elements, False otherwise.
- Return type:
- __contains__(pair)#
Check if an (item, pred) pair is in the context.
- __iter__()#
Iterate over the (item, pred) pairs in the context.
- __len__()#
Get the number of (item, pred) pairs in the context.
- Returns:
The number of pairs in the context.
- Return type:
- property universes: tuple[ItemUniverse, Sequence[Predicate]]#
Get the universes of this context.
This property returns the collection of universes associated with this context. It includes the item universe and the predicate universe, which are used to represent the items and predicates in the context, respectively.
- property domain: ItemUniverse#
Get the domain of this context.
This property returns the item universe associated with this context.
- Returns:
The domain
- Return type:
ItemUniverse
- property co_domain: PredicateUniverse#
Get the co-domain of this context.
This property returns the predicate universe associated with this context.
- Returns:
The co-domain
- Return type:
- successors(item)#
Compute the successors of item.
- Parameters:
item (
Item) – The item- Returns:
The successors of item
- Return type:
- Raises:
ValueError – If item is not in the domain
- predecessors(attr)#
Compute the predecessors of a predicate.
- Parameters:
attr (
Predicate) – The predicate- Returns:
The predecessors of attr
- Return type:
Collection[Item]- Raises:
ValueError – If attr is not in the co-domain
- property descriptions: tuple[Description, ...]#
Get the descriptions.
- Returns:
The descriptions
- Return type:
tuple[Description, …]
- class PredicateUniverse(**data)#
Bases:
Resource,Sequence[Predicate]Represents a universe of predicates.
This class is used to represent a collection of predicates that can be evaluated against items in a context. It is designed to be used as a container for predicates, allowing for operations such as checking membership and representation.
- Parameters:
descriptions (tuple[Description, ...]) – The description spaces to include in the global universe
- ALIAS#
The alias of the type in the resource registry.
- Type:
ClassVar[str] = “core.universe.PredicateUniverse”
Examples
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import ( ... MultipleDescription, ... ) >>> from galactic.algebras.convex.characteristics.core import Component, Integer >>> from galactic.algebras.convex.predicates.examples.arithmetic.core import ( ... Multiple, ... ) >>> characteristic = Integer(components=(Component(),)) >>> description = MultipleDescription(space=(characteristic,)) >>> predicate_universe = PredicateUniverse(descriptions=(description,)) >>> predicate_universe <galactic.algebras.convex.descriptions.core.PredicateUniverse object at 0x...> >>> multiple_3 = Multiple(space=description.space, number=3) >>> multiple_3 in predicate_universe True >>> len(predicate_universe) 0 >>> list(predicate_universe) [] >>> predicate_universe.descriptions == (description,) True
Configuration
If you want to specify an predicate universe in a TOML file, you can use the following syntax for a boolean description:
[components.my_component] "$type" = "core.Component" expr = "value" [characteristics.my_characteristic] "$type" = "core.characteristic.Boolean" components = [ {"$ref" = "components.my_component"} ] name = "my_name" [descriptions.my_description] "$type" = "core.description.Boolean" space = [ {"$ref" = "characteristics.my_characteristic"} ] [universes.my_predicate_universe] "$type" = "core.universe.PredicateUniverse" descriptions = [ {"$ref" = "descriptions.my_description"} ]
- __bool__()#
Check if the global universe is non-empty.
- Returns:
True if the global universe has elements, False otherwise
- Return type:
- __contains__(attr)#
Check if the predicate is in the global universe.
- __iter__()#
Iterate over the predicates in the global universe.
- __len__()#
Get the number of predicates in the global universe.
- Returns:
The number of predicates in the global universe
- Return type:
- __getitem__(index)#
Get an element or a slice from the universe.
- index(elem, start=None, stop=None)#
Get the index of an element.
- Parameters:
- Returns:
The index requested
- Return type:
- Raises:
ValueError – If the element is not in the universe or not found in the interval
- count(elem)#
Get the total number of occurrences of the element.
- model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)#
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.