From 5397c56a7f942863406d461d0e59b125853e935e Mon Sep 17 00:00:00 2001 From: Giulia Baldini Date: Wed, 24 Jul 2024 15:04:17 +0200 Subject: [PATCH 1/2] Fit tests such that they fail if weight is wrong --- tests/test.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test.py b/tests/test.py index 0586e13..54415b9 100644 --- a/tests/test.py +++ b/tests/test.py @@ -36,7 +36,9 @@ def calculate_costs( def assert_equals_computed( flspp: FLSpp, data: np.ndarray, sample_weight: Optional[np.ndarray] = None ) -> None: - labels, cost = calculate_costs(np.array(data), flspp.cluster_centers_) + labels, cost = calculate_costs( + np.array(data), flspp.cluster_centers_, sample_weight + ) assert flspp.inertia_ is not None and np.isclose( flspp.inertia_, cost ), f"Inertia: {flspp.inertia_} vs. cost {cost}" @@ -202,9 +204,10 @@ def test_n_clusters(self) -> None: def test_weights(self) -> None: flspp = FLSpp(n_clusters=2) - flspp.fit(self.example_data, sample_weight=[1, 2, 3, 4, 5, 6]) + weights = np.array([1, 2, 3, 4, 5, 6]) + flspp.fit(self.example_data, sample_weight=weights) - assert_equals_computed(flspp, self.example_data) + assert_equals_computed(flspp, self.example_data, sample_weight=weights) if __name__ == "__main__": From 498b5ed609362302b2aa6aa4f073618a4af57873 Mon Sep 17 00:00:00 2001 From: Giulia Baldini Date: Wed, 24 Jul 2024 22:36:05 +0200 Subject: [PATCH 2/2] Add copy of weight to copy constructor --- flspp/cpp/clustering.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flspp/cpp/clustering.cpp b/flspp/cpp/clustering.cpp index 002e9f8..32551a2 100644 --- a/flspp/cpp/clustering.cpp +++ b/flspp/cpp/clustering.cpp @@ -12,7 +12,7 @@ Point::Point(int dim, int ind, double w, std::vector coord) : dimension( { } -Point::Point(Point const &p) : dimension(p.dimension), index(p.index), coordinates(p.coordinates) +Point::Point(Point const &p) : dimension(p.dimension), index(p.index), coordinates(p.coordinates), weight(p.weight) { }