## Computational Geometry in Python

To illustrate a few advantages of the `scipy` stack in one of my upcoming talks, I have placed an `ipython` notebook with (a reduced version of) the current draft of Chapter 6 (Computational Geometry) of my upcoming book: **Mastering SciPy**.

The raw `ipynb` can be downloaded from my github repository [blancosilva/Mastering-Scipy/], or viewed directly from the nbviewer at [this other link]

I also made a selection with some fun examples for the talk. You can download the presentation by clicking in the image above.

Enjoy!

## Naïve Bayes

There is nothing naïve about **Naïve Bayes**—a very basic, but extremely efficient data mining method to take decisions when a vast amount of data is available. The name comes from the fact that this is the simplest application to this problem, upon (the naïve) assumption of independence of the events. It is based on Bayes’ rule of conditional probability: If you have a hypothesis and evidence that bears on that hypothesis, then

where as usual, denotes the probability of the event and denotes the probability of the event conditional to another event

I would like to show an example of this technique, of course, with yet another decision-making algorithm oriented to guess my reaction to a movie I have not seen before. From the data obtained in a previous post, I create a simpler table with only those movies that have been scored more than 28 times (by a pool of 87 of the most popular critics featured in www.metacritics.com) [I posted the script to create that table at the end of the post]

Let’s test it:

**>>> table=prepTable(scoredMovies,28)**

**>>> len(table)**

49

**>>> [entry[0] for entry in table]**

[‘rabbit-hole’, ‘carnage-2011’, ‘star-wars-episode-iii—revenge-of-the-sith’,

‘shame’, ‘brokeback-mountain’, ‘drive’, ‘sideways’, ‘salt’,

‘million-dollar-baby’, ‘a-separation’, ‘dark-shadows’,

‘the-lord-of-the-rings-the-return-of-the-king’, ‘true-grit’, ‘inception’,

‘hereafter’, ‘master-and-commander-the-far-side-of-the-world’, ‘batman-begins’,

‘harry-potter-and-the-deathly-hallows-part-2’, ‘the-artist’, ‘the-fighter’,

‘larry-crowne’, ‘the-hunger-games’, ‘the-descendants’, ‘midnight-in-paris’,

‘moneyball’, ‘8-mile’, ‘the-departed’, ‘war-horse’,

‘the-lord-of-the-rings-the-fellowship-of-the-ring’, ‘j-edgar’,

‘the-kings-speech’, ‘super-8’, ‘robin-hood’, ‘american-splendor’, ‘hugo’,

‘eternal-sunshine-of-the-spotless-mind’, ‘the-lovely-bones’, ‘the-tree-of-life’,

‘the-pianist’, ‘the-ides-of-march’, ‘the-quiet-american’, ‘alexander’,

‘lost-in-translation’, ‘seabiscuit’, ‘catch-me-if-you-can’, ‘the-avengers-2012’,

‘the-social-network’, ‘closer’, ‘the-girl-with-the-dragon-tattoo-2011’]

**>>> table[0]**

[‘rabbit-hole’, ”, ‘B+’, ‘B’, ”, ‘C’, ‘C+’, ”, ‘F’, ‘B+’, ‘F’, ‘C’, ‘F’, ‘D’,

”, ”, ‘A’, ”, ”, ”, ”, ‘B+’, ‘C+’, ”, ”, ”, ”, ”, ”, ‘C+’, ”, ”,

”, ”, ”, ”, ‘A’, ”, ”, ”, ”, ”, ‘A’, ”, ”, ‘B+’, ‘B+’, ‘B’, ”, ”,

”, ‘D’, ‘B+’, ”, ”, ‘C+’, ”, ”, ”, ”, ”, ”, ‘B+’, ”, ”, ”, ”, ”,

”, ‘A’, ”, ”, ”, ”, ”, ”, ”, ‘D’, ”, ”,’C+’, ‘A’, ”, ”, ”, ‘C+’, ”]

## Math still not the answer

I wrote a quick (but not very elegant) `python` script to retrieve locally enough data from www.metacritic.com for pattern recognition purposes. The main goal is to help me decide how much I will enjoy a movie, before watching it. I included the script at the end of the post, in case you want to try it yourself (and maybe improve it too!). It takes a while to complete, although it is quite entertaining to see its progress on screen. At the end, it provides with two lists of the same length: `critics`—a list of `str` containing the names of the critics; and `scoredMovies`—a list of `dict` containing, at index `k`, the evaluation of all the movies scored by the critic at index `k` in the previous list.

For example:

**>>> critics[43]**

‘James White’

**>>> scoredMovies[43]**

{‘hall-pass’: 60, ‘the-karate-kid’: 60, ‘the-losers’: 60,

‘the-avengers-2012’: 80, ‘the-other-guys’: 60, ‘shrek-forever-after’: 80,

‘the-lincoln-lawyer’: 80, ‘the-company-men’: 60, ‘jonah-hex’: 40,

‘arthur’: 60, ‘vampires-suck’: 20, ‘american-reunion’: 40,

‘footloose’: 60, ‘real-steel’: 60}

