lect4-stredit.ppt

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

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

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

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

View Full Document
Andrew McCallum, UMass Amherst, including material from William Cohen Dynamic Programming • (Not much to do with “programming” in the CS sense.) • Dynamic programming is efﬁcient in ﬁnding 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.
Andrew McCallum, UMass Amherst, including material from William Cohen Fibonacci Numbers 1 1 2 3 5 8 13 21 34 . ..

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

View Full Document
Andrew McCallum, UMass Amherst, including material from William Cohen 1
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)

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

View Full Document
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.
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.

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

View Full Document
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.
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”

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

View Full Document
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. ..
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/22/2012 for the course CMPSCI 585 taught by Professor Staff during the Fall '08 term at UMass (Amherst).

### Page1 / 39

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

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

View Full Document
Ask a homework question - tutors are online