Ask Your Question
2

What is the usage of CV_DTREE_CAT_DIR?

asked 2012-07-16 08:31:51 -0600

Niu ZhiHeng gravatar image

What is the usage of CV_DTREE_CAT_DIR when categorical variables are used?

I do not understand the meaning of the micro defined below:

#define CV_DTREE_CAT_DIR(idx,subset) \
(2*((subset[(idx)>>5]&(1 << ((idx) & 31)))==0)-1)

Please help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2012-07-17 00:31:12 -0600

Maria Dimashova gravatar image

Hi! One day I caught this. It's easy :)

In case of a categorical variable a tree split is a bitmap "subset". This mask determines which category of a split variable (ie which samples) has to go to the left child node (the direction -1) and to the right one (the direction +1). The macro is used to compute the direction for a given category of variable.

In the implementation the bitmap "subset" is an array of 'int'. "idx" is a given category.

(idx)>>5 - it's equivalent to division by sizeof(int), ie we find the index of element of the array "subset" that contains a bit for the given category;

(idx) & 31) - it's the remainder of dividing by sizeof(int). Here we find the index of a category bit in the array element.

1 << ((idx) & 31) - it gives a map filled with zeros and having one "1" in the required position.

(subset[(idx)>>5]&(1 << ((idx) & 31)))==0 - here we check the bit value for the given category.

(2*((subset[(idx)>>5]&(1 << ((idx) & 31)))==0)-1) - if the value is 0 we get direction -1, otherwise +1.

edit flag offensive delete link more

Comments

"It is easy"... after it is explained so clearly by Maria :)

Rui Marques gravatar imageRui Marques ( 2012-07-18 04:45:50 -0600 )edit

Question Tools

Stats

Asked: 2012-07-16 08:31:51 -0600

Seen: 567 times

Last updated: Jul 17 '12