Category Archives: Geeky

Book Review: “Think Bayes” by Allen Downey

I vaguely remember ever learned about Bayes’ Theorem in college. Until I read this book I never thought there are so many applications of Bayes’ Theorem in our daily life. The drug companies uses it to get FDA approvals on drugs. The food companies applies the theorem to “prove” certain foods are good for us. In a way, the theorem allows us to change our perception of certain events’ probability of occurring. I can imagine more applications than the ones he outlines in the book. By the way, the pdf format of this book can be freely downloaded here, thanks to the author’s generosity.

Because of this book and his Youtube videos, I got interested in re-learning Python as a practical/useful programming language. It opened my eyes to the wonderful world of Python and its ecosystem.

The book gets pretty technical fast after the first chapter which piqued my interest with his Cookie, M&M, and Monte Hall problems. At the end I don’t know if it’s really necessary to know all the various applications in prediction and simulation, but it could come in handy for people who work in the statistical field.

The key thing to remember is that Bayes Theorem gives a way to update or arrive at the posterior probability of a prior/known hypothesis, H, after learning some new piece of data. The equation is simple: P(H|D)=P(H)*P(D|H)/P(D)
As it turn out, the most difficult part is P(D) or the normalizing factor, which is the probability of seeing the data under any hypotheses at all.

Overall, all the concepts presented by the author make sense to me. I’m not sure I can actually implement and devise the models when the actual problem arrives. But at least I can recognize the Bayesian problem when I see one and know where to find help.

Chapter Summary:
1. Bayes’s Theorem was derived easily and discussed. He introduced the probability calculator of getting a heart attack.

2. Computational Statistics: The author provides a set of Python codes/tools to calculate the result quickly. I had to re-take a Python refresher course before getting any further. But the tools are powerful and help me understand the subject better. All the codes and downloadable from website. It took me a while to figure out Monte Hall’s problem – one of those paradox that’s hard to sink in.

3. Estimation: This chapter estimates the posterior probability upon rolling of a multi-face die (4-/6-/8-/12-/20-sides die) and successive rolling of dice (more data points changes the probability distribution), and probability of the number of locomotive given the observation of one locomotive number. This is when you really need to have the computer do the work for you. The intuitive part is that the more information you have, the better your estimation is going to be, as some data points would be ruled out. For example, finding 6 eliminates the 4-sided die.

4. More Estimation: In this chapter, the author covers the “biased” Euro coin problem. The interesting phenomenon is that the prior hypothesis makes little difference (provided you don’t rule things out with 0 probability), the posterior distribution will likely converge with more data points.

5. Odds and Addends: The author covers the “odds” form of the Bayesian Theorem, o(A|D)=o(A)*P(D/A)/P(D|B), which is probably easier to understand for most people. The Addends part of the chapter goes into getting the density and distribution functions.

6. Decision Analysis: Given a prior distribution function, what’s the best decision to make given some data. The author presented a Price Is Right scenario and solve the best price to bid for a show case showdown based the past data and best guess to adjust the bid. The PDF, Probability Density Function, is introduced here. Also the use of KDE (Kernel Density Estimation) is used to smooth PDF that fits the data. This is an interesting application of Bayes Theorem. The math is complicated and couldn’t be done without a computer. I guess it would be good to bring your computer to the Price Is Right game.

7. Prediction: Here the author presented a better way to predict the outcome of a playoff game score based on past data between two teams (Boston Bruin vs. Vancouver Canucks.) This should be no difference from how the gambling industry computes the odds before a big game. Just imagine all the gambling earning you could’ve made by mastering this chapter! I’m sure someone has applied the same idea/theory to the financial market like stocks, bonds and futures.

8. Observer Bias: This is another angle of predicting the outcome (like the wait time for the next train at a given time) taking into account of the observer bias.

9. Two Dimensions: Using the paintball example, the author applies the Bayesian framework to the two-dimensional problem. In addition, the joint distribution , marginal distribution, and conditional distribution. And you don’t think one dimensional Bayesian framework is confusing enough…

10. Approximate Bayesian Computation (ABC): When the likelihood of any particular dataset is 1) very small, 2) expensive to compute, 3) not really what we want. We don’t care of about the likelihood of seeing the exact dataset we saw but any dataset like that.

11. Hypothesis Testing: The Bayes Factor, the ratio of likelihood of a new scenario to that of the baseline, can be used to test the likelihood of a particular hypothesis, e.g. fairness/cheat of an Euro coin. Bayes factor of 1~3 is barely worth mentioning, 3~10 is substantial, 10~30 strong, 30~100 very strong, >100 decisive.

12. Evidence: Test for the strength of evidence. “How strong is the evidence that Alice is better than Bob, given their SAT score?”

13. Simulation: Simulate the tumor growth rate based on prior growth rate and the data points of current tumor size, age and etc.

14. A Hierarchical Model: reflects the structure of the system, with causes at the top and effects at the bottom. Instead of solving the “forward” problem, we can reverse engineer the distribution of the parameters given the data. The Gaiger counter problem demonstrates the connection between causation and hierarchical modeling.

15. Dealing with Dimensions: This last chapter combines all of the lessons so far and applies to the “Belly Button Bacteria” prediction and simulation. This is a very difficult chapter to understand and probably requires the full understanding of the previous lessons.

Corrupted Internet Explorer 11 Files – How I Fixed It

While fixing some Windows 7 system issues (like running Internet Explore or Quicken would hang) , I ran a lot of “sfc /scannow” command. And each time, it would complain that there were corrupted files that could not be fixed. (“Windows Resource Protection found corrupt files but was unable to fix some of them.”)

