TPCCLIB
Loading...
Searching...
No Matches
tpcmodels.h File Reference

Header file for libtpcmodels. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "tpcextensions.h"

Go to the source code of this file.

Enumerations

enum  mf {
  MF_UNKNOWN =0 , MF_LEVEL =100 , MF_LINE =101 , MF_POL2 ,
  MF_POL3 , MF_POL4 , MF_POL5 , MF_POL6 ,
  MF_POL7 , MF_POL8 , MF_POL9 , MF_RATF11 =211 ,
  MF_RATF21 =221 , MF_RATF22 =222 , MF_RATF32 =232 , MF_RATF33 =233 ,
  MF_EXP1 =301 , MF_EXP2 =302 , MF_EXP3 , MF_EXP4 ,
  MF_EXP5 , MF_LUNDQVIST =321 , MF_LUNDQVIST2 , MF_LUNDQVIST3 ,
  MF_EXPBOLUSINF =331 , MF_EXPBOLUSINF_RW =332 , MF_EXPBOLUSINF_AZ =334 , MF_PK11195 =351 ,
  MF_HILL =841 , MF_1MHILL =842 , MF_1MHILL_ADE =843 , MF_HILL_B =844 ,
  MF_AMHILL =845 , MF_EHILL_PAR =846 , MF_EHILL_MET =847 , MF_MAMEDE =851 ,
  MF_1MMAMEDE , MF_MAYER_PAR =861 , MF_MAYER_MET , MF_EMAYER_PAR ,
  MF_EMAYER_MET , MF_HILL3M_PAR =871 , MF_HILL3M_M1 , MF_HILL3M_M2 ,
  MF_HILL3M_M3 , MF_PF3M_PAR =881 , MF_PF3M_M1 , MF_PF3M_M2 ,
  MF_PF3M_M3 , MF_STEP =1010 , MF_RATF33D =1232 , MF_FENGM2S =1312 ,
  MF_FENGM2 =1313 , MF_FENGM2E =1314 , MF_GAMMAV =1401 , MF_GAMMAVB =1402 ,
  MF_WEIBULLCDF_D =1421 , MF_WEIBULLCDF_DD =1423 , MF_SURGE =1431 , MF_SURGE_TRAD =1432 ,
  MF_SURGE_RECIRC =1433 , MF_P2B_SRC =1434 , MF_SURGE_FDG =1435 , MF_HILL_D =1801 ,
  MF_HILL_DD =1811 , MF_HILL_SDD =1821 , MF_IMGPROFILE =2111 , MF_P2B_RF =2233 ,
  MF_P2B_FM2 =2313 , MF_P2B_HILL =2841 , MF_GRAHAM_INP =9501 , MF_GRAHAM_EINP ,
  MF_GRAHAM_INPM , MF_HUANG_MET =9601 , MF_CARSON_EMET , MF_NEW_MET ,
  MF_MLMCM =9701 , MF_LAST
}
 Deprecated identification codes of mathematical functions fitted to PET data. More...
enum  optimality_criterion {
  OPTCRIT_UNKNOWN , OPTCRIT_OLS , OPTCRIT_LMS , OPTCRIT_LAD ,
  OPTCRIT_MAD , OPTCRIT_ODR , OPTCRIT_LAST
}
 Optimality Criterion for statistical optimizations. More...

Functions

double aicSS (double ss, const unsigned int n, const unsigned int k)
 Calculate corrected AIC.
unsigned int parFreeNr (const unsigned int n, double *pLower, double *pUpper)
 Calculate the number of free parameters.
unsigned int modelNr ()
char * modelCode (const unsigned int i)
unsigned int modelOldId (const unsigned int i)
unsigned int modelOld2New (const unsigned int i)
char * modelDesc (const unsigned int i)
unsigned int modelCodeIndex (const char *s)
unsigned int modelParNr (const unsigned int code)
unsigned int optcritNr ()
char * optcritCode (optimality_criterion id)
char * optcritDesc (optimality_criterion id)
optimality_criterion optcritId (const char *s)

Detailed Description

Header file for libtpcmodels.

Header file for model description library.

Author
Vesa Oikonen

Definition in file tpcmodels.h.

Enumeration Type Documentation

◆ mf

enum mf

Deprecated identification codes of mathematical functions fitted to PET data.

Note
Do not change the existing id codes, because these are used in some data files to specify the applied function.

