Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorganize directories #58

Merged
merged 1 commit into from
Mar 14, 2024
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
45 changes: 0 additions & 45 deletions __init__.py

This file was deleted.

47 changes: 47 additions & 0 deletions artlib/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
2 changes: 1 addition & 1 deletion biclustering/BARTMAP.py → artlib/biclustering/BARTMAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file added artlib/biclustering/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion common/BaseART.py → artlib/common/BaseART.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
Empty file added artlib/common/__init__.py
Empty file.
65 changes: 65 additions & 0 deletions artlib/common/utils.py
Original file line number Diff line number Diff line change
@@ -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)
64 changes: 0 additions & 64 deletions common/utils.py → artlib/common/visualization.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions elementary/ART1.py → artlib/elementary/ART1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions elementary/ART2.py → artlib/elementary/ART2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 5 additions & 17 deletions elementary/FuzzyART.py → artlib/elementary/FuzzyART.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_))
Expand Down
Empty file added artlib/elementary/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion fusion/FusionART.py → artlib/fusion/FusionART.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Empty file added artlib/fusion/__init__.py
Empty file.
Loading