Swendsen–Wang algortihm for Monte Caro Simulation in Potts Model

4 views (last 30 days)
I have implemented this algorithm in matlab by I don't get the result which I am supposed to get. I would appreciate it if someone can tell me where I am making a mistake/s.
W: is k- mutual nearest neighbors matrix
J: interaction strength matrix
n: number of data points
q: # spins
T: temperature
[ S ] = init_S_gen( n,q ); % this generates random q spin values for n data point
for i=1:15
T=0.005*i;
[ chi(i),Cluster,S ] = Monte_Carlo_sim(W,J,M,n,q,T,S);
end
function [ chi,Cluster,S ] = Monte_Carlo_sim(W,J,M,n,q,T,S)
for ii=1:M
P=[];
[P]=frozen(W,J,S,T);
Cluster=[];
[ Cluster ] = SW_cluster( P );
%%Physical quantities
m_S(ii)=gen_magnetization(S,q,n);
[S]= update_S(Cluster,q);
end
chi=n/T*(nanmean(m_S.^2)-nanmean(m_S)^2);
end
function [ Cluster ] = SW_cluster( P )
%This function finds the SW_clusters
n=length(P);
d = rand(n,1); % The diagonal values
t = triu(bsxfun(@min,d,d.').*rand(n),1); % The upper trianglar random values
rand_N = diag(d)+t+t.'; % Put them together in a symmetric matrix
frozen_acc=rand_N<P;
PP=frozen_acc;
[nComponents,~,~,Cluster] = networkComponents(PP); % This function finds the connected components of the graph based on its adjacency matrix.
end
function [m_S]=gen_magnetization(S,q,n)
%This function computes the m_S, magnetization associated with a spin configuration S
spin_vec=1:q;
spin_mat=repmat(spin_vec,[n 1]);
S_mat=repmat(S',[1 q]);
N_S=sum((spin_mat== S_mat),1);
N_max_S=max(N_S);
m_S=(q*N_max_S-n)/((q-1)*n);
end
  1 Comment
John D'Errico
John D'Errico on 22 Feb 2016
Edited: Walter Roberson on 22 Feb 2016
Why do you think there is a mistake? GIVE US A HINT! Do you expect us to:
  1. Research what you want to do, so find someplace that describes the "Swendsen–Wang algortihm for Monte Caro Simulation in Potts Model"
  2. Read your code, trying to understand what you did.
  3. Run your code, debugging any and all bugs in the code.
  4. Provide fixes for the problems that we found
I'm sorry, but I don't have a few hours to waste. When you have a problem, make it easy for someone to help you. Otherwise, the crystal ball gets so foggy.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!