# compile and load the shared object. From unix type: # cc -c genfield.c # ld -o genfield.so -shared genfield.o -lc -lm # # Once in Splus, you need to dynamically load the shared object # file. Do this with the following command: # # dyn.load.shared("./genfield.so") # options("object.size"=5e7) # now simulate some things... # coefficients for straw # 10 01 1-1 11 20 02 precision bstraw_c(.595,-.209,.198,.105,-.179,-.011,1.0) x_matrix(rnorm(100*100),ncol=100,nrow=100) x_genfield(x,bstraw) image(x) best_mple12(straw) z_genfield(x,best,seed=2) image(z) # coefficients for wool # 10 01 1-1 11 20 02 precision wool_c(.440, .227,-.080,-.042,-.051, .005,1.0) leather_c(.548, .186,-.068,-.050,-.101,-.019,1.0) water_c(.51948, .14985,-.06494,-.07592,-.02597,-.00300,0.4995) wood_c(.43114, .21956,-.10679,-.10379, .06188,-.00200,0.500) xwool_genfield(matrix(rnorm(100*100),ncol=100,nrow=100),wool) xleather_genfield(matrix(rnorm(100*100),ncol=100,nrow=100),leather) xwater_genfield(matrix(rnorm(100*100),ncol=100,nrow=100),water) xwood_genfield(matrix(rnorm(100*100),ncol=100,nrow=100),wood) par(mfrow=c(2,3),pty="s",oma=c(0,0,0,0),mar=c(0,0,2,0)) image(x); mtext("straw",side=3,line=1) image(xwool); mtext("wool",side=3,line=1) image(xleather); mtext("leather",side=3,line=1) image(t(xwater)); mtext("water",side=3,line=1) image(xwood); mtext("wood",side=3,line=1) # generates a 3rd order Gaussian MRF # This function calls the C function sgenfield() # See the Splus manual for interfacing with C programs. genfield <- function(x,beta,iter=100,seed=1){ n_dim(x)[1]; m_dim(x)[2] lambda_beta[7] xv_as.vector(x) z_.C("sgenfield",x=as.double(xv), as.integer(n), as.integer(m), as.double(beta), as.double(lambda), as.integer(iter), as.integer(seed)) x_matrix(z$x,nrow=n) return(x) }