Commit 89930d71 authored by lucas_miranda's avatar lucas_miranda
Browse files

Modified cluster purity computation. Instead of KNN, we now look at...

Modified cluster purity computation. Instead of KNN, we now look at neighborhoods of a predefined radius
parent 1127311d
......@@ -202,7 +202,7 @@ class one_cycle_scheduler(tf.keras.callbacks.Callback):
)
class knn_cluster_purity(tf.keras.callbacks.Callback):
class neighbor_cluster_purity(tf.keras.callbacks.Callback):
"""
Cluster entropy callback. Computes assignment local entropy over a neighborhood of radius r in the latent space
......@@ -210,7 +210,7 @@ class knn_cluster_purity(tf.keras.callbacks.Callback):
"""
def __init__(
self, variational=True, validation_data=None, r=100, samples=10000, log_dir="."
self, variational=True, validation_data=None, r=2e-4, samples=10000, log_dir="."
):
super().__init__()
self.variational = variational
......@@ -269,7 +269,7 @@ class knn_cluster_purity(tf.keras.callbacks.Callback):
purity_vector[i] = (
np.sum(hard_groups[neighborhood] == hard_groups[sample])
/ self.k
/ np.sum(neighborhood)
* np.max(groups[sample])
)
......
......@@ -245,7 +245,7 @@ class SEQ_2_SEQ_GMVAE:
architecture_hparams: dict = {},
batch_size: int = 256,
compile_model: bool = True,
encoding: int = 16,
encoding: int = 6,
entropy_reg_weight: float = 0.0,
kl_warmup_epochs: int = 20,
loss: str = "ELBO",
......
......@@ -112,7 +112,7 @@ def get_callbacks(
profile_batch=2,
)
knn = deepof.model_utils.knn_cluster_purity(
knn = deepof.model_utils.neighbor_cluster_purity(
k=knn_neighbors,
samples=knn_samples,
validation_data=X_val,
......
......@@ -71,7 +71,7 @@ def test_get_callbacks(
assert type(runID) == str
assert type(tbc) == tf.keras.callbacks.TensorBoard
assert type(cpc) == tf.keras.callbacks.ModelCheckpoint
assert type(knn) == deepof.model_utils.knn_cluster_purity
assert type(knn) == deepof.model_utils.neighbor_cluster_purity
assert type(cycle1c) == deepof.model_utils.one_cycle_scheduler
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment