Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mean function #89

Closed
trappmartin opened this issue Jan 6, 2021 · 11 comments · Fixed by #140
Closed

Mean function #89

trappmartin opened this issue Jan 6, 2021 · 11 comments · Fixed by #140

Comments

@trappmartin
Copy link

Hi, I just played around with this.. it's awesome!

Some remarks / bugs:

  1. When calling mean(f) on a GP object, I get an error message in the lines of:
MethodError: no method matching iterate(::AbstractGPs.PosteriorGP{AbstractGPs.GP{AbstractGPs.ZeroMean{Float64},KernelFunctions.Matern32Kernel},NamedTuple{(:α, :C, :x, :δ),Tuple{Array{Float64,1},LinearAlgebra.Cholesky{Float64,Array{Float64,2}},KernelFunctions.ColVecs{Float64,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},SubArray{Float64,1,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},false}},Array{Float64,1}}}})
mean(::typeof(identity), ::AbstractGPs.PosteriorGP{AbstractGPs.GP{AbstractGPs.ZeroMean{Float64},KernelFunctions.Matern32Kernel},NamedTuple{(:α, :C, :x, :δ),Tuple{Array{Float64,1},LinearAlgebra.Cholesky{Float64,Array{Float64,2}},KernelFunctions.ColVecs{Float64,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},SubArray{Float64,1,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},false}},Array{Float64,1}}}})@Statistics.jl:62
mean(::AbstractGPs.PosteriorGP{AbstractGPs.GP{AbstractGPs.ZeroMean{Float64},KernelFunctions.Matern32Kernel},NamedTuple{(:α, :C, :x, :δ),Tuple{Array{Float64,1},LinearAlgebra.Cholesky{Float64,Array{Float64,2}},KernelFunctions.ColVecs{Float64,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},SubArray{Float64,1,LinearAlgebra.Adjoint{Float64,Array{Float64,2}},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},false}},Array{Float64,1}}}})@Statistics.jl:44
top-level scope@Local: 1[inlined]
  1. When calling mean(f, x) on a GP object for some x, then x has to be a vector. If the covariate space is multidimensional this has to be a vector of vectors. This should be written down somewhere as I didn't know how to use mean(f, x) on a GP on a multidimensional covariate space. Maybe it is, and I didn't see it? Anyways, maybe this function could also support Arrays?
@willtebbutt
Copy link
Member

willtebbutt commented Jan 6, 2021

👋

When calling mean(f) on a GP object, I get an error message in the lines of:

Hmmm yeah, I guess you wanted the mean function instead?

When calling mean(f, x) on a GP object for some x, then x has to be a vector. If the covariate space is multidimensional this has to be a vector of vectors. This should be written down somewhere as I didn't know how to use mean(f, x) on a GP on a multidimensional covariate space. Maybe it is, and I didn't see it? Anyways, maybe this function could also support Arrays?

Yeah, this is a convention that we've broadly adopted. You should wrap a matrix of inputs either in a ColVecs (if each column of said matrix corresponds to an input) or a RowVecs (if each row corresponds to a single input). Semantically these containers represent a vector-of-vectors, they just do stuff more efficiently under the hood than literally constructing a vector-of-vectors.

I agree that this needs to be documented somewhere. A PR would be very welcome :)

edit: when you say "support arrays", do you just mean matrices, or higher-dimensional things as well?

@theogf
Copy link
Member

theogf commented Jan 6, 2021

I think that mean(f::PosteriorGP) should automatically return the mean of the posterior distribution on the training data no (same with cov).

Also we should probably support mean(f, X::AbstractMatrix) in the same way that we support gp(X::AbstractMatrix)

@willtebbutt
Copy link
Member

I think that mean(f::PosteriorGP) should automatically return the mean of the posterior distribution on the training data no (same with cov).

I disagree with this. A PosteriorGP is just another GP -- it typically represents some infinite-dimensional thing, so it would be weird to support this functionality. I could get on board with adding additional functions such as mean_at_training_data and cov_at_training_data though.

@willtebbutt
Copy link
Member

I would have no problem with mean(f::PosteriorGP) returning a function that can compute the posterior mean at new locations -- it just feels a bit redundant because you can write mean(f_post(x)) instead.

@trappmartin
Copy link
Author

Yeah, I think it's mostly an issue of documentation tbh. I don't think it makes much sense to add functionality.

@trappmartin
Copy link
Author

But having a mean(f, X::AbstractMatrix) would make a lot of sense as you seem to be able to use X as a matrix on all other places too.

@willtebbutt
Copy link
Member

Do we know if anyone is likely to have time work on docs any time soon? I'm completely swamped with PhD stuff at the minute.

@trappmartin
Copy link
Author

edit: when you say "support arrays", do you just mean matrices, or higher-dimensional things as well?

Whatever makes sense. I'd say matrices, but maybe there are use-cases that would require higher-dimensional things? Dunno.

@trappmartin
Copy link
Author

Sorry. Wrong button...

@willtebbutt
Copy link
Member

Happens to me all the time

@theogf
Copy link
Member

theogf commented Jan 6, 2021

Actually @st-- proposed to help by working on some tutorials with AbstractGPs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants