1 / 14

Benchmarks

Benchmarks. Reference points for comparison and measurement. Brute Force. A definition: Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. What is the complexity of finding ? What algorithm would you use?.

Télécharger la présentation

Benchmarks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Benchmarks Reference points for comparison and measurement

  2. Brute Force • A definition:Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. • What is the complexity of finding ? • What algorithm would you use?

  3. Brute Force • A definition:Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. • What is the complexity of finding ? • What algorithm would you use? • Could it be done faster?

  4. Find Two Ways • #Find a^n in two ways • import math • import time • a = 2 • n = 1000 • m = 100000 • starttime = time.time() • for j in range (m): • p = 1 • for i in range (n): • p *= a • endtime = time.time() • elapsedtime1 = endtime - starttime • print (p, elapsedtime1) • starttime = time.time() • for j in range (m): • lg = math.log(a) • ex = n * lg • p = math.exp(ex) • endtime = time.time() • elapsedtime2 = endtime - starttime • print (p, elapsedtime2) • print(elapsedtime1/elapsedtime2)

  5. How Did O(1) Emerge? • Table look-up • Power series expansion using a fixed number of terms • , x>0 • , for all real values of x, and • Is this brute force?

  6. Brute Force • Examples: • Sorting • O(n!) or O(2^(n^2)) • O(n^2) • O(n log n) Under what circumstances c/would you call such an algorithm brute force? • O(n) Under what circumstances c/would you call such an algorithm brute force? • Others? • Searching

  7. Brute Force • Common elements: • Enumeration of outcomes? • What is the O(a brute force algorithm)?

  8. Exhaustive Search • Enumerating all possible outcomes in order to identify a compliant or best solution • Often arises from a direct interpretation of a problem statement • May exist as the only method of finding compliant or optimal solutions

  9. Optimization versus Constraint Satisfaction • For a function f, defined on a set S, if s* ε S such that f(s*) ≤ f(s) for all s ε S, then s* is said to be a minimum of f on S. The function f may be used as an objective function. • An optimization problem is a minimization problem subject to constraints: • g(s) ≤ 0 ; inequality constraints • h(s) = 0 ; equality constraints • If there is no objective function, the problem is a constraint satisfactionproblem.

  10. Example Formulation: TSP • Natural language: Find the shortest round trip to visit some number of cities so that each of the cities is visited exactly once. • Can we tighten and clarify this statement? • How will “shortest” be measured? • What is a “round trip”? • What is “exactly once”?

  11. TSP Continued • Given a set of n cities, label each with a distinct counting number from the set S = {0, …, n-1}. • Let p:S->S be a bijective (one-to-one and onto) function. The function p is a permutation of the city labels and may be used to represent a trip, where p(i) for i=0,…,n-1 is the city to visit at the ith step of the trip. • The cost of a trip can be determined by:

  12. TSP Constraints (cont’d) • The constraints are: • Visit each city • Only visit once • They are satisfied or enforced implicitly by the choice of a candidate solution as a permutation of the label set: • Each city label must be used (onto) • A city label may only be used once (one-to-one)

  13. TSP: Integer Programming Problem • An alternative formulation of TSP may be found at http://en.wikipedia.org/wiki/Travelling_salesman_problem • Note some of the key differences: • Cost function appears as a double summation (or is it?). • Constraints are explicitly expressed as equalities. • A 0/1 decision variable xij is introduced. (The 0/1 are the integer options in this integer programming problem. It is sometimes called a 0/1 IPP)

  14. For Your Course Project • Identify your group. • State the problem you will tackle using natural language. • Restate the problem formally. Employ the language of analysis to formulate the objective and any constraints • Identify several of the algorithms you will apply to the problem. • What will be the bases for assessing the relative merits of the alternative algorithms? Benchmarks should appear. here, as well as measurements you plan to employ. (By the due date) • What are your empirical results? • Interpret and analyze your findings. • With respect to the algorithms, what would you do differently next time?

More Related