Skip to content

Commit

Permalink
Merge pull request #999 from fhswf/oa/streams/ca
Browse files Browse the repository at this point in the history
OA: Cluster analysis - updates, corrections, improvements
  • Loading branch information
detlefarend authored May 30, 2024
2 parents cc9021a + 3eec0cd commit 74ae209
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 79 deletions.
2 changes: 2 additions & 0 deletions src/mlpro/bf/math/geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from mlpro.bf.math.geometry.point import Point, cprop_point, cprop_point1, cprop_point2
from mlpro.bf.math.geometry.hypercuboid import Hypercuboid, cprop_hypercuboid
88 changes: 88 additions & 0 deletions src/mlpro/bf/math/geometry/hypercuboid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## -------------------------------------------------------------------------------------------------
## -- Project : MLPro - The integrative middleware framework for standardized machine learning
## -- Package : mlpro.bf.math.geometry
## -- Module : hypercuboid.py
## -------------------------------------------------------------------------------------------------
## -- History :
## -- yyyy-mm-dd Ver. Auth. Description
## -- 2024-05-29 0.0.0 DA Creation
## -------------------------------------------------------------------------------------------------

"""
Ver. 0.0.0 (2024-05-29)
This module provides classes for hypercuboids.
"""


from mlpro.bf.plot import *
from mlpro.bf.math.properties import *
from mlpro.bf.math.normalizers import Normalizer
from mlpro.bf.plot import PlotSettings




## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class Hypercuboid (Property):
"""
Implementation of a point in a hyper space. Current position, velocity and acceleration are managed.
Attributes
----------
values
Current boundaries of the hypercuboid as two-dimensional array-like data object. For a
n-dimensional hypercuboid value[d][0] determines the lower boundary in dimension d while
value[d][1] specifies the upper boundary.
"""

C_PLOT_ACTIVE = True
C_PLOT_STANDALONE = False
C_PLOT_VALID_VIEWS = [PlotSettings.C_VIEW_2D, PlotSettings.C_VIEW_3D, PlotSettings.C_VIEW_ND]
C_PLOT_DEFAULT_VIEW = PlotSettings.C_VIEW_ND

## -------------------------------------------------------------------------------------------------
# def init_plot(self, p_figure: Figure = None, p_plot_settings: PlotSettings = None, **p_kwargs):
# super().init_plot(p_figure, p_plot_settings, **p_kwargs)


## -------------------------------------------------------------------------------------------------
def _update_plot_2d(self, p_settings: PlotSettings, **p_kwargs):
pass

## -------------------------------------------------------------------------------------------------
def _update_plot_3d(self, p_settings: PlotSettings, **p_kwargs):
pass


## -------------------------------------------------------------------------------------------------
def _update_plot_nd(self, p_settings: PlotSettings, **p_kwargs):
pass


## -------------------------------------------------------------------------------------------------
def _remove_plot_2d(self):
pass


## -------------------------------------------------------------------------------------------------
def _remove_plot_3d(self):
pass


## -------------------------------------------------------------------------------------------------
def _remove_plot_nd(self):
pass


## -------------------------------------------------------------------------------------------------
def renormalize(self, p_normalizer: Normalizer):
raise NotImplementedError





cprop_hypercuboid : PropertyDefinition = ( 'hypercuboid', 0, False, Hypercuboid )
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## -------------------------------------------------------------------------------------------------
## -- Project : MLPro - The integrative middleware framework for standardized machine learning
## -- Package : mlpro.bf.math
## -- Module : geometry.py
## -- Package : mlpro.bf.math.geometry
## -- Module : point.py
## -------------------------------------------------------------------------------------------------
## -- History :
## -- yyyy-mm-dd Ver. Auth. Description
Expand All @@ -13,10 +13,12 @@
## -- 2024-05-06 1.4.0 DA Class Point: refactoring
## -- 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.4.2 (2024-05-24)
Ver. 1.6.0 (2024-05-30)
This module provides class for geometric objects like points, etc.
Expand All @@ -38,15 +40,16 @@ class Point (Property):
"""
Implementation of a point in a hyper space. Current position, velocity and acceleration are managed.
Parameters
Attributes
----------
derivative_order_max : DerivativeOrderMax
Maximum order of auto-generated derivatives (numeric properties only).
p_visualize : bool
Boolean switch for visualisation. Default = False.
values
Current point coordinates
"""

C_PLOT_ACTIVE = True
C_PLOT_STANDALONE = False
C_PLOT_VALID_VIEWS = [PlotSettings.C_VIEW_2D, PlotSettings.C_VIEW_3D, PlotSettings.C_VIEW_ND]
C_PLOT_DEFAULT_VIEW = PlotSettings.C_VIEW_ND

## -------------------------------------------------------------------------------------------------
def init_plot(self, p_figure: Figure = None, p_plot_settings: PlotSettings = None, **p_kwargs):
Expand Down Expand Up @@ -155,4 +158,12 @@ def renormalize(self, p_normalizer: Normalizer):
self._value = p_normalizer.renormalize( p_data=np.array(self.value) )
self._derivatives[0] = self._value

