Ising Model

Author

Andres Efren Rocha Jayasinha

Ising Model via Gibbs Sampling

This document explains the algorithm implemented in ising.R, which simulates a 2D Ising model using Gibbs sampling.


Model Setup

  • g = 100 — interior grid is 100×100
  • trials = 100000 — number of single-site updates
  • betalist = (0, 0.441, 0.75, -1.5) — inverse temperature values
g <- 100
trials <- 100000
betalist <- c(0, 0.441, 0.75, -1.5)
par(mfrow = c(2, 2))

Interpretation of β:

  • β > 0 — attraction (spins prefer to align)
  • β = 0 — no interaction (pure randomness)
  • β < 0 — repulsion (spins prefer opposite neighbors)

Spins take values +1 (white) or −1 (black).


Algorithm

1. Loop Over β Values

For each value of β, one simulated configuration is generated.

for (beta in betalist) {

2. Initialize Grid

A (g+2) × (g+2) matrix of random ±1 spins is created, with the outer boundary set to 0. The boundary simplifies neighbor indexing and does not represent physical spins.

  grid <- matrix(sample(c(-1L, 1L), (g + 2)^2, replace = TRUE), nrow = g + 2)
  grid[c(1, g + 2), ] <- 0L
  grid[, c(1, g + 2)] <- 0L

3. Gibbs Sampling Updates

Repeat trials times:

  1. Randomly select an interior site (i, j).
  2. Compute the sum of its four neighbors.
  3. Compute the conditional probability:

\[p = \frac{1}{1 + \exp(-2\beta \cdot \text{deg})}\]

This equals \(P(\sigma_{ij} = +1 \mid \text{neighbors})\).

  1. Draw \(U \sim \text{Uniform}(0, 1)\):

    • If \(U < p\) → set spin to +1
    • Otherwise → set spin to −1
      for (m in seq_len(trials)) {
     i <- sample.int(g, 1) + 1L   # picks 2..(g+1)
     j <- sample.int(g, 1) + 1L
    
     deg <- grid[i, j + 1L] + grid[i, j - 1L] + grid[i - 1L, j] + grid[i + 1L, j]
     p <- 1 / (1 + exp(-beta * 2 * deg))
    
     grid[i, j] <- if (runif(1) < p) 1L else -1L
      }

4. Plot the Result

Remove the boundary and plot the interior grid (black = −1, white = +1).

  final <- grid[2:(g + 1), 2:(g + 1)]
  image(final, yaxt = "n", xaxt = "n", col = c("black", "white"))
}

Output

β Pattern
0 Completely random
0.441 Clustered regions (near critical behavior)
0.75 Strong alignment (large domains)
−1.5 Checkerboard tendency (antiferromagnetic)