Definition at line 27 of file tpcmodels.h.

27 {
28 MF_UNKNOWN=0,
29 MF_LEVEL=100,
30 MF_LINE=101,
31 MF_POL2, MF_POL3, MF_POL4, MF_POL5, MF_POL6, MF_POL7, MF_POL8, MF_POL9,
32 MF_RATF11=211, MF_RATF21=221, MF_RATF22=222, MF_RATF32=232, MF_RATF33=233,
33 MF_EXP1=301, MF_EXP2=302, MF_EXP3, MF_EXP4, MF_EXP5,
34 MF_LUNDQVIST=321, MF_LUNDQVIST2, MF_LUNDQVIST3,
35 MF_EXPBOLUSINF=331,
36 MF_EXPBOLUSINF_RW=332,
37 MF_EXPBOLUSINF_AZ=334,
38 MF_PK11195=351,
39 MF_HILL=841, MF_1MHILL=842, MF_1MHILL_ADE=843,
40 MF_HILL_B=844, MF_AMHILL=845,
41 MF_EHILL_PAR=846, MF_EHILL_MET=847,
42 MF_MAMEDE=851, MF_1MMAMEDE,
43 MF_MAYER_PAR=861, MF_MAYER_MET, MF_EMAYER_PAR, MF_EMAYER_MET,
44 MF_HILL3M_PAR=871, MF_HILL3M_M1, MF_HILL3M_M2, MF_HILL3M_M3,
45 MF_PF3M_PAR=881, MF_PF3M_M1, MF_PF3M_M2, MF_PF3M_M3,
46 MF_STEP=1010,
47 MF_RATF33D=1232,
48 MF_FENGM2S=1312, MF_FENGM2=1313, MF_FENGM2E=1314,
49 MF_GAMMAV=1401, MF_GAMMAVB=1402,
50 MF_WEIBULLCDF_D=1421, MF_WEIBULLCDF_DD=1423,
51 MF_SURGE=1431, MF_SURGE_TRAD=1432, MF_SURGE_RECIRC=1433, MF_P2B_SRC=1434, MF_SURGE_FDG=1435,
52 MF_HILL_D=1801, MF_HILL_DD=1811, MF_HILL_SDD=1821,
53 MF_IMGPROFILE=2111,
54 MF_P2B_RF=2233, MF_P2B_FM2=2313, MF_P2B_HILL=2841,
55 MF_GRAHAM_INP=9501, MF_GRAHAM_EINP, MF_GRAHAM_INPM,
56 MF_HUANG_MET=9601,
57 MF_CARSON_EMET,
58 MF_NEW_MET,
59 MF_MLMCM=9701,
60 MF_LAST
61} mf;
mf
Deprecated identification codes of mathematical functions fitted to PET data.
Definition tpcmodels.h:27

◆ optimality_criterion

Optimality Criterion for statistical optimizations.

Enumerator
OPTCRIT_UNKNOWN 

Unknown optimality criterion.

OPTCRIT_OLS 

Ordinary Least Squares (sum-of-squares, SS).

OPTCRIT_LMS 

Least Median of Squares.

OPTCRIT_LAD 

Least Absolute Deviations (sum of absolute deviations, LAE, LAV, LAR).

OPTCRIT_MAD 

Median Absolute Deviation.

OPTCRIT_ODR 

Orthogonal Distance Regression (sum of perpendicular distances).

OPTCRIT_LAST 

List end.

Definition at line 66 of file tpcmodels.h.

