Skip to content

Commit

Permalink
fix determinization
Browse files Browse the repository at this point in the history
  • Loading branch information
elazarg committed Aug 4, 2024
1 parent b95f1d1 commit c3970d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion experiment/k_means/instrumented.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import sklearn.datasets

np.random.seed(42)


def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
"""A simple clustering method that forms k clusters by iteratively reassigning
Expand All @@ -15,7 +17,6 @@ def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
The number of iterations the algorithm will run for if it does
not converge before that.
"""
np.random.seed(42)
nsamples, features = X.shape
centroids = X[np.random.choice(nsamples, k)]
clusters = list[list[int]]()
Expand Down
3 changes: 2 additions & 1 deletion experiment/k_means/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import sklearn.datasets

np.random.seed(42)


def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
"""A simple clustering method that forms k clusters by iteratively reassigning
Expand All @@ -14,7 +16,6 @@ def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
The number of iterations the algorithm will run for if it does
not converge before that.
"""
np.random.seed(42)
nsamples, features = X.shape
centroids = X[np.random.choice(nsamples, k)]
clusters = list[list[int]]()
Expand Down
3 changes: 2 additions & 1 deletion experiment/k_means/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import sklearn.datasets

np.random.seed(42)


def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
"""A simple clustering method that forms k clusters by iteratively reassigning
Expand Down Expand Up @@ -30,7 +32,6 @@ def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
sample_i,
y_pred,
] = (None,) * 13
np.random.seed(42)
nsamples, features = X.shape
centroids = X[np.random.choice(nsamples, k)]
clusters = list[list[int]]()
Expand Down
3 changes: 2 additions & 1 deletion experiment/k_means/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import sklearn.datasets

np.random.seed(42)


def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
"""A simple clustering method that forms k clusters by iteratively reassigning
Expand All @@ -15,7 +17,6 @@ def run(X: np.ndarray, k: int, max_iterations: int) -> np.ndarray:
The number of iterations the algorithm will run for if it does
not converge before that.
"""
np.random.seed(42)
nsamples, features = X.shape
centroids = X[np.random.choice(nsamples, k)]
clusters = list[list[int]]()
Expand Down

0 comments on commit c3970d0

Please sign in to comment.