def fit(self, X, y=None):
        """
        Compute agglomerative clustering.

        Parameters
        ----------
        X : array-like, shape=(n_samples, n_features)

        Returns
        -------
        self
        """

        if self.max_landmarks is not None:
            if self.n_clusters > self.n_landmarks:
                self.n_landmarks = self.max_landmarks
        
        if self.n_landmarks is None:
            distances = pdist(X, self.metric)
            tree = linkage(distances, method=self.linkage)
            self.landmark_labels_ = fcluster(tree, criterion='maxclust',
                                             t=self.n_clusters) - 1
            self.cardinality_ = np.bincount(self.landmark_labels_)
            self.squared_distances_within_cluster_ = np.zeros(self.n_clusters)

            n = len(X)
            for k in range(len(distances)):
                i = int(n - 2 - np.floor(np.sqrt(-8*k + 4*n*(n-1)-7)/2.0 - 0.5))
                j = int(k + i + 1 - n*(n-1)/2 + (n-i)*((n-i)-1)/2)
                if self.landmark_labels_[i] == self.landmark_labels_[j]:
                    self.squared_distances_within_cluster_[
                        self.landmark_labels_[i]] += distances[k] ** 2

            self.landmarks_ = X

        else:
            if self.landmark_strategy == 'random':
                land_indices = check_random_state(self.random_state).randint(
                    len(X), size=self.n_landmarks)
            else:
                land_indices = np.arange(len(X))[::(len(X) //
                                        self.n_landmarks)][:self.n_landmarks]

            distances = pdist(X[land_indices], self.metric)
            tree = linkage(distances, method=self.linkage)
            self.landmark_labels_ = fcluster(tree, criterion='maxclust',
                                             t=self.n_clusters) - 1
            self.cardinality_ = np.bincount(self.landmark_labels_)
            self.squared_distances_within_cluster_ = np.zeros(self.n_clusters)

            n = len(X[land_indices])
            for k in range(len(distances)):
                i = int(n - 2 - np.floor(np.sqrt(-8*k + 4*n*(n-1)-7)/2.0 - 0.5))
                j = int(k + i + 1 - n*(n-1)/2 + (n-i)*((n-i)-1)/2)
                if self.landmark_labels_[i] == self.landmark_labels_[j]:
                    self.squared_distances_within_cluster_[
                        self.landmark_labels_[i]] += distances[k] ** 2

            self.landmarks_ = X[land_indices]

        if self.metric != 'rmsd':
            cluster_centers_ = []
            for i in range(self.n_clusters):
                temp = list(np.mean(self.landmarks_[self.landmark_labels_==i], axis=0))
                cluster_centers_.append(temp)
            self.cluster_centers_ = np.array(cluster_centers_)

        return self
Compute agglomerative clustering.

        Parameters
        ----------
        X : array-like, shape=(n_samples, n_features)

        Returns
        -------
        self