# Stheno marginals

I’m trying to follow the examples but having some issues. What’s going wrong here?

[8188c328] Stheno v0.7.1

``````#
# This file just shows how some of the basic manipulations you can do in Stheno work in
# practice. See the main documentation and the rest of this examples folder for more info.
#

# Set up the environment to run this example. Make sure you're within the folder that this
# file lives in.

# The time-to-first-plot issue means that this might take a little while.
using LinearAlgebra, Random, Stheno
using Stheno: posterior, logpdf, marginals
rng = MersenneTwister(123456)

# Construct a Matern-5/2 kernel with lengthscale 0.5 and variance 1.2.
k = 1.2 * transform(Matern52Kernel(), 0.5)

# Construct a zero-mean GP with a simple kernel. Don't worry about the GPC object.
f = Stheno.wrap(GP(k), GPC())

# Specify some locations at which to consider the GP.
N = 50
x = rand(rng, N) * 10

# Specify the variance of the noise under which we'll make observations of the GP.
# We could also have made this a `Real` to specify isotropic noise.
Σ = Diagonal(rand(rng, N) .+ 0.1)

# Construct marginal distribution over `f` at `x` added to some independent zero-mean
# Gaussian noise with covariance matrix `Σ`.
fx = f(x, Σ)

# Generate a sample from the prior.
y = rand(rng, fx)

# Compute the log marginal probability of the sample under the prior.
# logpdf(fx, y)

# Do inference: compute the posterior distribution over `f` given we observe it + noise to
# be `y` at locations `x`.
f_post = posterior(fx, y);

# Specify some points at which to plot the posterior.
Npr = 1000
xpr = range(-3.0, 13.0; length=Npr)

# Construct the posterior predictive distribution at `xpr`. Add some jitter.
fx_post = f_post(xpr, 1e-9)

# Draw samples from the posterior.
y_post = rand(rng, fx_post)

# Compute the marginal posterior predictive probability of the samples.
logpdf(fx_post, y_post)

# Compute the posterior marginal distributions. (We could equally have done this with `fx`).
posterior_marginals = marginals(fx_post)
``````
``````
julia> posterior_marginals = marginals(fx_post)
ERROR: MethodError: no method matching marginals(::AbstractGPs.FiniteGP{AbstractGPs.PosteriorGP{Stheno.WrappedGP{GP{AbstractGPs.ZeroMean{Float64},ScaledKernel{TransformedKernel{Matern52Kernel,ScaleTransform{Float64}},Float64}}},NamedTuple{(:α, :C, :x, :δ),Tuple{Array{Float64,1},Cholesky{Float64,Array{Float64,2}},Array{Float64,1},Array{Float64,1}}}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Diagonal{Float64,FillArrays.Fill{Float64,1,Tuple{Base.OneTo{Int64}}}}})
Closest candidates are:
marginals(::SparseFiniteGP)
``````

I assume that `Stheno.marginals != AbstractGPs.marginals` and that it works if you replace `using Stheno: posterior, logpdf, marginals` with `using AbstractGPs`. I opened a potential fix in Stheno: Import `marginals` by devmotion · Pull Request #173 · JuliaGaussianProcesses/Stheno.jl · GitHub

2 Likes

Thanks @devmotion for the fix, it’s now merged.

@jzr please let us know if upgrading to 0.7.2 doesn’t fix the problem (should be available within the next hour or two)

1 Like

Yep it works.

@willtebbutt 0.7 is no longer compatible with Soss?

``````pkg> add Stheno@0.7.2 Soss
Updating registry at `~/.julia/registries/General`
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Optim [429524aa]:
Optim [429524aa] log:
├─possible versions are: [0.15.3, 0.16.0, 0.17.0-0.17.2, 0.18.0-0.18.1, 0.19.0-0.19.7, 0.20.0-0.20.6, 0.21.0, 0.22.0, 1.0.0, 1.1.0, 1.2.0-1.2.4, 1.3.0] or uninstalled
├─restricted by compatibility requirements with SimpleGraphs [55797a34] to versions: [0.15.3, 0.16.0, 0.17.0-0.17.2, 0.18.0-0.18.1, 0.19.0-0.19.7, 0.20.0-0.20.6, 0.21.0, 0.22.0]
│ └─SimpleGraphs [55797a34] log:
│   ├─possible versions are: [0.2.3-0.2.10, 0.3.0, 0.4.0-0.4.4, 0.5.0-0.5.3, 0.6.0-0.6.10, 0.7.0-0.7.6] or uninstalled
│   ├─restricted by compatibility requirements with Soss [8ce77f84] to versions: [0.2.3-0.2.10, 0.3.0, 0.4.0-0.4.4, 0.5.0-0.5.3, 0.6.0-0.6.10, 0.7.0-0.7.6]
│   │ └─Soss [8ce77f84] log:
│   │   ├─possible versions are: [0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.4, 0.15.0-0.15.3, 0.16.0-0.16.2, 0.17.0] or uninstalled
│   │   ├─restricted to versions * by an explicit requirement, leaving only versions [0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.4, 0.15.0-0.15.3, 0.16.0-0.16.2, 0.17.0]
│   │   ├─restricted by compatibility requirements with Stheno [8188c328] to versions: [0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.4, 0.15.0-0.15.3, 0.16.0-0.16.2, 0.17.0] or uninstalled, leaving only versions: [0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0-0.13.1, 0.14.0-0.14.4, 0.15.0-0.15.3, 0.16.0-0.16.2, 0.17.0]
│   │   │ └─Stheno [8188c328] log:
│   │   │   ├─possible versions are: [0.1.0-0.1.1, 0.2.0-0.2.1, 0.3.0-0.3.2, 0.4.0-0.4.2, 0.5.0, 0.6.0-0.6.20, 0.7.0-0.7.2] or uninstalled
│   │   │   └─restricted to versions 0.7.2 by an explicit requirement, leaving only versions 0.7.2
...
``````

(cc @cscherrer )

1 Like

Hmm yeah, it looks like Stheno and Soss have quite different deps now.

I’m looking into fixing this, will report back when I know more.

1 Like

Actually looks like it’s just related to SimpleGraphs.jl – it’s still depending on an old pre-1.0 version of Optim, which in turn is holding some other dependencies back.

I’ve opened a PR here which should hopefully fix the issue.

In the meantime, could you try `dev --local SimpleGraphs` and modify the `[compat]` entry in the `Project.toml` for `Optim.jl` to include version 1, and confirm this also fixes the problem for you?

edit: also, thank you for raising these issues – it’s very much appreciated that you let us know when stuff is broken!

edit2: fix typo

2 Likes

Thanks @jzr for catching this, and @willtebbutt for the quick fix! I think it’s worth noting that there are some big changes in Soss v0.17. Maybe most notably, we still depend on Distributions.jl but have started to move more toward MeasureTheory.jl. Distributions should still work just fine, but performance and flexibility can be a little better with MT. OTOH it’s still under heavy development, so we fall back to Distributions as needed.

1 Like