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

MeanLin MethodError? #227

Open
mis0butter opened this issue Aug 7, 2023 · 4 comments
Open

MeanLin MethodError? #227

mis0butter opened this issue Aug 7, 2023 · 4 comments

Comments

@mis0butter
Copy link

Hello,

I am trying to use the MeanLin function but keep running into method errors.

I saw that these issues related to MeanLin were opened and closed, but I have been unable to recreate their solution:
#222
#47

In issue #47, they used the following code (in Julia 0.5):

x = [-4.0,-3.0,-1.0,0.0,2.0];
y = 2.0x + 0.5rand(5);
xpred = collect(-5.0:0.1:5.0);
mean = MeanLin([0.5]) # linear mean function
kern = SE(0.0,0.0) # squared exponential kernel function
gp = GP(x,y,mean,kern) # fit the GP 

When I try running above code, here is the error text and the (beginning of the) stacktrace:

ERROR: MethodError: no method matching *(::Vector{Float64}, ::Vector{Float64})    
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:591
  *(::StridedMatrix{T}, ::StridedVector{S}) where {T<:Union{Float32, Float64, ComplexF32, ComplexF64}, S<:Real} at C:\Users\junet\AppData\Local\Programs\Julia-1.8.3\share\julia\stdlib\v1.8\LinearAlgebra\src\matmul.jl:49
  *(::StridedVecOrMat, ::LinearAlgebra.Adjoint{<:Any, <:LinearAlgebra.LQPackedQ}) at C:\Users\junet\AppData\Local\Programs\Julia-1.8.3\share\julia\stdlib\v1.8\LinearAlgebra\src\lq.jl:269
  ...
Stacktrace:
  [1] mean(mLin::MeanLin, X::LinearAlgebra.Adjoint{Float64, Vector{Float64}})     
    @ GaussianProcesses C:\Users\junet\.julia\packages\GaussianProcesses\dOato\src\means\mLin.jl:27
  [2] update_mll!(gp::GPE{LinearAlgebra.Adjoint{Float64, Vector{Float64}}, Vector{Float64}, MeanLin, SEIso{Float64}, GaussianProcesses.FullCovariance, GaussianProcesses.IsotropicData{Matrix{Float64}}, PDMats.PDMat{Float64, Matrix{Float64}}, GaussianProcesses.Scalar{Float64}}; noise::Bool, domean::Bool, kern::Bool)

I then tried updating the code so that MeanLin would use an actual vector input. Since the mean function is for the model prior, I set the length of the mean vector to be the same as the test / predict points, still didn't work. Just to try everything, I then set the mean vector length to be the same as the training points, no dice:

xtrain = [-4.0, -3.0, -1.0, 0.0, 2.0] 
ytrain = 2.0 * x + 0.5 * rand(5) 
xpred  = collect( -5.0 : 0.1 : 5.0 )
# mLin   = MeanLin( 0 * xtrain ) # linear mean function
mLin   = MeanLin( 0 * xpred ) # linear mean function
kern   = SE( 0.0, 0.0 )                         # squared exponential kernel function
gp     = GP( x, y, mLin, kern )                 # fit the GP 

In Issue #222, I cannot recreate his code at all as he uses code inputs that he doesn't include in his working example.

From mLin.jl, it looks like I should just be able to define some mean = MeanLin(β) where β is a vector and it should work? How to use MeanLin ?

mutable struct MeanLin <: Mean
    "Linear coefficients"
    β::Vector{Float64}
    "Priors for mean parameters"
    priors::Array 

    """
        MeanLin(β::Vector{Float64})

    Create `MeanLin` with linear coefficients `β`.
    """
    MeanLin(β::Vector{Float64}) = new(β, [])
end
@chris-nemeth
Copy link
Member

chris-nemeth commented Aug 9, 2023

If I remember correctly, it used to be possible to fix this issue by taking the transpose of the vector. Have you tried MeanLin(β') instead of MeanLin(β)?

@Jarrod-Angove
Copy link

Using the transpose of the vector no longer works. The method error remains. Have there been any updates on this?

@daniel-frisch-kit
Copy link

You can use MeanPoly([β;;]

@chris-nemeth
Copy link
Member

Thanks @daniel-frisch-kit. @Jarrod-Angove does that work?

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

No branches or pull requests

4 participants