When calibrating/estimating a model, it’s important to compute moments in an efficient way. In the current version of the toolkit, interp1 in the function StatsFromWeightedGrid is a bottleneck.
In my experience, interp1 is an old/slow routine for linear interpolation and it could be replaced with griddedInterpolant (which also works on gpu arrays). I quote from the Matlab website:
" There are memory and performance benefits to using griddedInterpolant objects over the interp functions. griddedInterpolant offers substantial performance improvements for repeated queries of the interpolant object, whereas the interp functions perform a new calculation each time they are called. Also, griddedInterpolant stores the sample points in a memory-efficient format (as a compact grid) and is multithreaded to take advantage of multicore computer processors."
Reference: https://www.mathworks.com/help/matlab/math/interpolating-gridded-data.html
Other alternatives, way faster than interp1:
- interp1q, even if Mathworks does not recommend it, https://www.mathworks.com/help/matlab/ref/interp1q.html
- https://www.mathworks.com/matlabcentral/fileexchange/43325-quicker-1d-linear-interpolation-interp1qr