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

Add Periodic Kernel #50

Merged
merged 10 commits into from
Apr 13, 2020
Merged

Add Periodic Kernel #50

merged 10 commits into from
Apr 13, 2020

Conversation

theogf
Copy link
Member

@theogf theogf commented Mar 17, 2020

Following the request #34 I implemented a first version of the periodic kernel described in http://www.inference.org.uk/mackay/gpB.pdf equation 47.
I also added the unconventional Sinus metric to keep the same style as other kernels.

src/distances/sinus.jl Outdated Show resolved Hide resolved
r::Vector{T}
end

@inline function Distances._evaluate(d::Sinus,a::AbstractVector{T},b::AbstractVector{T}) where {T}
Copy link
Member

Choose a reason for hiding this comment

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

In general, I think one should rather define Distances.parameters and Distances.eval_op (I guess the default definitions of eval_start, eval_reduce, and eval_end should be fine). A Zygote-compatible implementation could then be added in the definition of the custom adjoint.
Here's an example how these functions are used when evaluating the distance between two arrays:
https://github.com/JuliaStats/Distances.jl/blob/master/src/metrics.jl#L181-L210
Using these definitions, one could even just define

(dist::Sinus)(a::Number, b::Number) = Distances.eval_op(dist, a, b, first(dist.r))

similar to https://github.com/JuliaStats/Distances.jl/blob/7f3a28c0d1372e3b3edbcbc28f00ba5645e1bbdb/src/metrics.jl#L267.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks I implemented eval_op only now

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry I completely missed that 🙈 Somehow I assumed JuliaStats/Distances.jl#126 was fixed already.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will leave it as it is for now

Choose a reason for hiding this comment

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

The "UnionMetrics as a Union" issue is now resolved on master of Distances.jl, so @devmotion's suggestion should now be doable. There is a similar minimal example in JuliaStats/Distances.jl#151 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

@dkarrasch Thanks! We need to wait for a new release of Distances.jl now...

src/kernels/periodic.jl Outdated Show resolved Hide resolved
@theogf
Copy link
Member Author

theogf commented Apr 13, 2020

I could not put the eval_op approach as there is no release of Distances for it. I put it as commented and will leave it for another PR (solving DotProduct at the same time)

@theogf theogf merged commit 252f595 into master Apr 13, 2020
@theogf theogf deleted the periodickernel branch April 16, 2020 12:54
@dkarrasch
Copy link

Not sure where to post it, so I'll do it here. Distances.jl has released a new version, that allows to subtype Union*Metrics. If you do that, however, you'll need a lower compat bound for Distances.jl "0.9".

@devmotion
Copy link
Member

I've already added a lower bound for 0.9 (

Distances = "0.9"
) to get rid of the SqEuclidean hacks (was needed to avoid the negative results).

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.

3 participants