neville

Syntax

neville(X, Y, resampleRule, [closed='left'], [origin='start_day'], [outputX=false])

Parameters

X is a strictly increasing vector of temporal type.

Y is a numeric vector of the same length as X.

resampleRule is a string. See the parameter rule of function resample for the optional values.

closed and origin are the same as the parameters closed and origin of function resample.

outputX is a Boolean value indicating whether to output the resampled X. The default value is false.

Details

Resample X based on the specified resampleRule, closed and origin. Perform neville interpolation on Y based on the resampled X.

If outputX is unspecified, return a vector of Y after the interpolation.

If outputX=true, return a tuple where the first element is the vector of resampled X and the second element is a vector of Y after the interpolation.

Examples

Example 1
neville([2016.02.14 00:00:00, 2016.02.15 00:00:00, 2016.02.16 00:00:00], [1.0, 2.0, 4.0], resampleRule=`60min);

/* output:
[1,1.0217,1.0451,1.0703,1.0972,1.1259,1.1562,1.1884,1.2222,1.2578,
1.2951,1.3342,1.375,1.4175,1.4618,1.5078,1.5556,1.605,1.6562,1.7092,
1.7639,1.8203,1.8785,1.9384,2,2.0634,2.1285,2.1953,2.2639,2.3342,
2.4062,2.48,2.5556,2.6328,2.7118,2.7925,2.875,2.9592,3.0451,3.1328,
3.2222,3.3134,3.4062,3.5009,3.5972,3.6953,3.7951,3.8967,4]
*/
Example 2 Different values of closed affect the result.
// Data points fall exactly on 3-minute boundaries
X = 2022.01.01T00:00:00 + [0, 3, 6, 9] * 60  // 00:00, 00:03, 00:06, 00:09
Y = [1.0, 3.0, 7.0, 13.0]

// closed='left' (default): interval [t, t+3min); 00:03 is the start of the second bucket
neville(X, Y, `3min, closed=`left, outputX=true)

// closed='right': interval (t, t+3min]; 00:03 is the end of the first bucket
// Bucket boundaries shift, interpolation curve changes accordingly
neville(X, Y, `3min, closed=`right, outputX=true)
Example 3 Different values of origin affect the result.
// Data starts at 00:00:30 and is not aligned to whole minutes
X = 2022.01.01T00:00:30 + (0..4) * 60  // 00:00:30, 00:01:30, ..., 00:04:30
Y = [2.0, 4.0, 7.0, 11.0, 16.0]

// origin='start_day' (default): align to 00:00:00 of the same day
// Resampled X: 00:00:00, 00:01:00, 00:02:00, 00:03:00, 00:04:00
neville(X, Y, `1min, origin=`start_day, outputX=true)

// origin='start': align to the first data point 00:00:30
// Resampled X: 00:00:30, 00:01:30, 00:02:30, 00:03:30, 00:04:30
neville(X, Y, `1min, origin=`start, outputX=true)

// origin=custom timestamp: align to 00:00:10
// Resampled X: 00:00:10, 00:01:10, 00:02:10, 00:03:10, 00:04:10
neville(X, Y, `1min, origin=2022.01.01T00:00:10, outputX=true)
Example 4 Different values of outputX affect the result.
X = [2016.02.14T00:00:00, 2016.02.15T00:00:00, 2016.02.16T00:00:00]
Y = [1.0, 2.0, 4.0]

// outputX=false (default): return only the interpolated Y vector
neville(X, Y, `60min)

// outputX=true: return a tuple; [0] is the resampled timestamp vector, [1] is the interpolated Y
result = neville(X, Y, `60min, outputX=true)
result[0]  // One timestamp per hour, 49 in total
result[1]  // Corresponding interpolated Y values, 49 in total