online algorithms and competitive analysis. paging algorithms data brought from slower memory into...

59
Online Algorithms and Competitive Analysis

Upload: benedict-jennings

Post on 30-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Online Algorithms and Competitive Analysis

Page 2: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Paging Algorithms

• Data brought from slower memory into cache

RAM

CPU

Page 3: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Paging Algorithms

• Data brought from slow memory into small fast memory (cache) of size k

• Sequence of requests: equal size pages

• Hit: page in cache, • Fault: page not in cache

Page 4: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Minimizing Paging Faults

• On a fault evict a page from cache

• Paging algorithm ≡ Eviction policy

• Goal: minimize the number of page faults

Page 5: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Worst case

• In the worst case page, the number of page faults on n requests is n.

E.g. cache of size 4, request sequence

p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12

Page 6: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Difficult sequences

Cache of size 4, request sequence p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12

Sequence is difficult, for one it never repeats pages so it is impossible to have a page hit

Page 7: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Compare to optimal

p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13

… is hard for everyone (i.e. 13 faults)

p1 p2 p3 p4 p5 p1 p2 p3 p4 p5 p1 p2 p3 p4 … 8 faults

Optimal algorithm knows the future

Page 8: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Offline optimum

Optimal algorithm knows the future, i.e. offline OPT.

Compare online paging strategy to offline paging strategy

Page 9: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

cost of online algorithm on I cost of offline optimum on I

Competitive Ratio

supI

Page 10: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Paging• One of the earliest problems to be

studied under the online model• Competitive ratio defined by Sleator

and Tarjan

Page 11: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Competitive Ratio

• First appeared in the 1960’s in search context, e.g. – On the linear search problem (Beck, 1964)– More on the linear search problem (1965)– Yet more on the linear search problem (1970)– The return of the linear search problem (1972)– Son of the linear search problem (Beck & Beck 1984)– The linear search problem rides again (1986)– The revenge of the linear search problem (1992)

• Shmuel Gal – Search Games, Academic Press, 1980– The Theory of Search Games and Rendezvous (with Steve

Alpern), Kluwer Academic Press, 2002

Page 12: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Paging Algorithms • Least-Recently-Used (LRU)• First-In-First-Out (FIFO)• Flush-When-Full (FWF)

Classes of Paging algorithms• Lazy Algorithms: LRU and FIFO• Marking Algorithms: LRU and FWF

Page 13: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Paging

• Competitive analysis not always satisfactory, e.g. LRU “as good as” FWF

• Real life inputs well understood and characterized (temporal + spatial locality)

Goal: derive from first principles a new measure that better reflects observations in practice

Page 14: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Theory

1. Commonly studied under competitive ratio framework

2. Worst case analysis3. Marking algorithms

optimal4. In practice LRU is best5. LFD is offline optimal6. Competitive ratio is k 7. User is malicious

adversary8. No benefit from

lookahead

Systems

1. Commonly studied using fault rate measure

2. Typical case analysis3. LRU and friends is best4. LRU is impractical5. Huh?6. Competitive ratio is 2

or 37. User is your friend8. Lookahead helps

Page 15: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Fix the Theory-Practice disconnect

1. Make both columns matchHow?

• Fix reality

or

• Fix the model

A more realistic theoretical model is likely to lead to practical insights

Page 16: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Previous work1. Disconnect has been noted before.

2. Intense study of alternatives, viz.

1. Borodin and Ben David 2. Karlin et al. 3. Koutsoupias and Papadimitriou4. Denning5. Young 6. Albers et al.7. Boyar et al.8. Sleator and Tarjan + many others

Page 17: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Theory: competitive ratio of paging algorithms

• k for LRU, FIFO, and FWF• Thus LRU, FIFO, and FWF equally good• Lookahead does not helpPractice:

• LRU never encounters sequences with competitive ratio bigger than 4

• LRU better than FIFO and much better than FWF

• Lookahead helps

Page 18: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Previous work1. Partial separation :

• Access graph model. Borodin, Raghavan, Irani, Schieber [STOC ‘91]

• Diffuse adversary. Koutsopias and Papadimitrou [FOCS ‘94]

• Diffuse adversary. Young [SODA ‘98]• Accommodating ratio. Boyar, Larsen,

Nielsen [WADS ‘99] • Relative worst order ratio. Boyar,

Favrholdt, and Larsen [SODA ‘05]

Page 19: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Previous work• Concave Analysis. Albers, Favrholdt,

