27
1 CS5314 Randomized Algorithms Lecture 21: Markov Chains (Definitions, Solving 2SAT)

CS5314 Randomized Algorithms - NTHUCS

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS5314 Randomized Algorithms - NTHUCS

1

CS5314Randomized Algorithms

Lecture 21: Markov Chains(Definitions, Solving 2SAT)

Page 2: CS5314 Randomized Algorithms - NTHUCS

2

•Introduce Markov Chains–powerful model for special random processes

•Analyze a simple randomized algorithmsfor 2SAT and 3SAT problems

Objectives

Page 3: CS5314 Randomized Algorithms - NTHUCS

3

Definition: A collection of random variablesX = { Xt | t T } is called a stochasticprocess. The index t often representstime; Xt is called the state of X at time t

E.g., A gambler is playing a fair coin-flipgame: wins $1 if head, loses $1 if tail

Let X0 = a gambler’s initial moneyXt = a gambler’s money after t flips

{ Xt| t{0,1,2,…} } is a stochastic process

Stochastic Process

Page 4: CS5314 Randomized Algorithms - NTHUCS

4

Definition: If Xt assumes values from afinite set, then the process is afinite stochastic process

Definition: If T (where the index t is chosen) iscountably infinite, the process isa discrete time process

Question: In the previous example about agambler’s money, is the process finite?Is the process discrete time?

Stochastic Process (2)

Page 5: CS5314 Randomized Algorithms - NTHUCS

5

Markov Chain (Definition)

Definition: A discrete time stochasticprocess X = {X0, X1, X2, …} is a Markovchain if

Pr(Xt = a | Xt-1 = b, Xt-2 = at-2, …, X0 = a0)= Pr(Xt = a | Xt-1 = b) = Pb, a

That is, the value of Xt depends on the value of Xt-1, but notthe history how we arrived at Xt-1 with that value

Question: In the example about a gambler’smoney, is the process a Markov chain?

Page 6: CS5314 Randomized Algorithms - NTHUCS

6

In other words, if X is a Markov chain, thenPr(X1 = a | X0 = b) = Pb, a

Pr(X2 = a | X1 = b) = Pb, a

… Pb, a

= Pr(X1 = a | X0 = b)= Pr(X2 = a | X1 = b)= Pr(X3 = a | X2 = b) = …

Markov Chain (2)

Page 7: CS5314 Randomized Algorithms - NTHUCS

7

• Next, we focus our study on Markovchain whose state space (the set ofvalues that Xt can take) is finite

• So, without loss of generality, we labelthe states in the state space by 0,1,2,…,n

• The probability Pi,j = Pr(Xt = j | Xt-1 = i) isthe probability that the process movesfrom state i to state j in one step

Markov Chain (3)

Page 8: CS5314 Randomized Algorithms - NTHUCS

8

• The definition of Markov chain impliesthat we can define it using a one-steptransition matrix P with

Pi,j = Pr(Xt = j | Xt-1 = i)

Question: For a particular i, what is j Pi,j ?

Transition Matrix

Page 9: CS5314 Randomized Algorithms - NTHUCS

9

• The transition matrix representation ofa Markov chain is very convenient forcomputing the distribution of futurestates of the process

• Let pi(t) denote the probability that theprocess is at state i at time t

Question: Can we compute pi(t) from thetransition matrix P, assuming we knowp0(t-1), p1(t-1), …?

Transition Matrix (2)

Page 10: CS5314 Randomized Algorithms - NTHUCS

10

The value of pi(t) can be expressed as:

p0(t-1) P0,i + p1(t-1) P1,i + …+ pn(t-1) Pn,i

In other words, let p(t)denote the vector

(p0(t), p1(t), …pn(t))

Then, we havep(t)= p(t-1)P

Transition Matrix (3)

Page 11: CS5314 Randomized Algorithms - NTHUCS

11

• For any m, we define the m-steptransition matrix P(m) such that

P(m)i,j = Pr(Xt+m = j | Xt = i),

which is the probability that we movefrom state i to state j in exactly m steps

• It is easy to check that P(2) = P2,P(3) = P . P(2) = P3, and in general, P(m) = Pm

p(t+m)= p(t)Pm

Transition Matrix (4)

Page 12: CS5314 Randomized Algorithms - NTHUCS

12

• Markov chain can also be expressed by adirected weighted graph (V,E), such thatV = state spaceE = transition between statesweight of edge (i,j) = Pi,j

Directed Graph Representation

01

2

0.3

0.7

1

0.4

0.50.1

Page 13: CS5314 Randomized Algorithms - NTHUCS

13

• Given a Boolean formula F, with eachclause consisting exactly 2 literals. Ourtask is to determine if F has satisfiable Can be solved in linear time ! (how??)

• Let n = # variables in F• In the next slide, we describe a

randomized algorithm for solving thisproblem, which is not efficient…– However, we can modify the algorithm a bit

to solve the case when each clause has 3literals instead (3SAT is NP-complete !)

Application: Solving 2SAT

Page 14: CS5314 Randomized Algorithms - NTHUCS

14

1. Start with an arbitrary assignment2. Repeat 2cn2 times, terminating with all

clauses satisfied(a) Choose a clause that is currently not

satisfied(b) Choose uniformly at random one of

the literals in the clause and switchits value

3. If valid assignment found, return it4. Else, conclude that F is not satisfiable

Page 15: CS5314 Randomized Algorithms - NTHUCS

15

Questions:(1) When will the algorithm make a wrong

conclusion?Ans. …only when the formula is satisfiable,

but the algorithm fails to find asatisfying assignment