# 2024-04-30/DA Renormalization of derivates currently not implemented...
# 2024-04-30/DA Renormalization of derivates currently not implemented...





cprop_point : PropertyDefinition = ( 'point', 0, False, Point )
cprop_point1 : PropertyDefinition = ( 'point', 1, False, Point )
cprop_point2 : PropertyDefinition = ( 'point', 2, False, Point )
72 changes: 64 additions & 8 deletions src/mlpro/bf/math/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@
## -- - new parent classes Plottable, Renormalizable
## -- - implementation of *_plot() and renormalize
## -- - constructor: new parameters p_properties, p_visualization
## -- 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.7.0 (2024-05-27)
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 @@ -47,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 @@ -66,15 +78,21 @@ class Property (Plottable, Renormalizable):
Parameters
----------
p_name : str
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 @@ -85,15 +103,24 @@ class Property (Plottable, Renormalizable):
Current derivatives, stored by order (numeric properties only).
"""

C_PLOT_STANDALONE = False

## -------------------------------------------------------------------------------------------------
def __init__(self, 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_value_prev
self._derivatives = {}
self._derivatives_prev = {}

Expand All @@ -103,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 @@ -120,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 @@ -198,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 @@ -244,6 +278,7 @@ def __init__( self,
def add_property( self,
p_name : PropertyName,
p_derivative_order_max : DerivativeOrderMax = 0,
p_value_prev : ValuePrev = False,
p_cls : PropertyClass = Property,
p_visualize : bool = False ):
"""
Expand All @@ -257,16 +292,20 @@ def add_property( self,
Name of the property. Add a leading '_' to the name to make the related attribute protected.
p_derivative_order_max : DerivativeOrderMax
Maximum order of auto-generated derivatives. Default = 0 (no auto-derivation).
p_value_prev : bool
If True, the previous value is stored in value_prev whenever value is updated.
p_cls : PropertyClass
Optional property class to be used. Default = Property.
p_visualize : bool
Boolean switch for visualisation. Default = False.
"""

prop_obj = p_cls( 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 )
pass


## -------------------------------------------------------------------------------------------------
Expand All @@ -287,7 +326,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 All @@ -305,11 +345,22 @@ def get_properties(self):
return self._properties


## -------------------------------------------------------------------------------------------------
def set_plot_settings(self, p_plot_settings : PlotSettings ):

Plottable.set_plot_settings( self, p_plot_settings = p_plot_settings )

for prop in self.get_properties().values():
prop.set_plot_settings( p_plot_settings = p_plot_settings )


## -------------------------------------------------------------------------------------------------
def init_plot(self, p_figure: Figure = None, p_plot_settings: PlotSettings = None):

if not self.get_visualization(): return

Plottable.init_plot(self, p_figure = p_figure, p_plot_settings = p_plot_settings )

for prop in self.get_properties().values():
prop.init_plot( p_figure = p_figure, p_plot_settings = p_plot_settings)

Expand All @@ -319,20 +370,25 @@ def update_plot( self, **p_kwargs ):

if not self.get_visualization(): return

Plottable.update_plot(self, **p_kwargs )

for prop in self.get_properties().values():
prop.update_plot(**p_kwargs)


## -------------------------------------------------------------------------------------------------
def remove_plot(self, p_refresh:bool = True):

if not self.get_visualization(): return

for prop in self.get_properties().values():
prop.remove_plot( p_refresh = False)

Plottable.remove_plot(self, p_refresh = p_refresh )


## -------------------------------------------------------------------------------------------------
def renormalize(self, p_normalizer : Normalizer ):

for prop in self.get_properties().values():
prop.renormalize( p_normalizer = p_normalizer )
prop.renormalize( p_normalizer = p_normalizer )
16 changes: 2 additions & 14 deletions src/mlpro/bf/mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,23 +960,11 @@ def init_plot( self,
task_pos_x = 1
task_pos_y = 1
task_ax_id = 1
# task_plot_settings = PlotSettings( p_view = ps.view,
# p_axes = task_axes,
# p_pos_x = task_pos_x,
# p_pos_y = task_pos_y,
# p_step_rate = ps.step_rate,
# p_plot_depth = ps.plot_depth,
# p_detail_level = ps.detail_level,
# p_force_fg = ps.force_fg,
# p_id=task_ax_id,
# p_view_autoselect = ps.view_autoselect )
task_plot_settings = ps.copy()
task_plot_settings.axes = task_axes
task_plot_settings = ps.copy()
task_plot_settings.axes = task_axes
task_plot_settings.pos_x = task_pos_x
task_plot_settings.pos_y = task_pos_y
task_plot_settings.id = task_ax_id


else:
# Task plots embedded in the predecessor/workflow figure/subplot
task_figure = plot_host._figure
Expand Down
Loading

0 comments on commit 74ae209

Please sign in to comment.