Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

Order Statistics Sorted
David Luebke 1 4/22/2015 CS 332: Algorithms Quicksort.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 6.
Types of Algorithms.
Monte Carlo Methods and Statistical Physics
Algorithms + L. Grewe.
ADA: 5. Quicksort1 Objective o describe the quicksort algorithm, it's partition function, and analyse its running time under different data conditions.
WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
1 Today’s Material Medians & Order Statistics – Ch. 9.
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
QuickSort 4 February QuickSort(S) Fast divide and conquer algorithm first discovered by C. A. R. Hoare in If the number of elements in.
DIVIDE AND CONQUER APPROACH. General Method Works on the approach of dividing a given problem into smaller sub problems (ideally of same size).  Divide.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Quicksort CS 3358 Data Structures. Sorting II/ Slide 2 Introduction Fastest known sorting algorithm in practice * Average case: O(N log N) * Worst case:
Quicksort COMP171 Fall Sorting II/ Slide 2 Introduction * Fastest known sorting algorithm in practice * Average case: O(N log N) * Worst case: O(N.
Updated QuickSort Problem From a given set of n integers, find the missing integer from 0 to n using O(n) queries of type: “what is bit[j]
Fundamentals of Algorithms MCS - 2 Lecture # 16. Quick Sort.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
CSE 830: Design and Theory of Algorithms
Quicksort.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
1 Randomness in Computation Example 1: Breaking symmetry. Example 2: Finding witnesses. Example 3: Monte Carlo integration. Example 4: Approximation algorithms.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Monte Carlo Methods in Partial Differential Equations.
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
CS10 Final Review by Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Glenn Sugdenmons Attribution-NonCommercial-ShareAlike.
Scott Perryman Jordan Williams.  NP-completeness is a class of unsolved decision problems in Computer Science.  A decision problem is a YES or NO answer.
Chapter 14 Randomized algorithms Introduction Las Vegas and Monte Carlo algorithms Randomized Quicksort Randomized selection Testing String Equality Pattern.
Approximation Algorithms Pages ADVANCED TOPICS IN COMPLEXITY THEORY.
Machine Learning Lecture 23: Statistical Estimation with Sampling Iain Murray’s MLSS lecture on videolectures.net:
Randomized Algorithms Pasi Fränti Treasure island Treasure worth awaits 5000 DAA expedition 5000 ? ? Map for sale: 3000.
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
Fundamentals of Algorithms MCS - 2 Lecture # 7
Module 1: Statistical Issues in Micro simulation Paul Sousa.
CPSC 335 Randomized Algorithms Dr. Marina Gavrilova Computer Science University of Calgary Canada.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Monte Carlo Methods Versatile methods for analyzing the behavior of some activity, plan or process that involves uncertainty.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
Order Statistics David Kauchak cs302 Spring 2012.
Decision Trees Binary output – easily extendible to multiple output classes. Takes a set of attributes for a given situation or object and outputs a yes/no.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Computer Science 101 Fast Algorithms. What Is Really Fast? n O(log 2 n) O(n) O(n 2 )O(2 n )
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
The Markov Chain Monte Carlo Method Isabelle Stanton May 8, 2008 Theory Lunch.
ICS 353: Design and Analysis of Algorithms
NP-Completness Turing Machine. Hard problems There are many many important problems for which no polynomial algorithms is known. We show that a polynomial-time.
CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)
Quicksort This is probably the most popular sorting algorithm. It was invented by the English Scientist C.A.R. Hoare It is popular because it works well.
Random Sampling Algorithms with Applications Kyomin Jung KAIST Aug ERC Workshop.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Lecture 5 Dynamic Programming
Randomized Algorithms
Lecture 5 Dynamic Programming
CS 3343: Analysis of Algorithms
Objective of This Course
Unit-2 Divide and Conquer
Randomized Algorithms
Quicksort.
Major Design Strategies
Divide and Conquer Merge sort and quick sort Binary search
Major Design Strategies
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Quicksort.
Presentation transcript:

Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte Carlo – Las Vegas – We have already encountered some of both in this class Monte Carlo algorithms have a consistent time complexity, but there is a probability of returning an incorrect/poor answer – Can flexibly increase time to improve chance of a correct answer Las Vegas algorithms return a correct answer, but there is a probability that it could take a relatively long time or not return an answer at all – Why "Las Vegas"? - Because the house always wins (will get a correct answer for the house) even though it might take a while CS 312 – Stochastic Algorithms1

2 Monte Carlo Algorithm – Fermat Test If a number is prime then it will pass the Fermat primality test a c-1  1 mod c for a random a such that 1  a < c There is less than a 50% probability that a composite number c passes the Fermat primality test So try the test k times This is called Amplification of Stochastic Advantage function primality2(N) Input: Positive integer N Output: yes/no Choose a 1 …a k (k < N) random integers between 1 and N-1 if a i N-1  1 mod N for all a i then return yes with probability 1 - 1/(2 k ) else:return no

