$OpenXM: OpenXM/src/asir-contrib/packages/doc/nk_fb_gen_c/nk_fb_gen_c.oxg,v 1.3 2017/03/30 07:01:30 takayama Exp $ test1.c, test1.h はこのプログラムで生成された例. data, 初期値はすでに設定済. /* まだ書いてない. begin: include| @include nk_fb_gen_c_intro.ja end: */ /* まだ書いてない. begin: include| @include nk_fb_gen_c_intro.en end: */ /*&usage-ja begin: nk_fb_gen_c.gen_c(N) {N} 次元 Fisher-Bingham 分布についての最尤推定を HGD 法(holonomic gradient descent) でやるための C のプログラムを生成する. description: この関数により, testN.c, testN.h なる二つの C のプログラムが生成される. testN.c にデータ, 最尤推定探索用のパラメータ初期値を設定する. コマンド @quotation @code{gcc testN.c $OpenXM_HOME/lib/libko_fb.a -lgsl -lblas } @end quotation で実行可能形式のファイルを作成する. @* なお, libko_fb.a は @file{OpenXM/src/hgm/fisher-bingham/src/} で @code{make install} することにより生成される. またシステムには gsl がインストールされていないといけない. @file{OpenXM/src/hgm/fisher-bingham/src/Testdata} にサンプルの データ, 最尤推定探索用のパラメータ初期値がある. @* testN.h の @code{#define MULTIMIN_FDFMINIMIZER_TYPE} で gsl のどの最適化関数を呼び出すか変更できる. testN.h の @code{#define ODEIV_STEP_TYPE} で gsl のどの常微分方程式数値解析関数を呼び出すか変更できる. @* アルゴリズムの詳細は, T. Koyama, H. Nakayama, K. Nishiyama, N. Takayama, Holonomic Gradient Descent for the Fisher-Bingham Distribution on the d-dimensional Sphere, Computational Statistics (2013), @url{http://dx.doi.org/10.1007/s00180-013-0456-z} を参照. @* Authors; T.Koyama, H.Nakayama, K.Nishiyama, N.Takayama. example: [1854] load("nk_fb_gen_c.rr"); [2186] nk_fb_gen_c.gen_c(1); S^1 の問題を解く program を生成. generate test1.h generate test1.c 1 [2187] quit; $ emacs test1.c & Write data here. とコメントに書かれているところの後 に $(OpenXM_HOME)/src/hgm/fisher-bingham/Testdata/s1_wind_data.h を挿入. 保存終了. $ gcc test1.c $OpenXM_HOME/lib/libko_fb.a -lgsl -lblas $ ./a.out --- snip points = [1.11945, 3.33044, -0.469454, 0.904504, -0.770373] values = [3.4421, 1.13891, -0.0217944, 2.28474] grad ; 0.005644 -0.033429 -0.005644 0.045820 0.047695 norm(grad) ; 0.074535 --- snip ここで, points が parameter x11,x12,x22,y1,y2 の推定値. Value 3.4421 が 尤度値の逆数で, これが最小化されている. end: */ /*&usage-en begin: nk_fb_gen_c.gen_c(N) It generates a C program to make a MLE (maximal likelihood estimate) by the HGD (holonomic gradient descent) for {N} dimensional Fisher-Bingham distribution. description: This function generates two C programs testN.c and testN.h. After setting data and an initial point to make MLE in testN.c, build an executable file by the command @quotation @code{gcc testN.c $OpenXM_HOME/lib/libko_fb.a -lgsl -lblas } @end quotation The libray file libko_fb.a is generated by @code{make install} in the folder @file{OpenXM/src/hgm/fisher-bingham/src/} The GSL (Gnu Scientific Library) should also be installed in the system. Sample data and initial points are in @file{OpenXM/src/hgm/fisher-bingham/src/Testdata}. @* The definition @code{#define MULTIMIN_FDFMINIMIZER_TYPE} in testN.h specifies an optimization problem solver of gsl. The definition @code{#define ODEIV_STEP_TYPE} in testN.h specifies a solver of the ordinary differential equation of gsl. @* As to the algorithm, refer to T. Koyama, H. Nakayama, K. Nishiyama, N. Takayama, Holonomic Gradient Descent for the Fisher-Bingham Distribution on the d-dimensional Sphere, Computational Statistics (2013), @url{http://dx.doi.org/10.1007/s00180-013-0456-z} @* Authors; T.Koyama, H.Nakayama, K.Nishiyama, N.Takayama. example: [1854] load("nk_fb_gen_c.rr"); [2186] nk_fb_gen_c.gen_c(1); Generate a program to solve MLE on S^1 generate test1.h generate test1.c 1 [2187] quit; $ emacs test1.c & Find a line which contains Write data here and insert $(OpenXM_HOME)/src/hgm/fisher-bingham/Testdata/s1_wind_data.h. after this line. Save and quit emacs. $ gcc test1.c $OpenXM_HOME/lib/libko_fb.a -lgsl -lblas $ ./a.out --- snip points = [1.11945, 3.33044, -0.469454, 0.904504, -0.770373] values = [3.4421, 1.13891, -0.0217944, 2.28474] grad ; 0.005644 -0.033429 -0.005644 0.045820 0.047695 norm(grad) ; 0.074535 --- snip where ``points'' is the estimated value of the parameter x11,x12,x22,y1,y2. Value 3.4421 is the inverse of the likelihood which is minimized. end: */