Medians and blobs Prof. Ramin Zabih

Slides:



Advertisements
Similar presentations
Graph algorithms Prof. Noah Snavely CS1114
Advertisements

22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Analysis of Algorithms CS Data Structures Section 2.6.
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
David Luebke 1 4/22/2015 CS 332: Algorithms Quicksort.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Sorting and Selection, Part 1 Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
Computability Start complexity. Motivation by thinking about sorting. Homework: Finish examples.
CS 240: Data Structures Tuesday, July 24 th Searching, Hashing Graphs.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Data Structures Data Structures Topic #13. Today’s Agenda Sorting Algorithms: Recursive –mergesort –quicksort As we learn about each sorting algorithm,
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Prof. Ramin Zabih (CS) Prof. Ashish Raj (Radiology) CS5540: Computational Techniques for Analyzing Clinical Data.
CS 410 Applied Algorithms Applied Algorithms Lecture #3 Data Structures.
Interpolation Prof. Noah Snavely CS1114
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
Quicksort. Quicksort I To sort a[left...right] : 1. if left < right: 1.1. Partition a[left...right] such that: all a[left...p-1] are less than a[p], and.
Quicksort.
CS 1114: Sorting and selection (part one) Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Quicksort
CS 1114: Graphs and Blobs Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Robustness and speed Prof. Noah Snavely CS1114
Blobs and Graphs Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
Clustering and greedy algorithms Prof. Noah Snavely CS1114
Connected components and graph traversal Prof. Noah Snavely CS1114
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Graph Coloring.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
Interpolation, extrapolation, etc. Prof. Ramin Zabih
Physical Mapping of DNA Shanna Terry March 2, 2004.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Voronoi diagrams and applications Prof. Ramin Zabih
Finding dense components in weighted graphs Paul Horn
DP TSP Have some numbering of the vertices We will think of all our tours as beginning and ending at 1 C(S, j) = length of shortest path visiting each.
Image segmentation Prof. Noah Snavely CS1114
COT 5405 Spring 2009 Discussion Session 3. Introduction Our weekly discussion class are like organized TA office hours. Here we encourage students to.
Finding Red Pixels Prof. Ramin Zabih
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Robustness and speed Prof. Noah Snavely CS1114
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
Clustering Prof. Ramin Zabih
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Computability and Complexity 2-1 Problems and Languages Computability and Complexity Andrei Bulatov.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Graph problems Prof. Ramin Zabih
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
Blobs and Graphs Prof. Noah Snavely CS1114
Garbage collection; lightstick orientation
CS 1114: Sorting and selection (part three)
Data Structures – Stacks and Queus
Prof. Ramin Zabih Least squares fitting Prof. Ramin Zabih
So where is it anyway? Bounding box, median, centroids, and an introduction to algorithm analysis.
Quickselect Prof. Noah Snavely CS1114
Graph Coloring.
Sorting, selecting and complexity
CS 1114: Sorting and selection (part two)
Bounding Boxes, Algorithm Speed
Quicksort and selection
Prof. Ramin Zabih Graph Traversal Prof. Ramin Zabih
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

Medians and blobs Prof. Ramin Zabih

2 Administrivia  Assignment 2 is out, due in 2 pieces –Small amount is due this Friday –Most of it is due next Friday  Quiz 2 on Tuesday 9/18 –Coverage through today’s lecture

3  What is the complexity of:  Finding the 2 nd biggest element (>all but 1)? The 3 rd biggest (> all but 2)? –What do you think? –It’s actually O(n) –We do 2 (or 3) “find biggest” operations Each of which takes O(n) time  Finding the element bigger than all but 5%? –Assume we do this by repeated “find biggest” –What if we use modified quicksort?

4 Modified quicksort  This change to quicksort gives us a very practical way to find a particular element without actually sorting the array! –It’s actually much faster, as you will see  The worst case is still bad  Well beyond CS100R: for random input this method actually runs in linear time –You can try random input and see this