After looking into the log file residing in c:\windows\Log\CBS\CBS.log , I noticed that the majority of the corrupted files were related to Internet Explorer 11. Then I discovered this little “Search Protect” icon showing up in the task bar. Upon further search, I concluded that this was a malware from “Conduit”. I suspected this was the one that caused the Internet Explorer 11 to be corrupted.

First, I need to get rid of this malware. Based on the recommendation form my Google Search, I downloaded JRT (Junkware Removal Tool) and proceeded to remove the “Search Protect” from my system. Well, JRT didn’t quite remove it from the auto-start programs so I had to manually remove it using Microsoft’s autoruns. This was the only way to get rid of the annoying warning message that it couldn’t find the “backgroundcontainer.dll” software (already removed by JRT) upon logging into Windows 7 every time.

Since Internet Explorer 11 was the most up-to-date Internet Explorer, there was no new update to override it. I even tried downloading directly from Microsoft but the official download site was still down level. So I decided uninstall it, which was not a trivial task since Internet Explorer is an integrated software for Windows 7. Based on this recommendation, I would need to deselect Internet Explorer 11 in the Windows Features (Start -> Control Panel -> Programs and Features -> Select “Turning Windows Features On/off” on the left panel -> Deselect “Internet Explorer 10” ). Then go into Windows Update and Uninstall Internet Explorer 11 (Start -> Control Panel -> Click on “Installed Updated” on the left panel on the bottom -> Enter “Internet Explorer” -> Right Click on Windows Internet Explorer 11 ). By doing the above steps, upon reboot, the previous Internet Explorer (in my case IE 9) became the Internet Explorer app.

After doing more “sfc /scannow” and a few more reboots, I was able to run Internet Explorer 9 without any problem and my Quickens App was finally able to run without crashing. Evidently, Quickens uses Microsoft Framework which is integrated tightly with Internet Explorer.

Lessons learned:
1. Watch out for any strange icons on your task bars. Research their purposes. When in doubt, get rid of them so they don’t cause conflicts with other software.

2. Every so often (2 weeks), run “sfc /scannow” to check for any corrupted system files.

Migrating My Defected Ultrabook SSD to a New SSD – My Journey and Lessons Learned

Last few months I have been seeing strange behavior on my Windows 7 Ultrabook – like failing to boot on occasions and getting same Windows updates over and over, certain application wouldn’t install correctly, and etc. I figured the original 240GB SSD may be reaching its end of life, though I have been using my laptop for just 2 years. After downloading HD Tune Pro, my fear was confirmed. The SSD had more than 8% of damaged blocks. I quickly purchased another SSD from Amazon of the “same” size (at least I thought), then the real battle began…

First, the new Samsung SSD was advertised to have 250GB of storage when in fact has only 232.88GB of true storage (Lawyers’ ears should be perked up by now). My original Micron SSD was advertised to have 240GB by Acer when it has 238GB of true storage. So the new SSD is slightly smaller than the old one. This was bad news. It’s much easier to migrate from a small disk to large disk. Lesson #1: always buy a bigger disk than the original. When in doubt, go for the next bigger size. In order to overcome this issue, I had to shrink the original disk: 1) Right click on Computer and Select Manage, 2) Click on Storage->Disk Management, 3) Select the partition to be shrunk, 4) Right Click -> Shrunk Volume). So I managed to shrink just 8GB. This was good enough to scrape by and meet the new SSD size.

Next, I had to clone the disk to the new drive. The new Samsung SSD came with their migration tool. Unfortunately, their tool refused to work because my original disk had data corruption. It’s kind of silly to have a tool that wouldn’t work with the situation it’s called out to do. Then I tried CloneZilla, which was a nice tool I used to clone and backup disk image. It’s good at duplicating disk verbatim, as long as the destination disk is larger than the source disk. But it choked badly on this task because I needed to go from a slightly larger SSD to a smaller SSD. No Go. I tried manually copying the partition but the Windows partitions were a nightmare to copy correctly. I almost gave up and was ready to return the SSD back to Amazon for a next-size, 500GB SSD, which cost another $100. Then I remembered Acronis True Image (2009 version I used), whose “Clone Disk” function was smart enough to skip the empty partition when copying and eventually saved my butt and migrated correctly to the new disk. Another lesson learned, a good disk migration software goes a long way of solving a real challenging problem.

I’ll spare you the painful story I went through in replacing the SSD (12 screws on the cover, 5 screws on the SSD housing) on my Ultrabook. What a relief to see the new disk booted up nicely and performing well. A journey indeed. One last lesson: SSD may be a technology wonder in terms of its high performance but it’s still a way off to have the same reliability as a hard disk.

Book Review: “Think Python” by Allen Downey

It’s been a while since I used Python last. See my review on another Python book: “Invent Your Own Computer Game with Python” Unfortunately, like most spoken languages, you’d lose the ability to use a computer language if you don’t use it often. And I did forget most of it. This time, inspired by “Think Bayes,” my original intention to learn about Bayesian Statistics (more on this in future blogs), I decided to learn Python using Allen Downey’s book – Think Python.

Thanks to Downey’s teacher style, this time I think it’s going to stick with me. Also it helps to have the Enthought Canopy Express – a free tool with an integrated IDE to practice Python along the way.

Due to my previous programming experience with C, this time it took me just a week to finish the book during my “leisure” time. Also, having the free e-book (Thanks to Allen Downey’s generosity) side by side with Canopy makes a good hands-on experience. All the examples and downloadable directly from

It’s very helpful to do the exercises assigned to enhance the learning experience. Nothing beats actually coming up with the solutions on your own, then check against the downloaded solutions. Learning by doing it. That’s the ticket to retained learning. Also I refreshed my understanding of the object programming and learned a few things about GUI programming with Python and Tkinter.

“Think Python” accomplishes the goal of teaching the users how to program in Python – an excellent book and resource. Now moving on to “Think Bayes” next!