Skip to content

Commit

Permalink
OA: Design updates on cluster analysis #1015
Browse files Browse the repository at this point in the history
  • Loading branch information
detlefarend committed Jul 8, 2024
1 parent ab3cdd7 commit 1c30f11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
51 changes: 36 additions & 15 deletions src/mlpro/bf/math/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
## -- 2024-06-26 1.4.0 DA New method Properties.set_plot_color()
## -- 2024-06-30 1.5.0 DA Method Property.set(): new parameters p_upd_time_stamp,
## -- p_upd_derivatives
## -- 2026-07-08 1.6.0 DA Introduction of kwargs
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.5.0 (2024-06-30)
Ver. 1.6.0 (2024-07-08)
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 @@ -58,6 +59,7 @@
import numpy as np
from matplotlib.figure import Figure

from mlpro.bf.various import KWArgs
from mlpro.bf.plot import Plottable, PlotSettings
from mlpro.bf.math.normalizers import Normalizer, Renormalizable

Expand All @@ -77,7 +79,7 @@

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class Property (Plottable, Renormalizable):
class Property (Plottable, Renormalizable, KWArgs):
"""
This class implements an enriched managed property. It enables storing a value of any type. In
case of numeric data (one- or multi-dimensional), an auto-derivation up to a well-defined maximum
Expand All @@ -94,8 +96,10 @@ class Property (Plottable, Renormalizable):
If True, the previous value is stored in value_prev whenever value is updated.
p_visualize : bool
Boolean switch for visualisation. Default = False.
p_kwargs : dict
Keyword parameters.
Atttributes
Attributes
-----------
value : Any
Current value of the property.
Expand All @@ -118,9 +122,11 @@ def __init__( self,
p_name : str,
p_derivative_order_max : DerivativeOrderMax = 0,
p_value_prev : ValuePrev = False,
p_visualize : bool = False ):
p_visualize : bool = False,
**p_kwargs ):

Plottable.__init__(self, p_visualize=p_visualize)
KWArgs.__init__(self, **p_kwargs)

self.name = p_name
self._value = None
Expand Down Expand Up @@ -270,7 +276,9 @@ class Properties (Plottable, Renormalizable):
List of property definitions.
p_visualize : bool
Boolean switch for visualisation. Default = False.
p_kwargs : dict
Keyword parameters to be handed over to all properties.
Attributes
----------
C_PROPERTIES : PropertyDefinitions
Expand All @@ -282,12 +290,13 @@ class Properties (Plottable, Renormalizable):
## -------------------------------------------------------------------------------------------------
def __init__( self,
p_properties : PropertyDefinitions = [],
p_visualize : bool = False ):
p_visualize : bool = False,
**p_kwargs ):

self._properties = {}
self._property_definitions = {}
self.add_properties( p_property_definitions = self.C_PROPERTIES, p_visualize = p_visualize )
self.add_properties( p_property_definitions = p_properties, p_visualize = p_visualize )
self.add_properties( p_property_definitions = self.C_PROPERTIES, p_visualize = p_visualize, **p_kwargs )
self.add_properties( p_property_definitions = p_properties, p_visualize = p_visualize, **p_kwargs )
self._update_property_links()

Plottable.__init__( self, p_visualize = p_visualize )
Expand All @@ -299,7 +308,8 @@ def add_property( self,
p_derivative_order_max : DerivativeOrderMax = 0,
p_value_prev : ValuePrev = False,
p_cls : PropertyClass = Property,
p_visualize : bool = False ):
p_visualize : bool = False,
**p_kwargs ):
"""
Adds a new managed property as an attribute to the own class. Optionally, auto-derivation can
be added for numeric properties (scalar or vectorial). The property is stored in the protected
Expand All @@ -317,12 +327,15 @@ def add_property( self,
Optional property class to be used. Default = Property.
p_visualize : bool
Boolean switch for visualisation. Default = False.
p_kwargs : dict
Optional keyword parameters.
"""

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 )
p_visualize = p_visualize,
**p_kwargs )
self._properties[p_name] = (prop_obj, False)
self._property_definitions[p_name] = ( p_name, p_derivative_order_max, p_value_prev, p_cls )
setattr(self, p_name, prop_obj )
Expand All @@ -331,7 +344,8 @@ def add_property( self,
## -------------------------------------------------------------------------------------------------
def add_properties( self,
p_property_definitions : PropertyDefinitions,
p_visualize : bool = False ):
p_visualize : bool = False,
**p_kwargs ):
"""
Adds new managed properties to the own class. See method add_property() for further details.
Expand All @@ -341,14 +355,17 @@ def add_properties( self,
List of property definitions.
p_visualize : bool
Boolean switch for visualisation. Default = False.
p_kwargs : dict
Keyword parameters to be handed over to all properties.
"""

for p in p_property_definitions:
self.add_property( p_name = p[0],
p_derivative_order_max = p[1],
p_value_prev = p[2],
p_cls = p[3],
p_visualize = p_visualize )
p_visualize = p_visualize,
**p_kwargs )


## -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -499,6 +516,7 @@ def renormalize(self, p_normalizer : Normalizer ):
if not link: prop.renormalize( p_normalizer = p_normalizer )


## -------------------------------------------------------------------------------------------------
color = property( fget = Plottable.get_plot_color, fset = set_plot_color )


Expand All @@ -515,14 +533,17 @@ def __init__( self,
p_derivative_order_max: int = 0,
p_value_prev : ValuePrev = False,
p_properties : PropertyDefinitions = [],
p_visualize: bool = False ):
p_visualize: bool = False,
**p_kwargs ):

Property.__init__( self,
p_name,
p_derivative_order_max = p_derivative_order_max,
p_value_prev = p_value_prev,
p_visualize = p_visualize )
p_visualize = p_visualize,
**p_kwargs )

Properties.__init__( self,
p_properties = p_properties,
p_visualize = p_visualize )
p_visualize = p_visualize,
**p_kwargs )
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
## -- 2024-05-29 1.8.0 DA Class Cluster: order of colors changed
## -- 2024-06-08 1.9.0 DA New method Cluster.get_influence()
## -- 2024-06-18 2.0.0 DA Class Cluster: new parent class KWArgs
## -- 2024-07-08 2.1.0 DA Class Cluster: hand over of kwargs to inner properties
## -------------------------------------------------------------------------------------------------

"""
Ver. 2.0.0 (2024-06-18)
Ver. 2.1.0 (2024-07-08)
This module provides a template class for clusters to be used in cluster analyzer algorithms.
Expand Down Expand Up @@ -102,7 +103,7 @@ def __init__( self,
**p_kwargs ):

KWArgs.__init__( self, **p_kwargs )
Properties.__init__( self, p_properties = p_properties, p_visualize = p_visualize )
Properties.__init__( self, p_properties = p_properties, p_visualize = p_visualize, **p_kwargs )
Id.__init__( self, p_id = p_id )


Expand Down Expand Up @@ -152,4 +153,5 @@ def get_influence(self, p_inst : Instance ) -> float:
raise NotImplementedError


## -------------------------------------------------------------------------------------------------
color = property( fget = Properties.get_plot_color, fset = set_plot_color )

0 comments on commit 1c30f11

Please sign in to comment.