mlfut.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "mex.h"
  2. #include "lfev.h"
  3. void lfmxdata(lfdata *lfd, const mxArray *data)
  4. { const mxArray *tmp;
  5. double *x, *sc, *xl;
  6. int n, d, i, k;
  7. char c, ststr[16];
  8. n = lfd->n = mxGetM(mxGetField(data,0,"x"));
  9. d = lfd->d = mxGetN(mxGetField(data,0,"x"));
  10. x = mxGetPr(mxGetField(data,0,"x"));
  11. for (i=0; i<d; i++) lfd->x[i] = &x[i*n];
  12. lfd->y = mxGetPr(mxGetField(data,0,"y"));
  13. tmp = mxGetField(data,0,"weights");
  14. k = mxGetM(tmp);
  15. lfd->w = (k>1) ? mxGetPr(tmp) : NULL;
  16. tmp = mxGetField(data,0,"censor");
  17. k = mxGetM(tmp);
  18. lfd->c = (k>1) ? mxGetPr(tmp) : NULL;
  19. tmp = mxGetField(data,0,"baseline");
  20. k = mxGetM(tmp);
  21. lfd->b = (k>1) ? mxGetPr(tmp) : NULL;
  22. mxGetString(mxGetField(data,0,"style"),ststr,16);
  23. k = strlen(ststr);
  24. for (i=0; i<d; i++)
  25. { c = (k==1) ? ststr[0] : ststr[i];
  26. switch(c)
  27. { case 'a': lfd->sty[i] = STANGL; break;
  28. case 'l': lfd->sty[i] = STLEFT; break;
  29. case 'r': lfd->sty[i] = STRIGH; break;
  30. case 'c': lfd->sty[i] = STCPAR; break;
  31. default: lfd->sty[i] = 1; break;
  32. }
  33. }
  34. sc = mxGetPr(mxGetField(data,0,"scales"));
  35. k = mxGetN(mxGetField(data,0,"scales"));
  36. for (i=0; i<d; i++) lfd->sca[i] = (k==1) ? sc[0] : sc[i];
  37. xl = mxGetPr(mxGetField(data,0,"xlim"));
  38. for (i=0; i<d; i++)
  39. { lfd->xl[i] = xl[2*i];
  40. lfd->xl[i+d] = xl[2*i+1];
  41. }
  42. }
  43. void lfmxsp(smpar *sp, mxArray *mcell, int d)
  44. { double *alpha;
  45. char str[16];
  46. alpha = mxGetPr(mxGetField(mcell,0,"alpha"));
  47. nn(sp) = alpha[0];
  48. fixh(sp)= alpha[1];
  49. pen(sp) = alpha[2];
  50. mxGetString(mxGetField(mcell,0,"adaptive_criterion"),str,16);
  51. acri(sp) = lfacri(str);
  52. deg(sp) = mxGetPr(mxGetField(mcell,0,"degree"))[0];
  53. deg0(sp) = -1;
  54. mxGetString(mxGetField(mcell,0,"family"),str,16);
  55. fam(sp) = lffamily(str);
  56. mxGetString(mxGetField(mcell,0,"link"),str,16);
  57. link(sp) = lflink(str);
  58. setfamily(sp);
  59. mxGetString(mxGetField(mcell,0,"kernel"),str,16);
  60. ker(sp) = lfkernel(str);
  61. mxGetString(mxGetField(mcell,0,"kernel_type"),str,16);
  62. kt(sp) = lfketype(str);
  63. npar(sp) = calcp(sp,d);
  64. de_renorm = (int)(mxGetPr(mxGetField(mcell,0,"deren"))[0]);
  65. mxGetString(mxGetField(mcell,0,"deit"),str,16);
  66. de_itype = deitype(str);
  67. de_mint = (int)(mxGetPr(mxGetField(mcell,0,"demint"))[0]);
  68. lf_debug = (int)(mxGetPr(mxGetField(mcell,0,"debug"))[0]);
  69. }
  70. void lfmxevs(lfit *lf, mxArray *mcell)
  71. { int d, i, j;
  72. double *ll, *ur, *mg, *drv;
  73. char evstr[16], mod[16], mdir[256];
  74. evstruc *evs;
  75. fitpt *fp;
  76. deriv *dv;
  77. evs = &lf->evs;
  78. fp = &lf->fp;
  79. dv = &lf->dv;
  80. d = lf->lfd.d;
  81. if (mxIsChar(mxGetField(mcell,0,"type")))
  82. { mxGetString(mxGetField(mcell,0,"type"),evstr,16);
  83. ev(evs) = lfevstr(evstr);
  84. }
  85. else
  86. { ev(evs) = EPRES;
  87. evs->mg[0] = mxGetN(mxGetField(mcell,0,"type"));
  88. fp->xev = mxGetPr(mxGetField(mcell,0,"type"));
  89. }
  90. mxGetString(mxGetField(mxGetField(mcell,0,"module"),0,"name"),mod,16);
  91. mxGetString(mxGetField(mxGetField(mcell,0,"module"),0,"directory"),mdir,256);
  92. MODPARAMS(lf) = mxGetPr(mxGetField(mxGetField(mcell,0,"module"),0,"parameters"));
  93. MODNPARAMS(lf) = mxGetN(mxGetField(mxGetField(mcell,0,"module"),0,"parameters"));
  94. initmodule(&lf->mdl,mod,mdir,lf);
  95. ll = mxGetPr(mxGetField(mcell,0,"lower_left"));
  96. ur = mxGetPr(mxGetField(mcell,0,"upper_right"));
  97. mg = mxGetPr(mxGetField(mcell,0,"grid"));
  98. j = mxGetN(mxGetField(mcell,0,"grid"));
  99. cut(evs) = mxGetPr(mxGetField(mcell,0,"cut"))[0];
  100. for (i=0; i<d; i++)
  101. { evs->fl[i] = ll[i];
  102. evs->fl[i+d] = ur[i];
  103. if (ev(evs) != EPRES) evs->mg[i] = (j==1) ? mg[0] : mg[i];
  104. }
  105. mk(evs) = mxGetPr(mxGetField(mcell,0,"maxk"))[0];
  106. drv = mxGetPr(mxGetField(mcell,0,"derivative"));
  107. j = mxGetN(mxGetField(mcell,0,"derivative"));
  108. for (i=0; i<j; i++) dv->deriv[i] = drv[i]-1;
  109. dv->nd = (drv[0]>0) ? j : 0;
  110. }