mlpack (machine learning package)
インストールガイドは、ダウンロードしたものからdoxygenで生成。
yum install lapack-devel (1/4): blas-3.2.1-4.fc13.x86_64.rpm | 321 kB 00:02 (2/4): blas-devel-3.2.1-4.fc13.x86_64.rpm | 9.2 kB 00:00 (3/4): lapack-3.2.1-4.fc13.x86_64.rpm | 4.3 MB 00:19 (4/4): lapack-devel-3.2.1-4.fc13.x86_64.rpm | 9.2 kB 00:00 -------------------------------------------------------------------------------- 合計 197 kB/s | 4.6 MB 00:24 インストールしました: lapack-devel.x86_64 0:3.2.1-4.fc13 依存性関連をインストールしました: blas.x86_64 0:3.2.1-4.fc13 blas-devel.x86_64 0:3.2.1-4.fc13 lapack.x86_64 0:3.2.1-4.fc13
wget -4 http://sourceforge.net/projects/arma/files/armadillo-2.4.4.tar.gz tar -xzvf armadillo-2.4.4.tar.gzcmakeでコンパイルすることにするが、その前提としてLAPACK, BLAS, ATLAS, Boostが望ましいと書いてある。
cmake . 〜〜 最後の.は必要 make make install 〜〜 installにはroot権限必要
yum install libxml2 (1/2): libxml2-2.7.7-1.fc13_2.7.7-2.fc13.x86_64.drpm | 127 kB 00:02 (2/2): libxml2-python-2.7.7-1.fc13_2.7.7-2.fc13.x86_64.d | 31 kB 00:00 更新しました: libxml2.x86_64 0:2.7.7-2.fc13 依存性を更新しました: libxml2-python.x86_64 0:2.7.7-2.fc13 yum install libxml2-devel libxml2-devel x86_64 2.7.7-2.fc13 updates 1.1 M インストールしました: libxml2-devel.x86_64 0:2.7.7-2.fc13
wget -4 http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.gz/download tar -xzvf boost* cd boost* mv boost_1_49_0 /usr/local/ cd /usr/local/boost* ./booststrap.sh ./b2 install
cd build cmake ../ make make install
サンプル covariance
// Includes all relevant components of MLPACK. #include <mlpack/core.hpp> // Convenience. using namespace mlpack; int main() { // First, load the data. arma::mat data; // Use data::Load() which transposes the matrix. data::Load("data.csv", data, true); // Now compute the covariance. We assume that the data is already centered. // Remember, because the matrix is column-major, the covariance operation is // transposed. arma::mat cov = data * trans(data) / data.n_cols; // Save the output. data::Save("cov.csv", cov, true); }
コンパイルは
g++ -c -o covariance.o covariance.cpp -I/usr/include/libxml2 -I/usr/local/include/ g++ -o covariance covariance.o -lmlpack -larmadillo
実行する時に、もしldできないと言ってきたら(/usr/local/libがLDパスに入っていないため)
sudo ldconfig
とするか、実行前にいつも
LD_LIBRARY_PATH=/usr/local/lib export LD_LIBRARY_PATH
とするか。
gmm (Gaussian Mixture Model)を使うと、
gmm -h でヘルプ gmm -i 入力ファイル -o 出力ファイル -g 正規分布の数 で実行 gmm -i test.csv -g 2
これによって、test.csvが解析され、出力(デフォルト名)gmm.xmlが生成される。
OpenCVにもGMMのEMアルゴリズムがある ⇒ http://opencv.itseez.com/modules/ml/doc/expectation_maximization.html