Some Uses of Probability Randomized algorithms –for CS in general –for games and robotics in particular Testing Simulation Solving probabilistic problems.

Slides:



Advertisements
Similar presentations
Todd W. Neller Gettysburg College
Advertisements

Neural and Evolutionary Computing - Lecture 4 1 Random Search Algorithms. Simulated Annealing Motivation Simple Random Search Algorithms Simulated Annealing.
Building Java Programs
Modeling and Simulation Monte carlo simulation 1 Arwa Ibrahim Ahmed Princess Nora University.
Randomized Algorithms Kyomin Jung KAIST Applied Algorithm Lab Jan 12, WSAC
VK Dice By: Kenny Gutierrez, Vyvy Pham Mentors: Sarah Eichhorn, Robert Campbell.
Building Java Programs Chapter 5
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
GoldSim 2006 User Conference Slide 1 Vancouver, B.C. The Submodel Element.
Probabilities Random Number Generators –Actually pseudo-random –Seed Same sequence from same seed Often time is used. Many examples on web. Custom random.
ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
MAE 552 – Heuristic Optimization Lecture 6 February 6, 2002.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
CSC Programming for Science Lecture 22: Random Numbers & Macros.
Simulated Annealing Van Laarhoven, Aarts Version 1, October 2000.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
Introduction to Simulated Annealing 22c:145 Simulated Annealing  Motivated by the physical annealing process  Material is heated and slowly cooled.
1 Assessment of Imprecise Reliability Using Efficient Probabilistic Reanalysis Farizal Efstratios Nikolaidis SAE 2007 World Congress.
Randomized Turing Machines
Optimization in Engineering Design Georgia Institute of Technology Systems Realization Laboratory Mixed Integer Problems Most optimization algorithms deal.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Optimization Problems - Optimization: In the real world, there are many problems (e.g. Traveling Salesman Problem, Playing Chess ) that have numerous possible.
1 Simulated Annealing Contents 1. Basic Concepts 2. Algorithm 3. Practical considerations.
Simulation Time-stepping and Monte Carlo Methods Random Number Generation Shirley Moore CS 1401 Spring 2013 March 26, 2013.
Simulated Annealing.
CS2852 Week 2, Class 1 Today Generics (Section 051) Big-O runtime analysis Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See.
Markov Chain Monte Carlo and Gibbs Sampling Vasileios Hatzivassiloglou University of Texas at Dallas.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Comparison-Based Sorting & Analysis Smt Genap
Problem Set 5: Problem 2 22C:021 Computer Science Data Structures.
Chapter 5: Control Structures II
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
FORS 8450 Advanced Forest Planning Lecture 5 Relatively Straightforward Stochastic Approach.
M ONTE C ARLO SIMULATION Modeling and Simulation CS
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
Simulated Annealing G.Anuradha.
Probabilistic Algorithms Evolutionary Algorithms Simulated Annealing.
FORS 8450 Advanced Forest Planning Lecture 6 Threshold Accepting.
Chapter 6: Repetition Continued. 2 Validity Checks What’s weak about the following code ? do { s1 = JOptionPane.showInputDialog (“Enter a number: ”);
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 4 Introduction.
CS1101: Programming Methodology Preparing for Practical Exam (PE)
Week 9 - Friday.  What did we talk about last time?  Static method practice  Finished the Game of Life.
CPSC 322, Lecture 16Slide 1 Stochastic Local Search Variants Computer Science cpsc322, Lecture 16 (Textbook Chpt 4.8) Oct, 11, 2013.
Simulated Annealing To minimize the wire length. Combinatorial Optimization The Process of searching the solution space for optimum possible solutions.
CS-ROSETTA Yang Shen et al. Presented by Jonathan Jou.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
CS621: Artificial Intelligence
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CS 121 – Intro to Programming:Java - Lecture 4 Announcements Course home page: Owl due soon; another.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
CSCI 4310 Lecture 10: Local Search Algorithms
Building Java Programs
Monte Carlo simulation
Van Laarhoven, Aarts Version 1, October 2000
CS621: Artificial Intelligence
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Building Java Programs
Data types, assignment statements, and math functions allow you to compute You write a sequence of statements that tell the computer what needs to be done.
Random number generators
Arrays.
The Random Class The Random class is part of the java.util package
Week 4 Lecture-2 Chapter 6 (Methods).
CS 165: Project in Algorithms and Data Structures Michael T. Goodrich
Presentation transcript:

Some Uses of Probability Randomized algorithms –for CS in general –for games and robotics in particular Testing Simulation Solving probabilistic problems by simulation

Random Number Generators –Actually pseudo-random –Seed Same sequence from same seed Often time is used. Many examples on web. Custom random number generators exist. Can be used in algorithms.

A Simple Random Number Generator random_seed = random_seed * ; r = (int)(random_seed / 65536) % 32768;

Java Random Numbers double x= Math.random() –Generates a random double value in the range from 0.0 up to, but not including 1. –That calculation uses the current time of day to seed the random number generator such that each execution of a program yields a different sequence of random values.

Scaling double x = (B – A) * Math.random + A –Gives double value A  num < B int n = (int) ((B – A) * Math.random()) + A –Gives integer value A  num < B

Java Random Class import java.util.Random; Random g = new Random(); Random g2 = new Random( ); int r = g.nextInt(); –value any int int r = g.nextInt(n); –value 0  r < n double r = g.nextDouble() –value 0  r < 1

Quality of Generators Java implementation so so. –Careful about successive calls using time to set seed if calls will be within 1 millisecond of each other Best probably Mersenne Twister –available on net to replace Random

Actions Based on Probabilities Assign probabilities to each action. Probabilities must add to 1. Roulette wheel method –Range of random number generator is size of roulette wheel. –Give each action a section of the roulette wheel proportional to its probability. –Generate a random number. (Run the wheel.)

Example P(go straight) = 50% P(turn left) = 30% P(turn right) = 20% Use random numbers from 0 – Roulette wheel –0 ≤ Go straight <.50 –.50 ≤ turn left <.80 –.80 ≤ turn right < 1.00

Random Sequence

Java Shuffle The Collections class which can be found within the java.util namespace provides two methods which suffle the elements of a Collection. –static void shuffle(List list) static void shuffle(List list, Random rnd) Collections.shuffle(sl);

Example import java.util.*; public class ShuffleTest{ public static void main(String[] args){ List sl = new ArrayList (); sl.add("One"); sl.add("Two"); sl.add("Three"); Collections.shuffle(sl); } }

Sampling (Polling) Use random sequence but stop after needed number. Generate random numbers but check for repetition

Basic Approaches Monte Carlo –the resources used are bounded but the final result may not be 100% accurate. Las Vegas –always produces the correct result or it informs about the failure. In other words, it does not gamble with the verity of the result -- - it only gambles with the resources used for the computation.

Simulated Annealing A meta-algorithm for global optimization. Meta- –details differ for different problems Tries to avoid getting stuck in local optimum. Probablistic Jumping frog analogy –frog tires and gets caught by deepest pit

Simulated Annealing (2) Use a parameter called the temperature –Start with a high temperature (frog is fresh) Jump –Replace current solution with a “nearby” solution that is chosen based on a temperature dependent transition probability. Keep jumping as the temperature is decreased –The frog gets tired

Minimizing f Transition probability depends on temperature and the difference of the f values of the original and the new state. For high temperatures, the jump to higher f is about as likely as the jump to lower f. (frog is fresh) As temperatures lower, the jump to lower f is much more likely (frog tires)

Simulated Annealing s := s0; e := E(s) // Initial state, energy. k := 0 // Energy evaluation count. while k emax // While time remains & not // good enough: sn := neighbour(s) // Pick some neighbour. en := E(sn) // Compute its energy. if random() < P(e, en, temp(k/kmax)) then // Should we // move to it? s := sn; e := en // Yes, change state. k := k + 1 // One more evaluation done return s // Return current solution