comparison rDiff/src/locfit/Source/locf.h @ 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 /*
2 * Copyright 1996-2006 Catherine Loader.
3 */
4 #ifndef I_LOCF_H
5 #define I_LOCF_H
6
7 #include "stdlib.h"
8 #include "ctype.h"
9 #include "mut.h"
10
11 #ifdef WARN
12 #undef WARN
13 #endif
14
15 #define LERR(args) {mut_printf("Error: "); mut_printf args; mut_printf("\n"); lf_error=1;}
16 #define WARN(args) {mut_printf("Warning: "); mut_printf args; mut_printf("\n"); }
17
18 extern int lf_error;
19 #define LOGPI 1.144729885849400174143427
20 #define HUBERC 2.0
21 #define NOSLN 0.1278433
22 #define GFACT 2.5
23 #define EFACT 3.0
24 #define ISWAP(a,b) { int zz; zz = a; a = b; b = zz; }
25 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
26 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
27 #define SGN(x) (((x)>0) ? 1 : -1)
28 #define SQR(x) ((x)*(x))
29
30 extern int lf_error;
31
32 typedef struct {
33 double *wk, *coef, *xbar, *f;
34 jacobian xtwx;
35 int lwk, haspc;
36 } paramcomp;
37 #define haspc(pc) ((pc)->haspc)
38
39 /*
40 * MXDIM and MXDEG are maximum dimension and local polynomial
41 * degree for Locfit. Note that some parts of the code may be
42 * more restrictive.
43 */
44
45 #define MXDIM 15
46 #define MXDEG 7
47
48 typedef struct {
49 double *x[MXDIM];
50 double *y;
51 double *w;
52 double *b;
53 double *c;
54 double sca[MXDIM];
55 double xl[2*MXDIM];
56 int n, d, ord;
57 int sty[MXDIM];
58 } lfdata;
59 #define resp(lfd,i) (((lfd)->y==NULL) ? 0.0 : (lfd)->y[i])
60 #define base(lfd,i) (((lfd)->b==NULL) ? 0.0 : (lfd)->b[i])
61 #define prwt(lfd,i) (((lfd)->w==NULL) ? 1.0 : (lfd)->w[i])
62 #define cens(lfd,i) (((lfd)->c==NULL) ? 0 : (int)(lfd)->c[i])
63 #define datum(lfd,i,j) ((lfd)->x[i][j])
64 #define dvari(lfd,i) ((lfd)->x[i])
65
66
67 /*
68 * The design structure used in Locfit, and associated macro definitions.
69 */
70
71 typedef struct {
72 int des_init_id;
73 double *wk;
74 int *ind;
75 int lwk, lind;
76
77 double *xev; /* fitting point, length p */
78 double *X; /* design matrix, length n*p */
79 double *w, *di, *res, *th, *wd, h;
80 double *V, *P; /* matrices with length p*p */
81 double *f1, *ss, *oc, *cf; /* work vectors, length p */
82 double llk, smwt;
83 double tr0, tr1, tr2; /* traces for local df computation */
84 jacobian xtwx; /* to store X'WVX and decomposition */
85 int cfn[1+MXDIM], ncoef;
86 int *fix; /* integer vector for fixed coefficients. */
87 int (*itype)(); /* density integration function */
88 int n, p;
89 } design;
90
91 #define cfn(des,i) (des->cfn[i])
92 #define d_x(des) ((des)->X)
93 #define d_xi(des,i) (&(des)->X[i*((des)->p)])
94 #define d_xij(des,i,j) ((des)->X[i*((des)->p)+j])
95 #define is_fixed(des,i) ((des)->fix[i]==1)
96 #define wght(des,i) ((des)->w[i])
97 #define dist(des,i) ((des)->di[i])
98 #define fitv(des,i) ((des)->th[i])
99 #define DES_INIT_ID 34988372
100
101 extern int des_reqd(), des_reqi();
102
103 typedef struct {
104 int deflink, canlink, quasi, robust;
105 int (*vallink)(), (*family)(), (*initial)(), (*like)(), (*pcheck)();
106 } family;
107 #define isquasi(fam) ((fam)->quasi)
108 #define isrobust(fam) ((fam)->robust)
109 extern int inllmix; /* flag needed to ensure correct behavior in llmix. */
110
111 typedef struct {
112 double nn, fixh, adpen;
113 int ker, kt;
114 int deg, deg0, p;
115 int acri;
116 int fam, lin;
117 family fami;
118 int ubas;
119 double (*vb)();
120 void (*vbasis)();
121 } smpar;
122 #define nn(sp) ((sp)->nn)
123 #define fixh(sp) ((sp)->fixh)
124 #define pen(sp) ((sp)->adpen)
125 #define ker(sp) ((sp)->ker)
126 #define kt(sp) ((sp)->kt)
127 #define deg(sp) ((sp)->deg)
128 #define deg0(sp) ((sp)->deg0)
129 #define npar(sp) ((sp)->p)
130 #define acri(sp) ((sp)->acri)
131 #define ubas(sp) ((sp)->ubas)
132 #define fam(sp) ((sp)->fam)
133 #define fami(sp) (&(sp)->fami)
134 #define link(sp) ((sp)->lin)
135
136 typedef struct {
137 int deriv[MXDEG+2];
138 int nd;
139 } deriv;
140
141 /*
142 * Criteria for adaptive local fitting mi[MACRI]
143 * 1: localized CP; 2: ICI (katkovnik); 3: curvature model index
144 * 4: Increase bandwidth until locfit returns LF_OK
145 */
146 #define ANONE 0
147 #define ACP 1
148 #define AKAT 2
149 #define AMDI 3
150 #define AOK 4
151
152 /*
153 * weight functions mi[MKER].
154 * see Table 3.1 or the function W() in weights.c for definitions.
155 */
156 #define WRECT 1
157 #define WEPAN 2
158 #define WBISQ 3
159 #define WTCUB 4
160 #define WTRWT 5
161 #define WGAUS 6
162 #define WTRIA 7
163 #define WQUQU 8
164 #define W6CUB 9
165 #define WMINM 10
166 #define WEXPL 11
167 #define WMACL 12
168 #define WPARM 13
169
170 /*
171 * type of multivariate weight function mi[MKT]
172 * KSPH (spherical) KPROD (product)
173 * others shouldn't be used at present.
174 */
175 #define KSPH 1
176 #define KPROD 2
177 #define KCE 3
178 #define KLM 4
179 #define KZEON 5
180
181 /*
182 * Local likelihood family mi[MTG]
183 * for quasi-likelihood, add 64.
184 */
185 #define TNUL 0
186 #define TDEN 1
187 #define TRAT 2
188 #define THAZ 3
189 #define TGAUS 4
190 #define TLOGT 5
191 #define TPOIS 6
192 #define TGAMM 7
193 #define TGEOM 8
194 #define TCIRC 9
195 #define TROBT 10
196 #define TRBIN 11
197 #define TWEIB 12
198 #define TCAUC 13
199 #define TPROB 14
200 #define TQUANT 15
201
202 /*
203 * Link functions mi[MLINK].
204 * Mostly as in table 4.1 of the book.
205 * LDEFAU and LCANON are used to select default and canonical
206 * links respectively. LINIT shouldn't be selected by user...
207 */
208 #define LINIT 0
209 #define LDEFAU 1
210 #define LCANON 2
211 #define LIDENT 3
212 #define LLOG 4
213 #define LLOGIT 5
214 #define LINVER 6
215 #define LSQRT 7
216 #define LASIN 8
217
218 /*
219 * components of vector returned by the links() function
220 * in family.c. ZLIK the likelihood; ZMEAN = estimated mean;
221 * ZDLL = derivative of log-likelihood; ZDDLL = - second derivative
222 */
223 #define LLEN 4
224 #define ZLIK 0
225 #define ZMEAN 1
226 #define ZDLL 2
227 #define ZDDLL 3
228
229 /*
230 * return status for the locfit() function
231 */
232 #define LF_OK 0
233 #define LF_DONE 1 /* done - forced break from iterations */
234 #define LF_OOB 2 /* out of bounds, or large unstable parameter */
235 #define LF_PF 3 /* perfect fit; interpolation; deviance=0 */
236 #define LF_NCON 4 /* not converged */
237 #define LF_NSLN 5 /* no solution - eg separation in binomial. */
238 #define LF_NOPT 6 /* no or insufficient points with non-zero wt */
239 #define LF_INFA 7 /* initial failure e.g. log(0) */
240 #define LF_DEMP 10 /* density -- empty integration region */
241 #define LF_XOOR 11 /* density -- fit point outside xlim region */
242 #define LF_DNOP 12 /* density version of 6 */
243 #define LF_BADP 81 /* bad parameters e.g. neg prob for binomial */
244 #define LF_LNK 82 /* invalid link */
245 #define LF_FAM 83 /* invalid family */
246 #define LF_ERR 99 /* error */
247
248 #define STANGL 4
249 #define STLEFT 5
250 #define STRIGH 6
251 #define STCPAR 7
252
253 /*
254 * Integration type mi[MIT] for integration in
255 * density estimation.
256 */
257 #define INVLD 0
258 #define IDEFA 1
259 #define IMULT 2
260 #define IPROD 3
261 #define IMLIN 4
262 #define IHAZD 5
263 #define ISPHR 6
264 #define IMONT 7
265
266 /* density.c */
267 extern int densinit(), likeden(), deitype();
268 extern int fact[];
269 extern void prodintresp(), prresp();
270 extern int de_mint, de_itype, de_renorm;
271
272 /* dens_haz.c */
273 extern void haz_init();
274 extern int hazint();
275
276 /* dens_odi.c */
277 extern int onedint();
278 extern void recurint();
279
280 /* famquant.c */
281 extern void lfquantile();
282
283 /* family.c */
284 extern int lffamily(), lflink();
285 extern int links(), stdlinks(), defaultlink(), validlinks();
286 extern double b2(), b3(), b4(), lf_link(), invlink();
287 extern void setfamily();
288
289 /* lf_adap.c */
290 extern int alocfit(), lfacri();
291
292 /* lf_fitfun.c */
293 extern void fitfun(), makecfn(), designmatrix();
294 extern int calcp(), coefnumber();
295
296 /* lf_nbhd.c */
297 extern double kordstat(), rho();
298 extern void nbhd();
299
300 /* lf_robust.c */
301 extern double median();
302 extern void lf_robust();
303
304 /* lfstr.c */
305 extern int pmatch();
306
307 /* lf_vari.c */
308 extern void lf_vcov(), comp_vari(), local_df();
309
310 /* lf_wdiag.c */
311 extern int wdiag(), wdiagp();
312
313 /* locfit.c */
314 extern int locfit(), des_reqd(), des_reqi(), likereg();
315 extern int reginit();
316 extern void lfdata_init(), smpar_init(), deriv_init(), des_init(), lfiter();
317 extern int lf_maxit, lf_debug;
318 extern void lf_status_msg();
319
320 /* minmax.c */
321 extern double ipower(), minmax();
322
323 /* weight.c */
324 extern int lfkernel(), lfketype();
325 extern double W(), weight(), weightd(), Wd(), Wdd(), wint();
326 extern double Wconv(), Wconv1(), Wconv4(), Wconv5(), Wconv6(), Wikk();
327 extern int iscompact(), wtaylor();
328
329 #endif /* define I_LOCF_H */