TPCCLIB
Loading...
Searching...
No Matches
fitk4.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#include <unistd.h>
14#include <string.h>
15#include <time.h>
16/*****************************************************************************/
17#include "libtpcmisc.h"
18#include "libtpcmodel.h"
19#include "libtpccurveio.h"
20#include "libtpcsvg.h"
21#include "libtpcmodext.h"
22/*****************************************************************************/
23
24/*****************************************************************************/
25const int parNr=5;
26int refmodel=2;
27DFT input, dft;
28double *petmeas, *petsim;
29double fVb=-1.0;
30double pmin[MAX_PARAMETERS], pmax[MAX_PARAMETERS];
31double fk1k2=-1.0;
32int fitframeNr;
33double wss_wo_penalty=0.0;
34/*****************************************************************************/
35/* Local functions */
36double cm3Func(int parNr, double *p, void*);
37int resK1k2Median(char *filename, double *median, double *mean, char *msg);
38/*****************************************************************************/
39
40/*****************************************************************************/
41static char *info[] = {
42 "Non-linear fitting of two-tissue compartment model to plasma input, blood,",
43 "and tissue time-activity curves (PTAC, BTAC, and TTAC) to estimate",
44 "parameters K1, K1/k2, k3, k3/k4, and Vb.",
45 "Optionally, K1/k2 can be constrained to the value estimated in reference",
46 "region; either 1- (default) or 2-tissue compartmental model can be fitted to",
47 "reference region data.",
48 " ",
49 " ______ ___________________ ",
50 " | | K1 | k3 | ",
51 " | | --> | -------> | ",
52 " | Ca | <-- | C1 <------- C2 | ",
53 " | | k2 | k4 | ",
54 " |______| |___________________| ",
55 " ",
56 "Sample times must be in minutes.",
57 " ",
58 "Usage: @P [Options] ptacfile btacfile ttacfile endtime resultfile",
59 " ",
60 "Options:",
61 " -lim[=<filename>]",
62 " Specify the constraints for model parameters;",
63 " This file with default values can be created by giving this",
64 " option as the only command-line argument to this program.",
65 " Without filename the default values are printed on screen.",
66 " -SD[=<y|N>]",
67 " Standard deviations are estimated and saved in results (y),",
68 " or not calculated (N, default).",
69 " Program runs a lot faster if SD and CL are not calculated.",
70 " -CL[=<y|N>]",
71 " 95% Confidence limits are estimated and saved in results (y), or",
72 " not calculated (N, default).",
73 " -Vb=<Vb(%)>",
74 " Enter a fixed Vb; fitted by default.",
75 " -fk1k2=<<value> || <result filename>>",
76 " K1/k2 is constrained to the given value in all regions; if result",
77 " filename is entered, then K1/k2 is constrained to the median of",
78 " regional K1/k2 values in the result file.",
79 " -r=<Reference region id or filename>",
80 " Optional reference region is used to constrain K1/k2 in other regions;",
81 " with option -rmod=3 also k3 and k4 are fitted to reference region data,",
82 " thus any large brain region (for example cortex) could be used here.",
83 " -rmod=<2|3>",
84 " Specify the model (2- or 3-compartments) that is fitted to reference",
85 " region data; by default 2-CM (1-tissue compartment model).",
86 " -BPnd[=<reference region id>]",
87 " BPnd is calculated as BPnd=VtROI/VtREF-1; reference region name",
88 " is not needed if the same is specified with option -r.",
89 " -fit=<Filename>",
90 " Fitted regional TACs are written in DFT format.",
91 " -svg=<Filename>",
92 " Fitted and measured TACs are plotted in specified SVG file.",
93 " -stdoptions", // List standard options like --help, -v, etc
94 " ",
95 "Example 1: estimate K1, K1/k2, k3, k3/k4 and Vb, and report also BPnd using",
96 "region 'cereb' as reference region",
97 " @P -BPnd=cereb ua919ap.bld ua919ab.bld ua919.tac 60 ua919.res",
98 " ",
99 "Example 2: estimate K1, k3 and k3/k4; Vb is constrained to 1.5% and K1/k2 is",
100 "constrained to K1/k2 estimated from region 'occip' with 1-tissue compartment",
101 "model",
102 " @P -Vb=1.5 -r=occip -rmod=2 ua919ap.bld ua919ab.bld ua919.tac 60 ua919.res",
103 " ",
104 "Example 3: constrain K1/k2 to the regional median; Vb is set to 4%;",
105 " @P -Vb=4 ua919ap.kbq ua919ab.kbq ua919.dft 60 tmp.res",
106 " @P -Vb=4 -fk1k2=tmp.res ua919ap.kbq ua919ab.kbq ua919.dft 60 ua919.res",
107 " ",
108 "See also: logan, fitk2, fitk3, fitk5, p2t_v3c, tacweigh, taccbv, rescoll",
109 " ",
110 "Keywords: TAC, modelling, binding potential, reversible uptake, 2TCM",
111 0};
112/*****************************************************************************/
113
114/*****************************************************************************/
115/* Turn on the globbing of the command line, since it is disabled by default in
116 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
117 In Unix&Linux wildcard command line processing is enabled by default. */
118/*
119#undef _CRT_glob
120#define _CRT_glob -1
121*/
122int _dowildcard = -1;
123/*****************************************************************************/
124
125/*****************************************************************************
126 *
127 * Main
128 *
129 *****************************************************************************/
130int main(int argc, char *argv[])
131{
132 int ai, help=0, version=0, verbose=1;
133 int ri, fi, pi, m, n, bp_type=0, ret;
134 int ref=-1, bpref=-1, refAdded=0, inputtype;
135 char dfile[FILENAME_MAX], pfile[FILENAME_MAX], bfile[FILENAME_MAX],
136 rfile[FILENAME_MAX], ffile[FILENAME_MAX], svgfile[FILENAME_MAX],
137 limfile[FILENAME_MAX];
138 char *cptr, tmp[FILENAME_MAX],
139 refname[FILENAME_MAX], bprefname[FILENAME_MAX];
140 double fitdur, wss, aic;
141 RES res;
142 IFT ift;
143 int doBootstrap=0, doSD=0, doCL=0;
144 double *sd, *cl1, *cl2;
145 double def_pmin[MAX_PARAMETERS], def_pmax[MAX_PARAMETERS];
146 int tgoNr=0, neighNr=0, iterNr=0, fittedparNr=0;
147
148
149
150 /* Set parameter initial values and constraints */
151 /* K1 */ def_pmin[0]=0.0; def_pmax[0]=5.0;
152 /* K1/k2 */ def_pmin[1]=0.00001; def_pmax[1]=10.0;
153 /* k3 */ def_pmin[2]=0.0; def_pmax[2]=2.0;
154 /* k3/k4 */ def_pmin[3]=0.0; def_pmax[3]=10.0;
155 /* Vb */ def_pmin[4]=0.0; def_pmax[4]=0.08;
156
157
158 /*
159 * Get arguments
160 */
161 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
162 dfile[0]=pfile[0]=bfile[0]=rfile[0]=ffile[0]=refname[0]=svgfile[0]=(char)0;
163 limfile[0]=bprefname[0]=(char)0;
164 fitdur=fVb=-1.0;
165 iftInit(&ift); resInit(&res); dftInit(&dft); dftInit(&input);
166 /* Get options first, because it affects what arguments are read */
167 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
168 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
169 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
170 if(strncasecmp(cptr, "CL", 2)==0) {
171 if(strlen(cptr)==2) {doCL=1; continue;}
172 cptr+=2; if(*cptr=='=') {
173 cptr++;
174 if(*cptr=='Y' || *cptr=='y') {doCL=1; continue;}
175 if(*cptr=='N' || *cptr=='n') {doCL=0; continue;}
176 }
177 } else if(strncasecmp(cptr, "SD", 2)==0) {
178 if(strlen(cptr)==2) {doSD=1; continue;}
179 cptr+=2; if(*cptr=='=') {
180 cptr++;
181 if(*cptr=='Y' || *cptr=='y') {doSD=1; continue;}
182 if(*cptr=='N' || *cptr=='n') {doSD=0; continue;}
183 }
184 } else if(strncasecmp(cptr, "LIM=", 4)==0 && strlen(cptr)>4) {
185 strlcpy(limfile, cptr+4, FILENAME_MAX); continue;
186 } else if(strcasecmp(cptr, "LIM")==0) {
187 strcpy(limfile, "stdout"); continue;
188 } else if(strncasecmp(cptr, "R=", 2)==0 && strlen(cptr)>2) {
189 strlcpy(refname, cptr+2, FILENAME_MAX); continue;
190 } else if(strncasecmp(cptr, "RMOD=", 5)==0 && strlen(cptr)>5) {
191 refmodel=atoi(cptr+5); if(refmodel==2 || refmodel==3) continue;
192 } else if(strcasecmp(cptr, "BPnd")==0) {
193 bp_type=1; continue;
194 } else if(strncasecmp(cptr, "BPnd=", 5)==0) {
195 bp_type=1; strcpy(bprefname, cptr+5); if(strlen(bprefname)>0.0) continue;
196 } else if(strncasecmp(cptr, "FK1K2=", 6)==0 && strlen(cptr)>6) {
197 /* Try to read specified K1/k2 from option */
198 fk1k2=atof_dpi(cptr+6); def_pmin[1]=def_pmax[1]=fk1k2;
199 if(fk1k2>0.0) continue;
200 /* If not successful, then try to read median K1/k2 from specified
201 result file */
202 if(resK1k2Median(cptr+6, &fk1k2, NULL, tmp)==0) {
203 def_pmin[1]=def_pmax[1]=fk1k2; continue;
204 }
205 if(verbose>1) fprintf(stderr, "Error: %s\n", tmp);
206 } else if(strncasecmp(cptr, "Vb=", 3)==0 && strlen(cptr)>3) {
207 fVb=0.01*atof_dpi(cptr+3);
208 if(fVb>=0.0 && fVb<1.0) {
209 if(fVb<0.01) fprintf(stderr, "Warning: Vb was set to %g%%\n", 100.*fVb);
210 def_pmin[4]=def_pmax[4]=fVb;
211 continue;
212 }
213 fVb=-1.0;
214 } else if(strncasecmp(cptr, "FIT=", 4)==0) {
215 strlcpy(ffile, cptr+4, FILENAME_MAX); if(strlen(ffile)>0) continue;
216 } else if(strncasecmp(cptr, "SVG=", 4)==0) {
217 strlcpy(svgfile, cptr+4, FILENAME_MAX); if(strlen(svgfile)>0) continue;
218 }
219 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
220 return(1);
221 } else break;
222
223 /* Print help or version? */
224 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
225 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
226 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
227
228 /* Process other arguments, starting from the first non-option */
229 for(; ai<argc; ai++) {
230 if(!pfile[0]) {
231 strlcpy(pfile, argv[ai], FILENAME_MAX); continue;
232 } else if(!bfile[0]) {
233 strlcpy(bfile, argv[ai], FILENAME_MAX); continue;
234 } else if(!dfile[0]) {
235 strlcpy(dfile, argv[ai], FILENAME_MAX); continue;
236 } else if(fitdur<0) {
237 if(!atof_with_check(argv[ai], &fitdur) && fitdur>=0.0) continue;
238 fprintf(stderr, "Error: invalid fit time '%s'.\n", argv[ai]);
239 return(1);
240 } else if(!rfile[0]) {
241 strlcpy(rfile, argv[ai], FILENAME_MAX); continue;
242 }
243 /* we should never get this far */
244 fprintf(stderr, "Error: too many arguments: '%s'.\n", argv[ai]);
245 return(1);
246 }
247 if(doSD || doCL) doBootstrap=1; else doBootstrap=0;
248 if(bp_type>0 && !bprefname[0]) {
249 if(!refname[0]) {
250 fprintf(stderr, "Error: reference region name not specified.\n");
251 return(1);
252 }
253 // bprefname can only be set later!
254 }
255
256 /* In verbose mode print arguments and options */
257 if(verbose>1) {
258 printf("pfile := %s\n", pfile);
259 //printf("bfile := %s\n", bfile); Later!
260 printf("dfile := %s\n", dfile);
261 printf("rfile := %s\n", rfile);
262 printf("ffile := %s\n", ffile);
263 printf("svgfile := %s\n", svgfile);
264 printf("limfile := %s\n", limfile);
265 printf("refname := %s\n", refname);
266 printf("refmodel := %d\n", refmodel);
267 printf("fitdur := %g\n", fitdur);
268 //if(fVb>=0.0) printf("fVb := %g\n", fVb); Later!
269 printf("bp_type := %d\n", bp_type);
270 //if(fk1k2>0.0) printf("fk1k2 := %g\n", fk1k2); Later!
271 printf("doBootstrap := %d\n", doBootstrap);
272 printf("doSD := %d\n", doSD);
273 printf("doCL := %d\n", doCL);
274 }
275
276
277 /* If only filename for parameter constraints was given, then write one
278 with default contents, and exit */
279 if(limfile[0] && !pfile[0]) {
280 /* Check that initial value file does not exist */
281 if(strcasecmp(limfile, "stdout")!=0 && access(limfile, 0) != -1) {
282 fprintf(stderr, "Error: parameter constraint file %s exists.\n", limfile);
283 return(9);
284 }
285 if(verbose>1 && strcasecmp(limfile, "stdout")!=0)
286 printf("writing parameter constraints file\n");
287 /* Create parameter file */
288 iftPutDouble(&ift, "K1_lower", def_pmin[0], NULL, 0);
289 iftPutDouble(&ift, "K1_upper", def_pmax[0], NULL, 0);
290 iftPutDouble(&ift, "K1k2_lower", def_pmin[1], NULL, 0);
291 iftPutDouble(&ift, "K1k2_upper", def_pmax[1], NULL, 0);
292 iftPutDouble(&ift, "k3_lower", def_pmin[2], NULL, 0);
293 iftPutDouble(&ift, "k3_upper", def_pmax[2], NULL, 0);
294 iftPutDouble(&ift, "k3k4_lower", def_pmin[3], NULL, 0);
295 iftPutDouble(&ift, "k3k4_upper", def_pmax[3], NULL, 0);
296 iftPutDouble(&ift, "Vb_lower", def_pmin[4], NULL, 0);
297 iftPutDouble(&ift, "Vb_upper", def_pmax[4], NULL, 0);
298 ret=iftWrite(&ift, limfile, 0);
299 if(ret) {
300 fprintf(stderr, "Error in writing '%s': %s\n", limfile, ift.status);
301 iftEmpty(&ift); return(9);
302 }
303 if(strcasecmp(limfile, "stdout")!=0)
304 fprintf(stdout, "Parameter file %s with initial values written.\n", limfile);
305 iftEmpty(&ift); return(0);
306 }
307
308
309 /* Did we get all the information that we need? */
310 if(fitdur==0) fitdur=1.0E+100;
311 else if(fitdur<0) {tpcPrintUsage(argv[0], info, stderr); return(1);}
312 if(!rfile[0]) {
313 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
314 return(1);
315 }
316
317
318 /*
319 * Read model parameter upper and lower limits
320 * if file for that was given
321 */
322 if(limfile[0]) {
323 if(verbose>1) printf("reading %s\n", limfile);
324 ret=iftRead(&ift, limfile, 1, 0);
325 if(ret) {
326 fprintf(stderr, "Error in reading '%s': %s\n", limfile, ift.status);
327 return(9);
328 }
329 if(verbose>2) iftWrite(&ift, "stdout", 0);
330 double v;
331 int n=0;
332 /* K1 */
333 if(iftGetDoubleValue(&ift, 0, "K1_lower", &v, 0)>=0) {def_pmin[0]=v; n++;}
334 if(iftGetDoubleValue(&ift, 0, "K1_upper", &v, 0)>=0) {def_pmax[0]=v; n++;}
335 /* K1/k2 */
336 if(iftGetDoubleValue(&ift, 0, "K1k2_lower", &v, 0)>=0) {def_pmin[1]=v; n++;}
337 if(iftGetDoubleValue(&ift, 0, "K1k2_upper", &v, 0)>=0) {def_pmax[1]=v; n++;}
338 /* k3 */
339 if(iftGetDoubleValue(&ift, 0, "k3_lower", &v, 0)>=0) {def_pmin[2]=v; n++;}
340 if(iftGetDoubleValue(&ift, 0, "k3_upper", &v, 0)>=0) {def_pmax[2]=v; n++;}
341 /* k3/k4 */
342 if(iftGetDoubleValue(&ift, 0, "k3k4_lower", &v, 0)>=0) {def_pmin[3]=v; n++;}
343 if(iftGetDoubleValue(&ift, 0, "k3k4_upper", &v, 0)>=0) {def_pmax[3]=v; n++;}
344 /* Vb */
345 if(iftGetDoubleValue(&ift, 0, "Vb_lower", &v, 0)>=0) {def_pmin[4]=v; n++;}
346 if(iftGetDoubleValue(&ift, 0, "Vb_upper", &v, 0)>=0) {def_pmax[4]=v; n++;}
347 iftEmpty(&ift);
348 if(n==0) {fprintf(stderr, "Error: invalid parameter file.\n"); return(9);}
349 }
350 /* Check that these are ok */
351 for(pi=n=0, ret=0; pi<parNr; pi++) {
352 if(def_pmin[pi]<0.0) ret++;
353 if(def_pmax[pi]<def_pmin[pi]) ret++;
354 if(def_pmax[pi]>def_pmin[pi]) n++;
355 }
356 if(ret) {
357 fprintf(stderr, "Error: invalid parameter constraints.\n");
358 return(9);
359 }
360 if(n==0) {
361 fprintf(stderr, "Error: no model parameters left free for fitting.\n");
362 return(9);
363 }
364
365 /* Fixed/fitted Vb */
366 if(fVb>=0.0) def_pmin[4]=def_pmax[4]=fVb;
367 if(def_pmin[4]==def_pmax[4]) fVb=def_pmin[4];
368 if(fVb==0.0) strcpy(bfile, "");
369 if(verbose>1) {
370 printf("bfile := %s\n", bfile);
371 if(fVb>=0.0) printf("fVb := %g\n", fVb);
372 }
373 /* Fixed/fitted K1/k2 */
374 if(fk1k2>0.0) def_pmin[1]=def_pmax[1]=fk1k2;
375 else if(def_pmin[1]==def_pmax[1]) fk1k2=def_pmin[1];
376 if(verbose>1) {
377 if(fk1k2>0.0) printf("fk1k2 := %g\n", fk1k2);
378 }
379
380
381 /*
382 * Read tissue and input data
383 */
384 if(verbose>1) printf("reading tissue and input data\n");
385 ret=dftReadModelingData(dfile, pfile, bfile, NULL, &fitdur,
386 &fitframeNr, &dft, &input, stdout, verbose-2, tmp);
387 if(ret!=0) {
388 fprintf(stderr, "Error: %s\n", tmp);
389 return(2);
390 }
391 if(fitframeNr<4 || input.frameNr<4) {
392 fprintf(stderr, "Error: too few samples in specified fit duration.\n");
393 dftEmpty(&input); dftEmpty(&dft); return(2);
394 }
395 /* If there is no blood TAC, then create a zero blood TAC */
396 if(input.voiNr<2) {
397 if(verbose>2) printf("setting blood tac to zero\n");
398 ret=dftAddmem(&input, 1);
399 if(ret) {
400 fprintf(stderr, "Error: cannot allocate more memory.\n");
401 dftEmpty(&dft); dftEmpty(&input); return(3);
402 }
403 strcpy(input.voi[1].voiname, "blood");
404 strcpy(input.voi[1].name, input.voi[1].voiname);
405 for(fi=0; fi<input.frameNr; fi++) input.voi[1].y[fi]=0.0;
406 input.voiNr=2;
407 }
408 if(verbose>10) dftPrint(&dft);
409 if(verbose>10) dftPrint(&input);
410 /* Print the weights */
411 if(verbose>2) {
412 fprintf(stdout, "common_data_weights := %g", dft.w[0]);
413 for(fi=1; fi<dft.frameNr; fi++) fprintf(stdout, ", %g", dft.w[fi]);
414 fprintf(stdout, "\n");
415 }
416
417
418 /*
419 * Read reference TAC
420 */
421 /* Check if user even wants any reference region */
422 if(!refname[0]) {
423 if(verbose>1) printf("no reference region data\n");
424 ref=-1;
425 } else {
426 if(verbose>1) printf("reading reference region data\n");
427 if((n=dftReadReference(&dft, refname, &inputtype, &ref, tmp, verbose-3))<1) {
428 fprintf(stderr, "Error in reading '%s': %s\n", refname, tmp);
429 if(verbose>2) printf("dftReadReference()=%d\n", n);
430 dftEmpty(&dft); dftEmpty(&input); return(6);
431 }
432 if(verbose>30) dftPrint(&dft);
433 if(n>1) {
434 fprintf(stderr, "Warning: %s selected of %d reference regions.\n",
435 dft.voi[ref].name, n);
436 if(verbose>2)
437 fprintf(stdout, "selected reference region := %s\n", dft.voi[ref].name);
438 }
439 if(inputtype==5) { // Reference region name was given
440 refAdded=0; strcpy(refname, "");
441 } else { // reference file was given; ref TACs may have to be deleted later
442 refAdded=1;
443 }
444 if(verbose>15) dftPrint(&dft);
445 if(verbose>1) printf("Reference region: %s\n", dft.voi[ref].name );
446 }
447 /* Set reference for BP calculation */
448 if(bp_type>0) {
449 for(ri=0; ri<dft.voiNr; ri++) dft.voi[ri].sw2=dft.voi[ri].sw;
450 /* If not specified with option -bpnd, then take refname */
451 if(!bprefname[0]) {
452 strcpy(bprefname, refname); bpref=ref;
453 } else if(strcasecmp(refname, bprefname)==0) {
454 /* Same as goven with option -r */
455 strcpy(bprefname, refname); bpref=ref;
456 } else { /* Find the ref region from region list */
457 ret=dftSelectRegions(&dft, bprefname, 1);
458 if(ret>0) bpref=dftSelectBestReference(&dft); else bpref=-999;
459 if(bpref<0) {
460 fprintf(stderr, "Error: reference region %s not found\n", bprefname);
461 if(verbose>1) printf("ret=%d\n", n);
462 dftEmpty(&dft); dftEmpty(&input); return(6);
463 }
464 }
465 if(verbose>1)
466 fprintf(stdout, "selected reference region for BP := %s\n",
467 dft.voi[bpref].name);
468 for(ri=0; ri<dft.voiNr; ri++) dft.voi[ri].sw=dft.voi[ri].sw2;
469 }
470
471 /* Allocate an extra TAC for the bootstrap */
472 if(doBootstrap) {
473 ret=dftAddmem(&dft, 1); if(ret) {
474 fprintf(stderr, "Error: cannot allocate more memory.\n");
475 dftEmpty(&dft); dftEmpty(&input); return(9);
476 }
477 strcpy(dft.voi[dft.voiNr].voiname, "BS");
478 strcpy(dft.voi[dft.voiNr].name, "BS");
479 }
480 if(verbose>10) dftPrint(&dft);
481
482
483 /*
484 * Prepare the room for the results
485 */
486 if(verbose>1) printf("initializing result data\n");
487 ret=res_allocate_with_dft(&res, &dft); if(ret!=0) {
488 fprintf(stderr, "Error: cannot setup memory for results.\n");
489 dftEmpty(&input); dftEmpty(&dft); return(7);
490 }
491 /* Copy titles & filenames */
492 tpcProgramName(argv[0], 1, 1, res.program, 256);
493 strcpy(res.datafile, dfile);
494 strcpy(res.plasmafile, pfile);
495 strcpy(res.bloodfile, bfile);
496 if(ref>=0) sprintf(res.refroi, "%s", dft.voi[ref].name);
497 else if(bpref>=0) sprintf(res.refroi, "%s", dft.voi[bpref].name);
498 if(refname[0]) strcpy(res.reffile, refname);
499 strcpy(res.fitmethod, "TGO");
500 /* Constants */
501 res.isweight=dft.isweight;
502 if(fVb>=0.0) res.Vb=100.0*fVb;
503 /* Set data range */
504 sprintf(res.datarange, "%g - %g %s", 0.0, fitdur, dftTimeunit(dft.timeunit));
505 res.datanr=fitframeNr;
506 /* Set current time to results */
507 res.time=time(NULL);
508 /* Set parameter number, including also the extra "parameters"
509 and the parameter names and units */
510 res.parNr=8; if(bpref>=0) res.parNr++;
511 pi=0; strcpy(res.parname[pi], "K1"); strcpy(res.parunit[pi], "ml/(min*ml)");
512 pi++; strcpy(res.parname[pi], "K1/k2"); strcpy(res.parunit[pi], "");
513 pi++; strcpy(res.parname[pi], "k3"); strcpy(res.parunit[pi], "1/min");
514 pi++; strcpy(res.parname[pi], "k3/k4"); strcpy(res.parunit[pi], "");
515 pi++; strcpy(res.parname[pi], "Vb"); strcpy(res.parunit[pi], "%");
516 pi++; strcpy(res.parname[pi], "Vt"); strcpy(res.parunit[pi], "");
517 if(bpref>=0) {
518 pi++; strcpy(res.parname[pi], "BPnd"); strcpy(res.parunit[pi], "");
519 }
520 pi++; strcpy(res.parname[pi], "WSS"); strcpy(res.parunit[pi], "");
521 pi++; strcpy(res.parname[pi], "AIC"); strcpy(res.parunit[pi], "");
522
523
524
525 /*
526 * Fit at first the reference ROI(s), if required
527 */
528 if(ref>=0) for(ri=0; ri<dft.voiNr; ri++) if(dft.voi[ri].sw>0) {
529 if(verbose>0)
530 fprintf(stdout, "fitting %s as reference region with %d-TCM\n",
531 dft.voi[ri].name, refmodel-1);
532 /* Initiate values */
533 petmeas=dft.voi[ri].y; petsim=dft.voi[ri].y2;
534 /* Set constraints */
535 pmin[0]=def_pmin[0]; pmax[0]=def_pmax[0]; /* K1 */
536 pmin[1]=def_pmin[1]; pmax[1]=def_pmax[1]; /* K1/k2 */
537 pmin[4]=def_pmin[4]; pmax[4]=def_pmax[4]; /* Vb */
538 if(refmodel==2) { // 2CM
539 pmin[2]=0.0; pmax[2]=0.0; /* k3 */
540 pmin[3]=0.0; pmax[3]=0.0; /* k3/k4 */
541 } else if(refmodel==3) { // 3CM
542 pmin[2]=def_pmin[2]; pmax[2]=def_pmax[2]; /* k3 */
543 pmin[3]=def_pmin[3]; pmax[3]=def_pmax[3]; /* k3/k4 */
544 }
545 for(pi=fittedparNr=0; pi<parNr; pi++) if(pmax[pi]>pmin[pi]) fittedparNr++;
546 if(verbose>3) {
547 printf(" ref_constraints :=");
548 for(pi=0; pi<parNr; pi++) printf(" [%g,%g]", pmin[pi], pmax[pi]);
549 printf("\n");
550 printf("fittedparNr := %d\n", fittedparNr);
551 }
552 /* Fit */
555 // n=fittedparNr; if(n>4) n=4; tgoNr=50+50*n; neighNr=8;
556 tgoNr=50+25*fittedparNr;
557 neighNr=6*fittedparNr;
558 iterNr=0;
559 ret=tgo(
560 pmin, pmax, cm3Func, NULL, parNr, neighNr, &wss,
561 res.voi[ri].parameter, tgoNr, iterNr, verbose-8);
562 if(ret>0) {
563 fprintf(stderr, "Error in optimization (%d).\n", ret);
564 dftEmpty(&input); dftEmpty(&dft); resEmpty(&res); return(8);
565 }
566 /* Correct fitted parameters to match constraints like inside function */
567 (void)modelCheckParameters(parNr, pmin, pmax, res.voi[ri].parameter,
568 res.voi[ri].parameter, NULL);
569 wss=wss_wo_penalty;
570 /* If k3 or k3/k4 is zero, then both k3 and k3/k4 should be zero */
571 if(res.voi[ri].parameter[2]<1.0E-20 || res.voi[ri].parameter[3]<1.0E-20)
572 res.voi[ri].parameter[2]=res.voi[ri].parameter[3]=0.0;
573 if(verbose>1) {
574 fprintf(stdout, " K1/k2 := %g\n", res.voi[ri].parameter[1]);
575 if(refmodel==3)
576 fprintf(stdout, " k5/k6 := %g\n", res.voi[ri].parameter[3]);
577 }
578 if(verbose>4) {
579 printf("Original and fitted TACs:\n");
580 for(fi=0; fi<fitframeNr; fi++)
581 printf(" %8.3f %9.3f %9.3f\n", dft.x[fi], petmeas[fi], petsim[fi]);
582 printf("Original and fitted TACs:\n");
583 }
584 /* Fix K1/k2 to non-reference regions, but only after all reference
585 regions are fitted */
586 if(ri==ref) {
587 fk1k2=res.voi[ri].parameter[1];
588 if(verbose>2) {fprintf(stdout, " fixed K1/k2 := %g\n", fk1k2);}
589 }
590 /* Bootstrap */
591 if(doBootstrap) {
592 if(verbose>2) printf(" bootstrapping\n");
593 /* bootstrap changes measured and simulated data, therefore use copies */
594 petmeas=dft.voi[dft.voiNr].y2; petsim=dft.voi[dft.voiNr].y3;
595 if(doSD) sd=res.voi[ri].sd; else sd=NULL;
596 if(doCL) {cl1=res.voi[ri].cl1; cl2=res.voi[ri].cl2;} else cl1=cl2=NULL;
597 ret=bootstrap(
598 0, cl1, cl2, sd,
599 res.voi[ri].parameter, pmin, pmax, fitframeNr,
600 // measured original TAC, not modified
601 dft.voi[ri].y,
602 // fitted TAC, not modified
603 dft.voi[ri].y2,
604 // tissue TAC noisy data is written to be used by objf
605 petmeas,
606 parNr, dft.w, cm3Func, tmp, verbose-4
607 );
608 if(ret) {
609 fprintf(stderr, "Error in bootstrap: %s\n", tmp);
610 for(pi=0; pi<parNr; pi++) {
611 if(doSD) sd[pi]=nan("");
612 if(doCL) cl1[pi]=cl2[pi]=nan("");
613 }
614 }
615 }
616 /* Calculate AIC based on nr of parameters that actually are fitted */
617 for(pi=n=0; pi<parNr; pi++) if(pmax[pi]>pmin[pi]) n++;
618 if(verbose>2) printf("nr_of_fitted_parameters := %d\n", n);
619 for(fi=m=0; fi<fitframeNr; fi++) if(dft.w[fi]>0.0) m++;
620 if(verbose>2) printf("nr_of_fitted_samples := %d\n", m);
621 aic=aicSS(wss, m, n);
622
623 /* Set results wss and aic */
624 res.voi[ri].parameter[res.parNr-2]=wss;
625 res.voi[ri].parameter[res.parNr-1]=aic;
626
627 /* Calculate Vt */
628 res.voi[ri].parameter[5]=res.voi[ri].parameter[1];
629 if(res.voi[ri].parameter[3]>0.0)
630 res.voi[ri].parameter[5]*=(1.0+res.voi[ri].parameter[3]);
631
632 /* Convert Vb fraction to percentage */
633 res.voi[ri].parameter[4]*=100.;
634 if(doSD) res.voi[ri].sd[4]*=100.;
635 if(doCL) {res.voi[ri].cl1[4]*=100.; res.voi[ri].cl2[4]*=100.;}
636
637 } // next reference region
638
639
640 /*
641 * Fit other than reference regions
642 */
643 if(verbose>0) {fprintf(stdout, "fitting regional TACs: "); fflush(stdout);}
644 if(verbose>1) printf("\n");
645 /* Set K1/k2 constraint based on above fitted reference region, if required */
646 if(fk1k2>0.0) def_pmin[1]=def_pmax[1]=fk1k2;
647 /* One ROI at a time */
648 for(ri=0; ri<dft.voiNr; ri++) if(dft.voi[ri].sw==0) {
649 if(verbose>2) printf("\n %d %s:\n", ri, dft.voi[ri].name);
650
651 /* Initiate values */
652 petmeas=dft.voi[ri].y; petsim=dft.voi[ri].y2;
653
654 /* Set constraints */
655 pmin[0]=def_pmin[0]; pmax[0]=def_pmax[0]; /* K1 */
656 pmin[1]=def_pmin[1]; pmax[1]=def_pmax[1]; /* K1/k2 */
657 pmin[2]=def_pmin[2]; pmax[2]=def_pmax[2]; /* k3 */
658 pmin[3]=def_pmin[3]; pmax[3]=def_pmax[3]; /* k3/k4 */
659 pmin[4]=def_pmin[4]; pmax[4]=def_pmax[4]; /* Vb */
660 for(pi=fittedparNr=0; pi<parNr; pi++) if(pmax[pi]>pmin[pi]) fittedparNr++;
661 if(verbose>3) {
662 printf(" constraints :=");
663 for(pi=0; pi<parNr; pi++) printf(" [%g,%g]", pmin[pi], pmax[pi]);
664 printf("\n");
665 printf("fittedparNr := %d\n", fittedparNr);
666 }
667
668 /* Fit */
671 // n=fittedparNr; if(n>4) n=4; tgoNr=50*50*n; neighNr=8; iterNr=0;
672 tgoNr=50+25*fittedparNr;
673 neighNr=6*fittedparNr;
674 iterNr=0;
675 ret=tgo(
676 pmin, pmax, cm3Func, NULL, parNr, neighNr, &wss,
677 res.voi[ri].parameter, tgoNr, iterNr, verbose-8);
678 if(ret>0) {
679 fprintf(stderr, "\nError in optimization (%d).\n", ret);
680 dftEmpty(&input); dftEmpty(&dft); resEmpty(&res); return(8);
681 }
682 /* Correct fitted parameters to match constraints like inside function */
683 (void)modelCheckParameters(parNr, pmin, pmax, res.voi[ri].parameter,
684 res.voi[ri].parameter, NULL);
685 wss=wss_wo_penalty;
686 /* If k3 or k3/k4 is zero, then both k3 and k3/k4 should be zero */
687 if(res.voi[ri].parameter[2]<1.0E-20 || res.voi[ri].parameter[3]<1.0E-20)
688 res.voi[ri].parameter[2]=res.voi[ri].parameter[3]=0.0;
689
690 /* Bootstrap */
691 if(doBootstrap) {
692 if(verbose>2) printf(" bootstrapping\n");
693 /* bootstrap changes measured and simulated data, therefore use copies */
694 petmeas=dft.voi[dft.voiNr].y2; petsim=dft.voi[dft.voiNr].y3;
695 if(doSD) sd=res.voi[ri].sd; else sd=NULL;
696 if(doCL) {cl1=res.voi[ri].cl1; cl2=res.voi[ri].cl2;} else cl1=cl2=NULL;
697 ret=bootstrap(
698 0, cl1, cl2, sd,
699 res.voi[ri].parameter, pmin, pmax, fitframeNr,
700 // measured original TAC, not modified
701 dft.voi[ri].y,
702 // fitted TAC, not modified
703 dft.voi[ri].y2,
704 // tissue TAC noisy data is written to be used by objf
705 petmeas,
706 parNr, dft.w, cm3Func, tmp, verbose-4
707 );
708 if(ret) {
709 fprintf(stderr, "Error in bootstrap: %s\n", tmp);
710 for(pi=0; pi<parNr; pi++) {
711 if(doSD) sd[pi]=nan("");
712 if(doCL) cl1[pi]=cl2[pi]=nan("");
713 }
714 }
715 }
716
717 /* Calculate Vt */
718 res.voi[ri].parameter[5]=res.voi[ri].parameter[1];
719 if(res.voi[ri].parameter[3]>0.0)
720 res.voi[ri].parameter[5]*=(1.0+res.voi[ri].parameter[3]);
721
722 /* Calculate AIC, based on nr of parameters that actually are fitted */
723 for(pi=n=0; pi<parNr; pi++) if(pmax[pi]>pmin[pi]) n++;
724 if(verbose>2) printf("nr_of_fitted_parameters := %d\n", n);
725 for(fi=m=0; fi<fitframeNr; fi++) if(dft.w[fi]>0.0) m++;
726 if(verbose>2) printf("nr_of_fitted_samples := %d\n", m);
727 aic=aicSS(wss, m, n);
728
729 /* Set results wss and aic */
730 res.voi[ri].parameter[res.parNr-2]=wss;
731 res.voi[ri].parameter[res.parNr-1]=aic;
732
733 /* Convert Vb fraction to percentage */
734 res.voi[ri].parameter[4]*=100.;
735 if(doSD) res.voi[ri].sd[4]*=100.;
736 if(doCL) {res.voi[ri].cl1[4]*=100.; res.voi[ri].cl2[4]*=100.;}
737
738 /* done with this region */
739 if(dft.voiNr>2 && verbose==1) {fprintf(stdout, "."); fflush(stdout);}
740
741 } /* next region */
742 if(verbose>0) {fprintf(stdout, "\n"); fflush(stdout);}
743
744 /*
745 * Calculate BP
746 */
747 if(bpref>=0) {
748 for(ri=0; ri<dft.voiNr; ri++) {
749 if(bpref==ri) res.voi[ri].parameter[6]=0.0;
750 else res.voi[ri].parameter[6]=
751 (res.voi[ri].parameter[5]/res.voi[bpref].parameter[5])-1.0;
752 }
753 }
754
755 /*
756 * Print results on screen
757 */
758 if(verbose>0) {resPrint(&res); fprintf(stdout, "\n");}
759
760
761 /*
762 * Save results
763 */
764 if(verbose>1) printf("saving results\n");
765 ret=resWrite(&res, rfile, verbose-3);
766 if(ret) {
767 fprintf(stderr, "Error in writing '%s': %s\n", rfile, reserrmsg);
768 dftEmpty(&dft); dftEmpty(&input); resEmpty(&res);
769 return(11);
770 }
771 if(verbose>0) fprintf(stdout, "Model parameters written in %s\n", rfile);
772
773
774 /*
775 * Saving and/or plotting of fitted TACs
776 */
777 if(svgfile[0] || ffile[0]) {
778
779 /* Create a DFT containing fitted TACs */
780 char tmp[64];
781 DFT dft2;
782 dftInit(&dft2); ret=dftdup(&dft, &dft2);
783 if(ret) {
784 fprintf(stderr, "Error: cannot save fitted curves.\n");
785 dftEmpty(&dft); dftEmpty(&input); resEmpty(&res);
786 return(21);
787 }
788 for(ri=0; ri<dft.voiNr; ri++) for(fi=0; fi<fitframeNr; fi++)
789 dft2.voi[ri].y[fi]=dft2.voi[ri].y2[fi];
790 dft2.frameNr=fitframeNr;
791
792 /* Save SVG plot of fitted and original data */
793 if(svgfile[0]) {
794 if(verbose>1) printf("saving SVG plot\n");
795 sprintf(tmp, "K1-k4 fit: ");
796 if(strlen(dft.studynr)>0) strcat(tmp, dft.studynr);
797 ret=plot_fitrange_svg(&dft, &dft2, tmp, 0.0, 1.02*dft.x[fitframeNr-1],
798 0.0, nan(""), svgfile, verbose-8);
799 if(ret) {
800 fprintf(stderr, "Error (%d) in writing '%s'.\n", ret, svgfile);
801 dftEmpty(&dft2); dftEmpty(&dft); dftEmpty(&input); resEmpty(&res);
802 return(30+ret);
803 }
804 if(verbose>0) printf("Plots written in %s\n", svgfile);
805 }
806
807 /* Delete reference region(s) from the data */
808 if(refAdded!=0) {
809 for(ri=dft2.voiNr-1; ri>=0; ri--) if(dft2.voi[ri].sw!=0)
810 dftDelete(&dft2, ri);
811 }
812
813 /* Save fitted TACs */
814 if(ffile[0]) {
815 if(verbose>1) printf("saving fitted curves\n");
816 tpcProgramName(argv[0], 1, 0, tmp, 128);
817 sprintf(dft2.comments, "# program := %s\n", tmp);
818 if(dftWrite(&dft2, ffile)) {
819 fprintf(stderr, "Error in writing '%s': %s\n", ffile, dfterrmsg);
820 dftEmpty(&dft2); dftEmpty(&dft); dftEmpty(&input); resEmpty(&res);
821 return(22);
822 }
823 if(verbose>0) printf("Fitted TACs written in %s\n", ffile);
824 }
825
826 dftEmpty(&dft2);
827 }
828
829 dftEmpty(&dft); dftEmpty(&input); resEmpty(&res);
830 return(0);
831}
832/*****************************************************************************/
833
834/*****************************************************************************
835 *
836 * Functions to be minimized
837 *
838 *****************************************************************************/
839double cm3Func(int parNr, double *p, void *fdata)
840{
841 int fi, ret;
842 double k2, k3, k4, Vb, d, wss=0.0;
843 double pa[MAX_PARAMETERS], penalty=1.0;
844
845
846 /* Check parameters against the constraints */
847 ret=modelCheckParameters(parNr, pmin, pmax, p, pa, &penalty);
848 if(fdata) {}
849 /* Calculate k2, k3 & k4 */
850 k2=pa[0]/pa[1];
851 if(pa[3]>0.0) {k3=pa[2]; k4=k3/pa[3];} else k3=k4=0.0;
852 if(fVb>=0.0) Vb=fVb; else Vb=pa[4];
853
854 /* Simulate the tissue PET TAC */
855 ret=simC3vs(
856 input.x, input.voi[0].y, input.voi[1].y, input.frameNr,
857 pa[0], k2, k3, k4, 0, 0, 0.0, Vb, 1.0,
858 input.voi[0].y2, NULL, NULL, NULL, NULL, NULL);
859 if(ret) {
860 printf("error %d in simulation\n", ret);
861 return(nan(""));
862 }
863
864 /* Interpolate & integrate to measured PET frames */
866 ret=interpolate4pet(
867 input.x, input.voi[0].y2, input.frameNr,
868 dft.x1, dft.x2, petsim, NULL, NULL, fitframeNr);
869 else
870 ret=interpolate(
871 input.x, input.voi[0].y2, input.frameNr,
872 dft.x, petsim, NULL, NULL, fitframeNr);
873 if(ret) {
874 printf("error %d in interpolation\n", ret);
875 return(nan(""));
876 }
877
878 /* Calculate error */
879 for(fi=0, wss=0.0; fi<fitframeNr; fi++) if(dft.w[fi]>0.0) {
880 d=petmeas[fi]-petsim[fi];
881 wss+=dft.w[fi]*d*d;
882 }
883 wss_wo_penalty=wss;
884 wss*=penalty;
885 if(0) printf("%g %g %g %g => %g\n", pa[0], k2, pa[2], k4, wss);
886
887 return(wss);
888}
889/*****************************************************************************/
890
891/*****************************************************************************/
896int resK1k2Median(
898 char *filename,
900 double *median,
902 double *mean,
904 char *msg
905) {
906 RES res;
907 int ri, col, n;
908 char *cptr;
909 double *lista;
910
911 /* Read result file */
912 resInit(&res);
913 if(resRead(filename, &res, 0)!=0) {
914 if(msg!=NULL) sprintf(msg, "cannot read %s: %s", filename, reserrmsg);
915 return(1);
916 }
917 /* Which column contains K1/k2 */
918 col=-1; ri=0; cptr=strtok(res.titleline, " \t");
919 while(cptr!=NULL && col<0) {
920 if(strcasecmp(cptr, "K1/k2")==0) col=ri;
921 else if(strcasecmp(cptr, "K1k2")==0) col=ri;
922 ri++; cptr=strtok(NULL, " \t");
923 }
924 if(ri<0) {
925 if(msg!=NULL) sprintf(msg, "K1/k2 not found in %s", filename);
926 resEmpty(&res); return(3);
927 }
928 n=res.voiNr;
929 /* Calculate mean and median */
930 lista=(double*)malloc(n*sizeof(double));
931 for(ri=0; ri<n; ri++) lista[ri]=res.voi[ri].parameter[col];
932 resEmpty(&res);
933 if(mean!=NULL) {
934 *mean=dmean(lista, n, NULL);
935 if(*mean<=0.0) {
936 if(msg!=NULL) sprintf(msg, "invalid K1/k2 mean in %s", filename);
937 free(lista); return(6);
938 }
939 }
940 if(median!=NULL) {
941 *median=dmedian(lista, n);
942 if(*median<=0.0) {
943 if(msg!=NULL) sprintf(msg, "invalid K1/k2 median in %s", filename);
944 free(lista); return(5);
945 }
946 }
947 free(lista);
948 return 0;
949}
950/*****************************************************************************/
951
952/*****************************************************************************/
double aicSS(double ss, const int n, const int k)
Definition aic.c:20
int bootstrap(int iterNr, double *cLim1, double *cLim2, double *SD, double *parameter, double *lowlim, double *uplim, int frameNr, double *origTac, double *fitTac, double *bsTac, int parNr, double *weight, double(*objf)(int, double *, void *), char *status, int verbose)
Definition bootstrap.c:55
int modelCheckParameters(int par_nr, double *lower_p, double *upper_p, double *test_p, double *accept_p, double *penalty)
Definition constraints.c:15
int atof_with_check(char *double_as_string, double *result_value)
Definition decpoint.c:107
double atof_dpi(char *str)
Definition decpoint.c:59
void dftInit(DFT *data)
Definition dft.c:38
int dftdup(DFT *dft1, DFT *dft2)
Definition dft.c:655
char dfterrmsg[64]
Definition dft.c:6
int dftAddmem(DFT *dft, int voiNr)
Definition dft.c:107
int dftSelectBestReference(DFT *dft)
Definition dft.c:314
int dftDelete(DFT *dft, int voi)
Definition dft.c:538
void dftEmpty(DFT *data)
Definition dft.c:20
int dftSelectRegions(DFT *dft, char *region_name, int reset)
Definition dft.c:285
int dftReadReference(DFT *tissue, char *filename, int *filetype, int *ref_index, char *status, int verbose)
Definition dftinput.c:204
int dftReadModelingData(char *tissuefile, char *inputfile1, char *inputfile2, char *inputfile3, double *fitdur, int *fitframeNr, DFT *tis, DFT *inp, FILE *loginfo, int verbose, char *status)
Definition dftinput.c:342
void dftPrint(DFT *data)
Definition dftio.c:538
int dftWrite(DFT *data, char *filename)
Definition dftio.c:594
int res_allocate_with_dft(RES *res, DFT *dft)
Definition dftres.c:14
int iftPutDouble(IFT *ift, char *key, double value, char *cmt_type, int verbose)
Definition ift.c:145
void iftEmpty(IFT *ift)
Definition ift.c:60
void iftInit(IFT *ift)
Definition ift.c:45
int iftRead(IFT *ift, char *filename, int is_key_required, int verbose)
Definition iftfile.c:24
int iftWrite(IFT *ift, char *filename, int verbose)
Definition iftfile.c:282
int iftGetDoubleValue(IFT *ift, int si, const char *key, double *value, int verbose)
Definition iftsrch.c:268
int interpolate(double *x, double *y, int nr, double *newx, double *newy, double *newyi, double *newyii, int newnr)
Linear interpolation and integration.
Definition integr.c:28
int interpolate4pet(double *x, double *y, int nr, double *newx1, double *newx2, double *newy, double *newyi, double *newyii, int newnr)
Interpolate and integrate TAC to PET frames.
Definition integr.c:510
Header file for libtpccurveio.
char reserrmsg[64]
Definition result.c:6
void resInit(RES *res)
Definition result.c:52
void resPrint(RES *res)
Definition result.c:186
int resWrite(RES *res, char *filename, int verbose)
Definition result.c:565
int resRead(char *filename, RES *res, int verbose)
Definition result.c:199
#define DFT_TIME_STARTEND
void resEmpty(RES *res)
Definition result.c:22
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
void tpcProgramName(const char *program, int version, int copyright, char *prname, int n)
Definition proginfo.c:101
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158
Header file for libtpcmodel.
int simC3vs(double *t, double *ca, double *cb, int nr, double k1, double k2, double k3, double k4, double k5, double k6, double f, double vb, double fa, double *cpet, double *cta, double *ctb, double *ctc, double *ctab, double *ctvb)
Definition simulate.c:243
int tgo(double *lowlim, double *uplim, double(*objf)(int, double *, void *), void *objfData, int dim, int neighNr, double *fmin, double *gmin, int samNr, int tgoNr, int verbose)
Definition tgo.c:39
int TGO_LOCAL_INSIDE
Definition tgo.c:29
#define MAX_PARAMETERS
Definition libtpcmodel.h:31
int TGO_SQUARED_TRANSF
Definition tgo.c:27
double dmean(double *data, int n, double *sd)
Definition median.c:73
double dmedian(double *data, int n)
Definition median.c:48
int mean(double *x, double *y, int nr, double *xmean, double *xsd, double *ymean, double *ysd)
Definition pearson.c:341
Header file for libtpcmodext.
int plot_fitrange_svg(DFT *dft1, DFT *dft2, char *main_title, double x1, double x2, double y1, double y2, char *fname, int verbose)
Definition plotfit.c:16
Header file for libtpcsvg.
int timetype
Voi * voi
int timeunit
char studynr[MAX_STUDYNR_LEN+1]
double * w
double * x1
char comments[_DFT_COMMENT_LEN+1]
int voiNr
double * x2
int frameNr
int isweight
double * x
const char * status
Definition libtpcmisc.h:277
char titleline[1024]
int parNr
char parname[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
int voiNr
int datanr
ResVOI * voi
double Vb
char program[1024]
char plasmafile[FILENAME_MAX]
char datarange[128]
int isweight
char datafile[FILENAME_MAX]
char reffile[FILENAME_MAX]
char fitmethod[128]
char refroi[64]
char parunit[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
char bloodfile[FILENAME_MAX]
time_t time
double parameter[MAX_RESPARAMS]
double cl2[MAX_RESPARAMS]
double cl1[MAX_RESPARAMS]
double sd[MAX_RESPARAMS]
double * y2
char voiname[MAX_REGIONSUBNAME_LEN+1]
char sw
double * y
char name[MAX_REGIONNAME_LEN+1]
double * y3
char sw2