(2) What is the success probability?Ans. …let’s study it using Markov chain ^_^

Application: Solving 2SAT (3)

Page 16: CS5314 Randomized Algorithms - NTHUCS

16

• Firstly, suppose that the formula F issatisfiable (for the other case, we don’t care muchsince the algorithm must give correct answer)

That means, a particular assignment tothe n variables in F can make F true

• Let A* = this particular assignment• Also, let At = the assignment of variables

after the tth iteration of Step 2• Let Xt = the number of variables that are

assigned the same value in A* and At

Application: Solving 2SAT (4)

Page 17: CS5314 Randomized Algorithms - NTHUCS

17

E.g., suppose thatF = (x1_:x2) ^ (x2_ x3) ^ (:x1_:x3)

and A*: x1 = T, x2 = T, x3 = F• Also, suppose that after 4 iterations of

Step 2 in the algorithm, we haveA4: x1 = F, x2 = T, x3 = F

X4 = # variables that are assignedthe same value in A* and A4

= 2

Application: Solving 2SAT (5)

Page 18: CS5314 Randomized Algorithms - NTHUCS

18

• So, when Xt = n, the algorithm terminateswith a satisfying assignment…in fact, the algorithm may terminate before Xtreaches n, as it is possible that we find anothersatisfying assignment…but for our analysis, we are very pessimistic, and weconsider the algorithm only stops when Xt = n

• Let us take a closer look of how Xtchanges over time, so that we can tellhow long it takes for Xt to reach n

Application: Solving 2SAT (6)

Page 19: CS5314 Randomized Algorithms - NTHUCS

19

• First, when Xt = 0, any change in thecurrent assignment At must increase the# of matching assignment with A* by 1.So,

Pr(Xt+1 = 1 | Xt = 0) = 1

• When Xt = j, with 1 j n-1, we willchoose a clause that is false with thecurrent assignment At, and change theassignment of one of its variable next …

Application: Solving 2SAT (7)

Page 20: CS5314 Randomized Algorithms - NTHUCS

20

Question: What can be the value of Xt+1?Ans. …it can either be j-1 or j+1

Question: Which is more likely to be Xt+1?Ans. …j+1. It is because the assignment A*

will make this clause true, which mustmean that either one, or both thevariables in this clause is assigneddifferently in At If we change onevariable randomly, at least 1/2 of thetime At+1 will match more with A*

Application: Solving 2SAT (8)

Page 21: CS5314 Randomized Algorithms - NTHUCS

21

• So, for j, with 1 j n-1 we have

Pr(Xt+1 = j+1 | Xt = j) ¸ 1/2Pr(Xt+1 = j-1 | Xt = j) · 1/2

• Note: the stochastic process X0, X1, X2, …is not necessarily a Markov chain…– Reason : the transition probabilities, e.g.,

Pr(Xt+1 = j+1 | Xt = j), is not a constant(sometimes, it can be 1, sometimes, it can be 1/2 …

in fact, this value depends on which j variables arematching with A*, which in fact depends on thehistory of how we obtain At)

Application: Solving 2SAT (9)

Page 22: CS5314 Randomized Algorithms - NTHUCS

22

• To simplify the analysis, we invent a trueMarkov chain Y0, Y1, Y2, …as follows:

Y0 = X0

Pr(Yt+1 = 1 | Yt = 0) = 1Pr(Yt+1 = j+1 | Yt = j) = 1/2Pr(Yt+1 = j-1 | Yt = j) = 1/2

• When compared with the stochasticprocess X0, X1, X2, …, it takes more timefor Yt to increase to n …(why??)

Application: Solving 2SAT (10)

Page 23: CS5314 Randomized Algorithms - NTHUCS

23

• Thus, the expected time to reach n fromany point is larger for Markov chain Ythan for the stochastic process X

So, we haveE[ time for X to reach n starting at X0]· E[ time for Y to reach n starting at Y0]

Question: Can we upper bound the termE[time for Y to reach n starting at Y0]?

Application: Solving 2SAT (11)

Page 24: CS5314 Randomized Algorithms - NTHUCS

24

Let us take a look of how the Markov chainY looks like in the graph representation

• Recall that vertices represents the statespace, which are the values that any Ytcan take on:

Application: Solving 2SAT (12)

2 n-1 n30 1 …

1

0.5 0.5

0.5

0.5

0.5

1

0.5

Page 25: CS5314 Randomized Algorithms - NTHUCS

25

Let hj = E[time to reach n starting at state j]

Clearly,hn = 0 and h0 = h1 + 1

Also, for other values of j, we have

hj = ½(hj-1 + 1) + ½(hj+1 + 1)

By induction, we can show that for all j,hj = n2 –j2· n2

Application: Solving 2SAT (13)

Page 26: CS5314 Randomized Algorithms - NTHUCS

26

• Combining with previous argument :E[ time for X to reach n starting at X0]· E[time for Y to reach n starting at Y0]

· n2, which gives the following lemma:

Application: Solving 2SAT (13)

Lemma: Assume that F has a satisfyingassignment. Then, if the algorithm isallowed to run until it finds a satisfyingassignment, the expected number ofiterations is at most n2

Page 27: CS5314 Randomized Algorithms - NTHUCS

27

• Since the algorithm runs for 2cn2

iterations, we can show the following:

Application: Solving 2SAT (13)

Theorem: The 2SAT algorithm answerscorrectly if the formula is unsatisfiable.Otherwise, with probability 1 –1/2c,it returns a satisfying assignment

How to prove?(Hint: Break down the 2cn2 iterations into c groups, and

apply Markov inequality)