The answer behind an existential question, in python!

Image by Author

Have you ever gotten the warning in Pycharm that says:

Comparison with None performed with equality operators

and wondered why?

Well, today we are going to get to the bottom of the mystery once and for all!

Be prepared, this is actually quite a deep question that might cause you to question the meaning of life.

Is it Python?

Yes yes yes!

Python is known to have two operators: “is” and “==”, and in many conventional cases they produce the same results. …

An analysis of algorithms and complexities

(Image by Author)

In this story, we are going to talk about an interesting problem about finding maximum integers in a list. This problem is deceptive in that the simple solution is really simple, but there are a couple of not so obvious tricks you can apply to it that makes a big improvement on the performance.

Problem Statement

The maximum of the sliding window

suppose I am given a list of integers:

1, 2, 3, 5, 1, 4, 3

What is the sliding window maximums if my window size is 3?

[1 2 3]5 1 4 3
1[2 3 5]1 4 3
1 2[3…

Applying the dynamic programming techniques to an interesting optimization problem

Image by Author

In this story, we are going to discuss an application of dynamic programming techniques to an optimization algorithm. Through the process of developing an optimal solution, we get to study a variety of programming techniques that leads to better performance (with a surprise at the end!).

Problem Description

The Knapsack problem

This problem is called the knapsack problem, because one would encounter a similar problem when packing items into knapsack, while trying to optimize, say, weight and value of the items packed in.

So, given a list of strings:

r1 = ['001', '11', '01', '10', '1001']

and given a container that can…

Benefits of portfolio diversifications

(Image by Author)

Signal combinations are important in many fields, it is also important in portfolio construction, let’s find out why.

Should I blend?

Not always

Suppose I have a portfolio (1) that returns 1% on even days and 0.5% on odd days:

Exploring the basics of NLP: Cleaning, NER, POS, Fuzzy String Match

Imaged by Author, using flowchart (

Whenever people talk about Natural Language Processing(NLP), images of fancy machine learning models and prospects of powerful AI pop up. But nothing starts from nowhere, at the most rudimentary level, NLP is simply a collection of tools for processing textual data to makes them clean and more uniform. Let’s begin!

Text Cleaning

Clean up the sentence

First, let’s start with the a sentence:

test001 = "01 Google Gains In Popularity, Soon Surpassing Apple"

It’s a head line so all words are capitalized and there are punctuations, we need to clean them:

# remove punctuations
import string
translator = str.maketrans('', '', string.punctuation)
test002 = test001.translate(translator)
# Output:

How to combine programming techniques

As I accumulate more experience in coding and life in general, one of the things among my observations that stood out to me is that, whenever there is a problem to be solved, there usually exists a very intuitive solution to it. Sometimes this solution happens to be efficient, sometimes grossly suboptimal. This is especially noticeable in algorithms, because an algorithm is often times a conceptualization of a real life problem, and through the algorithm the essential elements of the problem is kept, allowing us to tackle the problem directly.

The largest rectangle in a matrix is one such problem…

Taking a tour through Kalman filter with an everyday example.

(Image by Author)

When I first started learning to use Kalman filter, it seemed very complicated to me, mainly because there were so many inputs to it and you never really knew if you’ve set them correctly. By going through this example, I hope my readers will understand that the motivations and logic behind it is really very pragmatic in nature and not so complicated after all.

Drop a Tennis Ball

So let’s get started with our example.

I am dropping a tennis ball from a helicopter (or maybe my airship), I would like to predict its position in the air until it hits the ground.

Improving lowest common ancestor algorithms with disjoint set off-line.

Tarjan’s Off-line LCA Algorithm (Image by Author)

Tarjan’s Off-line Lowest Common Ancestor Algorithm is an interesting application of the disjoint set structure for optimizing the performance of determining the lowest common ancestor(LCA) of two nodes within a tree, which also involves concepts such as caching and recursion. In preparation for this story, please refer to my previous story on Lowest Common Ancestor for context.

Ok, let’s get started!

Disjoint Set

In order to understand this algorithm, we first have to have a good grasp on the concept of disjoint sets…

Disjoint sets are collections of nodes, where there is no overlap between sets.

Sounds simple, right? Actually, it is…

Lowest common ancestor of two nodes within a binary tree and the algorithms available to find it.

Image by Author

What is “Lowest Common Ancestor (LCA)”?

It is the lowest level parent shared by two nodes within a tree.

Let’s take a look at an example:

What about multivariate normal distributions? Are they basically a few normally distributed variables bundled together? Let’s take a look.

Normal distribution, also called gaussian distribution, is one of the most widely encountered distributions. One of the main reasons is that the normalized sum of independent random variables tends toward a normal distribution, regardless of the distribution of the individual variables (for example you can add a bunch of random samples that only takes on values -1 and 1, yet the sum itself actually becomes normally distributed as the number of sample you have becomes larger). This is known as the central limit theorem. …

Shuo Wang

Interesting pieces on various topics in finance and technology.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store