Windows下关于稀疏编码建模工具箱SPAMS的配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JCY1009015337/article/details/53759211

SPAMS(SPArse Modeling Software)这里就不做过多地介绍啦,不懂的可以自行查找资料阅读,下面直接上干货~~

下载地址:http://spams-devel.gforge.inria.fr/index.html,我这里下载的是spams-matlab-v2.5,解压后的文件夹是这样的:


关于该工具箱各个函数的使用(每个函数都有一个测试文件供测试,在test_release文件夹中)可以参考doc文件夹下的doc_spams.pdf文件。

该工具包给出的是C++代码,所以需要编译才能最终使用。也正是因为如此,该工具箱不仅可以跨平台,而且运行速度也很快。

对于安装,可以在在HOW_TO_INSTALL.txt中有简单说明,这里稍微总结一下,就是叫你使用compile.m进行文件编译,对于不同的计算机,配置都在这个文件中调整,所以 使用matlab打开compile.m文件,前144行是用来做配置的,后面的就不要乱动了,作者是这样说的:


意思就是叫你不要乱动接下来的行。

从compile.m文件可以看到,前144行的配置主要涉及4个部分:COMPILER CONFIGURATION 编译器配置、BLAS/LAPACK CONFIGURATION 数学函数库配置、MULTITHREADING CONFIGURATION 多线程配置、PATH CONFIGURATION 路径配置。

那么我们所要做的就是根据自己的电脑修改相应的配置(其实就是设置参数,从compile.m文件中我们也可以看的出来)。我的电脑配置如下(win10 64bit、matlab R2014a、vs2013),那么我们相关配置如下:

1、COMPILER CONFIGURATION 编译器配置

%%%%%%%%%%%%% COMPILER CONFIGURATION %%%%%%%%%%%%%%%%
%编译器配置
% set up the compiler you want to use. Possible choices are
%   - 'mex' (default matlab compiler), this is the easy choice if your matlab
%           is correctly configured. Note that this choice might not compatible
%           with the option 'use_multithread=true'. 
%   - 'icc' (intel compiler), usually produces the fastest code, but the
%           compiler is not free and not installed by default.
%   - 'gcc' (gnu compiler), good choice (for Mac, use gcc >= 4.6 for
%           the multi-threaded version, otherwise set use_multithread=false).
%           For windows, you need to have cygwin installed.
%   - 'clang'
%   - 'open64' (amd compiler), optimized for opteron cpus.
%   - 'vs'  (visual studio compiler) for windows computers (10.0 or more is recommended)
%            for some unknown reason, the performance obtained with vs is poor compared to icc/gcc
compiler='mex';%这里我使用的matlab默认的编译器。我们可以使用mex -setup配置matlab默认编译器,比如我想编译现在的cpp文件,那么我配置matlab为“mex -setup C++ ”,如下图所示:


点击mex -setup C++就可以啦,其实就是执行了该命令。

注:这里其实就跟compiler='vs'一样了,只是如果配置成'vs',下面需要改vs编译器路径,使用'mex'相当于让matlab帮配置好了,后面的路径配置什么也不用管。

2、BLAS/LAPACK CONFIGURATION 数学函数库配置

 %%%%%%%%%%%% BLAS/LAPACK CONFIGURATION %%%%%%%%%%%%%%
%数学函数库配置
% set up the blas/lapack library you want to use. Possible choices are
%   - builtin: blas/lapack shipped with Matlab, 
%           same as mex: good choice if matlab is correctly configured.
%   - mkl: (intel math kernel library), usually the fastest, but not free.
%   - acml: (AMD Core math library), optimized for opteron cpus
%   - blas: (netlib version of blas/lapack), free
%   - atlas: (atlas version of blas/lapack), free,
% ==> you can also tweak this script to include your favorite blas/lapack library
blas='builtin';% 直接使用matlab自带的数学函数库就行

3、MULTITHREADING CONFIGURATION 多线程配置

%%%%%%%%%%%% MULTITHREADING CONFIGURATION %%%%%%%%%%%%%%
%多线程配置
% set true if you want to use multi-threaded capabilities of the toolbox. You
% need an appropriate compiler for that (intel compiler, most recent gcc, or visual studio pro)
use_multithread=false; % (might not compatible with compiler=mex)%上面配置编译器时已经有提示,选择mex,会与'use_multithread=true'有冲突,所以直接配置为false
% if the compilation fails on Mac, try the single-threaded version.
% to run the toolbox on a cluster, it can be a good idea to deactivate this

use_64bits_integers=true;%我的电脑是64bit,所以true。
% use this option if you have VERY large arrays/matrices 
% this option allows such matrices, but may slightly reduce the speed of the computations.

use_mkl_threads=false;
% use this option is you use the mkl library and intends to use intensively BLAS3/lapack routines
% (for multiclass logistic regression, regularization with the trace norm for instance)
% this results in a loss of performance for many other functions

% if you use the options 'mex' and 'builtin', you can proceed with the compilation by
% typing 'compile' in the matlab shell. Otherwise, you need to set up a few path below.

path_matlab='';%上面两行已经说得很清楚,使用mex编译器,直接跳过这里的两个配置即可
%path_matlab='/softs/bin/';

4、PATH CONFIGURATION 路径配置

%%%%%%%%%%%% PATH CONFIGURATION %%%%%%%%%%%%%%%%%%%%

%路径配置
% only if you do not use the options 'mex' and 'builtin'
% set up the path to the compiler libraries that you intend to use below

% 此后一律不动,只有如果使用了其他编译器、数学函数库,才需要改相应的路径

--------------------------------------------------------分割线----------------------------------------------------------------

按上面的过程配置好后,再matlab键入compile运行执行编译。编译过程顺利完成!我们可以看到在build文件夹下,有好多生成的.mexw64文件。


接下来我们进行一个代码运行测试过程,如何使用工具箱内的函数,可以参考刚才提到的doc_spams.pdf文件,里面介绍的比较详细。这里运行test_release/test_TrainDL.m文件做一个测试:

。。。。。。。。。。。。。。。。。。。。。还没运行好,估计计算量比较大吧,应该没问题,就不接着运行了~~



我的这个工具箱安装还挺顺利地呢,是不是从开始就一帆风顺呢???

no~~

我才开始也网上找了不少方法,看了好多博客(下面会给出参考博客的,参考博客包含一些遇到错误的解决方法~~)啥的,走了好多弯路,上面的是记录我的安装配置的一种情况,供大家分享交流~~

参考博客:

https://chunqiu.blog.ustc.edu.cn/?p=570

猜你喜欢

转载自blog.csdn.net/JCY1009015337/article/details/53759211