function NLP=NLLPnl(Bet,Rgh,Pnl,SclFct)
%
%**************************************************************************
%Illustration of non-stationary extreme value modelling in MATLAB accompanying 
%Threshold modeling of nonstationary extremes
%Paul Northrop, Philip Jonathan and David Randell
%in 
%Extreme Value Modeling and Risk Analysis: Methods and Applications
%Dipak Dey and Jun Yan (Editors)
%2015
%**************************************************************************
%
%**************************************************************************
%NEGATIVE LOG LIKELIHOOD PENALTY
%
%Bet      p x 1 Spline parameter vector
%Rgh      1 x 1 Roughness coefficient (lambda in: PNLL = NLL + lambda * (beta'*Pnl*beta))
%Pnl      p x p Spline penality matrix
%
%NLP      1 x 1 Negative log likelihood penalty
%**************************************************************************

%Calculate negative log likelihood of penalty

p=size(Pnl,1);
Mlt=floor(size(Bet,1)./p);

NLP=0;
for i=1:Mlt
    NLP=NLP+SclFct(i).^2*(1/2).*Rgh.*Bet((i-1)*p+(1:p))'*Pnl*Bet((i-1)*p+(1:p));
end

return;