From 3182b849fcafb57064f6f971e00e57bfb022004e Mon Sep 17 00:00:00 2001 From: niklas melton Date: Wed, 13 Mar 2024 23:11:18 -0500 Subject: [PATCH] reorganize directories --- __init__.py | 45 ------------- artlib/__init__.py | 47 ++++++++++++++ .../biclustering}/BARTMAP.py | 2 +- artlib/biclustering/__init__.py | 0 {common => artlib/common}/BaseART.py | 2 +- {common => artlib/common}/BaseARTMAP.py | 0 artlib/common/__init__.py | 0 artlib/common/utils.py | 65 +++++++++++++++++++ .../common/visualization.py | 64 ------------------ {elementary => artlib/elementary}/ART1.py | 4 +- {elementary => artlib/elementary}/ART2.py | 3 +- .../elementary}/BayesianART.py | 6 +- .../elementary}/DualVigilanceART.py | 2 +- .../elementary}/EllipsoidART.py | 4 +- {elementary => artlib/elementary}/FuzzyART.py | 22 ++----- .../elementary}/GaussianART.py | 4 +- .../elementary}/HypersphereART.py | 4 +- .../elementary}/QuadraticNeuronART.py | 6 +- artlib/elementary/__init__.py | 0 {fusion => artlib/fusion}/FusionART.py | 2 +- artlib/fusion/__init__.py | 0 .../hierarchical}/DeepARTMAP.py | 8 +-- .../hierarchical}/SMART.py | 4 +- artlib/hierarchical/__init__.py | 0 {supervised => artlib/supervised}/ARTMAP.py | 7 +- .../supervised}/SimpleARTMAP.py | 4 +- artlib/supervised/__init__.py | 0 .../topological}/TopoART.py | 2 +- artlib/topological/__init__.py | 0 examples/test_art1.py | 12 +--- examples/test_art2.py | 13 +--- examples/test_artmap.py | 17 +---- examples/test_bartmap.py | 21 ++---- examples/test_bayesian_art.py | 4 +- examples/test_dual_vigilance_art.py | 14 +--- examples/test_ellipsoid_art.py | 12 +--- examples/test_fusion_art.py | 16 +---- examples/test_fuzzy_art.py | 13 +--- examples/test_gaussian_art.py | 14 +--- examples/test_hypersphere_art.py | 12 +--- examples/test_quadratic_neuron_art.py | 12 +--- examples/test_smart.py | 17 +---- examples/test_topo_art.py | 14 +--- 43 files changed, 176 insertions(+), 322 deletions(-) delete mode 100644 __init__.py create mode 100644 artlib/__init__.py rename {biclustering => artlib/biclustering}/BARTMAP.py (99%) create mode 100644 artlib/biclustering/__init__.py rename {common => artlib/common}/BaseART.py (99%) rename {common => artlib/common}/BaseARTMAP.py (100%) create mode 100644 artlib/common/__init__.py create mode 100644 artlib/common/utils.py rename common/utils.py => artlib/common/visualization.py (82%) rename {elementary => artlib/elementary}/ART1.py (97%) rename {elementary => artlib/elementary}/ART2.py (98%) rename {elementary => artlib/elementary}/BayesianART.py (97%) rename {elementary => artlib/elementary}/DualVigilanceART.py (99%) rename {elementary => artlib/elementary}/EllipsoidART.py (98%) rename {elementary => artlib/elementary}/FuzzyART.py (93%) rename {elementary => artlib/elementary}/GaussianART.py (97%) rename {elementary => artlib/elementary}/HypersphereART.py (98%) rename {elementary => artlib/elementary}/QuadraticNeuronART.py (97%) create mode 100644 artlib/elementary/__init__.py rename {fusion => artlib/fusion}/FusionART.py (99%) create mode 100644 artlib/fusion/__init__.py rename {hierarchical => artlib/hierarchical}/DeepARTMAP.py (97%) rename {hierarchical => artlib/hierarchical}/SMART.py (97%) create mode 100644 artlib/hierarchical/__init__.py rename {supervised => artlib/supervised}/ARTMAP.py (93%) rename {supervised => artlib/supervised}/SimpleARTMAP.py (98%) create mode 100644 artlib/supervised/__init__.py rename {topological => artlib/topological}/TopoART.py (99%) create mode 100644 artlib/topological/__init__.py diff --git a/__init__.py b/__init__.py deleted file mode 100644 index ee5e8ca..0000000 --- a/__init__.py +++ /dev/null @@ -1,45 +0,0 @@ -from common.BaseART import BaseART -from common.BaseARTMAP import BaseARTMAP -from elementary.ART1 import ART1 -from elementary.ART2 import ART2A -from elementary.BayesianART import BayesianART -from elementary.DualVigilanceART import DualVigilanceART -from elementary.EllipsoidART import EllipsoidART -from elementary.GaussianART import GaussianART -from elementary.FuzzyART import FuzzyART -from elementary.HypersphereART import HypersphereART -from elementary.QuadraticNeuronART import QuadraticNeuronART - - -from supervised.ARTMAP import ARTMAP, SimpleARTMAP - -from hierarchical.SMART import SMART -from hierarchical.DeepARTMAP import DeepARTMAP - -from fusion.FusionART import FusionART - -from biclustering import BARTMAP - -from topological import TopoART - -__all__ = [ - "BaseART", - "BaseARTMAP", - "ART1", - "ART2A", - "BayesianART", - "GaussianART", - "EllipsoidART", - "HypersphereART", - "QuadraticNeuronART", - "FuzzyART", - "TopoART", - "DualVigilanceART", - "ARTMAP", - "SimpleARTMAP", - "DeepARTMAP", - "SMART", - "FusionART", - "BARTMAP", - -] \ No newline at end of file diff --git a/artlib/__init__.py b/artlib/__init__.py new file mode 100644 index 0000000..6fb4b5b --- /dev/null +++ b/artlib/__init__.py @@ -0,0 +1,47 @@ +from artlib.common.BaseART import BaseART +from artlib.common.BaseARTMAP import BaseARTMAP +from artlib.common.utils import normalize, compliment_code + +from artlib.elementary.ART1 import ART1 +from artlib.elementary.ART2 import ART2A +from artlib.elementary.BayesianART import BayesianART +from artlib.elementary.DualVigilanceART import DualVigilanceART +from artlib.elementary.EllipsoidART import EllipsoidART +from artlib.elementary.GaussianART import GaussianART +from artlib.elementary.FuzzyART import FuzzyART +from artlib.elementary.HypersphereART import HypersphereART +from artlib.elementary.QuadraticNeuronART import QuadraticNeuronART + +from artlib.supervised.ARTMAP import ARTMAP, SimpleARTMAP + +from artlib.hierarchical.SMART import SMART +from artlib.hierarchical.DeepARTMAP import DeepARTMAP + +from artlib.fusion.FusionART import FusionART + +from artlib.biclustering.BARTMAP import BARTMAP + +from artlib.topological.TopoART import TopoART + +__all__ = [ + "BaseART", + "BaseARTMAP", + "normalize", + "compliment_code", + "ART1", + "ART2A", + "BayesianART", + "GaussianART", + "EllipsoidART", + "HypersphereART", + "QuadraticNeuronART", + "FuzzyART", + "TopoART", + "DualVigilanceART", + "ARTMAP", + "SimpleARTMAP", + "DeepARTMAP", + "SMART", + "FusionART", + "BARTMAP", +] \ No newline at end of file diff --git a/biclustering/BARTMAP.py b/artlib/biclustering/BARTMAP.py similarity index 99% rename from biclustering/BARTMAP.py rename to artlib/biclustering/BARTMAP.py index 8bf115c..2b39fda 100644 --- a/biclustering/BARTMAP.py +++ b/artlib/biclustering/BARTMAP.py @@ -14,7 +14,7 @@ from typing import Optional from collections import defaultdict from matplotlib.colors import Colormap -from common.BaseART import BaseART +from artlib.common.BaseART import BaseART from sklearn.base import BaseEstimator, BiclusterMixin from scipy.stats import pearsonr diff --git a/artlib/biclustering/__init__.py b/artlib/biclustering/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/common/BaseART.py b/artlib/common/BaseART.py similarity index 99% rename from common/BaseART.py rename to artlib/common/BaseART.py index e05b12d..4d8aa03 100644 --- a/common/BaseART.py +++ b/artlib/common/BaseART.py @@ -5,7 +5,7 @@ from warnings import warn from sklearn.base import BaseEstimator, ClusterMixin from sklearn.utils.validation import check_is_fitted -from common.utils import normalize +from artlib.common.utils import normalize class BaseART(BaseEstimator, ClusterMixin): diff --git a/common/BaseARTMAP.py b/artlib/common/BaseARTMAP.py similarity index 100% rename from common/BaseARTMAP.py rename to artlib/common/BaseARTMAP.py diff --git a/artlib/common/__init__.py b/artlib/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/artlib/common/utils.py b/artlib/common/utils.py new file mode 100644 index 0000000..106e029 --- /dev/null +++ b/artlib/common/utils.py @@ -0,0 +1,65 @@ +import numpy as np + +def normalize(data: np.ndarray) -> np.ndarray: + """ + normalize data betweeon 0 and 1 + + Parameters: + - data: data set + + Returns: + normalized data + """ + normalized = (data-np.min(data))/(np.max(data)-np.min(data)) + return normalized + +def compliment_code(data: np.ndarray) -> np.ndarray: + """ + compliment code data + + Parameters: + - data: data set + + Returns: + compliment coded data + """ + cc_data = np.hstack([data, 1.0-data]) + return cc_data + +def l1norm(x: np.ndarray) -> float: + """ + get l1 norm of a vector + + Parameters: + - x: some vector + + Returns: + l1 norm + """ + return float(np.sum(np.absolute(x))) + +def l2norm2(data: np.ndarray) -> float: + """ + get (l2 norm)^2 of a vector + + Parameters: + - x: some vector + + Returns: + (l2 norm)^2 + """ + return float(np.matmul(data, data)) + +def fuzzy_and(x: np.ndarray, y: np.ndarray) -> np.ndarray: + """ + get the fuzzy AND operation between two vectors + + Parameters: + - a: some vector + - b: some vector + + Returns: + Fuzzy AND result + + """ + return np.minimum(x, y) diff --git a/common/utils.py b/artlib/common/visualization.py similarity index 82% rename from common/utils.py rename to artlib/common/visualization.py index 26bd72a..7214a9d 100644 --- a/common/utils.py +++ b/artlib/common/visualization.py @@ -1,70 +1,6 @@ import numpy as np from matplotlib.axes import Axes -def normalize(data: np.ndarray) -> np.ndarray: - """ - normalize data betweeon 0 and 1 - - Parameters: - - data: data set - - Returns: - normalized data - """ - normalized = (data-np.min(data))/(np.max(data)-np.min(data)) - return normalized - -def compliment_code(data: np.ndarray) -> np.ndarray: - """ - compliment code data - - Parameters: - - data: data set - - Returns: - compliment coded data - """ - cc_data = np.hstack([data, 1.0-data]) - return cc_data - -def l1norm(x: np.ndarray) -> float: - """ - get l1 norm of a vector - - Parameters: - - x: some vector - - Returns: - l1 norm - """ - return float(np.sum(np.absolute(x))) - -def l2norm2(data: np.ndarray) -> float: - """ - get (l2 norm)^2 of a vector - - Parameters: - - x: some vector - - Returns: - (l2 norm)^2 - """ - return float(np.matmul(data, data)) - -def fuzzy_and(x: np.ndarray, y: np.ndarray) -> np.ndarray: - """ - get the fuzzy AND operation between two vectors - - Parameters: - - a: some vector - - b: some vector - - Returns: - Fuzzy AND result - - """ - return np.minimum(x, y) - def plot_gaussian_contours_fading( ax: Axes, mean: np.ndarray, diff --git a/elementary/ART1.py b/artlib/elementary/ART1.py similarity index 97% rename from elementary/ART1.py rename to artlib/elementary/ART1.py index 2c4b66e..79660fd 100644 --- a/elementary/ART1.py +++ b/artlib/elementary/ART1.py @@ -6,8 +6,8 @@ import numpy as np from typing import Optional -from common.BaseART import BaseART -from common.utils import normalize, l1norm +from artlib.common.BaseART import BaseART +from artlib.common.utils import normalize, l1norm def prepare_data(data: np.ndarray) -> np.ndarray: normalized = normalize(data) diff --git a/elementary/ART2.py b/artlib/elementary/ART2.py similarity index 98% rename from elementary/ART2.py rename to artlib/elementary/ART2.py index d2c57b1..a14dcef 100644 --- a/elementary/ART2.py +++ b/artlib/elementary/ART2.py @@ -20,8 +20,7 @@ import numpy as np from typing import Optional from warnings import warn -from common.BaseART import BaseART -from common.utils import normalize +from artlib.common.BaseART import BaseART class ART2A(BaseART): diff --git a/elementary/BayesianART.py b/artlib/elementary/BayesianART.py similarity index 97% rename from elementary/BayesianART.py rename to artlib/elementary/BayesianART.py index 80aaca6..a498c0b 100644 --- a/elementary/BayesianART.py +++ b/artlib/elementary/BayesianART.py @@ -6,9 +6,9 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import normalize -from common.utils import plot_gaussian_contours_covariance +from artlib.common.BaseART import BaseART +from artlib.common.utils import normalize +from artlib.common.visualization import plot_gaussian_contours_covariance def prepare_data(data: np.ndarray) -> np.ndarray: normalized = normalize(data) diff --git a/elementary/DualVigilanceART.py b/artlib/elementary/DualVigilanceART.py similarity index 99% rename from elementary/DualVigilanceART.py rename to artlib/elementary/DualVigilanceART.py index a6f0d37..ba52d52 100644 --- a/elementary/DualVigilanceART.py +++ b/artlib/elementary/DualVigilanceART.py @@ -7,7 +7,7 @@ from typing import Optional, Callable, Iterable from warnings import warn from matplotlib.axes import Axes -from common.BaseART import BaseART +from artlib.common.BaseART import BaseART class DualVigilanceART(BaseART): diff --git a/elementary/EllipsoidART.py b/artlib/elementary/EllipsoidART.py similarity index 98% rename from elementary/EllipsoidART.py rename to artlib/elementary/EllipsoidART.py index 40fa669..ecce7ed 100644 --- a/elementary/EllipsoidART.py +++ b/artlib/elementary/EllipsoidART.py @@ -12,8 +12,8 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import l2norm2 +from artlib.common.BaseART import BaseART +from artlib.common.utils import l2norm2 class EllipsoidART(BaseART): # implementation of EllipsoidART diff --git a/elementary/FuzzyART.py b/artlib/elementary/FuzzyART.py similarity index 93% rename from elementary/FuzzyART.py rename to artlib/elementary/FuzzyART.py index 37be70d..860f619 100644 --- a/elementary/FuzzyART.py +++ b/artlib/elementary/FuzzyART.py @@ -6,22 +6,8 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import normalize, compliment_code, l1norm, fuzzy_and - -def prepare_data(data: np.ndarray) -> np.ndarray: - """ - prepare data for clustering - - Parameters: - - X: data set - - Returns: - normalized and compliment coded data - """ - normalized = normalize(data) - cc_data = compliment_code(normalized) - return cc_data +from artlib.common.BaseART import BaseART +from artlib.common.utils import normalize, compliment_code, l1norm, fuzzy_and def get_bounding_box(w: np.ndarray, n: Optional[int] = None) -> tuple[list[int], list[int]]: @@ -81,7 +67,9 @@ def prepare_data(X: np.ndarray) -> np.ndarray: Returns: normalized and compliment coded data """ - return prepare_data(X) + normalized = normalize(X) + cc_data = compliment_code(normalized) + return cc_data @staticmethod def validate_params(params: dict): diff --git a/elementary/GaussianART.py b/artlib/elementary/GaussianART.py similarity index 97% rename from elementary/GaussianART.py rename to artlib/elementary/GaussianART.py index 0d241f9..8dd7fa1 100644 --- a/elementary/GaussianART.py +++ b/artlib/elementary/GaussianART.py @@ -7,8 +7,8 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import plot_gaussian_contours_fading +from artlib.common.BaseART import BaseART +from artlib.common.visualization import plot_gaussian_contours_fading class GaussianART(BaseART): diff --git a/elementary/HypersphereART.py b/artlib/elementary/HypersphereART.py similarity index 98% rename from elementary/HypersphereART.py rename to artlib/elementary/HypersphereART.py index a64a1f3..30e95de 100644 --- a/elementary/HypersphereART.py +++ b/artlib/elementary/HypersphereART.py @@ -7,8 +7,8 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import l2norm2 +from artlib.common.BaseART import BaseART +from artlib.common.utils import l2norm2 class HypersphereART(BaseART): # implementation of HypersphereART diff --git a/elementary/QuadraticNeuronART.py b/artlib/elementary/QuadraticNeuronART.py similarity index 97% rename from elementary/QuadraticNeuronART.py rename to artlib/elementary/QuadraticNeuronART.py index 6ef31a3..c99a1ee 100644 --- a/elementary/QuadraticNeuronART.py +++ b/artlib/elementary/QuadraticNeuronART.py @@ -11,8 +11,9 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.utils import normalize, l2norm2, plot_weight_matrix_as_ellipse +from artlib.common.BaseART import BaseART +from artlib.common.utils import normalize, l2norm2 +from artlib.common.visualization import plot_weight_matrix_as_ellipse def prepare_data(data: np.ndarray) -> np.ndarray: normalized = normalize(data) @@ -187,7 +188,6 @@ def plot_cluster_bounds(self, ax: Axes, colors: Iterable, linewidth: int = 1): """ # kinda works - from matplotlib.patches import Rectangle for w, col in zip(self.W, colors): dim2 = self.dim_ * self.dim_ w_ = w[:dim2].reshape((self.dim_, self.dim_)) diff --git a/artlib/elementary/__init__.py b/artlib/elementary/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fusion/FusionART.py b/artlib/fusion/FusionART.py similarity index 99% rename from fusion/FusionART.py rename to artlib/fusion/FusionART.py index d8e6958..ebb3678 100644 --- a/fusion/FusionART.py +++ b/artlib/fusion/FusionART.py @@ -8,7 +8,7 @@ """ import numpy as np from typing import Optional, Union -from common.BaseART import BaseART +from artlib.common.BaseART import BaseART def get_channel_position_tuples(channel_dims: list[int]) -> list[tuple[int, int]]: positions = [] diff --git a/artlib/fusion/__init__.py b/artlib/fusion/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hierarchical/DeepARTMAP.py b/artlib/hierarchical/DeepARTMAP.py similarity index 97% rename from hierarchical/DeepARTMAP.py rename to artlib/hierarchical/DeepARTMAP.py index 56d2301..b92db15 100644 --- a/hierarchical/DeepARTMAP.py +++ b/artlib/hierarchical/DeepARTMAP.py @@ -7,10 +7,10 @@ from sklearn.base import BaseEstimator, ClassifierMixin, ClusterMixin from typing import Optional, cast, Union from collections import defaultdict -from common.BaseART import BaseART -from common.BaseARTMAP import BaseARTMAP -from supervised.SimpleARTMAP import SimpleARTMAP -from supervised.ARTMAP import ARTMAP +from artlib.common.BaseART import BaseART +from artlib.common.BaseARTMAP import BaseARTMAP +from artlib.supervised.SimpleARTMAP import SimpleARTMAP +from artlib.supervised.ARTMAP import ARTMAP class DeepARTMAP(BaseEstimator, ClassifierMixin, ClusterMixin): diff --git a/hierarchical/SMART.py b/artlib/hierarchical/SMART.py similarity index 97% rename from hierarchical/SMART.py rename to artlib/hierarchical/SMART.py index 5c352f9..29777d4 100644 --- a/hierarchical/SMART.py +++ b/artlib/hierarchical/SMART.py @@ -8,8 +8,8 @@ import numpy as np from typing import Union, Type, Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from hierarchical.DeepARTMAP import DeepARTMAP +from artlib.common.BaseART import BaseART +from artlib.hierarchical.DeepARTMAP import DeepARTMAP class SMART(DeepARTMAP): diff --git a/artlib/hierarchical/__init__.py b/artlib/hierarchical/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/supervised/ARTMAP.py b/artlib/supervised/ARTMAP.py similarity index 93% rename from supervised/ARTMAP.py rename to artlib/supervised/ARTMAP.py index 6de4856..72e1698 100644 --- a/supervised/ARTMAP.py +++ b/artlib/supervised/ARTMAP.py @@ -4,10 +4,9 @@ Neural Networks, 4, 565 – 588. doi:10.1016/0893-6080(91)90012-T. """ import numpy as np -from common.BaseART import BaseART -from common.BaseARTMAP import BaseARTMAP -from supervised.SimpleARTMAP import SimpleARTMAP -from sklearn.utils.validation import check_is_fitted, check_X_y +from artlib.common.BaseART import BaseART +from artlib.supervised.SimpleARTMAP import SimpleARTMAP +from sklearn.utils.validation import check_is_fitted class ARTMAP(SimpleARTMAP): diff --git a/supervised/SimpleARTMAP.py b/artlib/supervised/SimpleARTMAP.py similarity index 98% rename from supervised/SimpleARTMAP.py rename to artlib/supervised/SimpleARTMAP.py index e047f7d..d4da09a 100644 --- a/supervised/SimpleARTMAP.py +++ b/artlib/supervised/SimpleARTMAP.py @@ -6,8 +6,8 @@ import numpy as np from typing import Optional, Iterable from matplotlib.axes import Axes -from common.BaseART import BaseART -from common.BaseARTMAP import BaseARTMAP +from artlib.common.BaseART import BaseART +from artlib.common.BaseARTMAP import BaseARTMAP from sklearn.utils.validation import check_is_fitted, check_X_y from sklearn.utils.multiclass import unique_labels diff --git a/artlib/supervised/__init__.py b/artlib/supervised/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/topological/TopoART.py b/artlib/topological/TopoART.py similarity index 99% rename from topological/TopoART.py rename to artlib/topological/TopoART.py index 0b2716e..c89042e 100644 --- a/topological/TopoART.py +++ b/artlib/topological/TopoART.py @@ -12,7 +12,7 @@ from typing import Optional, Callable, Iterable from matplotlib.axes import Axes from warnings import warn -from common.BaseART import BaseART +from artlib.common.BaseART import BaseART class TopoART(BaseART): diff --git a/artlib/topological/__init__.py b/artlib/topological/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/test_art1.py b/examples/test_art1.py index b0434f3..11a77d4 100644 --- a/examples/test_art1.py +++ b/examples/test_art1.py @@ -1,17 +1,7 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.ART1 import ART1 -from common.utils import normalize +from artlib import ART1, normalize def cluster_blobs(): diff --git a/examples/test_art2.py b/examples/test_art2.py index 86cc675..e84fa58 100644 --- a/examples/test_art2.py +++ b/examples/test_art2.py @@ -1,7 +1,6 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys +from artlib import ART2A, normalize """ ================================================================== @@ -11,16 +10,6 @@ Stephan Grossberg himself has said ART2 does not work. ================================================================== """ -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.ART2 import ART2A, prepare_data -from common.utils import normalize - def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=2, cluster_std=0.50, random_state=0, shuffle=False) diff --git a/examples/test_artmap.py b/examples/test_artmap.py index e248811..542037b 100644 --- a/examples/test_artmap.py +++ b/examples/test_artmap.py @@ -2,19 +2,8 @@ from sklearn.datasets import load_iris, make_blobs import matplotlib.pyplot as plt +from artlib import FuzzyART, SimpleARTMAP -import path -import sys - -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.FuzzyART import FuzzyART, prepare_data -from supervised.SimpleARTMAP import SimpleARTMAP def cluster_iris(): from sklearn.model_selection import train_test_split @@ -23,7 +12,7 @@ def cluster_iris(): data, target = load_iris(return_X_y=True) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) X_train, X_test, y_train, y_test = train_test_split(X, target, test_size=0.33, random_state=0) @@ -55,7 +44,7 @@ def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) params = { diff --git a/examples/test_bartmap.py b/examples/test_bartmap.py index 5e9dd1f..2661fe6 100644 --- a/examples/test_bartmap.py +++ b/examples/test_bartmap.py @@ -1,20 +1,7 @@ - from sklearn.datasets import make_checkerboard import matplotlib.pyplot as plt -import path -import sys -import numpy as np - -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) -from biclustering.BARTMAP import BARTMAP -from elementary.FuzzyART import FuzzyART -from common.utils import normalize +from artlib import BARTMAP, FuzzyART, normalize def cluster_checkerboard(): @@ -37,9 +24,9 @@ def cluster_checkerboard(): "alpha": 0.0, "beta": 1.0 } - art_a = FuzzyART(params_a) - art_b = FuzzyART(params_b) - cls = BARTMAP(art_a, art_b, {"eta": -1.}) + art_a = FuzzyART(**params_a) + art_b = FuzzyART(**params_b) + cls = BARTMAP(art_a, art_b, eta=-1.) cls.fit(X) print(f"{cls.n_row_clusters} row clusters found") diff --git a/examples/test_bayesian_art.py b/examples/test_bayesian_art.py index 33eecc1..fe2e6a9 100644 --- a/examples/test_bayesian_art.py +++ b/examples/test_bayesian_art.py @@ -10,8 +10,8 @@ # setting path sys.path.append(directory.parent.parent) -from elementary.BayesianART import BayesianART -from common.utils import normalize +from artlib import BayesianART +from artlib.common.utils import normalize import numpy as np diff --git a/examples/test_dual_vigilance_art.py b/examples/test_dual_vigilance_art.py index 6d257a5..f6e323e 100644 --- a/examples/test_dual_vigilance_art.py +++ b/examples/test_dual_vigilance_art.py @@ -1,24 +1,14 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.DualVigilanceART import DualVigilanceART -from elementary.FuzzyART import FuzzyART, prepare_data +from artlib import DualVigilanceART, FuzzyART def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) params = { diff --git a/examples/test_ellipsoid_art.py b/examples/test_ellipsoid_art.py index 562adbb..6821da4 100644 --- a/examples/test_ellipsoid_art.py +++ b/examples/test_ellipsoid_art.py @@ -1,17 +1,7 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.EllipsoidART import EllipsoidART -from common.utils import normalize +from artlib import EllipsoidART, normalize def cluster_blobs(): diff --git a/examples/test_fusion_art.py b/examples/test_fusion_art.py index 6406587..3492035 100644 --- a/examples/test_fusion_art.py +++ b/examples/test_fusion_art.py @@ -1,18 +1,8 @@ import numpy as np from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from fusion.FusionART import FusionART -from elementary.FuzzyART import FuzzyART, prepare_data +from artlib import FusionART, FuzzyART def cluster_blobs(): @@ -22,8 +12,8 @@ def cluster_blobs(): data_channel_a = data[:,0].reshape((-1,1)) data_channel_b = data[:,1].reshape((-1,1)) - X_channel_a = prepare_data(data_channel_a) - X_channel_b = prepare_data(data_channel_b) + X_channel_a = FuzzyART.prepare_data(data_channel_a) + X_channel_b = FuzzyART.prepare_data(data_channel_b) X = np.hstack([X_channel_a, X_channel_b]) print("Prepared data has shape:", X.shape) diff --git a/examples/test_fuzzy_art.py b/examples/test_fuzzy_art.py index d059bec..b5729be 100644 --- a/examples/test_fuzzy_art.py +++ b/examples/test_fuzzy_art.py @@ -1,23 +1,14 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.FuzzyART import FuzzyART, prepare_data +from artlib import FuzzyART def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) params = { diff --git a/examples/test_gaussian_art.py b/examples/test_gaussian_art.py index 47924c5..9bba697 100644 --- a/examples/test_gaussian_art.py +++ b/examples/test_gaussian_art.py @@ -1,19 +1,9 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys - -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.GaussianART import GaussianART -from common.utils import normalize import numpy as np +from artlib import GaussianART, normalize + def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) diff --git a/examples/test_hypersphere_art.py b/examples/test_hypersphere_art.py index eea2157..e1d76c1 100644 --- a/examples/test_hypersphere_art.py +++ b/examples/test_hypersphere_art.py @@ -1,17 +1,7 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.HypersphereART import HypersphereART -from common.utils import normalize +from artlib import HypersphereART, normalize def cluster_blobs(): diff --git a/examples/test_quadratic_neuron_art.py b/examples/test_quadratic_neuron_art.py index 69272f1..099f655 100644 --- a/examples/test_quadratic_neuron_art.py +++ b/examples/test_quadratic_neuron_art.py @@ -1,17 +1,7 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.QuadraticNeuronART import QuadraticNeuronART -from common.utils import normalize +from artlib import QuadraticNeuronART, normalize def cluster_blobs(): diff --git a/examples/test_smart.py b/examples/test_smart.py index 18e0549..090f147 100644 --- a/examples/test_smart.py +++ b/examples/test_smart.py @@ -1,25 +1,14 @@ -from sklearn.datasets import load_iris, make_blobs +from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys - -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from elementary.FuzzyART import FuzzyART, prepare_data -from hierarchical.SMART import SMART +from artlib import FuzzyART, SMART def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) base_params = { diff --git a/examples/test_topo_art.py b/examples/test_topo_art.py index d5eec68..d346d0e 100644 --- a/examples/test_topo_art.py +++ b/examples/test_topo_art.py @@ -1,24 +1,14 @@ from sklearn.datasets import make_blobs import matplotlib.pyplot as plt -import path -import sys -# directory reach -directory = path.Path(__file__).abspath() - -print(directory.parent) -# setting path -sys.path.append(directory.parent.parent) - -from topological.TopoART import TopoART -from elementary.FuzzyART import FuzzyART, prepare_data +from artlib import TopoART, FuzzyART def cluster_blobs(): data, target = make_blobs(n_samples=150, centers=3, cluster_std=0.50, random_state=0, shuffle=False) print("Data has shape:", data.shape) - X = prepare_data(data) + X = FuzzyART.prepare_data(data) print("Prepared data has shape:", X.shape) params = {