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 Jun 16, 2024
1 parent ec8c14f commit 9f5b8a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
19 changes: 18 additions & 1 deletion src/mlpro/bf/math/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
## -- 2024-06-03 1.0.1 DA Method Properties.update_plot(): changed order of plotting
## -- 2024-06-05 1.1.0 DA New method Properties.replace_property()
## -- 2024-06-06 1.2.0 DA New custom method Properties._update_property_links()
## -- 2024-06-16 1.3.0 DA New method Properties.get_property_definitions()
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.2.0 (2024-06-06)
Ver. 1.3.0 (2024-06-16)
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 Down Expand Up @@ -272,6 +273,7 @@ def __init__( self,
p_visualize : bool = False ):

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._update_property_links()
Expand Down Expand Up @@ -310,6 +312,7 @@ def add_property( self,
p_value_prev = p_value_prev,
p_visualize = p_visualize )
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 Down Expand Up @@ -348,6 +351,20 @@ def get_properties(self):
"""

return self._properties


## -------------------------------------------------------------------------------------------------
def get_property_definitions(self) -> PropertyDefinitions:
"""
Returns a list of currently stored property definitions.
Returns
-------
PropertyDefinitions
List of property definitions
"""

return list(self._property_definitions.values())


## -------------------------------------------------------------------------------------------------
Expand Down
18 changes: 10 additions & 8 deletions src/mlpro/oa/streams/tasks/clusteranalyzers/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
## -- - renamed attributes C_MS_SCOPE_* to C_RESULT_SCOPE_*
## -- - new method _get_cluster_relations()
## -- - new method get_cluster_influences()
## -- 2024-06-16 1.2.1 DA Bugfix in ClusterAnalyzer.align_cluster_properties()
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.2.0 (2024-06-08)
Ver. 1.2.1 (2024-06-16)
This module provides a template class for online cluster analysis.
"""
Expand Down Expand Up @@ -72,7 +73,7 @@ class ClusterAnalyzer (OATask):
- Specify all cluster properties provided/maintained by your algorithm in C_CLUSTER_PROPERTIES.
- Implement method self._adapt() to update your cluster list on new instances
- Implement method self._adapt_reverse() to update your cluster list on obsolete instances
- New cluster: hand over self._cluster_properties on instantiation
- New cluster: hand over self._cluster_properties.values() on instantiation
Parameters
----------
Expand Down Expand Up @@ -149,10 +150,9 @@ def __init__( self,
self._cluster_limit = p_cluster_limit
self._next_cluster_id : ClusterId = -1

self._cluster_properties : PropertyDefinitions = self.C_CLUSTER_PROPERTIES.copy()
self._cluster_properties_dict = {}
for prop in self._cluster_properties:
self._cluster_properties_dict[prop[0]] = prop
self._cluster_properties = {}
for prop in self.C_CLUSTER_PROPERTIES:
self._cluster_properties[prop[0]] = prop


## -------------------------------------------------------------------------------------------------
Expand All @@ -175,9 +175,10 @@ def align_cluster_properties( self, p_properties : PropertyDefinitions ) -> list

for p_ext in p_properties:
try:
p_int = self._cluster_properties_dict[p_ext[0]]
p_int = self._cluster_properties[p_ext[0]]
p_int[1] = p_ext[1] # alignment of maximum order of derivatives
p_int[2] = p_ext[2] # alignment of property class
p_int[2] = p_ext[2] # alignment of storage of previous values
p_int[3] = p_ext[3] # alignment of property class
except:
# Property not supported by cluster algorithm
unknown_properties.append(p_ext[0])
Expand Down Expand Up @@ -316,6 +317,7 @@ def _get_cluster_relations( self,

if cluster_max_results is not None:
list_results_abs.append( cluster_max_results )
sum_results = cluster_max_results[1]


# 2 Determination of relative result values according to the required scope
Expand Down

0 comments on commit 9f5b8a2

Please sign in to comment.