reference points for comparison and measurement. brute force

14
Benchmarks Reference points for comparison and measurement

Upload: joel-hancock

Post on 03-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reference points for comparison and measurement. Brute Force

BenchmarksReference points for comparison and

measurement

Page 2: Reference points for comparison and measurement. Brute Force

Brute ForceA 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?

Page 3: Reference points for comparison and measurement. Brute Force

Brute ForceA 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?

Page 4: Reference points for comparison and measurement. Brute Force

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)

Page 5: Reference points for comparison and measurement. Brute Force

How Did O(1) Emerge?Table look-upPower series expansion using a fixed number

of terms, x>0, for all real values of x, and

Is this brute force?

Page 6: Reference points for comparison and measurement. Brute Force

Brute ForceExamples:

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

Page 7: Reference points for comparison and measurement. Brute Force

Brute ForceCommon elements:

Enumeration of outcomes?What is the O(a brute force algorithm)?

Page 8: Reference points for comparison and measurement. Brute Force

Exhaustive SearchEnumerating all possible outcomes in order

to identify a compliant or best solutionOften arises from a direct interpretation of a

problem statementMay exist as the only method of finding

compliant or optimal solutions

Page 9: Reference points for comparison and measurement. Brute Force

Optimization versus Constraint SatisfactionFor 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 constraintsh(s) = 0 ; equality constraints

If there is no objective function, the problem is a constraint satisfaction problem.

Page 10: Reference points for comparison and measurement. Brute Force

Example Formulation: TSPNatural 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”?

Page 11: Reference points for comparison and measurement. Brute Force

TSP ContinuedGiven 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:

Page 12: Reference points for comparison and measurement. Brute Force

TSP Constraints (cont’d)The constraints are:

Visit each cityOnly 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)

Page 13: Reference points for comparison and measurement. Brute Force

TSP: Integer Programming ProblemAn 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)

Page 14: Reference points for comparison and measurement. Brute Force

For Your Course ProjectIdentify 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 constraintsIdentify 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?