Skip to content

Add Fractional Brownian motion kernel #48

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

Merged
merged 21 commits into from
Mar 27, 2020
Merged

Add Fractional Brownian motion kernel #48

merged 21 commits into from
Mar 27, 2020

Conversation

sharanry
Copy link
Contributor

Issue #44

I am trying to implement Fractional Brownian motion covariance given by

    κ(x,y) =  ( |x|²ʰ + |z|²ʰ - |x-z|²ʰ ) / 2

with Hurst index h from (0,1).

I don't think the current structure of kappa and metric can be used directly implement this. I am considering implementing a modified kappa function to serve such cases. Any thoughts on this?

@sharanry
Copy link
Contributor Author

@willtebbutt
Copy link
Member

willtebbutt commented Mar 17, 2020

Yeah -- doesn't look doable with kappa and metric

The best way to go about implementing this will be to implement kernelmatrix and kerneldiagmatrix directly. The kappa and metric abstraction is just a convenient way of doing that anyway, so if its not applicable to a particular problem, you can always just implement kernelmatrix and kerneldiagmatrix directly. See eg. the KernelSum implementation for an example of how this would work.

sharanry and others added 2 commits March 20, 2020 00:25
Co-Authored-By: David Widmann <[email protected]>
Co-Authored-By: David Widmann <[email protected]>
Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor things. Not properly reviewed yet.

@sharanry sharanry changed the title [WIP] Add Fractional Brownian motion kernel Add Fractional Brownian motion kernel Mar 20, 2020
@sharanry sharanry requested a review from willtebbutt March 24, 2020 10:10
Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've left a few style-related comments that could do with addressing before merging though.

@sharanry
Copy link
Contributor Author

@willtebbutt Can we merge this now?

@devmotion
Copy link
Member

I guess it would be good to implement the inplace variants kernelmatrix! and kerneldiagmatrix! as well.

@sharanry
Copy link
Contributor Author

sharanry commented Mar 25, 2020

@theogf @devmotion
What is the purpose of kerneldiagmatrix and kerneldiagmatrix!?
We currently have implementations in general for

kerneldiagmatrix::Kernel, X::Matrix; obsdim::Int=2)
kerneldiagmatrix!(K::AbstractVector::Kernel, X::Matrix; obsdim::Int=2)

however we do not have implementations for

kerneldiagmatrix::Kernel, X::Matrix,Y::Matrix; obsdim::Int=2)
kerneldiagmatrix!(K::AbstractVector::Kernel, X::Matrix,Y::Matrix; obsdim::Int=2)

Any particular reason begin this?

@willtebbutt
Copy link
Member

willtebbutt commented Mar 25, 2020

Any particular reason begin this?

This is definitely something that I want, because it's crucial for Stheno.jl (see the docs for the rationale). I don't think this PR is the right place for it though -- I would stick with implementing the current interface, and we can re-visit later.

edit:

What is the purpose of kerneldiagmatrix and kerneldiagmatrix!?

The reason for these is computational efficiency. If you want to compute posterior marginal statistics or construct certain pseudo-point approximations, you only wind up needing the diagonal elements of certain covariance matrices.

@sharanry
Copy link
Contributor Author

@willtebbutt So are we going to implement kerneldiagmatrix and kerneldiagmatrix! for FBMKernel before merging or not?

@theogf
Copy link
Member

theogf commented Mar 25, 2020

kerneldiagmatrix(k, X) aims at computing the diagonal only of kernelmatrix(k, X). As @willtebbutt pointed out, this extremely useful for Gaussian Processes (and probably other stuff)
This would not make sense to do it for kerneldiagmatrix(k, X, Y) because the diagonal of a non-square matrix is not really useful

@willtebbutt
Copy link
Member

willtebbutt commented Mar 25, 2020

@willtebbutt So are we going to implement kerneldiagmatrix and kerneldiagmatrix! for FBMKernel before merging or not?

Yes, but only the single-input ones.

@sharanry
Copy link
Contributor Author

@theogf @willtebbutt I was confused because it always seems to return an array of ones. As it probably should. But I guess this is not the right place. I will discuss this over slack.

julia> kerneldiagmatrix(CosineKernel(), rand(3,3))
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

julia> kerneldiagmatrix(SqExponentialKernel(), rand(3,3))
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

julia> kerneldiagmatrix(ExponentialKernel(), rand(3,3))
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

@theogf
Copy link
Member

theogf commented Mar 25, 2020

Well it's because all these kernels are based on Euclidean distance and you will always get a distance of 0, hence all the ones! If you try with the LinearKernel, it won't be the case

@sharanry
Copy link
Contributor Author

@theogf Thanks a lot for that! Now it makes sense :)

@sharanry
Copy link
Contributor Author

@willtebbutt Please take a look. Implementing just _kernel specific to FBMKernel seems to suffice.

@sharanry sharanry requested a review from willtebbutt March 27, 2020 09:50
Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@willtebbutt
Copy link
Member

Actually, sorry, I've just thought: do we actually need to implement _kernel to make kerneldiagmatrix work? Looks like the _kernel implementations near here should do the trick.

@sharanry
Copy link
Contributor Author

@willtebbutt Yeah but that uses kappa which we don't have.

@willtebbutt willtebbutt merged commit 32888d5 into JuliaGaussianProcesses:master Mar 27, 2020
@sharanry sharanry deleted the fbm branch March 27, 2020 10:28
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 this pull request may close these issues.

4 participants