-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into atrutnev/new_tables
- Loading branch information
Showing
3 changed files
with
126 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -15,4 +15,4 @@ experiments/ | |
.DS_Store | ||
.vscode | ||
logs | ||
data | ||
data |
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,46 @@ | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from lkmeans.examples.data.experiment_data import get_experiment_data | ||
from lkmeans.examples.data.points_generator import generate_mix_distribution | ||
|
||
parser = ArgumentParser() | ||
|
||
parser.add_argument( | ||
'--path', | ||
type=Path, | ||
default=Path('images'), | ||
help='Path to save results' | ||
) | ||
|
||
|
||
def main(): | ||
args = parser.parse_args() | ||
args.path.mkdir(exist_ok=True) | ||
|
||
dimension = 20 | ||
n_points = 100 | ||
|
||
n_clusters, prob, mu_list, cov_matrices = get_experiment_data(num_clusters=2, dimension=dimension) | ||
|
||
for t in [0.2, 0.4, 0.9]: | ||
filename = args.path / f'{n_clusters}_cluster_hist_t_{t}.png' | ||
clusters, _, _ = generate_mix_distribution( | ||
probability=prob, | ||
mu_list=mu_list, | ||
cov_matrices=cov_matrices, | ||
n_samples=n_points, | ||
t=t | ||
) | ||
|
||
fig, ax = plt.subplots(figsize=(5, 3)) | ||
ax.hist(clusters[:, 0], bins=15) | ||
ax.grid(True, color='gray', linestyle='--', linewidth=0.5) | ||
fig.savefig(str(filename), dpi=300, bbox_inches='tight') | ||
plt.close(fig) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,79 @@ | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from lkmeans.clustering.utils import assign_to_cluster | ||
from lkmeans.distance import DistanceCalculator | ||
from lkmeans.examples.data.experiment_data import get_experiment_data | ||
from lkmeans.examples.data.points_generator import generate_mix_distribution | ||
|
||
parser = ArgumentParser() | ||
|
||
parser.add_argument( | ||
'--path', | ||
type=Path, | ||
default=Path('images'), | ||
help='Path to save results' | ||
) | ||
|
||
parser.add_argument( | ||
'--p', | ||
type=float, | ||
default=2, | ||
help='Minkowski parameter' | ||
) | ||
|
||
parser.add_argument( | ||
'--t', | ||
type=float, | ||
default=0., | ||
help='T parameter of distribution' | ||
) | ||
|
||
|
||
# pylint: disable=too-many-locals | ||
def main(): | ||
args = parser.parse_args() | ||
args.path.mkdir(exist_ok=True) | ||
p = int(args.p) if (args.p).is_integer() else args.p | ||
|
||
dimension = 20 | ||
n_points = 10 | ||
n_observation = 10000 | ||
|
||
distance_calculator = DistanceCalculator(p) | ||
|
||
n_clusters, prob, mu_list, cov_matrices = get_experiment_data(num_clusters=2, dimension=dimension) | ||
|
||
filename = args.path / f'plot_minkowski_function_with_p_{p}.png' | ||
samples, _, centroids = generate_mix_distribution( | ||
probability=prob, | ||
mu_list=mu_list, | ||
cov_matrices=cov_matrices, | ||
n_samples=n_points, | ||
t=0.1 | ||
) | ||
|
||
dim = 0 | ||
|
||
clusters, _ = assign_to_cluster(samples, centroids, n_clusters, p) | ||
cluster = np.array(clusters[0]) | ||
dimension_data = cluster[:,dim] | ||
|
||
points = np.linspace(min(dimension_data), max(dimension_data), n_observation) | ||
minkowski_values = distance_calculator.get_pairwise_distance( | ||
point_a = dimension_data, | ||
points=points, | ||
) | ||
|
||
fig, ax = plt.subplots(figsize=(5, 3)) | ||
ax.scatter(points, minkowski_values) | ||
ax.axis('off') | ||
fig.savefig(str(filename), dpi=300, bbox_inches='tight') | ||
plt.close(fig) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |