Skip to content

Commit

Permalink
BF/OA: Enhancements of stream processing #1000
Browse files Browse the repository at this point in the history
  • Loading branch information
detlefarend committed May 30, 2024
1 parent 907cf97 commit 1d1d6e5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/mlpro/bf/math/geometry/hypercuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ def renormalize(self, p_normalizer: Normalizer):



cprop_hypercuboid : PropertyDefinition = ( 'hypercuboid', 0, Hypercuboid )
cprop_hypercuboid : PropertyDefinition = ( 'hypercuboid', 0, False, Hypercuboid )
9 changes: 5 additions & 4 deletions src/mlpro/bf/math/geometry/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
## -- 2024-05-07 1.4.1 DA Bugfix in method Point.renormalize()
## -- 2024-05-24 1.4.2 DA Bugfix in method _update_plot_2d()
## -- 2024-05-29 1.5.0 DA Cleaned the code and completed the documentation
## -- 2024-05-30 1.6.0 DA Global aliases: new boolean param ValuePrev
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.5.0 (2024-05-29)
Ver. 1.6.0 (2024-05-30)
This module provides class for geometric objects like points, etc.
Expand Down Expand Up @@ -163,6 +164,6 @@ def renormalize(self, p_normalizer: Normalizer):



cprop_point : PropertyDefinition = ( 'point', 0, Point )
cprop_point1 : PropertyDefinition = ( 'point', 1, Point )
cprop_point2 : PropertyDefinition = ( 'point', 2, Point )
cprop_point : PropertyDefinition = ( 'point', 0, False, Point )
cprop_point1 : PropertyDefinition = ( 'point', 1, False, Point )
cprop_point2 : PropertyDefinition = ( 'point', 2, False, Point )
43 changes: 37 additions & 6 deletions src/mlpro/bf/math/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
## -- 2024-05-29 0.8.0 DA Class Property:
## -- - standalone plot turned off
## -- - new parameter p_name
## -- 2024-05-30 0.9.0 DA Class Property:
## -- - new attribute value_prev
## -- - new parameter p_value_prev
## -- Class Properties:
## -- - method add_property(): new parameter p_value_prev
## -- Global aliases:
## -- - new alias ValuePrev
## -- - extension of PropertyDefinition by ValuePrev
## -------------------------------------------------------------------------------------------------

