def test_array_not_equal(self, array): a1 = array([[0., 2.], [3., np.nan]]) a2 = array([[0., 2.], [4., np.nan]]) self.assertFalse(array_equal(a1, a2)) a3 = array([[0., 2.], [3., np.nan], [4., 5.]]) self.assertFalse(array_equal(a1, a3))
def test_csc_scr_equal(self): a1 = sp.csc_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3)) a2 = sp.csr_matrix(([5, 1, 4], ([1, 0, 0], [2, 0, 2])), shape=(2, 3)) self.assertTrue(array_equal(a1, a2)) a1 = sp.csc_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3)) a2 = sp.csr_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3)) self.assertTrue(array_equal(a1, a2))
def test_array_equal(self, array): a1 = array([[0., 2.], [3., np.nan]]) a2 = array([[0., 2.], [3., np.nan]]) self.assertTrue(array_equal(a1, a2)) a3 = np.array([[0., 2.], [3., np.nan]]) self.assertTrue(array_equal(a1, a3)) self.assertTrue(array_equal(a3, a1))
def set_data(self, data): self.data, old_data = data, self.data # Do not needlessly recluster the data if X hasn't changed if old_data and self.data and array_equal(self.data.X, old_data.X): if self.auto_commit: self.send_data() else: self.invalidate()
def _initialize(self): matrix_existed = self.effective_matrix is not None effective_matrix = self.effective_matrix self._invalidated = True self.data = None self.effective_matrix = None self.closeContext() self.clear_messages() # if no data nor matrix is present reset plot if self.signal_data is None and self.matrix is None: self.clear() self.init_attr_values() return if self.signal_data is not None and self.matrix is not None and \ len(self.signal_data) != len(self.matrix): self.Error.mismatching_dimensions() self.clear() self.init_attr_values() return if self.signal_data is not None: self.data = self.signal_data elif self.matrix_data is not None: self.data = self.matrix_data if self.matrix is not None: self.effective_matrix = self.matrix if self.matrix.axis == 0 and self.data is not None \ and self.data is self.matrix_data: names = [[attr.name] for attr in self.data.domain.attributes] domain = Domain([], metas=[StringVariable("labels")]) self.data = Table(domain, names) elif self.data.domain.attributes: preprocessed_data = MDS().preprocess(self.data) self.effective_matrix = Euclidean(preprocessed_data) else: self.Error.no_attributes() self.clear() self.init_attr_values() return self.init_attr_values() self.openContext(self.data) self._invalidated = not (matrix_existed and self.effective_matrix is not None and array_equal(effective_matrix, self.effective_matrix)) if self._invalidated: self.clear() self.graph.set_effective_matrix(self.effective_matrix)
def _initialize(self): matrix_existed = self.effective_matrix is not None effective_matrix = self.effective_matrix self._invalidated = True self.data = None self.effective_matrix = None self.closeContext() self.clear_messages() # if no data nor matrix is present reset plot if self.signal_data is None and self.matrix is None: self.clear() self.init_attr_values() return if self.signal_data is not None and self.matrix is not None and \ len(self.signal_data) != len(self.matrix): self.Error.mismatching_dimensions() self.clear() self.init_attr_values() return if self.signal_data is not None: self.data = self.signal_data elif self.matrix_data is not None: self.data = self.matrix_data if self.matrix is not None: self.effective_matrix = self.matrix if self.matrix.axis == 0 and self.data is not None \ and self.data is self.matrix_data: names = [[attr.name] for attr in self.data.domain.attributes] domain = Domain([], metas=[StringVariable("labels")]) self.data = Table.from_list(domain, names) elif self.data.domain.attributes: preprocessed_data = MDS().preprocess(self.data) self.effective_matrix = Euclidean(preprocessed_data) else: self.Error.no_attributes() self.clear() self.init_attr_values() return self.init_attr_values() self.openContext(self.data) self._invalidated = not ( matrix_existed and self.effective_matrix is not None and array_equal(effective_matrix, self.effective_matrix)) if self._invalidated: self.clear() self.graph.set_effective_matrix(self.effective_matrix)
def set_data(self, data): attr_x, attr_y = self.attr_x, self.attr_y data_existed = self.reference_data is not None effective_data = self.effective_data if data_existed else None super().set_data(data) self.reference_data = self.data if not (data_existed and self.reference_data is not None and array_equal(effective_data.X, self.effective_data.X)): self.clear() self.__invalidate_scores() self.__invalidate_clusters() elif attr_x is not self.attr_x or attr_y is not self.attr_y: self.clear() self.__invalidate_clusters()
def set_data(self, data): self.data, old_data = data, self.data self.selection = None self._set_input_summary() self.controls.normalize.setDisabled( bool(self.data) and sp.issparse(self.data.X)) # Do not needlessly recluster the data if X hasn't changed if old_data and self.data and array_equal(self.data.X, old_data.X): if self.auto_commit: self.send_data() else: self.invalidate(unconditional=True)
def set_data(self, data): data_existed = self.data is not None effective_data = self.effective_data if data_existed else None same_domain = (data_existed and data is not None and data.domain.checksum() == self.data.domain.checksum()) self.closeContext() self.data = data self.check_data() if not same_domain: self.init_attr_values() self.openContext(self.data) self._invalidated = not ( data_existed and self.data is not None and array_equal(effective_data.X, self.effective_data.X)) if self._invalidated: self.clear() self.enable_controls()
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 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()
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 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()
def set_data(self, data): data_existed = self.data is not None effective_data = self.effective_data if data_existed else None self.closeContext() self.data = data self.agg_func = DEFAULT_AGG_FUNC self.Warning.no_region.clear() self.Warning.no_lat_lon_vars.clear() self.init_attr_values() self.openContext(self.data) if not (data_existed and self.data is not None and array_equal(effective_data.X, self.effective_data.X)): self.clear(cache=True) self.input_changed.emit(data) self.setup_plot() self.update_agg() self.apply_selection() self.unconditional_commit()
def test_csc_unordered_array_equal(self): a1 = sp.csc_matrix(([1, 4, 5], [0, 0, 1], [0, 1, 1, 3]), shape=(2, 3)) a2 = sp.csc_matrix(([1, 5, 4], [0, 1, 0], [0, 1, 1, 3]), shape=(2, 3)) self.assertTrue(array_equal(a1, a2))
def test_csc_array_equal(self): a1 = sp.csc_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3)) a2 = sp.csc_matrix(([5, 1, 4], ([1, 0, 0], [2, 0, 2])), shape=(2, 3)) a2[0, 1] = 0 # explicitly setting to 0 self.assertTrue(array_equal(a1, a2))
def set_data(self, data): def prepare_data(): if len(cont_attrs) < len(attrs): self.Warning.ignoring_disc_variables() if len(cont_attrs) == 1: self.Warning.single_attribute() x = Table.from_table(Domain(cont_attrs), data).X if sp.issparse(x): self.data = data self.cont_x = x.tocsr() else: mask = np.all(np.isfinite(x), axis=1) if not np.any(mask): self.Error.no_defined_rows() else: if np.all(mask): self.data = data self.cont_x = x.copy() else: self.data = data[mask] self.cont_x = x[mask] self.cont_x -= np.min(self.cont_x, axis=0)[None, :] sums = np.sum(self.cont_x, axis=0)[None, :] sums[sums == 0] = 1 self.cont_x /= sums def set_warnings(): missing = len(data) - len(self.data) if missing == 1: self.Warning.missing_values(1, "", "is") elif missing > 1: self.Warning.missing_values(missing, "s", "are") cont_x = self.cont_x.copy() if self.cont_x is not None else None self.data = self.cont_x = None self.closeContext() self.clear_messages() if data is not None: attrs = data.domain.attributes cont_attrs = [var for var in attrs if var.is_continuous] if not cont_attrs: self.Error.no_numeric_variables() else: prepare_data() invalidated = cont_x is None or self.cont_x is None \ or not array_equal(cont_x, self.cont_x) if invalidated: self.stop_optimization_and_wait() self.clear() if self.data is not None: self.controls.attr_color.model().set_domain(data.domain) self.attr_color = data.domain.class_var set_warnings() self.openContext(self.data) self.set_color_bins() self.create_legend() if invalidated: self.recompute_dimensions() self.start_som() else: self._redraw()