From b8149b50da06a3485697b409f5e350fa580c29ee Mon Sep 17 00:00:00 2001 From: MarcusHolly Date: Thu, 17 Oct 2024 09:51:23 -0400 Subject: [PATCH] Make compute_sse a prviate method & move outside of class --- .../multiperiod/price_taker_model.py | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/idaes/apps/grid_integration/multiperiod/price_taker_model.py b/idaes/apps/grid_integration/multiperiod/price_taker_model.py index 10ddbffd8c..3427c071a3 100644 --- a/idaes/apps/grid_integration/multiperiod/price_taker_model.py +++ b/idaes/apps/grid_integration/multiperiod/price_taker_model.py @@ -55,6 +55,27 @@ _logger = idaeslog.getLogger(__name__) +def _compute_sse(data, centroids, idx): + """ + PRIVATE METHOD + + Method used to compute the inertia (sum of square errors) for k clusters. + + Args: + data: Columnar data for a given LMP signal + centroids: Array of k centroids + idx: Index for data + + Returns: + inertia: Sum of square errors for k clusters + """ + inertia = 0 + for i, centroid in enumerate(centroids): + cluster_points = data[idx == i] + inertia += np.sum((cluster_points - centroid) ** 2) + return inertia + + class PriceTakerModel(ConcreteModel): def __init__(self, seed=20, horizon_length=24): super().__init__() @@ -85,25 +106,6 @@ def horizon_length(self, value): ) self._horizon_length = value - @staticmethod - def compute_sse(data, centroids, idx): - """ - Method used to compute the inertia (sum of square errors) for k clusters. - - Args: - data: Columnar data for a given LMP signal - centroids: Array of k centroids - idx: Index for data - - Returns: - inertia: Sum of square errors for k clusters - """ - inertia = 0 - for i, centroid in enumerate(centroids): - cluster_points = data[idx == i] - inertia += np.sum((cluster_points - centroid) ** 2) - return inertia - def generate_daily_data(self, raw_data): """ Function used to generate the daily data in a usable format @@ -186,7 +188,7 @@ def get_optimal_n_clusters( idx, _ = vq(whitened_daily_data, centroids) # Compute the inertia (SSE) for k clusters - inertia = self.compute_sse(whitened_daily_data, centroids, idx) + inertia = _compute_sse(whitened_daily_data, centroids, idx) inertia_values.append(inertia) # Calculate the second derivative