-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from gmrukwa/develop
Release v2.3.11
- Loading branch information
Showing
36 changed files
with
1,060 additions
and
134 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "divik:dev", | ||
"context": "..", | ||
"dockerFile": "../docker/development.dockerfile", | ||
|
||
"runArgs": [ | ||
"-v", "${env:HOME}${env:USERPROFILE}/.ssh:/root/.ssh-localhost:ro", | ||
], | ||
|
||
"postCreateCommand": "cp -r ~/.ssh-localhost ~/.ssh && chmod 700 ~/.ssh && chmod 600 ~/.ssh/* && rm -f ~/.ssh/config", | ||
|
||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash", | ||
"python.pythonPath": "/usr/local/bin/python", | ||
"python.linting.pylintEnabled": true, | ||
"python.linting.pylintPath": "/usr/local/bin/pylint", | ||
"python.linting.enabled": true | ||
}, | ||
|
||
"extensions": [ | ||
"eamodio.gitlens", | ||
"mutantdino.resourcemonitor", | ||
"ms-python.python", | ||
"angelo-breuer.clock", | ||
"donjayamanne.githistory", | ||
"tabnine.tabnine-vscode", | ||
"redhat.vscode-yaml", | ||
"formulahendry.code-runner" | ||
] | ||
} |
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
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
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,12 @@ | ||
{ | ||
"python.pythonPath": "/usr/local/bin/python", | ||
"python.linting.pylintEnabled": true, | ||
"python.linting.enabled": true, | ||
"python.linting.pylintPath": "/usr/local/bin/pylint", | ||
"python.testing.unittestArgs": [ | ||
"discover" | ||
], | ||
"python.testing.unittestEnabled": true, | ||
"python.testing.nosetestsEnabled": false, | ||
"python.testing.pytestEnabled": false, | ||
} |
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
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
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,19 +1,16 @@ | ||
from ._dunn import DunnPicker | ||
from ._gap import gap, GapPicker | ||
from ._sampled_gap import sampled_gap, SamplingGapPicker | ||
from ._picker import Picker | ||
|
||
|
||
def make_picker(method, n_jobs: int = 1, gap=None): | ||
if gap is None: | ||
gap = {} | ||
if method == 'dunn': | ||
picker = DunnPicker(n_jobs=n_jobs) | ||
elif method == 'gap': | ||
if gap is None: | ||
gap = {} | ||
max_iter = gap.get('max_iter', 10) | ||
seed = gap.get('seed', 0) | ||
trials = gap.get('trials', 10) | ||
correction = gap.get('correction', True) | ||
picker = GapPicker(max_iter, seed, trials, correction, n_jobs=n_jobs) | ||
else: | ||
raise ValueError('Unknown quality measure {0}'.format(method)) | ||
return picker | ||
return DunnPicker(n_jobs=n_jobs) | ||
if method == 'gap': | ||
return GapPicker(n_jobs=n_jobs, **gap) | ||
if method == 'sampled_gap': | ||
return SamplingGapPicker(n_jobs=n_jobs, **gap) | ||
raise ValueError('Unknown quality measure {0}'.format(method)) |
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
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
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,66 @@ | ||
from functools import partial | ||
from typing import List, Union | ||
|
||
import numpy as np | ||
from sklearn.base import clone | ||
|
||
from divik._utils import Data, maybe_pool | ||
from divik._seeding import seeded | ||
from divik.sampler import UniformSampler, StratifiedSampler | ||
from divik._score._gap import _sampled_dispersion as _dispersion, GapPicker | ||
|
||
|
||
KMeans = 'divik.KMeans' | ||
|
||
|
||
@seeded(wrapped_requires_seed=True) | ||
def sampled_gap(data: Data, kmeans: KMeans, | ||
sample_size: Union[int, float] = 1000, | ||
n_jobs: int = None, | ||
seed: int = 0, | ||
n_trials: int = 100, | ||
return_deviation: bool = False, | ||
max_iter: int = 10) -> float: | ||
# TODO: Docs | ||
# TODO: Tests | ||
data_ = StratifiedSampler(n_rows=sample_size, n_samples=n_trials | ||
).fit(data, kmeans.labels_) | ||
reference_ = UniformSampler(n_rows=sample_size, n_samples=n_trials | ||
).fit(data) | ||
kmeans_ = clone(kmeans) | ||
kmeans_.max_iter = max_iter | ||
with data_.parallel() as d, reference_.parallel() as r, \ | ||
maybe_pool(n_jobs) as pool: | ||
compute_disp = partial(_dispersion, sampler=r, kmeans=kmeans_) | ||
ref_disp = pool.map(compute_disp, range(seed, seed + n_trials)) | ||
compute_disp = partial(_dispersion, sampler=d, kmeans=kmeans_) | ||
data_disp = pool.map(compute_disp, range(seed, seed + n_trials)) | ||
ref_disp = np.log(ref_disp) | ||
data_disp = np.log(data_disp) | ||
gap = np.mean(ref_disp) - np.mean(data_disp) | ||
result = (gap,) | ||
if return_deviation: | ||
std = np.sqrt(np.var(ref_disp) + np.var(data_disp)) / n_trials | ||
result += (std,) | ||
return result | ||
|
||
|
||
class SamplingGapPicker(GapPicker): | ||
def __init__(self, sample_size: int = 1000, max_iter: int = 10, | ||
seed: int = 0, n_trials: int = 10, | ||
correction: bool = True, n_jobs: int = 1): | ||
super().__init__( | ||
max_iter=max_iter, seed=seed, n_trials=n_trials, | ||
correction=correction, n_jobs=n_jobs) | ||
self.sample_size = sample_size | ||
|
||
def score(self, data: Data, estimators: List[KMeans]) -> np.ndarray: | ||
gap_ = partial(sampled_gap, data, | ||
sample_size=self.sample_size, | ||
n_jobs=self.n_jobs, | ||
seed=self.seed, | ||
n_trials=self.n_trials, | ||
return_deviation=True, | ||
max_iter=self.max_iter) | ||
scores = [gap_(kmeans=estimator) for estimator in estimators] | ||
return np.array(scores) |
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
Oops, something went wrong.