CXXNET安装

环境:ubuntu 14.04,  cuda 6.5

先安装cuda-toolkit, cuda-cublas, cudart, cuda-curand这四个安装包

cuda_6.5.14_linux_64.run

cuda-cublas-6-5_6.5-14_amd64.deb
cuda-cudart-6-5_6.5-14_amd64.deb
cuda-curand-6-5_6.5-14_amd64.deb

下载路径:http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/

安装 OpenCV

sudo apt-get install libopencv-2.4

 

配置环境变量

vi ~/.bashrc

export CUDA_HOME=/usr/local/cuda-6.5
export PATH=$CUDA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:/usr/local/lib:$LD_LIBRARY_PATH
export CPLUS_INCLUDE_PATH=/usr/local/cuda/include

 

下载一份cxxnet

git clone https://github.com/dmlc/cxxnet.git

切换至目录 cd cxxnet

拷贝一份配置到当前目录 cp make/config.mk .

修改 vi config.mk

USE_CUDA = 1

USE_BLAS = blas

USE_DIST_PS = 1
USE_OPENMP_ITER = 1

编辑 vi  Makefile, 修改如下:

CFLAGS += -g -O3 -I./mshadow/  -fPIC $(MSHADOW_CFLAGS) -fopenmp -I/usr/local/cuda/include
LDFLAGS = -pthread $(MSHADOW_LDFLAGS) -L/usr/local/cuda/lib64

 

最后编译文件

./build.sh

 

 

luarocks安装–Failed loading manifest

使用luarocks安装lunit,出现下面报错:

jerry@ubuntu:~$ sudo luarocks install lunit
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/torc h/rocks/master – Failed downloading https://raw.githubusercontent.com/torch/rocks/master/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rock s-moonscript-org/moonrocks-mirror/master – Failed downloading https://raw.githubusercontent.com/rocks-m oonscript-org/moonrocks-mirror/master/manifest

Error: No results matching query were found.

经查发现https://raw.githubusercontent.com/torch/rocks/master/manifest这个地址无法连接。只好切换另一个服务器了

方法1:

sudo luarocks install –verbose –only-server=http://rocks.moonscript.org lunit

方法2:

jerry@ubuntu:~$ mkdir ~/.cache/luarocks/https___rocks.moonscript.org

jerry@ubuntu:~$ sudo wget https://rocks.moonscript.org/manifest-5.1 -O ~/.cache/luarocks/https___rocks.moonscript.org/manifest-5.1

 

 

五种开源的深度学习软件的评估

环境: Windows 7,  Ubuntu 12.04,  H2O, RStudio, Pylearn2, Caffe, Cuba_convnet2, Octave

Java版本: H2O

可参与我的文章 : http://blog.itpub.net/16582684/viewspace-1255976/

优点:实现CPU集群,实现并行和分布式,与R语言结果比较方便处理数据
缺点:不支持GPU

C++版本 :Caffe, Cuba_convnet2

可参与我的文章 :http://blog.itpub.net/16582684/viewspace-1256400/      http://blog.itpub.net/16582684/viewspace-1254584/

Caffe  优点: 支持CPU和GPU,支持python, matlab接口,计算速度比较快,目前是图像分类效果比较好
缺点:不支持集群

Cuba_convnet2:  优点: 支持单机GPU集群
缺点: 不支持CPU, 操作有些复杂

Python版本:Pylearn2

可参与我的文章 : http://blog.itpub.net/16582684/viewspace-1243187/

优点:支持CPU和GPU
缺点:不支持并发和集群

Octave/Matlab版本: DeeplearnToolbox

可参与我的文章 :http://blog.itpub.net/16582684/viewspace-1255317/

优点: 编码简洁,容易理解其算法
缺点: 只支持单个cpu计算

总结: 以上各个版本都有自己的适应场景,没法去找出一个最好的。 目前深度学习架构发展朝两个方向: 1.  GPU集群,   2. CPU和GPU混合集群。  开源版本已经给出第一种,目前第二种也就只有一两家公司实现了。

Matlab 线性回归的向量化

环境: Ubuntu 12.04, Matlab 2013

数据如下:

jerry@hq:~/ml-class/mlclass-ex1$ more ex1data1.txt
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
5.7107,3.2522
14.164,15.505
5.734,3.1551
8.4084,7.2258
……

 

做一个线性回归,用梯度下降方法,代码如下:

matlab -nodesktop

data = load(‘ex1data1.txt’);
X = data(:, 1), y = data(:, 2);
m = length(y);
X = [ones(m, 1), X];
theta = zeros(size(data, 2), 1);

for i = 1:1500
htheta = X * theta;
theta = theta – (0.01 / m * sum(repmat((htheta – y), 1, 2) .* X, 1))’;
end

 

另一种简洁的方法如下:

inv(X’ * X) * X’ * y