XML: Request and Parse with Swift

This tutorial is about requesting and parsing XML using Swift.

XML stands for eXtensible Markup Language and is designed to carry data. To get the weather forecast information of Halifax, one can use the following RSS feed from the feeds.csv file:


Enter the following url into Chrome can show the forecast information in the form of raw text.


Next, we will get and parse the xml file using Xcode playground.

Continue reading “XML: Request and Parse with Swift”

Beta Distribution


In this post, I am going to talk about Beta Distribution and some intuitive interpretations behind it.

An Example
Suppose we have two coins (A and B), and we are making a statistical experiment to identify whether these coins are biased or not. For coin A, we tossed 5 times and the results are: 1,0,0,0,0. (1 indicates Head and 0 indicates Tail). For coin B, we tossed 10 times and the results are: 1,1,0,0,0,0,0,0,0,0. The probability for theses two coins to be Tail are identical: 0.2. Is it safe to say, both coins equally favour the Tail?

Continue reading “Beta Distribution”

Solved: not able to connect to Google Compute Engine on port 22

Google has provided its infrastructure via Google Cloud Platform to developers for building applications, as an alternative to Amazon Web Service. The setup of a new instance is simple and intuitive, however, it is frustrating not being able to connect to the instance via ssh. After some research, I found out how to resolve the problem, and I hope it can help others who are having the same issue.

The Problem
Connection Failed: We are not able to connect to the VM on port 22.
I could not even telnet IP 22

The Solution
1. Activate Google Cloud Shell
2. Add a rule to the firewall to allow traffic from port 22:
gcloud compute firewall-rules create allowssh –allow tcp:22 –source-ranges

How to read a paper

The first principle is that you must not fool yourself — and you are the easiest person to fool.  – Richard Feynman

It is often helpful to read with questions in mind. This post summarizes a list of questions worthy asking while reading a paper. I would like to make this post a living document about how to read a paper, as I read more materials and gain more understanding of scientific research. The content of this post is largely from the references listed in the end. I greatly acknowledge the contributions from the references. Continue reading “How to read a paper”

Understanding the prefix-function of the Knuth-Morris-Pratt algorithm

Intuition is nothing but the outcome of earlier intellectual experience.    – Albert Einstein

There are plenty of tutorials about the ideas of the KMP algorithm, leaving us the wonder and owe of its magnificent simplicity and effectiveness. But one important part is frequently missing – why the prefix function can be computed in that particular way; what is the rationale behind the computation of the prefix function. This post aims to demystify the prefix function and elaborate on the proofs to understand why it works.

Let’s first review the computation of the prefix function, as shown below.
Screen Shot 2016-04-20 at 5.37.41 PM Continue reading “Understanding the prefix-function of the Knuth-Morris-Pratt algorithm”

How to do research

One of the biggest questions that graduate students have is “how to do research”. This post summarizes resources online about how to do research, and I hope it is helpful to the audience.

[1] How to do research at MIT AI lab link
reading, making connections, learning other fields, notebooks, writing, talks,  programming, advisors, thesis, research methodology, emotional factors.

[2] How to do research (advice) link
thinking of the question, answering the question, communicating the answer

[3] How to do graduate-level research: some advice link
Personal and professional principles: motivations and goals, tracking progress, time management, dealing with people, collaboration and mentoring, quality, attitude, dealing with failure, taking advantage of opportunities
The craft of research: keeping a notebook, reading, listening, talking, writing, programming, mathematical analysis, background subject knowledge
The art of research: identifying a problem, formulating a well-defined problem, thinking about a research problem, your advisor, the thesis