Google Code Block

2018年4月24日

Switch CUDA between (8.0 / 9.0 / 9.1) quickly with bash script

Download bash script : switch_cuda.sh


#!/bin/bash
echo "------------- Current Cuda Version -------------"
nvcc --version
NVCC_VER="$(nvcc --version)"
NVCC_VER_D=$(echo $NVCC_VER | cut -d',' -f 3,4)
echo ""
echo "Cuda ="$NVCC_VER_D
V91="V9.1"
V90="V9.0"
V80="V8.0"
current_ver=""
if [[ $NVCC_VER_D == *"$V90"* ]]; then
read -p "Switch to (8.0 / 9.1) ? " tar_cuda_ver
current_ver="9.0"
elif [[ $NVCC_VER_D == *"$V80"* ]]; then
read -p "Switch to (9.0 / 9.1) ? " tar_cuda_ver
current_ver="8.0"
elif [[ $NVCC_VER_D == *"$V91"* ]]; then
read -p "Switch to (8.0 / 9.0) ? " tar_cuda_ver
current_ver="9.1"
fi
CUDA_PATH="/usr/local/cuda-"$tar_cuda_ver
if [ -d $CUDA_PATH ]; then
full_tar_ver=V$tar_cuda_ver
if [[ $NVCC_VER_D == *"$full_tar_ver"* ]]; then
echo "You are already in use of Cuda"$NVCC_VER_D
else
echo "Switching to Cuda "$full_tar_ver" ..."
sudo ln -sfn $CUDA_PATH /usr/local/cuda
echo "Switch to Cuda" $tar_cuda_ver " Success !!"
fi
else
echo "Incorrect Cuda Version "$tar_cuda_ver
fi
echo ""
echo "------------- Current Cuda Version -------------"
nvcc --version


ps. Tensorflow Version Sheet
VersioncuDNNCUDA
tensorflow_gpu-1.7.079
tensorflow_gpu-1.6.079
tensorflow_gpu-1.5.079
tensorflow_gpu-1.4.068
tensorflow_gpu-1.3.068
tensorflow_gpu-1.2.05.18
tensorflow_gpu-1.1.05.18
tensorflow_gpu-1.0.05.18

2018年4月9日

Setting up Sclite for Linux ( sclite Version: 2.10, SCTK Version: 1.3 )

Download the prebuilt Sclite 2.10 binary for linux
(Build Environment : Ubuntu 16.04 @ x86_64)

or Build Sclite
1. Go to the SCTK website and download SCKT
sctk-2.4.10-20151007-1312Z.tar.bz2

2. Extract and build
make config
make all

3. Test Sclite
sclite -h csrnab.hyp -r csrnab.ref -i wsj

sclite -h tests.hyp -r tests.ref -i spu_id

4. Success :)


Reference

  1. NIST:https://www.nist.gov/itl/iad/mig/tools
  2. Sclite Commandline Options http://www1.icsi.berkeley.edu/Speech/docs/sctk-1.2/options.htm#options_name_0
  3. Sclite Intro http://www1.icsi.berkeley.edu/Speech/docs/sctk-1.2/sclite.htm
  4. Speech Recognition – Setting up sclite word alignment:http://mariangemarcano.blogspot.tw/2012/09/speech-recognition-setting-up-sclite.html
  5. using slcite:http://troylee2008.blogspot.tw/2010/03/using-sclite.html
  6. How to compile and install NIST Scoring Toolkit (SCTK) on Red Hat Enterprise Linux (RHEL) 7.2 http://ellismis.com/2016/10/15/how-to-compile-and-install-nist-scoring-toolkit-sctk-on-red-hat-enterprise-linux-rhel-7-2/


2016年12月1日

Environment Setup for Torch and fast-neural-style on Ubuntu

1. Install CUDA 8.0 and CUDNN 5.1

Please refer to Setup CUDA / CUDNN and Chainer for deep learning on Ubuntu 16.04


2. Install Torch from Torch#GetStarted

# in a terminal, run the commands WITHOUT sudo
git clone https://github.com/torch/distro.git ~/torch --recursive cd ~/torch; bash install-deps; ./install.sh # On Linux with bash
source ~/.bashrc

3. Install lua dependencies from torch/rocks on GitHub

git clone https://github.com/torch/rocks

luarocks install totem-0-0.rockspec  && 
luarocks install util-0-0.rockspec  && 
luarocks install fn-0-0.rockspec  && 
luarocks install pprint-0-0.rockspec  && 
luarocks install logroll-0-0.rockspec  && 
luarocks install hdf5-20-0.rockspec  &&

4. Run a Torch project : fast-neural-style

git clone https://github.com/jcjohnson/fast-neural-style

 - Generate a styled image
th fast_neural_style.lua -model models/eccv16/starry_night.t7 -input_image images/content/chicago.jpg -output_image out.png

Setup CUDA / CUDNN and Chainer for deep learning on Ubuntu 16.04