Gielet [STOC ‘02]

LRU ≠ certain marking algorithms

• Adequate Analysis. Pangiotou, Souza [STOC 06]

+ many others. See survey L-O, Dorrigiv [SIGACT News ’05]

None provide full separation between LRU and FIFO and/or FWF

Page 20: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Online motion planning

1. Commonly studied under competitive ratio framework

2. Worst case analysis3. Continuous curved motions4. Perfect scans 5. Flawless detection6. No error in motion7. Architects are your enemy

Robotics

1. Commonly studied using distance & scan cost

2. Typical case analysis3. Piecewise linear 4. Scanning error5. High detection error 6. Forward & rotational lag 7. Architects are your friend

Page 21: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

“Architects are your friend”

Most of the time, anyhow.

Page 22: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Alternatives• Turn ratio• Performance Ratio• Search Ratio• Home Ratio• Travel Cost• Average Ratio• Effective Ratio• Smooth Analysis• Concave Analysis• Bijective Analysis• Others

Page 23: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

maxp { length of search from s to p }

maxq { length of path from s to q }

Performance Ratio

• general idea: focus on distant targets searches, those should be efficient

• allows high inefficiency for target’s near-by

Page 24: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

length of search from s to target p shortest off-line search from s to p

Search Ratio

supp

• finer, fairer measure than competitive ratio

• many on-line “unsearchable” scenarios suddenly practicable, e.g. trees

Page 25: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Example:

Searching for a node at depth h in a complete binary tree with unit length edges

Competitive ratio = O(2h / h)

Search ratio = O(1)

Search Ratio

Page 26: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

length of search from s to target p shortest path from s to p

Home Ratio

supp

where the position of p is known

• e.g. target has radioed for help, position known, shape of search area unknown

Page 27: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

• Surprisingly, in some cases is as large as competitive ratio, e.g. street polygons

• [L-O, Schuierer, 1996]

Home Ratio

Page 28: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

sup { length of search from s to target p }

Travel Cost

p

• unnormalized

• similar to standard algorithmic analysis

Page 29: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

length of search from s to target p shortest path from s to p

Average Ratio

avg supP p

• Searching on the real line is 4.59 competitive on the average

• Doubling is 5.27 competitive

Page 30: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Defined as :

Ψ ratio + F(cost of computing solution)

where Ψ є { Competitive, Performance, Turn, Search, Home, Average, etc.}

• Function F reflects the difference in computational and navigational costs

• Sensible adjustments n, n2, i.e.

F(solt’n) = time / n2

Effective Ratio

Page 31: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

• Robustness • navigational errors • detection errors (revisit area)

• Known probability densities of target location

• Time sensitive considerations

Other considerations

Page 32: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

• Rescue in high seas (man overboard)• High detection error• Known probability density from ocean currents data• Time sensitive (person must be found within 4 hours in North Atlantic)

Example

Page 33: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

• Current coast guard strategy• scan high probability area • when done . . . scan again• if several vessels available, rescan

Search and Rescue (SAR)

Page 34: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU
Page 35: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Bijective Analysis

Σn = {σ1,σ2,…,σ10}:

the set of all possible input sequences of length n

B(σ)

6743

107668

10

A(σ)

5739753757

cost

Page 36: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Bijective Analysis

A ≤ B

B ≤ A

A < B

B(σ)

6743

107668

10

A(σ)

5739753757

cost

Page 37: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Bijective Analysis

Competitive ratio of A: 9

Competitive ratio of B: 4

B(σ)

6743

107668

10

A(σ)

5739753757

OPT(σ)

3241342523

Page 38: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Strict separation is complex

Theorem If the performance measure does not distinguish between sequences of the same length, then no such separation exists

Σ*Σ1Σ2

Σ3

Input sequences

Page 39: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Proof

We prove strong equivalence of all lazy marking algorithms.

I.e. given two marking algorithms A1 and A2, there is a one-to-one correspondence b() between inputs such that the performance characteristics of A1(I) are identical to A2(b(I)).

Page 40: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Proof

A

B

σ1 σ3σ2 σ1 σ4

σ1 σ3σ2 σ1 σ4

map any σ2 in A’s sequence to σ3 in B’s sequence

σ4

σ4 σ3

σ2

Page 41: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Partitioning Input Space

• We need a natural model to partition space. How?

Σ*Σ1Σ2

Σ3

Input sequences

Page 42: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Not all inputs are equal

• Adversarial model is wrong model for paging.

