Functions with additional parentheses

question

#1

I noticed this syntax in the DynamicHMCExamples package.

function (problem::LogisticRegression)(θ)
    @unpack y, X, σ = problem
    @unpack β = θ
    loglik = sum(logpdf.(Bernoulli.(logistic.(X*β)), y))
    logpri = sum(logpdf.(Ref(Normal(0, σ)), β))
    loglik + logpri
end

Please can someone explain what this does - I haven’t found any instances of this form of declaration elsewhere.


#2

It is this: https://docs.julialang.org/en/v1/manual/methods/index.html#Function-like-objects-1

Methods are associated with types, so it is possible to make any arbitrary Julia object “callable” by adding methods to its type. (Such “callable” objects are sometimes called “functors.”)


#3

I should probably explain things like this in the package docs, which will eventually evolve into an introduction for programming, debugging, and optimizing your own log posteriors in Julia.


#4

Thank you both!