… using Stan & HMC

Here, I sample from an Ising-like model (I treat the random variables as continuous, between -1 and 1 and add a term to the pseudo-likelihood that resembles a beta log density).

functions {
    real log_p(matrix m, real T, real alpha) {
        int n = rows(m);
        return( (1/T) * sum(m[2:(n-1), 2:(n-1)] .* m[1:(n-2), 2:(n-1)] +
                            m[2:(n-1), 2:(n-1)] .* m[2:(n-1), 1:(n-2)] +
                            m[2:(n-1), 2:(n-1)] .* m[3:n    , 2:(n-1)] +
                            m[2:(n-1), 2:(n-1)] .* m[2:(n-1), 3:n    ]) +
                sum( log(m/2 + 0.5)*(alpha - 1) + log(0.5 - m/2)*(alpha - 1) ));
    }
}
data {
    int n;
    real T;
    real alpha;
}
parameters {
    matrix<lower = -1, upper = 1>[n, n] m;
}
model {
    target += log_p(m, T, alpha);
}

The matrix terms are essentially a vectorised product-sum of nearest neighbour spins.

Results:

2019

Back to Top ↑

2018

Back to Top ↑