5 Putting it all together  By modifying quicksort we can find the 5% largest (or smallest) element –This allows us to efficiently compute the trimmed mean Significantly faster than sorting  It’s possible to select in linear time (1973) –Rev. Dodgson’s problem –But the code is a little messy And the analysis is messier

6 What about the median?  Obvious way to avoid our bad data points: –Use the median instead of the mean  The median of a set of 5 numbers is the 3 rd largest (and thus the 3 rd smallest)  Mean, like median, was defined in 1D –For a 2D mean we used the centroid I.e., we took the mean of the x coordinates and y coordinates “separately” Call this the “mean vector” Does this work for the median also?

7 What is the 2D median  In 1900, statisticians wanted to find the “geographical center of the population” –In order to quantify the westward shift  Why not the centroid? –Someone being born in San Francisco changes the centroid much more than someone being born in Indiana  What about the “median vector”? –Take the median of the x coordinates and the median of the y coordinates separately

8 Median vector  A little thought will show you that this doesn’t really make a lot of sense –Nonetheless, it’s a common solution, and we will implement it for CS100R In situations like ours it works pretty well  It’s almost never an actual datapoint  It depends upon rotations!

9 Can we do even better?  None of what we described works that well if we have widely scattered red pixels –And we can’t figure out lightstick orientation  Is it possible to do even better? –Yes, and we’ll spend a few more weeks on this  In particular, we will focus on: –Finding “blobs” (connected red pixels) –Summarizing the shape of a blob –Computing orientation from this  We’ll need brand new tricks!

10 What is a blob?

11 How to find blobs  Pick a 1 to start with, where you don’t know which blob it is in –You’re done when there aren’t any  Give it a new blob number  Give the same blob number to each pixel that is part of the same blob –But how do we figure this out? –You are part of blob N if you are next to someone who is part of blob N But what exactly does “next to” mean?

12 What is a blob?

13 What is a neighbor?  We need a notion of neighborhood –Sometimes called a neighborhood system  One possibility, the standard one, only considers vertical and horizontal neighbors –Sometimes called “NEWS” North, east, west, south –4-connected, since you have 4 neighbors  Other possibility includes diagonals –8-connected neighborhood system

14 The long winding road to blobs  We actually need to cover a surprising amount of material to get to blob finding –Some of which is not obviously relevant –But (trust me) it will all hang together!

15 An amazingly useful concept  A single idea can be used to think about: –Assigning frequencies to radio stations –Scheduling your classes so they don’t conflict –Connecting computer chips on a motherboard –Figuring out if a chemical is already known –Finding groups in MySpace/Facebook –Searching for pages on the web –Determining how fragile the internet is  Which one of these problems is related to finding blobs?

16 Graphs: always the answer  We are going to look at an incredibly important concept called a graph –Note: not the same as a plot  Nearly all CS professors do research that somehow involves graphs –Many math professors as well  Most problems can be thought of in terms of graphs –But it may not be obvious, as with blobs –So, graph algorithms are very important

17 What is a graph?  Loosely speaking, a set of things that are somehow paired up  Precisely, a set of vertices V and edges E –Vertices sometimes called nodes –An edge (or link) connects a pair of vertices V1 V2 V3 V4 V5

18 Notes on graphs  What can a graph represent? –Cities and direct flights –People and friendships –Web pages and hyperlinks –Rooms and doorways –IMAGES!!!  A graph isn’t changed by: –Drawing the edges differently While preserving endpoints –Re-numbering the vertices

19 Problems, algorithms, programs  A central distinction in CS  Problem: what you want to compute –“Find the median” –Sometimes called a specification  Algorithm: how to do it, in general –“Modified quicksort”  Program: how to do it, in a particular programming language function [med] = find_median[A]...

20 Some major graph problems  Graph coloring –Ensuring that radio stations don’t clash  Planarity testing –Connecting computer chips on a motherboard  Graph isomorphism –Is a chemical structure already known?  Graph cycles –Helping FedEx/UPS/DHL plan a route  Graph connectivity –How fragile is the internet?