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 10, 2024
1 parent fc45000 commit c9cb4dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/mlpro/oa/streams/tasks/clusteranalyzers/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def _get_cluster_relations( self,
# 1 Determination of membership values of the instance for all clusters
sum_results = 0
list_results_abs = []
list_results_rel = []
cluster_max_results = None

for cluster in self.get_clusters().values():
Expand All @@ -304,27 +305,26 @@ def _get_cluster_relations( self,

sum_results += result_abs

if ( p_scope != self.C_RESULT_SCOPE_ALL ) and ( result_abs == 0 ): continue
if ( p_scope == self.C_RESULT_SCOPE_NONZERO ) and ( result_abs == 0 ): continue

if p_scope == self.C_RESULT_SCOPE_MAX:
# Cluster with highest membership value is buffered
if ( cluster_max_results is None ) or ( result_abs > cluster_max_result[1] ):
cluster_max_result = ( cluster, result_abs )

cluster_max_results = ( cluster, result_abs )
else:
list_results_abs.append( (cluster, result_abs) )

if sum_results == 0: return []

if cluster_max_results is not None:
list_results_abs.append( cluster_max_results )


# 2 Determination of relative result values according to the required scope
list_results_rel = []
for result_abs in list_results_abs:
try:
result_rel = result_abs[1] / sum_results
except:
result_rel = 0

for result_abs in list_result_abs:
result_rel = result_abs[1] / sum_results
list_results_rel.append( ( result_abs[0].id, result_rel, result_abs[0] ) )

return list_results_rel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
This module provides templates for cluster analysis to be used in the context of online adaptivity.
"""

#from typing import List, Tuple

import sys

from mlpro.bf.streams import Instance
Expand Down Expand Up @@ -112,7 +110,7 @@ def get_influence(self, p_inst: Instance) -> float:
if self._centroid_elem is None:
self._centroid_elem = Element( p_set=feature_data.get_related_set() )

self._centroid_elem.set_values( p_value=self.centroid.value )
self._centroid_elem.set_values( p_values=self.centroid.value )

try:
return 1 / feature_data.get_related_set().distance( p_e1 = feature_data, p_e2 = self._centroid_elem )
Expand Down

0 comments on commit c9cb4dc

Please sign in to comment.