-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clustering, 4 wrappers, notebook and documentation
- Loading branch information
Showing
9 changed files
with
505 additions
and
157 deletions.
There are no files selected for viewing
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
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,13 @@ | ||
from ._clustream import Clustream | ||
from ._clustream_with_kmeans import Clustream_with_kmeans | ||
from ._clustree import ClusTree | ||
from ._denstream_with_dbscan import Denstream_with_dbscan | ||
# from ._dstream import Dstream | ||
|
||
__all__ = [ | ||
"Clustream", | ||
"Clustream_with_kmeans", | ||
"ClusTree", | ||
"Denstream_with_dbscan", | ||
# "Dstream" | ||
] |
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,57 @@ | ||
from capymoa.base import MOAClusterer, ClusteringResult | ||
import os | ||
import typing | ||
from moa.clusterers.clustream import Clustream as _MOA_Clustream | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
# import numpy as np | ||
|
||
class Clustream(MOAClusterer): | ||
""" | ||
Clustream clustering algorithm without Macro-clustering. | ||
""" | ||
def __init__( | ||
self, | ||
schema: typing.Union[Schema, None] = None, | ||
time_window: int = 1000, | ||
max_num_kernels: int = 100, | ||
kernel_radi_factor: float = 2 | ||
): | ||
"""Clustream clusterer. | ||
:param schema: The schema of the stream. | ||
:param time_window: The size of the time window. | ||
:param max_num_kernels: Maximum number of micro kernels to use. | ||
:param kernel_radi_factor: Multiplier for the kernel radius | ||
""" | ||
|
||
mapping = { | ||
"time_window": "-h", | ||
"max_num_kernels": "-k", | ||
"kernel_radi_factor": "-t" | ||
} | ||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
self.moa_learner = _MOA_Clustream() | ||
super(Clustream, self).__init__( | ||
schema=schema, | ||
CLI=config_str, | ||
moa_learner=self.moa_learner | ||
) | ||
|
||
def implements_micro_clusters(self) -> bool: | ||
return True | ||
|
||
def implements_macro_clusters(self) -> bool: | ||
return False | ||
|
||
# def predict(self, X): | ||
# clusters = self.get_micro_clustering_result() | ||
# min_dist = np.inf | ||
# closest_center = None | ||
# for center in clusters.get_centers(): | ||
# if np.linalg.norm(center - X) < min_dist: | ||
# min_dist = np.linalg.norm(center - X) | ||
# closest_center = center | ||
# print(closest_center) | ||
# return closest_center |
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,62 @@ | ||
from capymoa.base import MOAClusterer | ||
import typing | ||
from moa.clusterers.clustream import WithKmeans as _MOA_Clustream_WKM | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
# import numpy as np | ||
|
||
class Clustream_with_kmeans(MOAClusterer): | ||
""" | ||
Clustream clustering algorithm without Macro-clustering. | ||
""" | ||
def __init__( | ||
self, | ||
schema: typing.Union[Schema, None] = None, | ||
time_window: int = 1000, | ||
max_num_kernels: int = 100, | ||
kernel_radi_factor: float = 2, | ||
k_option: int = 5 | ||
): | ||
"""Clustream clusterer with K-means offline clustering. | ||
:param schema: The schema of the stream. | ||
:param time_window: The size of the time window. | ||
:param max_num_kernels: Maximum number of micro kernels to use. | ||
:param kernel_radi_factor: Multiplier for the kernel radius | ||
:param k_option: Number of clusters to use in the k-means offline step | ||
""" | ||
|
||
mapping = { | ||
"time_window": "-h", | ||
"max_num_kernels": "-m", | ||
"kernel_radi_factor": "-t", | ||
"k_option": "-k" | ||
} | ||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
self.moa_learner = _MOA_Clustream_WKM() | ||
super(Clustream_with_kmeans, self).__init__( | ||
schema=schema, | ||
CLI=config_str, | ||
moa_learner=self.moa_learner | ||
) | ||
|
||
def implements_micro_clusters(self) -> bool: | ||
return True | ||
|
||
def implements_macro_clusters(self) -> bool: | ||
return True | ||
|
||
# def predict(self, X): | ||
# clusters = self.get_micro_clustering_result() | ||
# min_dist = np.inf | ||
# closest_center = None | ||
# for center in clusters.get_centers(): | ||
# if np.linalg.norm(center - X) < min_dist: | ||
# min_dist = np.linalg.norm(center - X) | ||
# closest_center = center | ||
# print(closest_center) | ||
# return closest_center | ||
|
||
def __str__(self): | ||
return "Clustream with KMeans" |
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,57 @@ | ||
from capymoa.base import MOAClusterer, ClusteringResult | ||
import os | ||
import typing | ||
from moa.clusterers.clustree import ClusTree as _MOA_ClusTree | ||
from capymoa.stream import Schema | ||
from capymoa._utils import build_cli_str_from_mapping_and_locals | ||
# import numpy as np | ||
|
||
class ClusTree(MOAClusterer): | ||
""" | ||
ClusTree clustering algorithm without Macro-clustering. | ||
""" | ||
def __init__( | ||
self, | ||
schema: typing.Union[Schema, None] = None, | ||
horizon: int = 1000, | ||
max_height: int = 8, | ||
breadth_first_strategy: bool = False | ||
): | ||
"""Clustream clusterer. | ||
:param schema: The schema of the stream | ||
:param horizon: The size of the time window | ||
:param max_height: The maximum height of the tree | ||
:param breadth_first_strategy: Whether to use breadth-first strategy | ||
""" | ||
|
||
mapping = { | ||
"horizon": "-h", | ||
"max_height": "-H", | ||
"breadth_first_strategy": "-B" | ||
} | ||
|
||
config_str = build_cli_str_from_mapping_and_locals(mapping, locals()) | ||
self.moa_learner = _MOA_ClusTree() | ||
super(ClusTree, self).__init__( | ||
schema=schema, | ||
CLI=config_str, | ||
moa_learner=self.moa_learner | ||
) | ||
|
||
def implements_micro_clusters(self) -> bool: | ||
return True | ||
|
||
def implements_macro_clusters(self) -> bool: | ||
return False | ||
|
||
# def predict(self, X): | ||
# clusters = self.get_micro_clustering_result() | ||
# min_dist = np.inf | ||
# closest_center = None | ||
# for center in clusters.get_centers(): | ||
# if np.linalg.norm(center - X) < min_dist: | ||
# min_dist = np.linalg.norm(center - X) | ||
# closest_center = center | ||
# print(closest_center) | ||
# return closest_center |
Oops, something went wrong.