• Aucun résultat trouvé

Unweighted Sampling for Binary Trees

Dans le document Get a Sample for a Discount (Page 27-40)

Unweighted Sampling for Binary Trees

I We first present a sampling algorithm for binary trees and extend the algorithm to any unranked trees.

I First phase: Subtree Counting. We start by computing a matrix Dsuch that, for every node ni of the input tree tand any value 0≤k≤size(t),Di[k]is the number of subtrees of sizek rooted at nodeni.

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I We first present a sampling algorithm for binary trees and extend the algorithm to any unranked trees.

I First phase: Subtree Counting. We start by computing a matrix Dsuch that, for every node ni of the input tree tand any value 0≤k≤size(t),Di[k]is the number of subtrees of sizek rooted at nodeni.

10 / 25

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I

I For leaf nodes, there is one rooted subtree of 

size 1 and one rooted subtree of size 0, 

therefore  1,1

1,2,1 therefore  1,1,2,1

1,2,3,3,1 therefore  1,1,2,3,3,1

1,2,3,5,6,4,1 therefore  1,1,2,3,5,6,4,1

I

size=0 size=1 size=1

size=3

size=1 size=0 size=1

size=2

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I

I For leaf nodes, there is one rooted subtree of 

size 1 and one rooted subtree of size 0, 

therefore  1,1

1,2,1 therefore  1,1,2,1

1,2,3,3,1 therefore  1,1,2,3,3,1

1,2,3,5,6,4,1 therefore  1,1,2,3,5,6,4,1

I

size=0 size=1 size=1

size=3

size=1 size=0 size=1

size=2

11 / 25

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I

I For leaf nodes, there is one rooted subtree of 

size 1 and one rooted subtree of size 0, 

therefore  1,1

1,2,1 therefore  1,1,2,1

1,2,3,3,1 therefore  1,1,2,3,3,1

1,2,3,5,6,4,1 therefore  1,1,2,3,5,6,4,1

I

size=0,  empty tree

size=0 size=0 size=1

size=0 size=1 size=1

size=3

size=1 size=0 size=1

size=2

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I Second phase: Uniform Sampling. We sample a rooted subtree from t in a recursive top-down manner, based on the matrix Dcomputed.

I The basic idea is that to sample a rooted subtree at node ni, we decide on the size of the subtrees rooted at each child node, biased by the number of outcomes as counted inD, and then sample rooted subtrees of the desired sizes recursively.

12 / 25

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted  subtree of size 3. From  , we know  that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case. (2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability  .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

I

1,1 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted subtree of size 3. From  , we know that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case. (2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted  subtree of size 3. From  , we know  that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability  .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

I

1,1 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted subtree of size 3. From  , we know that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case. (2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted  subtree of size 3. From  , we know  that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability  . Assume we sample the second case. Then we need to sample a rooted  I

1,1 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted subtree of size 3. From  , we know that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability .

I

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted  subtree of size 3. From  , we know  that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability  .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

I

1,1 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted subtree of size 3. From  , we know that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability .

Assume we sample the second case. Then we need to sample a rooted  submtree at  of size 0 and sample a rooted subtree at  of size 2. We  recursively operates the above process.

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted  subtree of size 3. From  , we know  that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability  . Assume we sample the second case. Then we need to sample a rooted  I

1,1 1,1,2,1 , 1,1,2,3,3,1

1,1,2,3,5,6,4,1

Assume we want to sample a rooted subtree of size 3. From  , we know that there are 3 such rooted subtrees.

must be included in the sample. We have to sample 2  rooted subtrees at  , respectively whose sizes sum up to 2.

Only 2 possibilities: 

(1) a rooted subtree at  of size 1 and a rooted subtree at  of size 1. There is  1 1 1such case.

(2) a rooted subtree at  of size 0 and a rooted subtree at  of size 2. There are  0 2 2such case.

We sample the first case with probability  and the second case with probability .

I

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I Complexity of Phase 1 (the size of tis n) is O(n3).

I EachDi has size at mostn. Therefore computing the convolution sum of two suchDi’s is in O(n2).

I We need to compute at mostnconvolution sums. Therefore the overall complexity isO(n3).

I Complexity of Phase 2 (the size of tis n) is O(n2).

I At each nodeni, the number of possibilities to consider is O(n), since ni has at most two children.

I There arennodes, hence the overall complexity isO(n2).

14 / 25

Get a Sample for a Discount Algorithms for Tractable Sampling

Unweighted Sampling for Binary Trees

Unweighted Sampling for Binary Trees

I Complexity of Phase 1 (the size of tis n) is O(n3).

I EachDi has size at mostn. Therefore computing the convolution sum of two suchDi’s is in O(n2).

I We need to compute at mostnconvolution sums. Therefore the overall complexity isO(n3).

I Complexity of Phase 2 (the size of tis n) is O(n2).

I At each nodeni, the number of possibilities to consider is O(n), since ni has at most two children.

I There arennodes, hence the overall complexity isO(n2).

Get a Sample for a Discount Algorithms for Tractable Sampling

Dans le document Get a Sample for a Discount (Page 27-40)

Documents relatifs