Skip to content

Commit

Permalink
Update quick start tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
breimanntools committed Sep 24, 2023
1 parent 7841f29 commit 1feee77
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 1,828 deletions.
Binary file modified aaanalysis/__pycache__/utils.cpython-39.pyc
Binary file not shown.
Binary file modified aaanalysis/_utils/__pycache__/_utils_check.cpython-39.pyc
Binary file not shown.
Binary file modified aaanalysis/_utils/__pycache__/utils_aaclust.cpython-39.pyc
Binary file not shown.
7 changes: 3 additions & 4 deletions aaanalysis/_utils/_utils_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ def check_tuple(name=None, val=None, n=None):

# Array checking functions
def check_feat_matrix(X=None, names=None, labels=None):
"""Check if X and y match (y can be labels or names). Otherwise, transpose X or give error."""
# TODO type check
X = check_array(X)
"""Transpose matrix and check if X and y match (y can be labels or names). Transpose back otherwise """
X = check_array(X).transpose()
if labels is not None:
check_consistent_length(X, labels)
n_samples, n_features = X.shape
if n_samples == 0 or n_features == 0:
raise ValueError(f"Shape of X ({n_samples}, {n_features}) indicates empty feature matrix.")
raise ValueError(f"Shape of 'X' ({n_samples}, {n_features}) indicates empty feature matrix.")
if names is None:
return X, names
else:
Expand Down
6 changes: 6 additions & 0 deletions aaanalysis/_utils/utils_aaclust.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ def check_merge_metric(merge_metric=None):
error = f"'merge_metric' should be None or one of following: {LIST_METRICS}"
raise ValueError(error)
return merge_metric

def check_feat_matrix_n_clust_match(X=None, n_clusters=None):
""""""
n_samples, n_features = X.shape
if n_samples <= n_clusters:
raise ValueError(f"'X' must contain more samples ({n_samples}) then 'n_clusters' ({n_clusters})")
Binary file modified aaanalysis/aaclust/__pycache__/aaclust.cpython-39.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion aaanalysis/aaclust/aaclust.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


# I Helper Functions


# Obtain centroids and medoids
def cluster_center(X):
"""Compute cluster center (i.e., arithmetical mean over all data points/observations of a cluster)"""
Expand All @@ -29,7 +31,7 @@ def _cluster_medoid(X):
"""Obtain cluster medoids (i.e., scale closest to cluster center used as representative scale for a cluster)"""
# Create new array with cluster center and given
center_X = np.concatenate([cluster_center(X), X], axis=0)
# Get index for scale with highest correlation with cluster center
# Get index for scale with the highest correlation with cluster center
ind_max = np.corrcoef(center_X)[0, 1:].argmax()
return ind_max

Expand Down Expand Up @@ -410,6 +412,7 @@ def fit(self, X, names=None, on_center=True, min_th=0, merge_metric="euclidean"
ut.check_min_th(min_th=min_th)
merge_metric = ut.check_merge_metric(merge_metric=merge_metric)
X, names = ut.check_feat_matrix(X=X, names=names)
ut.check_feat_matrix_n_clust_match(X=X, n_clusters=n_clusters)
args = dict(model=self.model, model_kwargs=self._model_kwargs, min_th=min_th, on_center=on_center)
# Clustering using given clustering models
if n_clusters is not None:
Expand Down
Binary file modified aaanalysis/cpp/__pycache__/cpp.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions aaanalysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
check_feat_matrix, check_col_in_df)
from aaanalysis._utils._utils_output import (print_red, print_start_progress, print_progress, print_finished_progress)
from aaanalysis._utils.utils_aaclust import (check_model, check_min_th, check_merge_metric,
check_feat_matrix_n_clust_match,
METRIC_CORRELATION, LIST_METRICS)
from aaanalysis._utils.utils_cpp import (check_color, check_y_categorical, check_labels, check_ylim,
check_args_len, check_args_len, check_list_parts,
Expand Down
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/generated/aaanalysis.AAclust.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/generated/tutorial1_quick_start.doctree
Binary file not shown.
Binary file modified docs/build/html/_images/output_13_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1feee77

Please sign in to comment.