def check_tree(self, settings, data):
        """
        check if tree violates any sanity check
        """
        if settings.debug:
            #print '\nchecking tree'
            print '\nchecking tree: printing tree first'
            self.print_tree(settings)
        for node_id in self.non_leaf_nodes:
            assert node_id.left.parent == node_id.right.parent == node_id
            assert not node_id.is_leaf
            if settings.optype == 'class':
                assert np.count_nonzero(self.counts[node_id]) > 1
            assert not self.pause_mondrian(node_id, settings)
            if node_id != self.root:
                assert np.all(node_id.min_d >= node_id.parent.min_d)
                assert np.all(node_id.max_d <= node_id.parent.max_d)
            if settings.optype == 'class':
                try:
                    check_if_zero(np.sum(np.abs(self.counts[node_id] - \
                            self.counts[node_id.left] - self.counts[node_id.right])))
                except __HOLE__:
                    print 'counts: node = %s, left = %s, right = %s' \
                            % (self.counts[node_id], self.counts[node_id.left], self.counts[node_id.right])
                    raise AssertionError
            if settings.budget == -1:
                assert math.isinf(node_id.budget)
            check_if_zero(self.split_times[node_id] - self.get_parent_split_time(node_id, settings) \
                    - self.max_split_costs[node_id])
        if settings.optype == 'class':
            num_data_points = 0
        for node_id in self.leaf_nodes:
            assert node_id.is_leaf
            assert math.isinf(self.max_split_costs[node_id])
            if settings.budget == -1:
                assert math.isinf(node_id.budget)
            if settings.optype == 'class':
                num_data_points += self.counts[node_id].sum()
                assert np.count_nonzero(self.counts[node_id]) == 1
                assert self.pause_mondrian(node_id, settings)
            if node_id != self.root:
                assert np.all(node_id.min_d >= node_id.parent.min_d)
                assert np.all(node_id.max_d <= node_id.parent.max_d)
        if settings.optype == 'class':
            print 'num_train = %s, number of data points at leaf nodes = %s' % \
                    (data['n_train'], num_data_points)
        set_non_leaf = set(self.non_leaf_nodes)
        set_leaf = set(self.leaf_nodes)
        assert (set_leaf & set_non_leaf) == set([])
        assert set_non_leaf == set(self.node_info.keys())
        assert len(set_leaf) == len(self.leaf_nodes)
        assert len(set_non_leaf) == len(self.non_leaf_nodes)
dataset/ETHPy150Open balajiln/mondrianforest/src/mondrianforest.py/MondrianTree.check_tree