Policy function interpolation - error

Hi,

I need to ask for help regarding splines/interpolation. I just implemented value function iteration code (simple discretization), and now, I need to interpolate resulting discrete policy function (for purpose of model simulation).

I followed this notebook https://lectures.quantecon.org/jl/general_packages.html (section multivariate interpolation). Examples from this notebook worked fine (except scatter plotting function). However, when I tried to use same function to my data (discretized policy function), I get following error:

julia> Policy = CubicSplineInterpolation((hcat(GridK),A),PolicyDiscrete)
ERROR: MethodError: no method matching CubicSplineInterpolation(::Tuple{Array{Float64,2},Array{Float64,2}}, ::Array{Float64,2})
Closest candidates are:
CubicSplineInterpolation(::Tuple{Vararg{AbstractRange,N}}, ::AbstractArray{T,N}; bc, extrapolation_bc) where {N, T} at C:\Users\janze.julia\packages\Interpolations\jXoPW\src\convenience-constructors.jl:19
Stacktrace:
[1] top-level scope at none:0

My imput arguments are following:

julia> typeof(GridK)
Array{Float64,1}
julia> size(GridK)
(1500,)

julia> typeof(A)
Array{Float64,2}
julia> size(A)
(1, 3)

julia> typeof(PolicyDiscrete)
Array{Float64,2}
julia> size(PolicyDiscrete)
(1500, 3)

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel® Core™ i7-8750H CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = “C:\Users\janze\AppData\Local\atom\app-1.38.2\atom.exe” -a
JULIA_NUM_THREADS = 6

Any advice/guidance will be wellcomed!

Best
Jan Žemlička

Jan,
The Interpolations.jl cubic splines are only for regular grids (as far as I know). If you are using a regular grid, then pass your gridK, etc. as a range (e.g. the -7.0:0.1:7.0, etc.) instead. Regular grids have a different and higher performance algorithm for both linearinterpolation/cubicspline/etc.

If an irregular grid is required then:

As with everything in Julia, you are best off making sure that you have a Manifest.toml and Project.toml file associated with your project that has the appropriate versions of packages established in it. It makes trying different packages less dangerous since they won’t suddenly break on you.

Thank you for your guidance!

I managed to interpolate my policy function using GridInterpolations.jl package, it works fine. I tried to pass GridK to Interpolation.jl, but I get just some dimesions incompatibility error (but in GridInterpolations, it works perfectly fine).

Best Regards
Jan Žemlička

I think it probably has to do with what the interface is expecting. i.e. ranges rather than arrays. If you really want to use Interpolations.jl , you could start by taking one of the examples from the help files and then do a minimal amount of changes on it. I think that instead of trying to pass in your GridK, you should try to figure out what form it wants and adapt your GridK to that form.