<commit_before>#!/usr/bin/env python

from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
import numpy as np
from .._shared.helpers import *

def cluster(x, n_clusters=8, ndims=None):

    x = format_data(x)

    if type(x) is list:
        x = np.vstack(x)
    if ndims:
        x = PCA(n_components=ndims).fit_transform(x)
    kmeans = KMeans(init='k-means++', n_clusters=n_clusters, n_init=10)
    kmeans.fit(x)
    return list(kmeans.labels_)<commit_msg>added docstring to cluster.py<commit_after>#!/usr/bin/env python

from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
import numpy as np
from .._shared.helpers import *

def cluster(x, n_clusters=8, ndims=None):
    """
    Aligns a list of arrays

    This function takes a list of high dimensional arrays and 'hyperaligns' them
    to a 'common' space, or coordinate system following the approach outlined by
    Haxby et al, 2011. Hyperalignment uses linear transformations (rotation,
    reflection, translation, scaling) to register a group of arrays to a common
    space. This can be useful when two or more datasets describe an identical
    or similar system, but may not be in same coordinate system. For example,
    consider the example of fMRI recordings (voxels by time) from the visual
    cortex of a group of subjects watching the same movie: The brain responses
    should be highly similar, but the coordinates may not be aligned.

    <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, Gobbini
    MI, <NAME>, and Ramadge PJ (2011)  A common, high-dimensional model of
    the representational space in human ventral temporal cortex.  Neuron 72,
    404 -- 416.

    Parameters
    ----------
    data : list
            A list of Numpy arrays or Pandas Dataframes

    method : str
            Either 'hyper' or 'SRM'.  If 'hyper' (default),

    Returns
    ----------
    aligned : list
            An aligned list of numpy arrays

    """

    x = format_data(x)

    if type(x) is list:
        x = np.vstack(x)
    if ndims:
        x = PCA(n_components=ndims).fit_transform(x)

    kmeans = KMeans(init='k-means++', n_clusters=n_clusters, n_init=10)
    kmeans.fit(x)
    
    return list(kmeans.labels_)
{'fraction_non_alphanumeric': 0.09234234234234234, 'fraction_numerical': 0.00990990990990991, 'mean_word_length': 2.9802867383512543, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2459344', 'n_tokens_mistral': 717, 'n_tokens_neox': 670, 'n_words': 252}