comparison rDiff/src/locfit/Source/mlfut.c @ 0:0f80a5141704

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