|
TPCCLIB
|
Linear integration. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include <string.h>#include "tpcextensions.h"#include "tpcli.h"Go to the source code of this file.
Functions | |
| int | liIntegrate (double *x, double *y, const int nr, double *yi, const int se, const int verbose) |
| Linear integration of TAC with trapezoidal method. | |
| int | liIntegratePET (double *x1, double *x2, double *y, int nr, double *ie, double *iie, const int verbose) |
| Calculate PET TAC AUC from start to each time frame, as averages during each frame. | |
| int | liIntegrateFE (double *x1, double *x2, double *y, int nr, double *ie, double *iie, const int verbose) |
| Linear integration of PET TAC to frame end times. | |
| int | liIntegrateHalfFrame (double *x1, double *x2, double *y, const size_t nr, double *fhi, const int verbose) |
| Calculate the integrals (AUC) of the first halves of PET frames based on dot-to-dot linear interpolation, assuming that original y values represent the mean value during the frame, i.e. AUC(frame start - frame end time)/frame duration. | |
| int | liDerivate (double *x, double *y, const int nr, double *d, double *dd, const int verbose) |
| Simplistic derivation of TAC as Δy divided by Δx, in relation to the previous point. | |
| int | liDerivate3 (double *x, double *y, const int nr, double *d, double *dd, const int verbose) |
| Simplistic derivation of PET TAC using regression line over three points. | |
Linear integration.
Definition in file integrate.c.
| int liDerivate | ( | double * | x, |
| double * | y, | ||
| const int | nr, | ||
| double * | d, | ||
| double * | dd, | ||
| const int | verbose ) |
Simplistic derivation of TAC as Δy divided by Δx, in relation to the previous point.
The derivative for point i is calculated as d[i]=(y[i]-y[i-1])/(x[i]-x[i-1]). For the first point, i=0, it is assumed that d[0]=0 if y[0]=0; otherwise we assume an imaginary previous data point y[-1]=0 at x[-1]=x[0]-(x[1]-x[0]) and thus d[0]=y[0]/(x[1]-x[0]).
| x | Array of input data x (time) values; obligatory. Data must be sorted by ascending x, and consecutive points must not have the same x. Negative x is accepted. |
| y | Array of input data y (concentration) values; obligatory. |
| nr | Number of samples in input data; obligatory; must be >1. |
| d | Array for derivatives at each x; obligatory. |
| dd | Array for 2nd derivatives at each x; NULL if not needed. |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 444 of file integrate.c.
Referenced by tacDelayCMFit().
| int liDerivate3 | ( | double * | x, |
| double * | y, | ||
| const int | nr, | ||
| double * | d, | ||
| double * | dd, | ||
| const int | verbose ) |
Simplistic derivation of PET TAC using regression line over three points.
| x | Array of input data x values (sample times); obligatory. |
| y | Array of input data y (concentration) values; obligatory. |
| nr | Number of samples in input data; obligatory; must be >1. |
| d | Array for derivatives at each x; obligatory. |
| dd | Array for 2nd derivatives at each x; NULL if not needed. |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 493 of file integrate.c.
Referenced by liDerivate3(), and tacDelayCMFit().
| int liIntegrate | ( | double * | x, |
| double * | y, | ||
| const int | nr, | ||
| double * | yi, | ||
| const int | se, | ||
| const int | verbose ) |
Linear integration of TAC with trapezoidal method.
Use this function for input data, or PET data when frame start and end times are not known. Data must be frequently sampled to get accurate results. AUC calculation is started from time 0 or first input sample time, whichever is smaller. Very simple data extrapolation can be optionally enabled. Results will be wrong if data contains NaNs. To get the same result as with integrate() in the libtpcmodel, set se=3.
| x | Array of input data x (time) values; obligatory. Data must be sorted by ascending x, but consecutive points may have the same x. Negative x is accepted, AUCs are then started from the first x, otherwise from 0. |
| y | Array of input data y (concentration) values; obligatory. |
| nr | Number of samples in input data; obligatory. |
| yi | Array for integrals (AUCs) at each x; obligatory. |
| se | Extrapolation setting for the start of data:
|
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 33 of file integrate.c.
Referenced by tacDelayCMFit(), and tacIntegrate().
| int liIntegrateFE | ( | double * | x1, |
| double * | x2, | ||
| double * | y, | ||
| int | nr, | ||
| double * | ie, | ||
| double * | iie, | ||
| const int | verbose ) |
Linear integration of PET TAC to frame end times.
Use this function for PET data when frame start and end times are known. AUC calculation is started from first frame start time, ignoring possible time gap before it. Any gaps between time frames are filled with an imaginary frame calculated as weighted average of previous and next frame. Frames must be in ascending time order and frame overlaps removed.
| x1 | Array of input data x1 (frame start time) values; obligatory. Negative frame times are accepted. |
| x2 | Array of input data x2 (frame end time) values; obligatory. Negative frame times are accepted, but it is required that for each frame x2>=x1. |
| y | Array of frame mean y (concentration) values; obligatory. |
| nr | Number of samples (frames); obligatory. |
| ie | Array for integrals (AUCs) at each x (frame middle time); enter NULL if not needed. |
| iie | Array for 2nd integrals (AUCs) at each x (frame middle time); enter NULL if not needed. |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 219 of file integrate.c.
Referenced by tacDelayCMFit(), and tacIntegrateFE().
| int liIntegrateHalfFrame | ( | double * | x1, |
| double * | x2, | ||
| double * | y, | ||
| const size_t | nr, | ||
| double * | fhi, | ||
| const int | verbose ) |
Calculate the integrals (AUC) of the first halves of PET frames based on dot-to-dot linear interpolation, assuming that original y values represent the mean value during the frame, i.e. AUC(frame start - frame end time)/frame duration.
Original data and new x values must be sorted by ascending x. Subsequent x values can have equal values, enabling the use of step functions. Negative x (time) values can be processed. Results will be wrong if data contains NaNs. The beginning and end of true TAC is assumed to follow a line drawn based on the two first/last TAC middle frame y values.
| x1 | Array of PET frame start times; obligatory. Data must be sorted by ascending x, but consecutive points may have the same x. Negative x is accepted. |
| x2 | Array of PET frame end times; obligatory. Data must be sorted by ascending x, but consecutive points may have the same x. Negative x is accepted, but frame duration (x2-x1) must be >=0. |
| y | Array of original TAC y (concentration) values, representing the average concentration during the PET frame; obligatory |
| nr | Number of samples in the data; obligatory |
| fhi | Array for first-half frame integrals of TAC y (concentration) values for each PET frame; obligatory |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 309 of file integrate.c.
| int liIntegratePET | ( | double * | x1, |
| double * | x2, | ||
| double * | y, | ||
| int | nr, | ||
| double * | ie, | ||
| double * | iie, | ||
| const int | verbose ) |
Calculate PET TAC AUC from start to each time frame, as averages during each frame.
Use this function for PET data when frame start and end times are known. AUC at the end of frame i is calculated as AUCe[i]=AUCe[i-1]+y[i]*(x2[i]-x1[i]), and the integral for frame i is calculated as an average AUC[i]=(AUCe[i]+AUCe[i-1])/2. AUC calculation is started from first frame start time, ignoring possible time gap before it. Any gaps between time frames are filled with an imaginary frame calculated as weighted average of previous and next frame. Frames must be in ascending time order and frame overlaps removed; wrong order or large overlaps will lead to substantial errors in integrals without warning. Results will be wrong if data contains NaNs.
| x1 | Array of input data x1 (frame start time) values; obligatory. Negative frame times are accepted. |
| x2 | Array of input data x2 (frame end time) values; obligatory. Negative frame times are accepted, but it is required that for each frame x2>=x1. |
| y | Array of frame mean y (concentration) values; obligatory. |
| nr | Number of samples (frames); obligatory. |
| ie | Array for integrals (AUCs) at each x (frame middle time); enter NULL if not needed. |
| iie | Array for 2nd integrals (AUCs) at each x (frame middle time); enter NULL if not needed. |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 120 of file integrate.c.
Referenced by bfm1TCM(), tacIntegrate(), tacInterpolate(), and tacInterpolateInto().