Пример #1
0
    def set_data(self, data):
        self.closeContext()
        self.Error.clear()

        prev_data, self.data = self.data, data
        self.openContext(self.data)
        # Make sure to properly enable/disable slider based on `apply_pca` setting
        self.controls.pca_components.setEnabled(self.apply_pca)

        if prev_data and self.data and ut.array_equal(prev_data.X,
                                                      self.data.X):
            if self.auto_commit:
                self._send_data()
            return

        # Clear the outputs
        self.Outputs.annotated_data.send(None)
        if Graph is not None:
            self.Outputs.graph.send(None)

        # Clear internal state
        self.clear()
        self._invalidate_pca_projection()

        # Make sure the dataset is ok
        if self.data is not None and len(self.data.domain.attributes) < 1:
            self.Error.empty_dataset()
            self.data = None

        if self.data is None:
            return

        # Can't have more PCA components than the number of attributes
        n_attrs = len(data.domain.attributes)
        self.pca_components_slider.setMaximum(min(_MAX_PCA_COMPONENTS,
                                                  n_attrs))
        self.pca_components_slider.setValue(
            min(_DEFAULT_PCA_COMPONENTS, n_attrs))
        # Can't have more k neighbors than there are data points
        self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1))
        self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS,
                                           len(data) - 1))

        self.info_label.setText("Clustering not yet run.")

        self.commit()
Пример #2
0
    def set_data(self, data):
        self.closeContext()
        self.Error.clear()

        prev_data, self.data = self.data, data
        self.openContext(self.data)
        # Make sure to properly enable/disable slider based on `apply_pca` setting
        self.controls.pca_components.setEnabled(self.apply_pca)

        if prev_data and self.data and ut.array_equal(prev_data.X, self.data.X):
            if self.auto_commit:
                self._send_data()
            return

        # Clear the outputs
        self.Outputs.annotated_data.send(None)
        if Graph is not None:
            self.Outputs.graph.send(None)

        # Clear internal state
        self.clear()
        self._invalidate_pca_projection()

        # Make sure the dataset is ok
        if self.data is not None and len(self.data.domain.attributes) < 1:
            self.Error.empty_dataset()
            self.data = None

        if self.data is None:
            return

        # Can't have more PCA components than the number of attributes
        n_attrs = len(data.domain.attributes)
        self.pca_components_slider.setMaximum(min(_MAX_PCA_COMPONENTS, n_attrs))
        self.pca_components_slider.setValue(min(_DEFAULT_PCA_COMPONENTS, n_attrs))
        # Can't have more k neighbors than there are data points
        self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1))
        self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS, len(data) - 1))

        self.info_label.setText("Clustering not yet run.")

        self.commit()
Пример #3
0
 def test_with_different_values(self, array):
     x = array([0, 1, 0, 0, 2])
     y = array([0, 3, 0, 0, 2])
     self.assertFalse(array_equal(x, y))
Пример #4
0
 def test_with_different_shapes(self, array):
     x = array(np.eye(4))
     y = array(np.eye(5))
     self.assertFalse(array_equal(x, y))
Пример #5
0
 def test_same_matrices(self, array):
     x = array([0, 1, 0, 0, 2])
     self.assertTrue(array_equal(x, x))
Пример #6
0
 def test_with_different_values(self, array):
     x = array([0, 1, 0, 0, 2])
     y = array([0, 3, 0, 0, 2])
     self.assertFalse(array_equal(x, y))
Пример #7
0
 def test_with_different_shapes(self, array):
     x = array(np.eye(4))
     y = array(np.eye(5))
     self.assertFalse(array_equal(x, y))
Пример #8
0
 def test_same_matrices(self, array):
     x = array([0, 1, 0, 0, 2])
     self.assertTrue(array_equal(x, x))