annotate rDiff/src/locfit/Source/mlfut.c @ 3:29a698dc5c7e default tip

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