comparison talk/talk.tex @ 64:d5ec0659b26b

write last section
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 17 May 2016 23:35:36 -0400
parents 73b369370665
children
comparison
equal deleted inserted replaced
63:bd102ae06bc4 64:d5ec0659b26b
316 Pick the median. 316 Pick the median.
317 \end{frame} 317 \end{frame}
318 318
319 \begin{frame}{Computing the medcouple} 319 \begin{frame}{Computing the medcouple}
320 \begin{overlayarea}{\textwidth}{8cm} 320 \begin{overlayarea}{\textwidth}{8cm}
321 \only<1>{% 321 \only<1>{
322 \begin{center} 322 \begin{center}
323 \pgfimage[height=2in]{img/naive/medc-computation-init.png} 323 \pgfimage[height=2in]{img/naive/medc-computation-init.png}
324 \end{center} 324 \end{center}
325 Split up $X$ into $X^+$ and $X^-$ along the median.} 325 Split up $X$ into $X^+$ and $X^-$ along the median.
326 \only<2>{% 326 }
327 \only<2>{
327 \begin{center} 328 \begin{center}
328 \pgfimage[height=2in]{img/naive/medc-computation.png} 329 \pgfimage[height=2in]{img/naive/medc-computation.png}
329 \end{center} 330 \end{center}
330 Evaluate the kernel for all couples. 331 Evaluate the kernel for all couples.
331 \[ 332 \[
332 \frac{ (x_i - x_m) - (x_m - x_j)}{x_i - x_j}, 333 \frac{ (x_i - x_m) - (x_m - x_j)}{x_i - x_j},
333 \quad x_i \in X^+, \quad x_j \in X^- 334 \quad x_i \in X^+, \quad x_j \in X^-
334 \]} 335 \]
335 \only<3>{% 336 }
337 \only<3>{
336 \begin{center} 338 \begin{center}
337 \pgfimage[height=2in]{img/naive/medc-computation-done.png} 339 \pgfimage[height=2in]{img/naive/medc-computation-done.png}
338 \end{center} 340 \end{center}
339 The median of this matrix is the medcouple.} 341 The median of this matrix is the medcouple.
340 \end{overlayarea} 342 }
343 \end{overlayarea}
344 \end{frame}
345
346 \begin{frame}
347 Problem: this algorithm is $O(n^2)$!!
341 \end{frame} 348 \end{frame}
342 349
343 \section{Computation of the Medcouple} 350 \section{Computation of the Medcouple}
344 351
345 \begin{frame} 352 \begin{frame}
346 wtf 353 Now pure CS:
354 \pause
355 \begin{problem}
356 Find the median of a matrix with sorted rows and sorted columns.
357 \end{problem}
358 \end{frame}
359
360 \begin{frame}
361 \emph{Donald B. Johnson; Tetsuo Mizoguchi (May 1978). "Selecting The
362 Kth Element In X + Y And X1 + X2 +...+ Xm". SIAM Journal of
363 Computing 7 (2): 147-153. doi:10.1137/0207013.}
364 \pause
365 \begin{itemize}
366 \item Old paper, hard to read. But cool ideas!
367 \pause
368 \item Paper generalises to $n$-dimensional array with sorted slices
369 \end{itemize}
370 \end{frame}
371
372 \begin{frame}{Preliminaries}
373 Helper algorithms:
374 \pause
375 \begin{description}
376 \item[Selection Algorithm:] e.g. quickselect,
377 \texttt{nth\_element} in C++ or \texttt{partition} in numpy, $O(n)$ time
378 \pause
379 \item[Weighted Median:] binary search using
380 selection algorithm, $O(n)$ time.
381 \end{description}
382 \end{frame}
383
384 \begin{frame}
385 We now make two important observations
386 \end{frame}
387
388 \begin{frame}{Two observations}
389 Compare against whole matrix in $O(n)$ time
390 \begin{overlayarea}{\textwidth}{6cm}
391 \only<1>{
392 \begin{center}
393 \pgfimage[width=2in]{img/kth-pair/greater-than}
394 \end{center}
395
396 Bottom-up.
397 }
398 \only<2>{
399 \begin{center}
400 \pgfimage[width=2in]{img/kth-pair/less-than}
401 \end{center}
402
403 Top-down.
404 }
405 \end{overlayarea}
406 \end{frame}
407
408 \begin{frame}{Two observations}
409 Compare against half the matrix in $O(1)$ time
410 \begin{center}
411 \pgfimage[width=2in]{img/kth-pair/middle-of-middle}
412 \end{center}
413 \end{frame}
414
415 \begin{frame}{Putting it together}
416 Iteratively, we have bounds for the global median
417 \begin{center}
418 \pgfimage[width=2in]{img/kth-pair/row-medians}
419 \end{center}
420 \end{frame}
421
422 \begin{frame}{Putting it together}
423 If we align the row medians...
424 \begin{center}
425 \pgfimage[width=2in]{img/kth-pair/row-medians-aligned}
426 \end{center}
427 \end{frame}
428
429 \begin{frame}{Putting it together}
430 With the weighted median (in $O(n)$ time), we compare to at least half the
431 remaining entries, discarding at least $1/4$.
432 \begin{center}
433 \pgfimage[width=2in]{img/kth-pair/row-medians-compared}
434 \end{center}
435 \end{frame}
436
437 \begin{frame}
438 So, final algorithm!
439 \end{frame}
440
441 \begin{frame}{Grand finale}
442 Procedure (serves one medcouple)
443
444 \begin{enumerate}
445 \item Compute ingredients for medcouple matrix: $O(n \log n)$
446 \pause
447 \begin{enumerate}[(A)]
448 \item \label{loop} Compute $t = \text{median of row medians}$: $O(n)$
449 \pause
450 \item \label{compare} Compare $t$ to the whole matrix: $O(n)$
451 \pause
452 \item Found the median? Found the medcouple! DONE.
453 \pause
454 \item \label{compare} Use comparison from \eqref{compare} to
455 throw out entries.
456 \pause
457 \item More than $n$ entries remaining? LOOP TO \eqref{loop}.
458 \end{enumerate}
459 \pause
460 \item Use selection algorithm on remaining entries: $O(n)$.
461 \end{enumerate}
462 \pause
463
464 Step \eqref{compare} throws out at least $1/4$ of all entries, so
465 the whole algorithm is $O(n \log n)$.
466 \end{frame}
467
468 \begin{frame}
469 \begin{center}
470 \LARGE{Questions?}
471 \end{center}
347 \end{frame} 472 \end{frame}
348 473
349 \end{document} 474 \end{document}