Dealing with Local Optima Assume an algorithm has a probability p of finding the optimal answer for a certain problem – Just run it multiple times with different random start states – If chance of hitting a true optima is p, then running the problem k times gives probability 1-(1-p) k of finding an optimal solution – This is a Monte Carlo approach Another approach is to add some randomness to the algorithm and occasionally allow it to move to a neighbor which increases the objective, allowing it to potentially escape local optima – This is more of a Las Vegas approach CS 312 – Stochastic Algorithms3

Monte Carlo Algorithms – General Approach Powerful approach for many tasks with no efficient deterministic algorithm – Especially useful in complicated tasks with a large number of coupled variables – Also useful when there is uncertainty in the inputs 1. Define a domain of possible inputs 2. Generate inputs randomly from the domain using an appropriate specified probability distribution (sampling) 3. Perform a deterministic computation using the sampled inputs 4. Aggregate the results of the individual computations into the final result CS 312 – Stochastic Algorithms4

Monte Carlo Algorithm to Calculate π CS 312 – Stochastic Algorithms5 r Want to calculate the value of π using darts and a blindfold

Monte Carlo Algorithm to Calculate π for every 4 darts thrown about π of them will land in the circle CS 312 – Stochastic Algorithms6 r Want to calculate the value of π using darts and a blindfold Ratio of the area of the inscribed circle to the area of the square is πr 2 /(2r) 2 = π/4

Monte Carlo Algorithm to Calculate π for every 4 darts thrown about π of them will land in the circle Choose n points in the square from a uniform random distribution (e.g. throw n darts with a blindfold, etc.) nπ/4 darts should land in the circle π = 4(number of darts in circle)/n Does this follow the general form? How does the accuracy of the approximation change with n? Make sure you sample from the representative distribution CS 312 – Stochastic Algorithms7 r Want to calculate the value of π using darts and a blindfold Ratio of the area of the inscribed circle to the area of the square is πr 2 /(2r) 2 = π/4

Monte Carlo Integration – Solving complex definite integrals – Symbolic Integration software How long would that take? Solve all integrals? – What would be a Monte Carlo solution? How hard to code? How general and how well would it do? – Multi-variate, high dimensional, complex, etc. CS 312 – Stochastic Algorithms8

Markov Chain Monte Carlo Techniques Sampling complex probability distributions? MCMC - Markov Chain Monte Carlo algorithms – Start from an initial arbitrary state – Travel a Markov chain representing the distribution Probability of next state is just a function of the current state Follow this chain of states, sampling as you go, until space is "sufficiently" sampled according to the probability distribution Need a short "burn-in" phase where we discard early samples to avoid dependency on the arbitrary initial state – Good approach for solving Bayesian Networks, etc. Monte Carlo methods commonly used in computational physics, molecular biology, applied statistics, finance, optimization, machine learning, etc. CS 312 – Stochastic Algorithms9

10 Las Vegas Algorithms Quicksort sorts in place, using partitioning – Example: Pivot about a random element (e.g. first element (3)) – before – after At most n swaps – Pivot element ends up in it’s final position – No element left or right of pivot will flip sides again Sort each side independently Recursive Divide and Conquer approach Average case complexity is O(nlogn) but empirically better constants than other sorting algorithms Speed depends on how well the random pivot splits the data Worst case is O(n 2 ) – Thus a Las Vegas algorithm Selection algorithm for median finding is also a Las Vegas algorithm

When to use what Algorithm? Not always just one best approach for a task Can depend on what style you like However, some algorithms will often fit a task more efficiently Have given you an initial toolkit: – Divide and Conquer – Graph Algorithms – Greedy – Dynamic Programming – Linear Programming – Intelligent Search – Local Search – Stochastic Algorithms TSP, Sort, Shortest Path, Knapsack, Multiplication, … CS 312 – Stochastic Algorithms11

When to use what Algorithm? Divide and Conquer – Problem has natural hierarchy with independent branches – Speed-up happens when we can find short-cuts during partition/merge that can be taken because of the divide and conquer Graph Algorithms – When finding reachability, paths, and properties of graphs, often fall under other approaches Greedy – Common simple and fast approximation approach, occasionally optimal Dynamic Programming – Overlapping subproblems (given by a recursive definition) that are only slightly (constant factor) smaller than the original problem, solved with the proper ordering Linear Programming – Any optimization with linear objective and constraints Intelligent Search – Effective when we have some heuristic knowledge of the search space to allow pruning Local Search – Simple optimization technique for many complex search spaces – local optima issues Stochastic Algorithms – Sampling problems, amplification of stochastic advantage, takes advantage of fast computers, etc. CS 312 – Stochastic Algorithms12

Algorithms Can often use a combination of different algorithms – Divide and Conquer followed by different algorithm on subproblems – Stochastic algorithms can often improve many of the base algorithms for certain tasks – Greedy components within algorithms – etc. Be Creative! – Don't get stuck on just one "Hammer" – The ways in which you apply these algorithmic techniques will not always be initially obvious You now have a powerful toolbox of algorithmic techniques and philosophies which will prove beneficial as you solve complex tasks in the future CS 312 – Stochastic Algorithms13