def set_indices(self,indices):
        # need to perform check before base class updated self.indices
        # if (self.compute_moment_matrix_function is not None and
        #         (self.indices is None or
        #              self.indices.shape[1]!=indices.shape[1] or
        #         not np.allclose(indices,self.indices))):
        #     update_rotation=True
        # else:
        #     update_rotation=False

        # TODO eventually use following. need to distinguish between
        # indices for pce and indices used for computing basis rotation


        update_indices=False
        if self.indices is None:
            update_indices=True
        else:
            # check indices is subset of self.indices
            if indices.shape[1]>self.indices.shape[1]:
                update_indices=True
            else:
                # check indices is subset of self.indices
                update_indices=set_difference(
                    self.indices,indices).shape[1]!=0


        if update_indices:
            super(APC,self).set_indices(indices)
            if (self.compute_moment_matrix_function is not None or 
                self.moments is not None or
                self.compute_grammian_function is not None):
                self.compute_rotation()
Пример #2
0
    def test_set_difference_2d_array(self):
        num_vars = 2
        level1 = 1
        p = 1.0
        indices1 = compute_hyperbolic_indices(num_vars, level1, p)

        level2 = 2
        indices2 = compute_hyperbolic_indices(num_vars, level2, p)

        indices = set_difference(indices1, indices2)

        true_indices = np.asarray([[2, 0], [0, 2], [1, 1]]).T
        assert np.allclose(indices, true_indices)
Пример #3
0
 def test_set_difference_1d_array(self):
     indices1 = np.arange(0, 10, 2)
     indices2 = np.arange(10)
     indices = set_difference(indices1, indices2)
     true_indices = np.arange(1, 10, 2)
     assert np.allclose(indices, true_indices)