def plot_clusters(self, save=True, folder='.', **kwargs): """ Creates a 3D-plot to visualize each cluster each cluster is assigned a different color in the plot. When save=True, it also stores the 3D-plot per cluster in DATA_PATH. :param save: Boolean specifying if image should be saved :type save: `bool` :param folder: Directory where the sprites will be saved inside DATA_PATH folder :type folder: `str` :param kwargs: a dictionary of cluster-analysis-specific parameters :type kwargs: `dict` :return: None """ self.set_params(**kwargs) if not self.clusters_by_class: self.cluster_activations() # Get activations reduced to 3-components: separated_reduced_activations = [] for ac in self.activations_by_class: reduced_activations = reduce_dimensionality(ac, nb_dims=3) separated_reduced_activations.append(reduced_activations) # For each class generate a plot: for class_id, (labels, coordinates) in enumerate(zip(self.clusters_by_class, separated_reduced_activations)): f_name = '' if save: f_name = os.path.join(folder, 'plot_class_' + str(class_id) + '.png') plot_3d(coordinates, labels, save=save, f_name=f_name)
def plot_clusters(self, save: bool = True, folder: str = ".", **kwargs) -> None: """ Creates a 3D-plot to visualize each cluster each cluster is assigned a different color in the plot. When save=True, it also stores the 3D-plot per cluster in ART_DATA_PATH. :param save: Boolean specifying if image should be saved. :param folder: Directory where the sprites will be saved inside ART_DATA_PATH folder. :param kwargs: a dictionary of cluster-analysis-specific parameters. """ self.set_params(**kwargs) if not self.clusters_by_class: self.cluster_activations() # Get activations reduced to 3-components: separated_reduced_activations = [] for activation in self.activations_by_class: reduced_activations = reduce_dimensionality(activation, nb_dims=3) separated_reduced_activations.append(reduced_activations) # For each class generate a plot: for class_id, (labels, coordinates) in enumerate(zip(self.clusters_by_class, separated_reduced_activations)): f_name = "" if save: f_name = os.path.join(folder, "plot_class_" + str(class_id) + ".png") plot_3d(coordinates, labels, save=save, f_name=f_name)
def test_3D_plot(self): points = [[1, 1, 1], [2, 2, 2], [3, 3, 3]] labels = [0, 1, 1] plot_3d(points, labels, save=False)
def test_3D_plot_fail(self): points = [[1, 1, 1], [2, 2, 2], [3, 3, 3]] labels = [1, 1, 3] # Shouldn't work because labels don't start in zero. plot_3d(points, labels, save=False)
def test_3D_plot(self): points = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) labels = np.array([0, 1, 1]) plot_3d(points, labels, save=False)