lect4-stredit.ppt - S t r in g E d it D is t a n c e ( a n...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen String Edit Distance (and intro to dynamic programming) Lecture #4 Computational Linguistics CMPSCI 591N, Spring 2006 University of Massachusetts Amherst Andrew McCallum
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen Dynamic Programming • (Not much to do with “programming” in the CS sense.) • Dynamic programming is efficient in finding optimal solutions for cases with lots of overlapping sub-problems . • It solves problems by recombining solutions to sub-problems, when the sub-problems themselves may share sub-sub-problems.
Background image of page 2
Andrew McCallum, UMass Amherst, including material from William Cohen Fibonacci Numbers 1 1 2 3 5 8 13 21 34 . ..
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen 1
Background image of page 4
Andrew McCallum, UMass Amherst, including material from William Cohen Calculating Fibonacci Numbers F(n) = F(n-1) + F(n-2), where F(0)=0, F(1)=1. Non-Dynamic Programming implementation For fib(8) , how many calls to function fib(n) ? def fib(n): if n == 0 or n == 1: return n else: return fib(n-1) + fib(n-2)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen DP Example: Calculating Fibonacci Numbers table = {} def fib(n): global table if table.has_key(n): return table[n] if n == 0 or n == 1: table[n] = n return n else: value = fib(n-1) + fib(n-2) table[n] = value return value Dynamic Programming: avoid repeated calls by remembering function values already calculated.
Background image of page 6
Andrew McCallum, UMass Amherst, including material from William Cohen DP Example: Calculating Fibonacci Numbers def fib(n): table = [0] * (n+1) table[0] = 0 table[1] = 1 for i in range(2,n+1): table[i] = table[i-2] + table[i-1] return table[n] ...or alternately, in a list instead of a dictionary. .. We will see this pattern many more times in this course: 1. Create a table (of the right dimensions to describe our problem. 2. Fill the table, re-using solutions to previous sub-problems.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen String Edit Distance Andrew Amdrewz 1. substitute m to n 2. delete the z Distance = 2 Given two strings (sequences) return the “distance” between the two strings as measured by. .. ...the minimum number of “character edit operations” needed to turn one sequence into the other.
Background image of page 8
Andrew McCallum, UMass Amherst, including material from William Cohen String distance metrics: Levenshtein • Given strings s and t – Distance is shortest sequence of edit commands that transform s to t, (or equivalently s to t ) . – Simple set of operations: • Copy character from s over to t (cost 0) • Delete a character in s (cost 1) • Insert a character in t (cost 1) • Substitute one character for another (cost 1) • This is “Levenshtein distance”
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Andrew McCallum, UMass Amherst, including material from William Cohen Levenshtein distance - example • distance(“William Cohen”, “Willliam Cohon”) 2 S O E C C C C C C C C I C C C C 2 1 1 1 1 1 1 1 1 0 0 0 0 N H O C _ M A I L L L I W N H O C _ M A I L L I W s t edit op cost so far. ..
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 39

lect4-stredit.ppt - S t r in g E d it D is t a n c e ( a n...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online