Name

c_KNN1SIM — Function to resample daily values

Calling Sequence

[SIMn]=c_KNN1SIM(NBK,WIN,DMAT,WEI,DMATSELEC,NNdep,RND)

Parameters

NBK

Number of nearest neighbours (integer). Should be inferior to 20. Common value is 5.

WIN

Size of the window in days to look for nearest neighbours (integer). Common value is inferior to 60.

DMAT

Matrix of data permitting to calculate the euclidian distance (matrix [NxP]). Each line represents a day. Each column represents a variable used to calculate the euclidian distance.

WEI

Weights used to calculate the euclidiant distance (matrix [Px1]).

DMATSELEC

Vector [Nx1] permitting to include or exclude certain days from the nearest neighbours. If DMATSELEC[i]>0, the day i is included in the neighbours list otherwise the function jumps over this day.

RND

Random numbers in ]0..1[ (matrix [Nrx1]). The size of this matrix determines the size of the resampled vector.

NNdep

Initial neighbours chosen (integer inferior to N). To start on the same day than SMAT, choose NNdep=1.

SIMn

Position (day number) of the Resampled values (matrix [Nrx1]).

Description

  • WARNING : This function is written in C language and interfaced with SCILAB (HYDROGR.dll).

    CAUTION : This function is designed to use daily data. Other time steps are not accepted as the alghorithm use the searching window (WIN) expressed in days.

    Be patient ! The calculation can take up to one hour if DMAT has more than one thousand lines.

Examples

   // Data to identify nearest neighbours (3 variables presenting an annual cycle)
   // The data is supposed to start on the 01/01/1990
   i=(1:800)';
   rnd = rand(790,3);
   rnd2=[];for k=1:3, rnd2(:,k)=convol(ones(11,1),rnd(:,k))'; end; 
   
   // Data used to identify the neighbours
   DMAT = exp(sin(i*%pi/180))*ones(1,3)+rnd2;
   
   // Data to be resampled
   SMAT = (sin(i*%pi/180))*ones(1,2)+rnd2(:,1:2)/10;
   
   rnd3 = rand(2000,1);
   WEI = ones(3,1);
   DMATSELEC=ones(800,1); // No neighbours exclusion
   // Identification of nearest neighbours
   // The 3 variables have the same weight in the euclidiant distance
   SimNN=c_KNN1SIM(5,30,DMAT,WEI,DMATSELEC,1,rnd3);
   
   // Resampling
   Sim = SMAT(SimNN,:);

  

Authors

Julien Lerat

CEMAGREF Antony, HBAN Unit, julien.lerat@cemagref.fr

Bibliography

Lall, U., Sharma, A., 1996. A nearest neighbour bootstrap for time series resampling. Water Resources Research 32 (3), 679–693