。Install CUDA / CUDNN and Chainer with GPU enabled

1 . Install CUDA 8.0 ( Ubuntu 14.04 )
    1. download http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_8.0.44-1_amd64.deb
    2. sudo dpkg -i cuda-repo-ubuntu1404_8.0.44-1_amd64.deb
    3. sudo apt-get update
    4. sudo apt-get install cuda
2 . Install CUDNN 5.1 for CUDA 8.0
    1. Download https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod/8.0/cudnn-8.0-linux-x64-v5.1-tgz
    2. Extract tgz file
    3. sudo cp lib64/* /usr/local/cuda/lib64/
    4. sudo cp include/* /usr/local/cuda/include/
3. Set environment to build Chainer
    1. export CFLAGS=-I/usr/local/cuda/include
    2. export LDFLAGS=-L/usr/local/cuda/lib64
    3. export LD_LIBRARY_PATH=/usr/local/cuda/lib64
4. pip install chainer --no-cache-dir -vvvv


5. Don't forget to setup the nvcc path
nano ~/.bashrc ( or nano ~/.zshrc if you use zsh :p )
add the following line to the end of the rc file
export PATH=/usr/local/cuda/bin:$PATH


。If you need image processing library on Python ...
pip install Pillow


。Install ffmpeg
tar xvf ffmpeg-release-64bit-static.tar

sudo cp ffmpeg-3.2-64bit-static/* /usr/local/bin/ 

2016年10月14日

Raspberry Pi 常用指令

Default Account password : pi / raspberry


。Machine Info Raspberry Pi B+ 
Architecture:          armv6l
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
Model name:            ARMv6-compatible processor rev 7 (v6l)
CPU max MHz:           1000.0000
CPU min MHz:           700.0000

。Updating
sudo apt-get clean

sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade && sudo apt-get -y autoremove

。Firmware Updating
sudo apt-get install rpi-update
sudo rpi-update

。Screen
sudo apt-get install screen
screen
screen -list
Reconnect : screen -r

。Show disk info / space
lsblk
df -h
show disk size: du -hs dic/*

。Python 
sudo apt-get install python-pip

。Crontab
 - 編輯 : crontab -e
 - 顯示執行 log : grep CRON /var/log/syslog
 - check status : sudo service cron status
 - restart : sudo service cron restart

。Git
 - Add and push files

git add .
git commit -a -m "commit" (do not need commit message either)
git push
 - Remember Git login info:
git config --global credential.helper 'cache --timeout 360000'

2012年6月20日

以台股歷史收盤價的統計分布為基礎的籌碼管控機制

籌碼管控絕對是在資本市場能夠獲勝的一個重要關鍵,其基本概念是在市場指數低點時增加持股水位,在市場高點時降低持股。若以台股為例,應該要在大盤點數幾點時減碼,幾點時加碼?

我收集了1995年1月至2012年6月的台股每日收盤指數, 算出其平均值為6814,標準差為1428。接著以每0.1個標準差為區間,計算出區間內指數出現次數及機率,整理出一分布圖,如下圖所示:


我發現了幾個蠻有趣的現象:

1. 本來以為分布圖會相當接近於常態分佈,但從分布圖中可以看到兩個峰值並不屬於常態分佈,原來股市點數也早已M型化了。最常出現的指數區間為 5814 ~ 5957點(B區),出現頻率為4.32%,第二出現次數較多的區間為7528~7671點(C區),出現頻率為 4.06%。這說明了在股票市場中,投資者不是較為悲觀,就是較為樂觀,造成了兩個在離均值半個標準的區間中出現了峰值(常態分布中,峰值應為均值),至於A區和D區則是過度恐慌區和過度樂觀區。

2.  在標準差 1.7 ~2.4 的指數區間,即大盤為9242以上,機率為4.28%,另在標準差 -1.7~-2.4 指數為 4386以下時,統計機率為 2.88%。換言之,指數在極端不合理的價位時,高點出現次數為低點的1.5倍,這說明了投資者勇於追高炒熱泡沫的心態。

以上是投資心理學的部分,投資者的心態的確可以從此分布圖中得到呼應。

既然已經知道了台股各區間指數出現的頻率,那就可以用一個很簡單的方法來做籌碼管控:

     100% - (台股最低點至目前指數所出現的統計機率) = 持股比例

按照這個公式所算出來的持股比例為:



這是一個很簡單,應該也會是一個有效的方法,在低點不斷加碼,而在指數墊高時賣出。
改天有空來寫一篇驗證文,例如以台灣50(0050)為標的,在使用此籌碼管控模型時的績效如何?

2012年2月25日

Words of Wisdom

 

Watch your thoughts,
for they become words.

Watch your words,
for they become actions.

Watch your actions,
for they become habits.

Watch your habits,
for they become your character.

And watch your character,
for it becomes your destiny.

What we think, we become.

Said from Margaret Thatcher, The Movie Iron Lady