Ejemplo n.º 1
0
    def _join_array_by_indices(left, right, lefti, righti, string_cols=None):
        """Join (horizontally) two arrays, taking pairs of rows given in indices
        """
        def prepare(arr, inds, str_cols):
            try:
                newarr = arr[inds]
            except IndexError:
                newarr = np.full_like(arr, np.nan)
            else:
                empty = np.full(arr.shape[1], np.nan)
                if str_cols:
                    assert arr.dtype == object
                    empty = empty.astype(object)
                    empty[str_cols] = ''
                newarr[inds == -1] = empty
            return newarr

        left_width = left.shape[1]
        str_left = [i for i in string_cols or () if i < left_width]
        str_right = [
            i - left_width for i in string_cols or () if i >= left_width
        ]
        res = hstack((prepare(left, lefti,
                              str_left), prepare(right, righti, str_right)))
        return res
Ejemplo n.º 2
0
    def _setup_plot(self, new=False):
        emb_x, emb_y = self.embedding[:, 0], self.embedding[:, 1]
        coords = np.vstack((emb_x, emb_y)).T

        data = self.data

        primitive_metas = tuple(a for a in data.domain.metas
                                if a.is_primitive())
        keys = [k for k, a in enumerate(data.domain.metas) if a.is_primitive()]
        data_metas = data.metas[:, keys].astype(float)

        attributes = self.data.domain.attributes + (self.variable_x, self.variable_y) + \
                     primitive_metas
        domain = Domain(attributes=attributes,
                        class_vars=self.data.domain.class_vars)
        if data_metas is not None:
            data_x = (self.data.X, coords, data_metas)
        else:
            data_x = (self.data.X, coords)
        data = Table.from_numpy(domain, X=hstack(data_x), Y=self.data.Y)
        subset_data = data[
            self._subset_mask] if self._subset_mask is not None else None
        self.graph.new_data(data, subset_data=subset_data, new=new)
        self.graph.update_data(self.variable_x, self.variable_y, True)
        self.connect_pairs()
Ejemplo n.º 3
0
    def test_hstack(self):
        numpy = np.array([[1., 2.], [3., 4.]])
        csr = sp.csr_matrix(numpy)
        csc = sp.csc_matrix(numpy)

        self.assertCorrectArrayType(hstack([numpy, numpy]),
                                    shape=(2, 4),
                                    sparsity="dense")
        self.assertCorrectArrayType(hstack([csr, numpy]),
                                    shape=(2, 4),
                                    sparsity="sparse")
        self.assertCorrectArrayType(hstack([numpy, csc]),
                                    shape=(2, 4),
                                    sparsity="sparse")
        self.assertCorrectArrayType(hstack([csc, csr]),
                                    shape=(2, 4),
                                    sparsity="sparse")
Ejemplo n.º 4
0
    def test_hstack(self):
        numpy = np.array([[1., 2.], [3., 4.]])
        csr = sp.csr_matrix(numpy)
        csc = sp.csc_matrix(numpy)

        self.assertCorrectArrayType(
            hstack([numpy, numpy]),
            shape=(2, 4), sparsity="dense")
        self.assertCorrectArrayType(
            hstack([csr, numpy]),
            shape=(2, 4), sparsity="sparse")
        self.assertCorrectArrayType(
            hstack([numpy, csc]),
            shape=(2, 4), sparsity="sparse")
        self.assertCorrectArrayType(
            hstack([csc, csr]),
            shape=(2, 4), sparsity="sparse")
Ejemplo n.º 5
0
    def construct_output_data_table(embedded_images, embeddings):
        if sparse.issparse(embedded_images.X):
            X = util.hstack((embedded_images.X, embeddings))
        else:
            X = util.hstack((embedded_images.X, embeddings))
        Y = embedded_images.Y

        attributes = [
            ContinuousVariable.make('n{:d}'.format(d))
            for d in range(embeddings.shape[1])
        ]
        attributes = list(embedded_images.domain.attributes) + attributes

        domain = Domain(attributes=attributes,
                        class_vars=embedded_images.domain.class_vars,
                        metas=embedded_images.domain.metas)

        return Table(domain, X, Y, embedded_images.metas)
Ejemplo n.º 6
0
    def _setup_plot(self, new=False):
        emb_x, emb_y = self.embedding[:, 0], self.embedding[:, 1]
        coords = np.vstack((emb_x, emb_y)).T

        data = self.data
        attributes = data.domain.attributes + (self.variable_x, self.variable_y)
        domain = Domain(attributes=attributes,
                        class_vars=data.domain.class_vars,
                        metas=data.domain.metas)
        data = Table.from_numpy(domain, X=hstack((data.X, coords)),
                                Y=data.Y, metas=data.metas)
        subset_data = data[self._subset_mask] if self._subset_mask is not None else None
        self.graph.new_data(data, subset_data=subset_data, new=new)
        self.graph.update_data(self.variable_x, self.variable_y, True)
        self.connect_pairs()
Ejemplo n.º 7
0
    def _setup_plot(self, new=False):
        emb_x, emb_y = self.embedding[:, 0], self.embedding[:, 1]
        coords = np.vstack((emb_x, emb_y)).T

        data = self.data
        attributes = data.domain.attributes + (self.variable_x, self.variable_y)
        domain = Domain(attributes=attributes,
                        class_vars=data.domain.class_vars,
                        metas=data.domain.metas)
        data = Table.from_numpy(domain, X=hstack((data.X, coords)),
                                Y=data.Y, metas=data.metas)
        subset_data = data[self._subset_mask] if self._subset_mask is not None else None
        self.graph.new_data(data, subset_data=subset_data, new=new)
        self.graph.update_data(self.variable_x, self.variable_y, True)
        self.connect_pairs()
Ejemplo n.º 8
0
    def _join_array_by_indices(left, right, indices, string_cols=None):
        """Join (horizontally) two arrays, taking pairs of rows given in indices
        """
        def prepare(arr, inds, str_cols):
            try:
                newarr = arr[inds]
            except IndexError:
                newarr = np.full_like(arr, np.nan)
            else:
                empty = np.full(arr.shape[1], np.nan)
                if str_cols:
                    assert arr.dtype == object
                    empty = empty.astype(object)
                    empty[str_cols] = ''
                newarr[inds == -1] = empty
            return newarr

        left_width = left.shape[1]
        str_left = [i for i in string_cols or () if i < left_width]
        str_right = [i - left_width for i in string_cols or () if i >= left_width]
        res = hstack((prepare(left, indices[0], str_left),
                      prepare(right, indices[1], str_right)))
        return res