File: [local] / OpenXM / src / asir-contrib / packages / src / tk_r.rr (download)
Revision 1.1, Thu Jan 31 05:00:11 2013 UTC (11 years, 3 months ago) by takayama
Branch: MAIN
CVS Tags: RELEASE_1_3_1_13b, HEAD
tk_r.markov(L) returns the Markov basis of L in the R format.
R can parse the result by
eval(parse(text= output of tk_r.markov ))
Example. tk_r.markov([[1,2,3]]);
tk_r.markov calls nk_4ti2.markov.
|
/* $OpenXM: OpenXM/src/asir-contrib/packages/src/tk_r.rr,v 1.1 2013/01/31 05:00:11 takayama Exp $ */
/*
See also,
src/asir-port/cgi/cgi-asir-r-markov.sh
src/R/r-client/Roxm/ in the R package format. Get Markov basis by cgi-asir
*/
import("nk_gfan_4ti2/nk_4ti2.rr")$
/* #define TEST */
#ifndef TEST
module tk_r;
localf asir2r_list$
localf asir2r_c$
localf markov$
#endif
def asir2r_list(L) {
if (!((type(L) >= 4) && (type(L) <=6))) return rtostr(L);
if (type(L) == 5) L = vtol(L);
if (type(L) == 6) L = matrix_matrix_to_list(L);
if (length(L) == 0) return "list()";
L = map(asir2r_list,L);
S = "list(";
for (I=0; I<length(L)-1; I++) S += L[I]+",";
S += L[length(L)-1]+")";
return S;
}
def asir2r_c(L) {
if (!((type(L) >= 4) && (type(L) <=6))) return rtostr(L);
if (type(L) == 5) L = vtol(L);
if (type(L) == 6) L = matrix_matrix_to_list(L);
if (length(L) == 0) return "c()";
L = map(asir2r_c,L);
S = "c(";
for (I=0; I<length(L)-1; I++) S += L[I]+",";
S += L[length(L)-1]+")";
return S;
}
/*
example: markov([[1,2,3]]);
example: markov([[1,1,1,1],[0,1,0,1],[0,0,1,1]]);
*/
def markov(L) {
M=nk_4ti2.markov(L);
return asir2r_list(map(asir2r_c,M));
}
#ifndef TEST
endmodule$
#endif
end$