TPCCLIB
Loading...
Searching...
No Matches
aic.c File Reference

Functions for using Akaike's information criteria. More...

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

Go to the source code of this file.

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.
 

Detailed Description

Functions for using Akaike's information criteria.

Definition in file aic.c.

Function Documentation

◆ aicSS()

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

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}

◆ parFreeNr()

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

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}