Good explanation for BFGS and L-BFGS can be found in this textbook: https://www.dropbox.com/s/qavnl2hr170njbd/NumericalOptimization2ndedJNocedalSWright%282006%29.pdf?dl=0 In my own words: Gradient descent and its various variants have been proved to learn parameters well in practical unconstrained optimization problems. However, it may converge too slowly or too roughly depending on how you set learning rate. Remember the optimum in unconstrained …
Author Archives: czxttkl
Configure PySpark in Eclipse/Pydev
Go here and download some prebuilt version for spark. (So that you don’t need to compile spark locally later) Follow this slide: http://www.slideshare.net/prossblad/install-eclipse-for-sparkpython-49100874 to setup up Python interpretor/environment in Eclipes/Pydev
Recommendation System Review
Traditional Collaborative Filtering each user is represented by a O(N) length vector. N is the number of items. Therefore, user-item matrix has size O(MN). M is the number of users. for a user we want to recommend items for, we scan through user-item matrix, and find most similar k users. Based on the item vectors …
My Lempel-Ziv Compressor
Lempel-Ziv algorithm is a widely known compression algorithm. Its compression rate is proved to asymptotically reach the entropy of per symbol in the sequence to be compressed, when the length of the sequence is long enough.i.e., , where is per symbol entropy in the sequence . If, for example, you have a sequence of letters …
Graph Model Recap
I wrote a post before talking about sum-product algorithm: http://maider.blog.sohu.com/307377602.html At that time, I had fresh memory on how graph model works. However, today when I read the post again, I am lost again. Therefore, I want to recap the basic motivations of graph models. This post can serve as an intro to the old post. …
Use PDB to check variables before crashes
1. Use `python -i your_script.py` to execute your program with interactive mode. This means, after your program finishes executing, or your program crashes in the midway, you will enter a python shell. 2. Suppose your script has a bug so that you enter the python shell after it crashes. Now you can play with pdb …
Continue reading “Use PDB to check variables before crashes”
Leetcode 209: Minimum Size Subarray Sum
https://leetcode.com/problems/minimum-size-subarray-sum/ Minimum Size Subarray Sum Total Accepted: 20591 Total Submissions: 84896 Difficulty: Medium Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn’t one, return 0 instead. For example, given the array [2,3,1,2,4,3] and s = 7,the …
Leetcode 208: Implement Trie (Prefix Tree)
https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix Tree) Total Accepted: 18703 Total Submissions: 75061 Difficulty: Medium Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs are consist of lowercase letters a-z. Code class TrieNode(object): def __init__(self): “”” Initialize your data structure here. “”” self.nodes = dict() self.is_word = False class Trie(object): …
Continue reading “Leetcode 208: Implement Trie (Prefix Tree)”
Leetcode 220: Contains Duplicate III
https://leetcode.com/problems/contains-duplicate-iii/ Contains Duplicate III Total Accepted: 15083 Total Submissions: 90517 Difficulty: Medium Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k. Code …
Leetcode 261: Graph Valid Tree
https://leetcode.com/problems/graph-valid-tree/ Graph Valid Tree Total Accepted: 2794 Total Submissions: 10778 Difficulty: Medium Given n nodes labeled from 0 to n – 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. For example: Given n = 5 and …