2017年6月23日 星期五

Jupyter Notebook Keyboard Shortcut

Command Mode (press Esc to enable)

Enter
enter edit mode
Shift-­Enter
run cell, select below
Ctrl-Enter
run cell
Alt-Enter
run cell, insert below
Y
to code
M
to markdown
R
to raw
1
to heading 1
2,3,4,5,6
to heading 2,3,4,5,6
Up/K
select cell above
Down/J
select cell below
A/B
insert cell above/­below
X
cut selected cell
C
copy selected cell
Shift-V
paste cell above
V
paste cell below
Z
undo last cell deletion
D,D
delete selected cell
Shift-M
merge cell below
Ctrl-S
Save and Checkpoint
L
toggle line numbers
O
toggle output
Shift-O
toggle output scrolling
Esc
close pager
H
show keyboard shortcut help dialog
I,I
interrupt kernel
0,0
restart kernel
Space
scroll down
Shift-­Space
scroll up
Shift
ignore
 

Edit Mode (press Enter to enable)

Tab
code completion or indent
Shift-Tab
tooltip
Ctrl-]
indent
Ctrl-[
dedent
Ctrl-A
select all
Ctrl-Z
undo
Ctrl-S­hift-Z
redo
Ctrl-Y
redo
Ctrl-Home
go to cell start
Ctrl-Up
go to cell start
Ctrl-End
go to cell end
Ctrl-Down
go to cell end
Ctrl-Left
go one word left
Ctrl-Right
go one word right
Ctrl-B­ack­space
delete word before
Ctrl-D­elete
delete word after
Esc
command mode
Ctrl-M
command mode
Shift-­Enter
run cell, select below
Ctrl-Enter
run cell
Alt-Enter
run cell, insert below
Ctrl-S­hif­t-S­ubtract
split cell
Ctrl-S­hift--
split cell
Ctrl-S
Save and Checkpoint
Up
move cursor up or previous cell
Down
move cursor down or next cell
Ctrl-/
toggle comment on current or selected lines

2017年6月9日 星期五

Matlab Advanced Data Structure

Reference:

http://blog.sina.com.cn/s/blog_4cf8aad30102wcu3.html

 

第一代的 matlab user (包含我)主要驚艷於 matrix (or vector, array) data type.  可以很方便做 matrix and vector operations. 特別是 element-wise operation (e.g. .* .^) 獨樹一幟,非常有用。但之後缺乏亮點,雖然也有 OOP matlab, 比起 python, caffe, tensorflow,  並沒有引起太大的注意 (at least for me).

隨著 machine learning and deep learning 變成主流應用。Matlab 終於找到新的舞台。除了提供相關的 toolbox, app, xxxLearner (e.g. ClassificationLearner),  visualization tools 之外。也更新了 data structure and load function.  本文討論 Matlab advanced data structure.  

 

Table

Matlab 2013b 引入新的 data structure 叫做 table.  Table 類似 statistics toolbox 的 dataset.  Table 的目的就是取代 dataset.   Table 用於各類數據,比起 array 更廣泛。

NewImage

2017年5月29日 星期一

漢語拼音

 

我的中文打字是從大易開始。當時大易是熱門的輸入法,和倉頡並列為最快的專業輸入法。大易和倉頡都是字根輸入法,有別於注音的拼音輸入法。

字根輸入法 pro:  不用選字,速度快。con: 必須記得所有字根。

拼音輸入法 pro: 只要記得發音,不需要記任何字型字根。con: 同音字很多。需要選字自然速度就慢。

不過風水輪流轉,拼音結合自動選字選詞,可以大幅加速輸入法的速度。

甚至只要打聲母就可以選詞。加上手機大多只支持拼音輸入法。

 

台灣最普遍的拼音就是注音輸入法,不用學就可用。不過我想挑戰自己。看老狗是否能學新把戲-漢語拼音。加上重新 refresh 注音。另外以後也可以看懂漢語拼音。

這篇文章就是用漢語拼音打成。

 

Step 1: 設定漢語拼音輸入法,但用繁體字型。

Windows  裡其實已有內建漢語拼音輸入法,只要稍微變更下設定,便能輸出繁體中文字,不用再安裝其他的漢語拼音輸入法。

請參考本文

 

Step 2: 最重要就是以下注音和漢語拼音對照表!!!!

https://hiraku.tw/2011/10/2784/

NewImage 

一xx => i xx

X xx => u xx

U xx => u xx

2017年5月7日 星期日

Google Cloud Platform GCP - Tensorflow Hello

 

本文介紹如何在 GCP install Anaconda and Tensorflow.  就我而言是最簡單的方式。

Step0: Create a VM (choose OS: Debian 8 或 Ubuntu TLS 14.04).  請參考前文。

Step1:  Install Anaconda

Reference: 

https://haroldsoh.com/2016/04/28/set-up-anaconda-ipython-tensorflow-julia-on-a-google-compute-engine-vm/

> mkdir downloads

> cd downloads

wget http://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86_64.sh

bash Anaconda3-4.3.1-Linux-x86_64.sh

source ~/.bashrc

 

2017/8/13 update

Anaconda update to 4.4.0 version

 

 

Step2: Install Tensorflow

Reference:

https://www.tensorflow.org/install/install_linux#InstallingAnaconda

Anaconda install Tensorflow 非常容易也非常快 (because of GCP?) !

>  conda create -n tensorflow

> source activate tensorflow

再來是 install python tensorflow packages.  先 check python version: 3.6.0

(Tensorflow)$ > pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp36-cp36m-linux_x86_64.whl

 

2017/8/13 update

Tensorflow update to 1.2.1 version

 

下一步是確認 tensorflow 是否 ok.

Run python

>>>import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>>print(sess.run(hello))

 

Step3: Do a linear regression

參考以下 tutorial.

https://www.tensorflow.org/get_started/get_started

import numpy as np
import tensorflow as tf

# Model parameters
W
= tf.Variable([.3], tf.float32)
b
= tf.Variable([-.3], tf.float32)
# Model input and output
x
= tf.placeholder(tf.float32)
linear_model
= W * x + b
y
= tf.placeholder(tf.float32)
# loss
loss
= tf.reduce_sum(tf.square(linear_model - y))# sum of the squares
# optimizer
optimizer
= tf.train.GradientDescentOptimizer(0.01)
train
= optimizer.minimize(loss)
# training data
x_train
=[1,2,3,4]
y_train
=[0,-1,-2,-3]
# training loop
init
= tf.global_variables_initializer()
sess
= tf.Session()
sess
.run(init)# reset values to wrong
for i in range(1000):
  sess
.run(train,{x:x_train, y:y_train})

# evaluate training accuracy
curr_W
, curr_b, curr_loss  = sess.run([W, b, loss],{x:x_train, y:y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))


2017年5月5日 星期五

Google Cloud Platform GCP - Tutorial

 

Google Cloud Platform 的 Quickstarts 蠻有參考價值。

https://cloud.google.com/getting-started/#ten-min-tutorial-section

 

Step1: Create a VM instance running Debian 8 OS

Step2: Install Apache(2) server and put /var/www/html/index.html

Step3: Try compute engine, 其實就是 step 1 + use python for a simple http server.

Step4: Try to run github sample code.  I pick the Python Flask Skeleton for Google App Engine

 

(a) pip use apt-get (Debian) or yum (centos or redhat)

   > sudo apt-get install python-pip

(b) install google cloud SDK 包含 gcloud, gsutil, bq, etc. command-line tools.  

How?   可以參考 https://cloud.google.com/sdk/downloads

Download sdk.

Run install.sh

Initialize SDK:  > sudo gcloud init

不過應該有更容易的方法 install Cloud SDK, to be checked.

 

(c) install App Engine Python SDK:  How : > sudo gcloud components install app-engine-python

(d) > sudo gcloud components install app-engine-python-extras

 

接下來就是參考 git 的 tutorial

https://github.com/GoogleCloudPlatform/appengine-flask-skeleton

> sudo apt-get install git

> sudo  git clone https://github.com/GoogleCloudPlatform/appengine-flask-skeleton.git 

> cd appengine-flask-skeleton

> sudo pip install -r requirements.txt -t lib

不過 python 仍然有問題。這是 python 最麻煩的地方。要解決 packages 之間的相容性問題。一般需要 pip, virtualenv, etc.  請參考前文用 anaconda 解決 pip, virtualenv, 和相容性問題。

我找到一個很好的 blog.

https://haroldsoh.com/2016/04/28/set-up-anaconda-ipython-tensorflow-julia-on-a-google-compute-engine-vm/

 

Finally I made one work in “google Interactive Tutorial” 中的 “my-instance” VM.

I install anaconda2 and anaconda3, and tensor flow on anaconda3. 

 

 


2017年5月1日 星期一

Google Cloud Platform for Machine Learning

 

之前在 linux (including using Raspberry pi) 作了一些 Machine Learning (ML) 的試驗。用了 OpenCV, Caffe. 

自從 Google promote TensorFlow 之後。一直想再試一試。之前都是想用電競的主機或 notebook.  考慮價格高同時設定比較麻煩。因此開始留意幾家 cloud service providers. 

包含 Google (Google Cloud Platform - GCP), Amazon (AWS), Ali (阿里雲), Microsoft (Azure).

最後選用 GCP 主要是 (1) TensorFlow 就是 Google 提供,相容性應該最好。 (2) 有 300 hour free trial.

 

I checked on the web, following the following link on Udacity example

 

Step 1. 

Register in Google Cloud Platform -- easy if you have google account already.  

Create a project : My First Project (default)

NewImage

 

Step 2: Click on the "Activate Google Cloud Shell" on the top right button.

 

Step 3: in the shell window

List machine types:

> gcloud compute machine-types list

 

Step 4: Create an instance (VM?)

> gcloud compute instances create tf  --image container-vm  --zone asia-east1-c  --machine-type n1-standard-2

=> tf is the name of the VM?  (image container)  The container-vm is deprecate.  

=> asia-east1 can change to europe or us-west or us-east

=> n1 type computer and 2 CPUs

 

Step 5:  copy a tensor flow example from Udacity

sudo docker run -d -p 8888:8888 --name tf b.gcr.io/tensorflow-udacity/assignments:0.5.0

 

 

Step 6: Find the instance in the dashboard and edit default network

 

NewImage

NewImage

 

Too hard to get it works.

 

Finally I made one work in “google Interactive Tutorial” 中的 “my-instance” VM.

I install anaconda2 and anaconda3, and tensor flow on anaconda3. 

 

 

Back to wordpress first.   參考梅問題教學網

以下是 wordpress 的 ip address and paswd.

 

NewImage

NewImage

 

Finally I found the "Getting Started with Google Cloud Platform"

追蹤者