Speed up model in Turing

Note that I am new to Turing as well as to Bayesian inference.
I have to following simple Bayesian linear regression model. (This is pretty much the tutorial example)

    Turing.@model function linear_regression(x, y)
        s ~ Distributions.truncated(Distributions.Normal(0, 10), 0, Inf)
        b ~ Distributions.MvNormal(zeros(size(x, 2)), 1)
        y ~ Distributions.MvNormal(x * b, s)
    end

    model = linear_regression(X_train_norm, y_train_norm)
    chain = Turing.sample(model, Turing.NUTS(0.65), 1000)

where X_train_norm and y_train_norm have been both normalized.
The size of X is 5760x74

The model works for smaller sample sizes and less predictors (360x20 @ 20s) but with the data size from above from above it takes such a long time that I simply stopped it.

Is there something wrong? Are other samplers better for this job? Is there something obvious that I can do to speed it up?

My goal is to make a Markov switching model where in each regime the model is a linear regression.

I mean, that’s a lot of data, so it’s not surprising that it’s taking you a long time. The only fix I would suggest is using ReverseDiff, with

Turing.setadbackend(:reversediff)

at the top of your script, after you import Turing.

3 Likes