• The user is not out to get you (contrast this with crypto case).

• Compilers go to great lengths to preserve locality of reference.

• Designers go to great lengths to create cache friendly (conscious) algorithms.

Page 43: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Updated model

Competitive ratio

Friendly models:

• Fault model, Torng [FOCS ’95]

• Concave analysis, Albers et al. [STOC ’02]

ALG(I)

nice(I)

Cooperative

Page 44: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Cooperative ratio

• Agreement between user and algorithm about inputs which are:

– likely– common– good– important

Page 45: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Cooperative ratio

• Badly written code (not cache conscious)– (Rightly) considered the programmer’s fault – Paging strategy not responsible for

predicting non-standard paging behaviour

• Well written code (cache conscious)– Code can rely on well defined paging

behaviour to produce better code (e.g. I/O model, cache oblivious model)

Page 46: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Friendly models

• Torng fault model doesn’t fully separate • Albers et al. concave analysis doesn’t

either

• Bijective + concave analysis separates

Page 47: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Concave analysisf( ): an increasing concave function

Definition A request sequence is consistent with f if the number of distinct pages in any window of size n is at most f(n)

Intuition Not too many consecutive newly requested pages, i.e. locality of reference

Proposed by Albers et al. [AFG05], based on Denning’s working set model

Page 48: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Subpartitioning of Input Space

• Subsets compatible with f( )

Σ*

Input sequences

Σf3

Σf4 Σf

5

Page 49: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Bijective analysis

Theorem. LRU ≤f,b A

for all paging algorithms A

Proof. Construct a continuation of b() such that b(σ∙r)= b(σ)∙r’ and LRU(σ∙r) ≤ A(b(σ∙r))

Corollary. avg(LRU) ≤ avg(A)

Page 50: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Strict separation

Theorem For any given paging algorithm A there exists f such that

A >f,avg LRU

i.e. LRU is unique best [SODA ’07]

Page 51: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Strict separation

Theorem For any algorithm A there exists f such that

A >f,avg LRU

Proof. We want to show avg(A) > avg(LRU).

I.e. Σσ A(σ) > Σσ LRU(σ)

Use double counting technique: Compute the number of faults at time i across all sequences, then add for i = 1..n.

Page 52: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Strict separation

Σσ A(σ) > Σσ LRU(σ) [sum by rows]

Compute the number of faults at time i across all sequences, then add for i = 1..n. [sum by columns]

This shows A(i, σ) ≥ LRU(i, σ). Finally we exhibit one sequence σ for which A(i, σ) > LRU(i, σ).

Page 53: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Other results

• Lookahead: the next L items in the list are known in advance

• It does not improve competitive ratio of any of the standard strategies

Theorem LRU with lookahead L is strictly better than LRU with lookahead L’ for all L > L’

Page 54: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Applications to other problems

• Similar open problem for List Update: “An important open question is whether

there exist alternative ways to define competitiveness such that MTF and other good online algorithms for the list update problem would be competitive“ [Martinez and Roura].

• Bijective analysis separates MTF from rest

Page 55: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Applications to other problems

• Leads to better compression results for Burrows-Wheeler based compression

• BWT reorders text in a way that increases repetitions in text

• Reordering is compressed using MTF

Page 56: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Applications to other problems

Observation: BWT permutations have high locality of reference

• Use list update algorithms which are designed under locality of reference assumptions, instead of adversarial worst case inputs

• Leads to better compression

Page 57: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Cooperative ratio for motion planning

• Robot must search efficiently scenes which are “reasonable”

• Can perform somewhat worse in “unreasonable” scenes

• Leads to adaptive-style analysis. E.g. define niceness measure of office floor plan in terms of orthogonality of scene, number of rooms/corridors, size of smallest relevant feature, etc.

Page 58: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Other results

• It leads to deterministic algorithms that outperform randomized ones in the classical model.

single bad case

simple cases

Under competitive ratio algorithm must tend to single bad case, even if at the expense of the simple case

Randomized algorithm can toss a coin and sometimes do one, sometimes do the other

Bijective analysis naturally prefers the majority of good cases

Page 59: Online Algorithms and Competitive Analysis. Paging Algorithms Data brought from slower memory into cache RAM CPU

Conclusions• Introduced refined measurement

technique for online analysis• Resolved long standing open problem:

LRU is unique optimum• Bridged theory-practice disconnect• Result applicable to

– List update (MTF is unique optimum)– BWT compression– Motion planning

• Leads to new cooperative analysis model