Skip to main content

Posts

Showing posts from 2015

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

Using markdown with blogspot

How to use markdown with blogspot Originally, BlogSpot does not support markdown very well. It makes its disadvantage compared with new services such as github.io. However, we still can write markdown then post it to blogspot with online tools. Markdown editor I am using http://dillinger.io/ but there are other services. Convert Markdown code to HTML code Dillinger can export Markdown code to HTML code, but we have to download a new generated HTML file. I do not like it so much, so there is a website http://daringfireball.net/projects/markdown/dingus so we can convert and get HTML code directly, then just copy and paste it to Blogspot.

Installing tensorflow on Mac OS 10.11

Tensorflow (https://www.tensorflow.org/) is the open source deep learning library from Google (http://www.wired.com/2015/11/google-open-sources-its-artificial-intelligence-engine/). Installing Tensorflow is not easy on Mac if you follow exactly the installation instruction on the homepage. I have no idea why. I have error then error while trying to install Tensorflow with pip, with virtualenv, or even with Docker. However, with Anaconda (https://www.continuum.io/downloads), it will be easy. The trick is you should download the wheel file and install it offline other than retrieving it online as suggested by Tensorflow homepage. So, with anaconda for python2 installed, I did: # create a new environment with sklearn installed, up to you # if you want a pure Python, replace scikit-learn by python conda create -n tensorflow scikit-learn # activate the new environment source activate tensorflow # download the wheel file curl https://storage.googleapis.com/tensorflo...

Testing the difference between two correlations in R

Introduction Correlation is the measurement to measure how two datasets increase or decrease together. It's a real number range from -1 (i.e, when one dataset increases, another one decreases and vice versa) to +1 (i.e, these two datasets increase or decrease together). Value 0 means there is no relationship between two datasets. Calculating correlation Calculating correlation of two datasets in R is quite straightforward: In R: > x = c (1,5,2,6,7) > y = c (2,4,3,9,-5) > cor(x,y) [1] -0.1459338 Usually, a single value does not say much in statistics. You need a confidence level. > cor.test (x, y) Pearson's product-moment correlation data:  x and y t = -0.2555, df = 3, p-value = 0.8149 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval:  -0.9109173  0.8451475 sample estimates:        cor  -0.1459338  The function 'cor.test' will gives you the correlation, ...

An interesting card game

Here is a very interesting card game which has been introduced by Prof. Kandori at University of Tokyo. There are two players, one is Red and one is Black. Each players have four cards in corresponding colors: King (K), Ace (A), 2 and 3. Each round, both two players simultaneously (i.e, together) select one card from their hand, and determine the winner as the rule in the picture: - If two cards are two Kings, Red wins. - If one card is King and other card is not, Black wins. - Otherwise, if number of two cards are different, Red wins. If number of two cards are identical, Black wins. At first sight, it is very easy to say that the game is favor on Red. But it is not true. Even if both players play randomly, the Black has a bigger chance to win. You can check the simulation at: http://www.codeskulptor.org/#user39_B0DWPHGSyD_1.py It is easy to calculate the chance to win of Black is 9/16. But we can go further. Take into account the fact that K is very important ...

Generating a random number between 1 and 6 using only a function which generate 0 or 1

Suppose you have a function toss, which returns 0 or 1 randomly. Now you need to write a function which uses toss () to generate a random integer number between 1 and 6. The idea is: you toss 3 times, and if the value is outside of first six values, you toss 3 times again. The Python code is following: #suppose we have a function called "toss" which return 0 and 1 randomly #we need to write a function to generate number between 1 and 6 #means 1 <= x <= 6 use only the function "toss" from random import randint def toss (): return randint (0, 1) def generateRandomBetween1And6 (): while (True): sum = 0 for i in range (3): sum += toss () * (2 ** i) if (sum >= 1 and sum <= 6): return sum #test res = [0] * 6 for i in range (10000): num = generateRandomBetween1And6 (); res [num - 1] += 1 for i in range (6): print(str(res[i]) + '\n')