LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ljcd_interpolate.m
1function Xval = ljcd_interpolate(nvec, cutoffs, table, K)
2% LJCD_INTERPOLATE Multi-linear interpolation for LJCD scaling tables
3%
4% Xval = LJCD_INTERPOLATE(nvec, cutoffs, table, K)
5%
6% Performs multi-linear interpolation of a throughput value from an LJCD
7% scaling table for non-integer population vectors.
8%
9% Parameters:
10% nvec - [n1, n2, ..., nK] continuous population vector (clamped to cutoffs)
11% cutoffs - [N1, N2, ..., NK] per-class cutoffs
12% table - Linearized throughput table (1-D array indexed by ljd_linearize)
13% K - Number of classes
14%
15% Returns:
16% Xval - Interpolated throughput value
17%
18% For K classes, interpolates between 2^K corner points of the hypercube
19% containing the population vector using multi-linear interpolation.
20%
21% Copyright (c) 2012-2026, Imperial College London
22% All rights reserved.
23
24% Get floor and ceiling for each dimension
25nFloor = floor(nvec);
26nCeil = ceil(nvec);
27
28% Clamp to valid range
29nFloor = max(0, min(nFloor, cutoffs));
30nCeil = max(0, min(nCeil, cutoffs));
31
32% Compute fractional parts (weights)
33frac = nvec - nFloor;
34
35% Handle edge case: all integer values
36if all(abs(frac) < 1e-10)
37 idx = ljd_linearize(nFloor, cutoffs);
38 if idx <= length(table)
39 Xval = table(idx);
40 else
41 Xval = 0;
42 end
43 return;
44end
45
46% Multi-linear interpolation over 2^K corners
47Xval = 0;
48numCorners = 2^K;
49
50for corner = 0:(numCorners - 1)
51 % Build corner point: bit i determines floor (0) or ceil (1) for class i
52 cornerPoint = nFloor;
53 weight = 1.0;
54
55 for i = 1:K
56 if bitget(corner, i)
57 % Use ceiling for this dimension
58 cornerPoint(i) = nCeil(i);
59 weight = weight * frac(i);
60 else
61 % Use floor for this dimension
62 weight = weight * (1 - frac(i));
63 end
64 end
65
66 % Look up table value at corner point
67 idx = ljd_linearize(cornerPoint, cutoffs);
68 if idx <= length(table)
69 Xval = Xval + weight * table(idx);
70 end
71end
72
73end