TABLE OF CONTENTS


CinitRoutine/InitSmoothnessPenalty [ Functions ]

NAME

    InitSmoothnessPenalty --- compute the smoothness penalty during initialization

FUNCTION

Special function to compute the smoothness penalty during initialization. This differs from SmoothnessPenalty in that this routine does not take a CCurve as input, rather only the relevant components, and can thus be called directly from R.

SYNOPSIS

498 void InitSmoothnessPenalty(double *pen, double *par, double *P, int *penaltyType, double *sigma2, int *nj)

INPUTS

    pen       output storage
    par       parameters of the spline
    P         penalty matrix
    penaltyType   integer indexing the type of penalty (0=gaussian, 1=2diff, 2=2deriv, 3=log2deriv)
    sigma2    prior variance
    nj        number of B-spline basis functions

SOURCE

502 {
503     if(*penaltyType==0){  // Gaussian
504         int c1 = 1;
505         *pen = pow(F77_CALL(dnrm2)(nj, par, &c1),2.0);
506         *pen = *pen / (2 * *sigma2);
507     }
508     // second differences or second derivative
509     if(*penaltyType==1 || *penaltyType==2 || *penaltyType==3){   
510         double * temp = (double *) calloc((*nj) , sizeof(double));
511         int c1 = 1;
512         double c1d = 1.0;
513         char uplo = 'u';
514         // compute par %*% P %*% par
515         F77_CALL(dsymv)( &uplo, nj, &c1d, P, nj, par, &c1, &c1d, temp, &c1);
516         *pen = F77_CALL(ddot)( nj, temp, &c1, par, &c1);
517         if(*penaltyType==3) *pen=log(*pen+1);
518         *pen = *pen / (2 * *sigma2);
519         free( temp );
520     }
521 }