66 {
optimality_criterion
Optimality Criterion for statistical optimizations.
Definition tpcmodels.h:66
@ OPTCRIT_OLS
Ordinary Least Squares (sum-of-squares, SS).
Definition tpcmodels.h:68
@ OPTCRIT_LAD
Least Absolute Deviations (sum of absolute deviations, LAE, LAV, LAR).
Definition tpcmodels.h:70
@ OPTCRIT_ODR
Orthogonal Distance Regression (sum of perpendicular distances).
Definition tpcmodels.h:72
@ OPTCRIT_LAST
List end.
Definition tpcmodels.h:73
@ OPTCRIT_MAD
Median Absolute Deviation.
Definition tpcmodels.h:71
@ OPTCRIT_UNKNOWN
Unknown optimality criterion.
Definition tpcmodels.h:67
@ OPTCRIT_LMS
Least Median of Squares.
Definition tpcmodels.h:69

Function Documentation

◆ aicSS()

double aicSS ( double ss,
const unsigned int n,
const unsigned int k )
extern

Calculate corrected AIC.

Calculate AICc in the special case of sum-of-squares optimization from the SS, number of fitted samples, and number of fitted parameters.

If variance is different between the data points, weighted SS must be given.

See also
parFreeNr, tacWSampleNr
Returns
Returns the AIC value, or NaN in case of invalid input values.
Parameters
ssSum-of-Squares of the fit (weighted, if necessary).
nSample size, i.e. number of fitted samples; do not include samples with zero weight.
kNumber of fitted model parameters; do not include fixed parameters; AICc calculation is valid only when (n-k)>1.

Definition at line 29 of file aic.c.

37 {
38 if(!(ss>=0.0) || n<1 || (n-k)<2) return(nan(""));
39
40 int dr=n-k-1;
41 int dv=2*k*(k+1);
42 double aic=0.0, bias_adj=0.0, css;
43 if(dr>0) bias_adj=((double)dv)/((double)dr); else bias_adj=0.0;
44 if(ss<1.0e-50) css=1.0e-50; else css=ss; /* Because log(0) is an error */
45 aic= n*log(css/(double)n) + 2.0*(double)k + bias_adj;
46 return(aic);
47}

◆ modelCode()

char * modelCode ( const unsigned int i)
extern

Get string representation of a model code.

Returns
pointer to string representation of the code, or NULL if not identified.
Author
Vesa Oikonen
See also
modelDesc, modelCodeIndex, modelNr
Parameters
imodel list index.

Definition at line 175 of file modell.c.

178 {
179 if(i>=modelNr()) return((char*)NULL);
180 return(tpc_model[i].code);
181}
unsigned int modelNr()
Definition modell.c:161

Referenced by mfCreateTAC(), parWriteCSV(), and parWriteXML().

◆ modelCodeIndex()

unsigned int modelCodeIndex ( const char * s)
extern

Get model index for the string representation of model code.

Returns
index number, 0, if unknown model code.
Author
Vesa Oikonen
See also
modelCode, modelDesc
Parameters
smodel code as a string; code is case-insensitive, but otherwise exact match is required.

Definition at line 236 of file modell.c.

239 {
240 if(s==NULL || *s=='\0') return(0);
241 unsigned int i=0;
242 while(tpc_model[i].code[0]!='\0') {
243 if(!strcasecmp(tpc_model[i].code, s)) return(i);
244 i++;
245 }
246 return(0);
247}

Referenced by parExamplePerfectBolus(), parExampleRadiowaterBolus(), parExampleTTACs(), and parReadCSV().

◆ modelDesc()

char * modelDesc ( const unsigned int i)
extern

Get description of a model.

Returns
pointer to string, or NULL if not identified.
Author
Vesa Oikonen
See also
modelCode
Parameters
imodel list index.

Definition at line 221 of file modell.c.

224 {
225 if(i>=modelNr()) return((char*)NULL);
226 return(tpc_model[i].desc);
227}

◆ modelNr()

unsigned int modelNr ( )
extern

Number of listed models.

Returns
Nr of models.

Definition at line 161 of file modell.c.

162{
163 unsigned int i=0;
164 while(tpc_model[i].code[0]!='\0') i++;
165 return(i);
166}

Referenced by modelCode(), modelDesc(), modelOld2New(), and modelParNr().

◆ modelOld2New()

unsigned int modelOld2New ( const unsigned int i)
extern

Convert the deprecated function id to the model list index.

Returns
model/function list index, or 0 if not identified.
Author
Vesa Oikonen
See also
modelOldId, modelCode, modelCodeIndex, modelNr
Parameters
iDeprecated function id.

Definition at line 204 of file modell.c.

207 {
208 unsigned int n=modelNr();
209 if(i==0) return(0);
210 for(unsigned int j=1; j<n; j++) if(tpc_model[j].id==i) return(j);
211 return(0);
212}

Referenced by parReadFIT().

◆ modelOldId()

unsigned int modelOldId ( const unsigned int i)
extern

Get the deprecated function id for working with older file formats.

Returns
function id, or 0 if not identified.
Author
Vesa Oikonen
See also
modelOld2New, modelCode, modelCodeIndex, modelNr
Parameters
imodel list index.

Definition at line 190 of file modell.c.

193 {
194 return(tpc_model[i].id);
195}

Referenced by parWriteFIT().

◆ modelParNr()

unsigned int modelParNr ( const unsigned int code)
extern

Get model parameter number.

Returns
parameter number, or 0 if invalid model code.
Author
Vesa Oikonen
Parameters
codemodel code; can be retrieved using modelCodeIndex().

Definition at line 255 of file modell.c.

258 {
259 if(code<1 || code>=modelNr()) return(0);
260 return(tpc_model[code].parNr);
261}

Referenced by mfCreateTAC(), parExamplePerfectBolus(), parExampleRadiowaterBolus(), and parExampleTTACs().

◆ optcritCode()

char * optcritCode ( optimality_criterion id)
extern

Get string representation of an optimality criterion.

Returns
pointer to string representation of the code, or NULL if not identified.
See also
optcritDesc, optcritId, modelCode
Parameters
idOptimality criterion.

Definition at line 60 of file optcrit.c.

63 {
64 for(unsigned int i=0; i<optcritNr(); i++) if(id==tpc_optcrit[i].id) return(tpc_optcrit[i].code);
65 return((char*)NULL);
66}
unsigned int optcritNr()
Definition optcrit.c:47

◆ optcritDesc()

char * optcritDesc ( optimality_criterion id)
extern

Get description of an optimality criterion.

Returns
pointer to string, or NULL if not identified.
See also
optcritCode, optcritId
Parameters
idOptimality criterion.

Definition at line 74 of file optcrit.c.

77 {
78 for(unsigned int i=0; i<optcritNr(); i++) if(id==tpc_optcrit[i].id) return(tpc_optcrit[i].desc);
79 return((char*)NULL);
80}

◆ optcritId()

optimality_criterion optcritId ( const char * s)
extern

Get the Id for the string representation of optimality criterion code string.

Returns
Enumerated optimality criterion id, OPTCRIT_UNKNOWN, if unknown code.
See also
optcritCode, optcritDesc
Parameters
sOptimality criterion code string; code is case-insensitive, but otherwise exact match is required.

Definition at line 88 of file optcrit.c.

92 {
93 if(s==NULL || *s=='\0') return(OPTCRIT_UNKNOWN);
94 for(unsigned int i=0; i<optcritNr(); i++)
95 if(!strcasecmp(tpc_optcrit[i].code, s)) return(tpc_optcrit[i].id);
96 /* Try also some alternative names */
97 if(!strcasecmp("SS", s)) return(OPTCRIT_OLS);
98 if(!strcasecmp("WSS", s)) return(OPTCRIT_OLS);
99 if(!strcasecmp("SUMSQR", s)) return(OPTCRIT_OLS);
100 if(!strcasecmp("LAE", s)) return(OPTCRIT_LAD);
101 if(!strcasecmp("LAV", s)) return(OPTCRIT_LAD);
102 if(!strcasecmp("LAR", s)) return(OPTCRIT_LAD);
103 if(!strcasecmp("Deming", s)) return(OPTCRIT_ODR);
104 return(OPTCRIT_UNKNOWN);
105}

◆ optcritNr()

unsigned int optcritNr ( )
extern

Number of optimality criteria.

Returns
Nr of criteria.

Definition at line 47 of file optcrit.c.

48{
49 unsigned int i=0;
50 while(tpc_optcrit[i].code[0]!='\0') i++;
51 return(i);
52}

Referenced by optcritCode(), optcritDesc(), and optcritId().

◆ parFreeNr()

unsigned int parFreeNr ( const unsigned int n,
double * pLower,
double * pUpper )
extern

Calculate the number of free parameters.

Model parameters can be fixed by setting lower and upper limit to equal values. This function simply checks the limits for each parameter.

Returns
Returns the number of free parameters.
Author
Vesa Oikonen
See also
aicSS, tacWSampleNr
Parameters
nNr of parameters
pLowerLower limits (array of length n)
pUpperUpper limits (array of length n)

Definition at line 60 of file aic.c.

67 {
68 if(n==0 || pLower==NULL || pUpper==NULL) return(0);
69 unsigned int nf=0;
70 for(unsigned int i=0; i<n; i++) {
71 double range=pUpper[i]-pLower[i];
72 if(range>1.0E-10) nf++;
73 }
74 return(nf);
75}