-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time complexity calculation, benchmark results, add __version__ and v…
…ectorise set_nodes_supplies (#48) - Time complexity calculation - Benchmark scripts, notebook and results - Add __version__ - Use vectorised set_nodes_supplies
- Loading branch information
Showing
9 changed files
with
520 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ commit = True | |
tag = True | ||
|
||
[bumpversion:file:setup.cfg] | ||
[bumpversion:file:k_means_constrained/__init__.py] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from argparse import ArgumentParser | ||
from sklearn.cluster import KMeans | ||
import numpy as np | ||
import time | ||
import os | ||
|
||
p = ArgumentParser() | ||
p.add_argument("-n", "--data-points", required=True, type=int, help="Number of data-points") | ||
p.add_argument("-d", "--dimensions", required=True, type=int, help="Number of dimensions/features each data-point has") | ||
p.add_argument("-K", "--clusters", required=True, type=int, help="Number of clusters") | ||
p.add_argument("-ge", "--min-cluster-size", default=None, help="Minimum number of clusters assigned to each data-point") | ||
p.add_argument("-le", "--max-cluster-size", default=None, help="Maximum number of clusters assigned to each data-point") | ||
p.add_argument("-s", "--seed", type=int, default=42, help="Random state seed") | ||
p.add_argument("-i", "--info", action='store_true', default=False , help="Print system info. `cpuinfo` is required to be installed.") | ||
args = p.parse_args() | ||
|
||
print(f"K-means benchmark: data-points={args.data_points}, dimensions={args.dimensions}, clusters={args.clusters}, min-cluster-size={args.min_cluster_size}, max-cluster-size={args.max_cluster_size}, seed={args.seed}") | ||
|
||
if args.info: | ||
import scipy, ortools, joblib, platform, cpuinfo, sklearn, k_means_constrained | ||
print(f"OS: {platform.platform()}") | ||
print(f"CPU: {cpuinfo.get_cpu_info()['brand_raw']}") | ||
print(f"CPU cores: {cpuinfo.get_cpu_info()['count']}") | ||
print(f"k-means-constrained version: {k_means_constrained.__version__}") | ||
print(f"numpy version: {np.__version__}") | ||
print(f"scipy version: {scipy.__version__}") | ||
print(f"ortools version: {ortools.__version__}") | ||
print(f"joblib version: {joblib.__version__}") | ||
print(f"sklearn version: {sklearn.__version__}") | ||
|
||
np.random.seed(args.seed) | ||
|
||
X = np.random.rand(args.data_points, args.dimensions) | ||
|
||
os.environ['OMP_NUM_THREADS'] = '10' # Used instead of joblib/n_jobs in latest version of sklearn | ||
|
||
t = time.perf_counter() | ||
clf = KMeans( | ||
n_clusters=args.clusters, | ||
random_state=args.seed+1, | ||
algorithm='lloyd', | ||
init='k-means++', | ||
n_init=10, | ||
max_iter=300, | ||
tol=0.0001, | ||
) | ||
clf.fit_predict(X) | ||
|
||
total_time = time.perf_counter() - t | ||
print(f"Total time: {total_time:.2f} seconds") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from argparse import ArgumentParser | ||
import k_means_constrained | ||
import numpy as np | ||
import time | ||
import logging | ||
import os | ||
|
||
p = ArgumentParser() | ||
p.add_argument("-n", "--data-points", required=True, type=int, help="Number of data-points") | ||
p.add_argument("-d", "--dimensions", required=True, type=int, help="Number of dimensions/features each data-point has") | ||
p.add_argument("-K", "--clusters", required=True, type=int, help="Number of clusters") | ||
p.add_argument("-ge", "--min-cluster-size", default=None, help="Minimum number of clusters assigned to each data-point") | ||
p.add_argument("-le", "--max-cluster-size", default=None, help="Maximum number of clusters assigned to each data-point") | ||
p.add_argument("-s", "--seed", type=int, default=42, help="Random state seed") | ||
p.add_argument("-i", "--info", action='store_true', default=False , help="Print system info. `cpuinfo` is required to be installed.") | ||
args = p.parse_args() | ||
|
||
|
||
logging.basicConfig( | ||
level=os.environ.get('LOGLEVEL', 'DEBUG').upper() | ||
) | ||
|
||
print(f"K-mean-constrained benchmark: data-points={args.data_points}, dimensions={args.dimensions}, clusters={args.clusters}, min-cluster-size={args.min_cluster_size}, max-cluster-size={args.max_cluster_size}, seed={args.seed}") | ||
|
||
if args.info: | ||
import scipy, ortools, joblib, platform, cpuinfo, sklearn, k_means_constrained | ||
print(f"OS: {platform.platform()}") | ||
print(f"CPU: {cpuinfo.get_cpu_info()['brand_raw']}") | ||
print(f"CPU cores: {cpuinfo.get_cpu_info()['count']}") | ||
print(f"k-means-constrained version: {k_means_constrained.__version__}") | ||
print(f"numpy version: {np.__version__}") | ||
print(f"scipy version: {scipy.__version__}") | ||
print(f"ortools version: {ortools.__version__}") | ||
print(f"joblib version: {joblib.__version__}") | ||
print(f"sklearn version: {sklearn.__version__}") | ||
|
||
np.random.seed(args.seed) | ||
|
||
X = np.random.rand(args.data_points, args.dimensions) | ||
|
||
t = time.perf_counter() | ||
clf = k_means_constrained.KMeansConstrained( | ||
n_clusters=args.clusters, | ||
size_min=int(args.min_cluster_size) if args.min_cluster_size else None, | ||
size_max=int(args.max_cluster_size) if args.max_cluster_size else None, | ||
random_state=args.seed+1, | ||
#algorithm='lloyd', # implied | ||
init='k-means++', | ||
n_init=10, | ||
max_iter=300, | ||
tol=0.0001, | ||
n_jobs=10, | ||
) | ||
clf.fit_predict(X) | ||
|
||
total_time = time.perf_counter() - t | ||
print(f"Total time: {total_time:.2f} seconds") | ||
|
File renamed without changes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
__all__ = ['KMeansConstrained'] | ||
__version__ = '0.7.3' | ||
|
||
from .k_means_constrained_ import KMeansConstrained | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters