📘 Characteristics#
The galactic.algebras.convex.characteristics.core module defines the foundational
building blocks of characteristics.
It provides the
Characteristic protocol,
JMESPath-based Component
extraction, and concrete value types like:
Characteristics compute lists of possible values (imprecision) from item data and
combine component outputs through an abstract
_call() method.
The module also supplies an
identity component class
instance.
Creating components#
Components are the atomic elements constituting a characteristic. They are defined using
a JMESPath-based expression and are able
to give each datum an iterator of possible values representing imprecision using the
find() method.
from galactic.algebras.concept.core import Item
from galactic.algebras.convex.characteristics.core import Component
component = Component(expr="value")
display(component)
print(component)
dataset = [
{"value": 5},
{},
]
display(component.find(Item(value=dataset[0])))
display(component.find(Item(value=dataset[1])))
Component(expr='value')
value
[5]
None
Creating characteristics#
A characteristic is created from a sequence of components and is determined by its
optional name and other parameters depending on the characteristic type. Its string
representation is done using a template with the mechanism of the
format() method.
from galactic.algebras.convex.characteristics.core import (
Component,
Integer,
)
component = Component(expr="value")
characteristic = Integer(component=component)
display(str(characteristic))
dataset = [
{"value": 1},
{"value": "a"},
{},
]
display(
characteristic(Item(value=dataset[0])),
characteristic(Item(value=dataset[1])),
characteristic(Item(value=dataset[2])),
)
characteristic = Integer(component=Component(expr="value", multiple=True))
display(str(characteristic))
dataset = [
{"value": [1.2, 2.3]},
{"value": [3]},
]
display(
characteristic(Item(value=dataset[0])),
characteristic(Item(value=dataset[1])),
)
'int(value)'
[1]
None
None
'int(value)'
[1, 2]
[3]
Caching characteristics#
Calls to characteristics can be cached:
from galactic.algebras.convex.characteristics.core import (
Component,
Integer,
)
component = Component(expr="value")
characteristic = Integer(component=component, cache=True)
display(characteristic.cache_info())
dataset = [
{"value": 1},
{"value": "a"},
{},
]
items = [Item(value=dataset[0]), Item(value=dataset[1]), Item(value=dataset[2])]
display(
characteristic(items[0]),
characteristic(items[1]),
characteristic(items[2]),
)
display(characteristic.cache_info())
display(
characteristic(items[0]),
characteristic(items[1]),
characteristic(items[2]),
)
display(characteristic.cache_info())
characteristic.cache_clear()
display(characteristic.cache_info())
CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)
[1]
None
None
CacheInfo(hits=0, misses=3, maxsize=None, currsize=3)
[1]
None
None
CacheInfo(hits=3, misses=3, maxsize=None, currsize=3)
CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)