"""
Ver. 0.8.0 (2024-05-29)
Ver. 0.9.0 (2024-05-30)
This module provides a systematics for enriched managed properties. MLPro's enriched properties
store any data like class attributes and they can be used like class attributes. They extend the
Expand All @@ -50,9 +58,10 @@
# Type aliases for property definitions
PropertyName = str
DerivativeOrderMax = int
ValuePrev = bool
PropertyClass = type

PropertyDefinition = Tuple[ PropertyName, DerivativeOrderMax, PropertyClass ]
PropertyDefinition = Tuple[ PropertyName, DerivativeOrderMax, ValuePrev, PropertyClass ]
PropertyDefinitions = List[ PropertyDefinition ]


Expand All @@ -73,13 +82,17 @@ class Property (Plottable, Renormalizable):
Name of the property
p_derivative_order_max : DerivativeOrderMax
Maximum order of auto-generated derivatives (numeric properties only).
p_value_prev : bool
If True, the previous value is stored in value_prev whenever value is updated.
p_visualize : bool
Boolean switch for visualisation. Default = False.
Atttributes
-----------
value : Any
Current value of the property.
value_prev : Any
Previous value of the property (readonly).
dim : int
Dimensionality of the stored value. In case of strings the length is returned.
time_stamp : Union[datetime, float, int]
Expand All @@ -93,15 +106,21 @@ class Property (Plottable, Renormalizable):
C_PLOT_STANDALONE = False

## -------------------------------------------------------------------------------------------------
def __init__(self, p_name : str, p_derivative_order_max : DerivativeOrderMax = 0, p_visualize : bool = False ):
def __init__( self,
p_name : str,
p_derivative_order_max : DerivativeOrderMax = 0,
p_value_prev : ValuePrev = False,
p_visualize : bool = False ):

Plottable.__init__(self, p_visualize=p_visualize)

self.name = p_name
self._value = None
self._value_prev = None
self._time_stamp = None
self._time_stamp_prev = None
self._derivative_order_max = p_derivative_order_max
self._sw_value_prev = p_
self._derivatives = {}
self._derivatives_prev = {}

Expand All @@ -111,6 +130,11 @@ def _get(self):
return self._value


## -------------------------------------------------------------------------------------------------
def _get_prev(self):
return self._value_prev


## -------------------------------------------------------------------------------------------------
def set(self, p_value, p_time_stamp : Union[datetime, int, float] = None):
"""
Expand All @@ -128,7 +152,8 @@ def set(self, p_value, p_time_stamp : Union[datetime, int, float] = None):
"""

# 1 Set value
self._value = p_value
if self._sw_value_prev: self._value_prev = self._value
self._value = p_value


# 2 Preparation of time stamp
Expand Down Expand Up @@ -206,6 +231,7 @@ def _get_time_stamp(self):

## -------------------------------------------------------------------------------------------------
value = property( fget = _get, fset = set)
value_prev = property( fget = _get_prev )
dim = property( fget = _get_dim )
time_stamp = property( fget = _get_time_stamp )
derivatives = property( fget = _get_derivatives )
Expand Down Expand Up @@ -252,6 +278,7 @@ def __init__( self,
def add_property( self,
p_name : PropertyName,
p_derivative_order_max : DerivativeOrderMax = 0,
p_value_prev : ValuePrev,
p_cls : PropertyClass = Property,
p_visualize : bool = False ):
"""
Expand All @@ -271,7 +298,10 @@ def add_property( self,
Boolean switch for visualisation. Default = False.
"""

prop_obj = p_cls( p_name = p_name, p_derivative_order_max = p_derivative_order_max, p_visualize = p_visualize )
prop_obj = p_cls( p_name = p_name,
p_derivative_order_max = p_derivative_order_max,
p_value_prev = p_value_prev,
p_visualize = p_visualize )
self._properties[p_name] = prop_obj
setattr(self, p_name, prop_obj )

Expand All @@ -294,7 +324,8 @@ def add_properties( self,
for p in p_property_definitions:
self.add_property( p_name = p[0],
p_derivative_order_max = p[1],
p_cls = p[2],
p_value_prev = p[2],
p_cls = p[3],
p_visualize = p_visualize )


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
## -- 2024-05-07 0.2.0 DA Extensions
## -- 2024-05-24 0.3.0 SK Addition of further properties
## -- 2024-05-29 0.4.0 DA Moved Centroid-based properties to centroid.py
## -- 2024-05-30 0.5.0 DA Global aliases: new boolean param ValuePrev
## -------------------------------------------------------------------------------------------------

"""
Ver. 0.3.0 (2024-05-24)
Ver. 0.5.0 (2024-05-30)
This module provides typical cluster properties to be reused in own cluster analyzers.
"""
Expand All @@ -26,27 +27,27 @@
#

# Size (=number of associated instances) with 0,1,2 order derivatives
cprop_size : PropertyDefinition = ( 'size', 0, Property )
cprop_size1 : PropertyDefinition = ( 'size', 1, Property )
cprop_size2 : PropertyDefinition = ( 'size', 2, Property )
cprop_size : PropertyDefinition = ( 'size', 0, False, Property )
cprop_size1 : PropertyDefinition = ( 'size', 1, False, Property )
cprop_size2 : PropertyDefinition = ( 'size', 2, False, Property )

# Age with 0,1,2 order derivatives
cprop_age : PropertyDefinition = ( 'age', 0, Property )
cprop_age1 : PropertyDefinition = ( 'age', 1, Property )
cprop_age2 : PropertyDefinition = ( 'age', 2, Property )
cprop_age : PropertyDefinition = ( 'age', 0, False, Property )
cprop_age1 : PropertyDefinition = ( 'age', 1, False, Property )
cprop_age2 : PropertyDefinition = ( 'age', 2, False, Property )

# Density with 0,1,2 order derivatives
cprop_density : PropertyDefinition = ( 'density', 0, Property )
cprop_density1 : PropertyDefinition = ( 'density', 1, Property )
cprop_density2 : PropertyDefinition = ( 'density', 2, Property )
cprop_density : PropertyDefinition = ( 'density', 0, False, Property )
cprop_density1 : PropertyDefinition = ( 'density', 1, False, Property )
cprop_density2 : PropertyDefinition = ( 'density', 2, False, Property )

# Geometric size with 0,1,2 order derivatives
cprop_size_geo : PropertyDefinition = ( 'size_geo', 0, Property )
cprop_size_geo1 : PropertyDefinition = ( 'size_geo', 1, Property )
cprop_size_geo2 : PropertyDefinition = ( 'size_geo', 2, Property )
cprop_size_geo : PropertyDefinition = ( 'size_geo', 0, False, Property )
cprop_size_geo1 : PropertyDefinition = ( 'size_geo', 1, False, Property )
cprop_size_geo2 : PropertyDefinition = ( 'size_geo', 2, False, Property )

# Compactness with 0,1,2 order derivatives
cprop_compactness : PropertyDefinition = ( 'compactness', 0, Property )
cprop_compactness1 : PropertyDefinition = ( 'compactness', 1, Property )
cprop_compactness2 : PropertyDefinition = ( 'compactness', 2, Property )
cprop_compactness : PropertyDefinition = ( 'compactness', 0, False, Property )
cprop_compactness1 : PropertyDefinition = ( 'compactness', 1, False, Property )
cprop_compactness2 : PropertyDefinition = ( 'compactness', 2, False, Property )

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
## -- yyyy-mm-dd Ver. Auth. Description
## -- 2024-05-04 0.1.0 DA Creation
## -- 2024-05-29 0.2.0 DA Refactoring
## -- 2024-05-30 0.3.0 DA Global aliases: new boolean param ValuePrev
## -------------------------------------------------------------------------------------------------

"""
Ver. 0.2.0 (2024-05-29)
Ver. 0.3.0 (2024-05-29)
This module provides ...
Expand Down Expand Up @@ -256,11 +257,11 @@ def _remove_plot_3d(self):


# Centroid with 0,1,2 order derivatives and plot functionality
cprop_centroid : PropertyDefinition = ( 'centroid', 0, Centroid )
cprop_centroid1 : PropertyDefinition = ( 'centroid', 1, Centroid )
cprop_centroid2 : PropertyDefinition = ( 'centroid', 2, Centroid )
cprop_centroid : PropertyDefinition = ( 'centroid', 0, False, Centroid )
cprop_centroid1 : PropertyDefinition = ( 'centroid', 1, False, Centroid )
cprop_centroid2 : PropertyDefinition = ( 'centroid', 2, False, Centroid )

# Geometric center with 0,1,2 order derivatives and plot functionality
cprop_center_geo : PropertyDefinition = ( 'center_geo', 0, Centroid )
cprop_center_geo1 : PropertyDefinition = ( 'center_geo', 1, Centroid )
cprop_center_geo2 : PropertyDefinition = ( 'center_geo', 2, Centroid )
cprop_center_geo : PropertyDefinition = ( 'center_geo', 0, False, Centroid )
cprop_center_geo1 : PropertyDefinition = ( 'center_geo', 1, False, Centroid )
cprop_center_geo2 : PropertyDefinition = ( 'center_geo', 2, False, Centroid )

0 comments on commit 1d1d6e5

Please sign in to comment.