Skip to main content

Size Constrained Clustering Solver

Implementation of Deterministic Annealing Size Constrained Clustering. Size constrained clustering can be treated as an optimization problem. Details could be found in a set of reference paper.

This is a fork of https://github.com/jingw2/size_constrained_clustering that solves installation issues. And mantains only the Determinstic Annealing clustering.

Installation

Requirement Python >= 3.6, Numpy >= 1.13

  • install from PyPI
pip install light-size-constrained-clustering

Methods

  • Deterministic Annealling Algorithm: Input target cluster distribution, return correspondent clusters

Usage:

Deterministic Annealing

# setup
from light_size_constrained_clustering import da
import numpy as np

n_samples = 40 # number cells in spot
n_clusters = 4 # distinct number of cell types
distribution= [0.4,0.3,0.2,0.1] # distribution of each cell type (form deconv)
seed = 17

print(np.sum(distribution))
np.random.seed(seed)

X = np.random.rand(n_samples, 2)
# distribution is the distribution of cluster sizes
model = da.DeterministicAnnealing(n_clusters, distribution= distribution, random_state=seed)

model.fit(X)
centers = model.cluster_centers_
labels = model.labels_
print("Labels:")
print(labels)
print("Elements in cluster 0: ", np.count_nonzero(labels == 0))
print("Elements in cluster 1: ", np.count_nonzero(labels == 1))
print("Elements in cluster 2: ", np.count_nonzero(labels == 2))
print("Elements in cluster 3: ", np.count_nonzero(labels == 3))

In case of provided distributions not being respected due to lack of convergence, distribution can be nforced by using the parameter enforce_cluster_distribution

model.fit(X, enforce_cluster_distribution=True)

Cluster size: 16, 12, 8 and 4 in the figure above, corresponding to distribution [0.4, 0.3, 0.2, 0.1]

Copyright

Copyright (c) 2023 Jing Wang & Albert Pla. Released under the MIT License.

Third-party copyright in this distribution is noted where applicable.

Reference

Metadata

Release files for light-size-constrained-clustering 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for light-size-constrained-clustering 0.0.7
File Size Uploaded
light_size_constrained_clustering-0.0.7.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for light-size-constrained-clustering 0.0.7
File Interpreter ABI Platform
light_size_constrained_clustering-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / light_size_constrained_clustering-0.0.7.tar.gz

Download URL light_size_constrained_clustering-0.0.7.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e508b428d477cd5168cb1fb915f60ac10ea3489561db37786e68ccd23a3eb521
BLAKE2b-256 checksum
How to use checksums
9697da317abf3d7b0c71142c9cf2abbf9b2af1a47b05b2db821bc0bfb7ce24c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / light_size_constrained_clustering-0.0.7-py3-none-any.whl

Download URL light_size_constrained_clustering-0.0.7-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a6b29939d2cedcb60ecba3bcee65d8718383c20ed8d474f7809bdddc9617d1c
BLAKE2b-256 checksum
How to use checksums
56d2820208b33944351545be548055d5960df77b46261181210ce1e90e54f68d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page