annotate rDiff/src/locfit/Source/mexpp.c @ 1:08d3a6143873

Deleted selected files
author vipints
date Tue, 08 Oct 2013 06:54:25 -0400
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 /*=================================================================
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2 * mexpp.c
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 *
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 * starting a locfit interface.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5 *
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 * $Revision: 1.5 $ */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 #include "mex.h"
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 #include "lfev.h"
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10 extern void lfmxdata(), lfmxevs();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 design des;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 lfit lf;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 int lf_error;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 { int i, vc, nc, mvc, mg[MXDIM], where, m, wh, dir, nkap;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18 const mxArray *dat, *fpc, *sp, *pc, *evs, *iwkc;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19 double *y, *x, *fy, *fx[MXDIM], *kap, cv, *fh, *se, *lo, *hi, lev;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 char band[16], wher[16], what[16], rest[16];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 if (nrhs<6) mexErrMsgTxt("ppmex requires 5 inputs.");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23 lf_error = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 mut_redirect(mexPrintf);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 dat= mxGetField(prhs[1],0,"data");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27 evs= mxGetField(prhs[1],0,"evaluation_structure");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28 sp = mxGetField(prhs[1],0,"smoothing_parameters");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 fpc= mxGetField(prhs[1],0,"fit_points");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
30 pc = mxGetField(prhs[1],0,"parametric_component");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
31 mxGetString(prhs[2],band,16);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
32 mxGetString(prhs[3],what,16);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
33 mxGetString(prhs[4],rest,16);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
34 dir = mxGetPr(prhs[5])[0];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
35 kap = mxGetPr(prhs[6]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
36 nkap = mxGetN(prhs[6]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
37 lev = mxGetPr(prhs[7])[0];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
38 lfmxdata(&lf.lfd,dat);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
39 lfmxsp(&lf.sp,sp,lf.lfd.d);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
40 lfmxevs(&lf,evs); /* this has initialized module */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
41
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
42 if (rest[0]=='n')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
43 wh = ppwhat(what);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
44 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
45 wh = 64+restyp(rest);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
46
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
47 lf.fp.xev = mxGetPr(mxGetField(fpc,0,"evaluation_points"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
48 lf.lfd.d = lf.fp.d = mxGetM(mxGetField(fpc,0,"evaluation_points"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
49 lf.fp.nv = lf.fp.nvm = mxGetN(mxGetField(fpc,0,"evaluation_points"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
50 lf.fp.wk = mxGetPr(mxGetField(fpc,0,"fitted_values"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
51 lf.fp.h = NULL;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
52 if (lf.mdl.alloc!=NULL) lf.mdl.alloc(&lf);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
53
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
54 iwkc = mxGetField(fpc,0,"evaluation_vectors");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
55 vc = mxGetM(mxGetField(iwkc,0,"cell"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
56 nc = mxGetN(mxGetField(iwkc,0,"cell"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
57 mvc = mxGetN(mxGetField(iwkc,0,"splitvar"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
58 lf.evs.iwk = mxCalloc(vc*nc+3*mvc,sizeof(int));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
59 lf.evs.nce = lf.evs.ncm = nc;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
60 y = mxGetPr(mxGetField(iwkc,0,"cell"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
61 lf.evs.ce = lf.evs.iwk;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
62 for (i=0; i<vc*nc; i++) lf.evs.ce[i] = y[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
63 y = mxGetPr(mxGetField(iwkc,0,"splitvar"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
64 lf.evs.s = &lf.evs.iwk[vc*nc];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
65 for (i=0; i<mvc; i++) lf.evs.s[i] = y[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
66 y = mxGetPr(mxGetField(iwkc,0,"lo"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
67 lf.evs.lo = &lf.evs.s[mvc];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
68 for (i=0; i<mvc; i++) lf.evs.lo[i] = y[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
69 y = mxGetPr(mxGetField(iwkc,0,"hi"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
70 lf.evs.hi = &lf.evs.lo[mvc];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
71 for (i=0; i<mvc; i++) lf.evs.hi[i] = y[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
72 lf.fp.hasd = deg(&lf.sp)>0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
73
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
74 lf.fp.kap = mxGetPr(mxGetField(fpc,0,"kappa"));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
75
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
76 lf.pc.wk = mxGetPr(pc);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
77 lf.pc.lwk = mxGetN(pc);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
78 pcchk(&lf.pc,lf.fp.d,npar(&lf.sp),1);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
79 haspc(&lf.pc) = !noparcomp(&lf.sp);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
80 lf.pc.xtwx.st = JAC_EIGD;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
81
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
82 where = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
83 if (mxIsCell(prhs[0])) /* interpret as grid margins */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
84 { m = 1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
85 for (i=0; i<lf.fp.d; i++)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
86 { fx[i] = mxGetPr(mxGetCell(prhs[0],i));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
87 mg[i] = mxGetM(mxGetCell(prhs[0],i));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
88 m *= mg[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
89 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
90 where = 2;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
91 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
92 if (mxIsChar(prhs[0]))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
93 { mxGetString(prhs[0],wher,16);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
94 where = 3; /* data */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
95 m = mg[0] = lf.lfd.n;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
96 if (wher[0] == 'f') /* or fit points */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
97 { where = 4;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
98 m = mg[0] = lf.fp.nv;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
99 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
100 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
101 if (where==0) /* interpret as numeric vector */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
102 { x = mxGetPr(prhs[0]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
103 m = mg[0] = mxGetM(prhs[0]); /* should check mxGetN == d */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
104 for (i=0; i<lf.lfd.d; i++)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
105 fx[i] = &x[i*m];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
106 where=1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
107 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
108
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
109 plhs[0] = mxCreateDoubleMatrix(m,1,mxREAL); /* fitted values */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
110 plhs[1] = mxCreateDoubleMatrix(m,1,mxREAL); /* std errors */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
111 fh = mxGetPr(plhs[0]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
112 se = mxGetPr(plhs[1]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
113
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
114 preplot(&lf,fx,fh,se,band[0],mg,where,wh,dir);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
115
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
116 cv = 0.0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
117 if (band[0] != 'n')
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
118 { cv = critval(1-lev,kap,nkap,lf.lfd.d,TWO_SIDED,0.0,GAUSS);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
119 plhs[2] = mxCreateDoubleMatrix(m,2,mxREAL);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
120 lo = mxGetPr(plhs[2]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
121 hi = &lo[m];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
122 for (i=0; i<m; i++)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
123 { lo[i] = fh[i]-cv*se[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
124 hi[i] = fh[i]+cv*se[i];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
125 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
126 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
127 else plhs[2] = mxCreateDoubleScalar(0.0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
128 }