Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flspp/cpp/clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Point::Point(int dim, int ind, double w, std::vector<double> 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)
{
}

Expand Down
9 changes: 6 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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__":
Expand Down