The number of scored films by critic varies: there are individuals that gave their opinion on a few dozen movies, and others that took the trouble to evaluate up to four thousand flicks! Note also that the names of the movies correspond with their web pages in www.metacritic.com. For example, to see what critics have to say about the “Karate Kid” and other relevant information online, point your browser to www.metacritic.com/movie/**the-karate-kid**. It also comes in very handy if there are several versions of a single title: *Which “Karate Kid” does this score refer to, the one in the eighties, or Jackie Chan’s?*

Feel free to download a copy of the resulting data [here] (note it is a large file: 1.6MB).

But the fact that we have that data stored locally allows us to gather that information with simple `python` commands, and perform many complex operations on it.

### We have moved!

### In the news:

### Recent Posts

- Migration
- Computational Geometry in Python
- Searching (again!?) for the SS Central America
- Jotto (5-letter Mastermind) in the NAO robot
- Robot stories
- Advanced Problem #18
- Book presentation at the USC Python Users Group
- Areas of Mathematics
- More on Lindenmayer Systems
- Some results related to the Feuerbach Point
- An Automatic Geometric Proof
- Sympy should suffice
- A nice application of Fatou’s Lemma
- Have a child, plant a tree, write a book
- Project Euler with Julia
- Seked
- Nezumi San
- Ruthless Thieves Stealing a Roll of Cloth
- Which one is the fake?
- Stones, balances, matrices
- Buy my book!
- Trigonometry
- Naïve Bayes
- Math still not the answer
- Sometimes Math is not the answer
- What if?
- Edge detection: The Convolution Approach
- OpArt
- So you want to be an Applied Mathematician
- Smallest Groups with Two Eyes
- The ultimate metapuzzle
- Where are the powers of two?
- Geolocation
- Boundary operators
- The Cantor Pairing Function
- El País’ weekly challenge
- Math Genealogy Project
- Basic Statistics in sage
- A Homework on the Web System
- Apollonian gaskets and circle inversion fractals
- Toying with basic fractals
- Unusual dice
- Wavelets in sage
- Edge detection: The Scale Space Theory
- Bertrand Paradox
- Voronoi mosaics
- Image Processing with numpy, scipy and matplotlibs in sage
- Super-Resolution Micrograph Reconstruction by Nonlocal-Means Applied to HAADF-STEM
- The Nonlocal-means Algorithm
- The hunt for a Bellman Function.
- Presentation: Hilbert Transform Pairs of Wavelets
- Presentation: The Dual-Tree Complex Wavelet Transform
- Presentation: Curvelets and Approximation Theory
- Poster: Curvelets vs. Wavelets (Mathematical Models of Natural Images)
- Wavelet Coefficients
- Modeling the Impact of Ebola and Bushmeat Hunting on Western Lowland Gorillas
- Triangulations
- Mechanical Geometry Theorem Proving

### Pages

- About me
- Books
- Curriculum Vitae
- Research
- Teaching
- Mathematical Imaging
- Introduction to the Theory of Distributions
- An Introduction to Algebraic Topology
- The Basic Practice of Statistics
- MA598R: Measure Theory
- MA122—Fall 2014
- MA141—Fall 2014
- MA142—Summer II 2012
- MA241—Spring 2014
- MA242—Fall 2013
- Past Sections
- MA122—Spring 2012
- MA122—Spring 2013
- Lesson Plan—section 007
- Lesson Plan—section 008
- Review for First part (section 007)
- Review for First part (section 008)
- Review for Second part (section 007)
- Review for Third part (section 007)
- Review for the Second part (section 008)
- Review for the Fourth part (section 007)
- Review for Third and Fourth parts (section 008)

- MA122—Fall 2013
- MA141—Spring 2010
- MA141—Fall 2012
- MA141—Spring 2013
- MA141—Fall 2013
- MA141—Spring 2014
- MA141—Summer 2014
- MA142—Fall 2011
- MA142—Spring 2012
- MA241—Fall 2011
- MA241—Fall 2012
- MA241—Spring 2013
- MA242—Fall 2012
- MA242—Spring 2012
- First Midterm Practice Test
- Second Midterm-Practice Test
- Third Midterm—Practice Test
- Review for the fourth part of the course
- Blake Rollins’ code in Java
- Ronen Rappaport’s project: messing with strings
- Sam Somani’s project: Understanding Black-Scholes
- Christina Papadimitriou’s project: Diffusion and Reaction in Catalysts

- Problem Solving
- Borsuk-Ulam and Fixed Point Theorems
- The Cantor Set
- The Jordan Curve Theorem
- My oldest plays the piano!
- How many hands did Ernie shake?
- A geometric fallacy
- What is the next number?
- Remainders
- Probability and Divisibility by 11
- Convex triangle-square polygons
- Thieves!
- Metapuzzles
- What day of the week?
- Exact Expression
- Chess puzzles
- Points on a plane
- Sequence of right triangles
- Sums of terms from Fibonacci
- Alleys
- Arithmetic Expressions
- Three circles
- Pick a point
- Bertrand Paradox
- Unusual dice
- El País’ weekly challenge
- Project Euler with Julia

- LaTeX

### Categories

### Archives

- November 2014
- September 2014
- August 2014
- July 2014
- June 2014
- March 2014
- December 2013
- October 2013
- September 2013
- July 2013
- June 2013
- April 2013
- January 2013
- December 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- November 2011
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- February 2011
- January 2011
- December 2010
- May 2010
- April 2010
- September 2008
- September 2007
- August 2007

### @eseprimo

- RT @becarioenhoth: Cómo vaciar una botella de agua de forma rápida gracias a la Física https://t.co/vWdvjJrXkh 8 hours ago
- RT @beesandbombs: wild circles https://t.co/dk21MHG1nv 8 hours ago
- Is this like students that are great at taking tests (e.g. multiple choice) without really knowing the material wel… twitter.com/i/web/status/9… 1 day ago
- RT @simongerman600: This #infographic allows you to pick your ideal city of residence based on whether you like it cold or hot. Very cute i… 2 days ago
- RT @AldaCenter: @alanalda demonstrates the mirror exercise @coopermedschool "If I’m trying to communicate something to you and you don’t f… 2 days ago
- RT @mathematicsprof: Considered by many as the go-to reference for the history of math notation is Florian Cajori's History of Mathematical… 2 days ago
- RT @UofSClibraries: #GISDay at @UofSClibraries has started! Come learn about the amazing real world applications of GIS...like predicting a… 2 days ago
- RT @ArtsSciencesUSC: Join our geography students and experts today @UofSClibraries. GIS is cool! 🌎 😎 https://t.co/iO26gppQEu 2 days ago
- RT @SamHartburn: I will take a moment to bask in the glory of winning the Best Maths in a Cake competition with Diagonal Cross Sections of… 2 days ago
- RT @mathematicsprof: Math quote: A rule of thumb for any good math talk is that it should have one proof and one joke and they should not… 3 days ago
- RT @simongerman600: Lovely piece of work: @SisterFarts pointed me to this wonderful #infographic. The Feeling Wheel by Dr Gloria Willcox. P… 3 days ago
- RT @zeynep: Narrator: “Instead, he ended up igniting a Vim vs. Emacs war in his mentions.” twitter.com/tomforutah/sta… 4 days ago
- RT @USCObservatory: The observatory will be OPEN this evening from 8:00-10:00 pm. We will be observing Uranus, the Andromeda Galaxy, and mo… 4 days ago
- RT @pypi_updates2: xonda 0.2: A xonsh wrapper around conda bit.ly/2zSFhsz 4 days ago
- RT @simongerman600: #Map shows most popular news website across #Europe. A few sports newspapers seem to have crept in. Source: https://t.c… 4 days ago
- RT @robdelaney: Before Midnight isn’t number 1 on this list so it’s toilet paper. We stopped writing s1 of Catastrophe when we saw it & sai… 4 days ago
- RT @SAVEURMAG: 3D printers make incredible pastas your nonna could only dream about saveur.cc/YmBvDw https://t.co/R6VdraPd9y 4 days ago
- RT @BedtimeMath: This guitar is more than 1/2 mile long and is made out of 100s of trees! Learn more about the math in its design: https://… 4 days ago
- RT @jakevdp: from math import* def F(x):N=len(x);t=N<2or(F(x[::2]),F(x[1::2]));return N<2and x or[ a+s*b*e**(-2j*pi*n/N)for s in[1,-1]for(n… 5 days ago
- RT @mathhombre: Euler's elementary algebra book, notes by Bernoulli, translated into English, free books.google.com/books?id=X8yv0… #mathhistory cc… 6 days ago

### Math updates on arXiv.org

- First and second $K$-groups of an elliptic curve over a global field of positive characteristic. (arXiv:1711.05749v1 [math.KT])
- Thomas Precession for Dressed Particles. (arXiv:1711.05753v1 [hep-th])
- Spaces of Types in Positive Model Theory. (arXiv:1711.05754v1 [math.LO])
- Scaled Boundary Parametrizations in Isogeometric Analysis. (arXiv:1711.05760v1 [math.NA])
- Random gradient extrapolation for distributed and stochastic optimization. (arXiv:1711.05762v1 [math.OC])
- Reconstructing general plane quartics from their inflection lines. (arXiv:1711.05776v1 [math.AG])
- On the values of unipotent characters in bad characteristic. (arXiv:1711.05778v1 [math.RT])
- Integral Formulas for Higher Order Higher Spin Conformally Invariant Differential Operators. (arXiv:1711.05782v1 [math.RT])
- A Parameter Estimation Method Using Linear Response Statistics: Numerical Scheme. (arXiv:1711.05786v1 [math.NA])
- On the proximity of large primes. (arXiv:1711.05793v1 [math.NT])

### Computational Geometry updates on arXiv.org

- An error has occurred; the feed is probably down. Try again later.

### sagemath

- An error has occurred; the feed is probably down. Try again later.