$OpenXM: OpenXM/src/asir-contrib/packages/doc/nk_fb_gen_c/nk_fb_gen_c.oxg,v 1.2 2014/04/03 07:34:30 takayama Exp $
test1.c, test1.h $B$O$3$N%W%m%0%i%`$G@8@.$5$l$?Nc(B. data, $B=i4|CM$O$9$G$K@_Dj:Q(B.
/* $B$^$@=q$$$F$J$$(B.
begin: include|
@include nk_fb_gen_c_intro.ja
end:
*/
/* $B$^$@=q$$$F$J$$(B.
begin: include|
@include nk_fb_gen_c_intro.en
end:
*/
/*&usage-ja
begin: nk_fb_gen_c.gen_c(N)
{N} $B<!85(B Fisher-Bingham $BJ,I[$K$D$$$F$N:GL`?dDj$r(B HGD $BK!(B(holonomic gradient descent) $B$G$d$k$?$a$N(B C $B$N%W%m%0%i%`$r@8@.$9$k(B.
description:
$B$3$N4X?t$K$h$j(B, testN.c, testN.h $B$J$kFs$D$N(B C $B$N%W%m%0%i%`$,@8@.$5$l$k(B.
testN.c $B$K%G!<%?(B, $B:GL`?dDjC5:wMQ$N%Q%i%a!<%?=i4|CM$r@_Dj$9$k(B.
$B%3%^%s%I(B
@quotation
@code{gcc testN.c $OpenXM_HOME/lib/libko_fb.a -lgsl -lblas }
@end quotation
$B$G<B9T2DG=7A<0$N%U%!%$%k$r:n@.$9$k(B. @*
$B$J$*(B,
libko_fb.a $B$O(B @file{OpenXM/src/hgm/fisher-bingham/src/} $B$G(B @code{make install} $B$9$k$3$H$K$h$j@8@.$5$l$k(B.
$B$^$?%7%9%F%`$K$O(B gsl $B$,%$%s%9%H!<%k$5$l$F$$$J$$$H$$$1$J$$(B.
@file{OpenXM/src/hgm/fisher-bingham/src/Testdata} $B$K%5%s%W%k$N(B
$B%G!<%?(B, $B:GL`?dDjC5:wMQ$N%Q%i%a!<%?=i4|CM$,$"$k(B. @*
testN.h $B$N(B @code{#define MULTIMIN_FDFMINIMIZER_TYPE} $B$G(B gsl $B$N$I$N:GE,2=4X?t$r8F$S=P$9$+JQ99$G$-$k(B.
testN.h $B$N(B @code{#define ODEIV_STEP_TYPE} $B$G(B gsl $B$N$I$N>oHyJ,J}Dx<0?tCM2r@O4X?t$r8F$S=P$9$+JQ99$G$-$k(B. @*
$B%"%k%4%j%:%`$N>\:Y$O(B,
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}
$B$r;2>H(B. @*
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 $B$NLdBj$r2r$/(B program $B$r@8@.(B.
generate test1.h
generate test1.c
1
[2187] quit;
$ emacs test1.c &
Write data here.
$B$H%3%a%s%H$K=q$+$l$F$$$k$H$3$m$N8e(B
$B$K(B $(OpenXM_HOME)/src/hgm/fisher-bingham/Testdata/s1_wind_data.h $B$rA^F~(B.
$BJ]B8=*N;(B.
$ 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
$B$3$3$G(B, points $B$,(B parameter x11,x12,x22,y1,y2 $B$N?dDjCM(B.
Value 3.4421 $B$,(B $BL`EYCM$N5U?t$G(B, $B$3$l$,:G>.2=$5$l$F$$$k(B.
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:
*/