Code: class MergeSort(): def sort(self, arr): if len(arr) <= 1: return arr mid = len(arr) / 2 arr_left = self.sort(arr[:mid]) arr_right = self.sort(arr[mid:]) i, j, k = 0, 0, 0 while i < len(arr_left) and j < len(arr_right): if arr_left[i] < arr_right[j]: arr[k] = arr_left[i] i += 1 else: arr[k] = arr_right[j] j += 1 …
Monthly Archives: September 2016
QuickSort
Just a post for reviewing QuickSort. Every time you prepare interviews, you will need to review this classic sorting algorithm. Code # class QuickSort(): def sort(self, arr): self.sort_helper(arr, 0, len(arr) – 1) return arr def sort_helper(self, arr, left, right): if left >= right + 1: return pivot = left for i in xrange(left, right): if …
Leetcode 216: Combination Sum III
216. Combination Sum III https://leetcode.com/problems/combination-sum-iii/ Total Accepted: 45842 Total Submissions: 115036 Difficulty: Medium Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Example 1: Input: k = 3, …
“file pdftex.def” not found on Mac OS
After installing MacTex, I still encountered “File pdftex.def not found” error when compiling a tex file in TexMaker/TexShop. Here is the way to solve it: Download from pdfetx-def package from https://www.ctan.org/pkg/pdftex-def Unzip Copy the unzipped folder to the texlive installation directory. Below is what I used: sudo cp -R graphics-def /usr/local/texlive/2016/texmf-dist/
Restricted Boltzmann Machine
In this post, I am going to share with you my understanding in Restricted Boltzmann Machine (RBM). Restricted Boltzmann Machine is a stochastic artificial neural network that learns the probability distribution of input. A stochastic artificial neural network means a structure contains a series of units with values between 0 to 1 that depend on …
How to add footnote in Latex Table?
If you just use \footnote in a latex table, the footnote usually will not appear in the real pdf. The workaround is to use tablefootnote package: \usepackage{tablefootnote} at the top of `.tex` file anywhere in table you want to add footnote, use \tablefootnote{…}
Understand “Markov Chain Sampling Methods for Dirichlet Process Mixture Models”
In this post I am going to share my understanding of the paper: Markov Chain Sampling Methods for Dirichlet Process Mixture Models. In chapter 2, it introduces the basic concept of Dirichlet Process Mixture Models. In (2.1), we have: $latex y_i | \theta_i \sim F(\theta_i) \newline \theta_i | G \sim G \newline G \sim DP(G_0, \alpha)$ …
Continue reading “Understand “Markov Chain Sampling Methods for Dirichlet Process Mixture Models””
Read SAS output tables
The following tables were generated right after a simple linear regression with three independent variables was fit in SAS: The linear regression is Gallons_sold ~ price + line_ad + display. I will mainly illustrate how to read the first table. To give you a background, the number of samples is $latex n=406$ and the number …