-
Notifications
You must be signed in to change notification settings - Fork 26
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
Flux compatible types that transform inputs #104
Comments
Thanks for opening this! Definitely, the plan is to get I'm not sure that the transformation objects in Comment from here:
This isn't quite right. The The thing I'm thinking about is precisely what you say about constraining kernel length scales and variances -- but here that corresponds to constraining the parameters of To do this, I was imagining having types along the following lines: struct Positive{Tx, Tf} <: AbstractParameter
x::Ref{Tx}
f::Tf
Positive(y, f) = new{Tx, Tf}(Ref(inv(f)(y)), f)
end
Positive(y) = Positive(y, Exp())
value(y::Positive) = y.f(y.x[]) where a To construct it one would pass in the value you want, and the bijector that you want to use to map from unconstrained to constrained. eg. for a positive-valued quantity, you could use The constructor would map the value from the positive reals to the whole of the real line using You could also have a default constructor that provides a reasonable fallback ie. the We could implement a few of these to handle various types of constraints, probably just using the things in I suspect that the reduction in total code won't be incredible, but it will definitely abstract away some of the detail from the kernel implementations in Maybe we don't want to constrain the input transformation to be bijectors, but we can figure that detail out later. |
Hi @willtebbutt , sorry for this late response. I was busy on my project last week and just get time to carefully think about your comment.
So, just summarize what I think we are going to have ( in case where hyperparameters are scalar ) # define abstract parameter type
abstract type AbstractParameter{T} end
const AP{T} = AbstractParameter{T}
# define scalar parameter type
struct ScalarParameter{T, Tf<:Bijector} <: AbstractParameter{T}
x::Ref{T}
f::Tf
end
value(y::ScalarParameter) = y.f(y.x[])
# define vector parameter type ....
# modify transformation function
struct Stretched{Ta<:AP{<:Real}, Tk<:Kernel} <: Kernel
a::Ta
k::Tk
end
function ew(k::Stretched{<:AP{<:Real}}, x::AV{<:Real}, x′::AV{<:Real})
return ew(k.k, value(k.a) .* x, value(k.a) .* x′)
end parameters passed to transformation functions such as Should we depend on Bijector.jl or implement our own Bijectors ? Also notice you guys are working on improving KernelFunctions.jl here 👍 |
Yes, this is exactly what I had in mind!
Definitely we should depend on Bijectors. Rolling our own would be bad imho.
Yup, I'm hoping it will be ready for use with Stheno.jl in the not-too-distant future! |
Cool!, I will collect them into a PR after I finish my assignment this weeks :) |
Based on our discussion here, we agree to design some types to transform input variables, we wish these types work seamlessly with Flux's API, transformations in KernelFunctions.jl are good examples.
Could we achieve it by just letting Stheno.jl work with KernelFunctions.jl ?
The text was updated successfully, but these errors were encountered: