Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
622 changes: 622 additions & 0 deletions .github/.pylintrc

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ jobs:
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
export PYTHONPATH=${PYTHONPATH}:.
# pylint $(git ls-files '*.py') --fail-under=9.94
- name: Tests
export PYTHONPATH=${PYTHONPATH}:$(pwd)
pylint $(git ls-files '*.py') --rcfile .github/.pylintrc
- name: Test optimizers
run: |
mkdir -p images
export PYTHONPATH=${PYTHONPATH}:.
pytest lib/*_test.py -v
export PYTHONPATH=${PYTHONPATH}:$(pwd)
pytest tests -v -m optimizers
- name: Test KMeans
run: |
export PYTHONPATH=${PYTHONPATH}:$(pwd)
pytest tests -v -m kmeans
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
venv
lib/__pycache__
notebooks/.ipynb_checkpoints
.pytest_cache
images
cache
.env

*.png
*__pycache__
100 changes: 0 additions & 100 deletions experiments/experiment_1_sigma_1/experiment_1.tex

This file was deleted.

64 changes: 0 additions & 64 deletions experiments/experiment_2_sigma_1/experiment_1.tex

This file was deleted.

5 changes: 5 additions & 0 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lib.decomposition import get_tsne_clusters
from lib.experiment_metrics import get_average_experiment_metrics
from lib.kmeans import KMeans
from lib.metric_meter import MetricTable, insert_hline
from lib.experiment import run_experiment
35 changes: 25 additions & 10 deletions lib/decomposition.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
from sklearn.decomposition import PCA
from typing import Optional

import matplotlib.pyplot as plt
import numpy as np
from sklearn.manifold import TSNE


def fit_to_2d_tsne(data):
"""Fit data to 2d."""
tsne = TSNE(n_components=2, random_state=0, perplexity=30, n_iter=5000)
return tsne.fit_transform(data)
def get_tsne_clusters(clusters: np.ndarray,
labels: np.ndarray,
centroids: Optional[np.ndarray] = None):

fig = plt.figure()
axe = fig.add_subplot(1, 1, 1)
color_map = {0: 'red', 1: 'green', 2: 'blue', 3: 'yellow', 4: 'purple'}

colors = [color_map[label] for label in labels]
tsne = TSNE(n_components=2, random_state=42)

if not isinstance(centroids, type(None)):
concuted = np.concatenate((clusters, np.array(centroids)), axis=0)
clusters_tsne = tsne.fit_transform(concuted)

def fit_to_2d_PCA(data):
"""Fit data to 2d."""
pca = PCA(n_components=2)
pca.fit(data)
return pca.transform(data)
axe.scatter(clusters_tsne[:-len(centroids), 0],
clusters_tsne[:-len(centroids), 1], c=colors)
axe.scatter(clusters_tsne[-len(centroids):, 0],
clusters_tsne[-len(centroids):, 1], marker='*', s=100, c='black')
else:
clusters_tsne = tsne.fit_transform(clusters)
axe.scatter(clusters_tsne[:, 0], clusters_tsne[:, 1], c=colors)
return fig
18 changes: 0 additions & 18 deletions lib/deprecated.py

This file was deleted.

67 changes: 0 additions & 67 deletions lib/distance.py

This file was deleted.

66 changes: 0 additions & 66 deletions lib/distance_test.py

This file was deleted.

Loading