JuliaGaussianProcesses / Stheno.jl

Probabilistic Programming with Gaussian processes in Julia
Other
338 stars 26 forks source link

BlockArray pullback is inadequate #238

Closed RalphAS closed 1 year ago

RalphAS commented 1 year ago

While trying to run the Mauna Loa CO2 example I encountered a missing method for the pullback because somewhere a BlockArray{UpperTriangular} is differentiated:

ERROR: MethodError: no method matching (::Stheno.var"#Array_pullback#8"{BlockArrays.BlockMatrix{Float64, Matrix{Matrix{Float64}}, Tuple{BlockArrays.BlockedUnitRange{Vector{Int64}}, BlockArrays.BlockedUnitRange{Vector{Int64}}}}})(::LinearAlgebra.UpperTriangular{Float64, Matrix{Float64}})
RalphAS commented 1 year ago

Here is a reduced case which throws the error:

using LinearAlgebra
using AbstractGPs
using Stheno
using Zygote

function build_gp(θ)
    return @gppp let
        fbb1 = θ[2] * stretch(GP(SEKernel()), θ[3])
    end
end

function trial()
    n1 = 50
    ftrue(x) = exp(-x^2)
    x1 = randn(n1)
    err1 = 0.01 * randn(n1)
    x = BlockData(GPPPInput(:fbb1, x1))
    y = ftrue.(x1) + err1
    function build_obs_cov(θ)
        var1 = θ[1]
        return Diagonal(fill(var1,n1))
    end
    function nlml(θ)
        fm = build_gp(θ)
        C = build_obs_cov(θ)
        loss = -logpdf(fm(x, C), y)
        return loss
    end
    θ0 = ones(3)
    val, grad = Zygote.withgradient(nlml, θ0)
end

trial()
willtebbutt commented 1 year ago

Resolved by #244