Skip to content

Commit 362242c

Browse files
committed
Add docstring for cluster_config.CentroidInitialization
1 parent 8465279 commit 362242c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

tensorflow_model_optimization/python/core/clustering/keras/cluster.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,8 @@ def cluster_weights(to_cluster,
108108
number_of_clusters: the number of cluster centroids to form when
109109
clustering a layer/model. For example, if number_of_clusters=8 then only
110110
8 unique values will be used in each weight array.
111-
cluster_centroids_init: enum value that determines how the cluster
112-
centroids will be initialized.
113-
Can have following values:
114-
1. RANDOM : centroids are sampled using the uniform distribution
115-
between the minimum and maximum weight values in a given layer
116-
2. DENSITY_BASED : density-based sampling. First, cumulative
117-
distribution function is built for weights, then y-axis is evenly
118-
spaced into number_of_clusters regions. After this the corresponding x
119-
values are obtained and used to initialize clusters centroids.
120-
3. LINEAR : cluster centroids are evenly spaced between the minimum
121-
and maximum values of a given weight
111+
cluster_centroids_init: `cluster_config.CentroidInitialization` instance
112+
that determines how the cluster centroids will be initialized.
122113
**kwargs: Additional keyword arguments to be passed to the keras layer.
123114
Ignored when to_cluster is not a keras layer.
124115

tensorflow_model_optimization/python/core/clustering/keras/cluster_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919

2020
class CentroidInitialization(str, enum.Enum):
21+
"""Specifies how the cluster centroids should be initialized.
22+
* `LINEAR`: Cluster centroids are evenly spaced between the minimum and
23+
maximum values of a given weight tensor.
24+
* `RANDOM`: Centroids are sampled using the uniform distribution between the
25+
minimum and maximum weight values in a given layer.
26+
* `DENSITY_BASED`: Density-based sampling obtained as follows: first a
27+
cumulative distribution function is built for the weights, then the Y
28+
axis is evenly spaced into as many regions as many clusters we want to
29+
have. After this the corresponding X values are obtained and used to
30+
initialize the clusters centroids.
31+
"""
2132
LINEAR = "LINEAR"
2233
RANDOM = "RANDOM"
2334
DENSITY_BASED = "DENSITY_BASED"

0 commit comments

Comments
 (0)