-
Notifications
You must be signed in to change notification settings - Fork 1
/
aux2.c
327 lines (289 loc) · 9.17 KB
/
aux2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "SW.h"
/**
\section{AverageInteraction}
\subsection{Description}
calculates the average interaction between neighbors.
\subsection{Input parameters}
\begin{itemize}
\item[J] the interaction array. J.p[i][j] is the interaction between point i
and its jth neighbour.
\end{itemize}
\subsection{Return value}
returns ``the Characteristic Distance''.
\subsection{file}
aux2.c
**/
float AverageInteraction( RaggedArray J )
{
int i,k;
int sum = 0;
float J1 = 0;
for(i = 0; i < J.n; i++)
for(k = 0; k<J.c[i]; k++) {
J1 += J.p[i][k];
sum++;
}
J1 /= ((float) sum);
return(J1);
}
/**
\section{GlobalCorrelation}
\subsection{Description}
Builds the correlations array. If two points belongs to the same cluster,
one is added to the coresponding matrix element.
\subsection{Input parameters}
\begin{itemize}
\item[CorrN] the correlations array. CorrN.p[i][j] is the number of times
vertex i and vertex NK.p[i][j] were in the same cluster so far.
\item[NK] nearest neighbours array. NK.p[i][j] is the j-th neighbour of
vertex i.
\item[Block] the cluster each vertex belongs to.
vertex i belongs to cluster number Block[i].
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[CorrN] the updated correlation array.
\end{itemize}
\subsection{file}
aux2.c
**/
void GlobalCorrelation( UIRaggedArray CorrN, UIRaggedArray NK,
unsigned int *Block )
{
int i,k;
for(i = 0; i < NK.n; i++)
for(k = 0; k<NK.c[i]; k++)
if( Block[i] == Block[ NK.p[i][k] ] ) CorrN.p[i][k]++;
return;
}
/**
\section{FourPointCorrelation}
\subsection{Description}
Builds the four point correlations array. If four points belongs to
the same cluster, one is added to the coresponding matrix element.
\subsection{Input parameters}
\begin{itemize}
\item[FPCorr] the four point correlation array. CorrN.p[i][j].p[k][l]
is the number of times vertices i, NK.p[i][j], k and NK.p[k][l]
were in the same cluster so far.
\item[NK] nearest neighbours array. NK.p[i][j] is the j-th neighbour of
vertex i.
\item[Block] the cluster each vertex belongs to.
vertex i belongs to cluster number Block[i].
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[FPCorr] the updated four point correlation array.
\end{itemize}
\subsection{file}
aux2.c
**/
void FourPointCorrelation( RARaggedArray FPCorr, UIRaggedArray NK,
unsigned int *Block) {
int i,j,k;
int i1,j1,k1;
for(i = 0; i < NK.n; i++)
for(k = 0; k<NK.c[i]; k++)
if(NK.p[i][k]>i)
for(i1 = 0; i1 < NK.n; i1++)
for(k1 = 0; k1<NK.c[i1]; k1++)
if (NK.p[i1][k1]>i1)
if(Block[i] == Block[NK.p[i][k]]
&& Block[i1]==Block[NK.p[i1][k1]])
(FPCorr.p[i][k]).p[i1][k1]++;
}
/* an auxiliary function for magnetization() and OrderClusterSize(). */
/* returns the opposite result to this of uicomp in edge.c */
int uicompare(const void *i, const void *j)
{ return (int)( *((unsigned int*)j) - *((unsigned int*)i) ); }
/**
\section{Magnetization}
\subsection{Description}
Obtain how many points have each spin value. order the groups in
discending order of size. Calculate the magnetization for each spin
color as \[ m_q = {Q N_q - N \over N (Q-1)}, \] where $N_q$ in the
number of points with spin color $q$.
\subsection{Input parameters}
\begin{itemize}
\item[N] number of points.
\item[Q] number of spin values (colors).
\item[nc] number of clusters.
\item[*ClusterSize] cluster sizes.
\item[$N_q$] previously allocated workspace of
size $>=$ Q*sizeof(unsigned int).
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[mag] the magnetization vector.
\end{itemize}
\subsection{Auxiliary function}
int uicompare(const void *i, const void *j)
\subsection{file}
aux2.c
**/
float Magnetization( int N, int Q, int nc, unsigned int *ClusterSize,
float* mag, unsigned int *N_q )
{
int k, q;
memset( N_q, 0, Q*sizeof(unsigned int) );
for(k = 0; k < nc; k++)
N_q[ IRAND(Q) ] += ClusterSize[k];
qsort(N_q,Q,sizeof(unsigned int),uicompare);
for(q = 0; q < Q; q++)
mag[q] = (float)( (int)(Q * N_q[q] - N) ) / (N*(Q - 1.0));
return mag[0];
}
/**
\section{OrderClusterSize}
\subsection{Description}
Order cluster sizes list in discending order..
\subsection{Input parameters}
\begin{itemize}
\item[nc] number of clusters.
\item[*ClusterSize] cluster sizes.
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[*ClusterSize] ordered cluster sizes.
\end{itemize}
\subsection{Auxiliary function}
int uicompare(const void *i, const void *j)
\subsection{file}
aux2.c
**/
void OrderClusterSize( int nc, unsigned int *ClusterSize )
{
qsort(ClusterSize,nc,sizeof(unsigned int),uicompare);
}
/**
\section{ClusterAverage}
\subsection{Description}
Calculate cluster size averages. Returns the mean value and
variance of the larger, second larger, .., smaller cluster sizes.
\subsection{Input parameters}
\begin{itemize}
\item[nc] number of clusters.
\item[*Size1] cluster size conumlant. The i-th element is the comulant of
the i-th larger cluster size.
\item[*size2] cluster size$^2$ comulant.
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[*Size1] sizes mean value.
\item[*Size2] sizes variance.
\end{itemize}
\subsection{file}
aux2.c
**/
void ClusterAverage(int ncy, int N, float *Size1, float *Size2)
{
int i;
/* assume Size1[] is in descending order */
for(i = 0; i<N && Size1[i]>0; i++) {
Size1[i] /= (float)ncy;
Size2[i] /= (float)ncy;
Size2[i] -= (Size1[i] * Size1[i]);
}
}
/**
\section{Susceptibility}
\subsection{Description}
Calculate magnatizations mean value and susceptibilities.
\subsection{Input parameters}
\begin{itemize}
\item[Q] number of spin values.
\item[ncy] number of SW sweeps performed = numbers of samples taken.
\item[*M1] magnetizations comulant.
\item[*M2] magnetizations$^2$ comulant.
\end{itemize}
\subsection{Output parameters}
\begin{itemize}
\item[*M1] magnetizations mean value.
\item[*xi] susceptibilities.
\end{itemize}
\subsection{file}
aux2.c
**/
void Susceptibility( int Q, int ncy, float* M1, float* M2, float* xi )
{
int q;
for(q=0;q<Q;q++) {
M1[q] /= (float)ncy;
M2[q] /= (float)ncy;
xi[q] = (M2[q] - M1[q] * M1[q]);
}
}
int Thresholding(int ncy, float threshold,
UIRaggedArray Corr, UIRaggedArray NK, CRaggedArray Bond,
unsigned int *Block, unsigned int *ClusterSize,
unsigned int *OldBlock, int *n_cols, unsigned int *ws)
{
int i,k,nc;
float th;
th = threshold * ncy;
for(i=0; i< NK.n; i++)
for(k = 0; k<NK.c[i]; k++)
if(th < Corr.p[i][k]) {
if ( OldBlock[i] == OldBlock[ NK.p[i][k] ] ) {
Bond.p[i][k] = 1;
}
else {
Bond.p[i][k] = 0;
(*n_cols)++;
}
}
else
Bond.p[i][k] = 0;
nc = Coarsening(Bond,Block,NK,ClusterSize,ws);
OrderingClusters(NK.n,nc,Block,ClusterSize,ws);
return(nc);
}
/* ---------------------------------------------------------------------- */
/* We perform a directed growth in order to determin a partition */
/* Two points belongs to the same cluster if they have a common */
/* predesessor (see Fukunaga). */
/* The predessessor of each point is the point with maximal correlation */
/* among its neighboors. */
/* The threshold is the number for which we consider that the */
/* correlation is "zero" */
/* ---------------------------------------------------------------------- */
/* actually, here each point is joined to the cluster of */
/* its predessessor -- Guy */
int DirectedGrowth( int ncy, float threshold,
UIRaggedArray Corr, UIRaggedArray NK, UIRaggedArray KN,
CRaggedArray Bond, unsigned int *Block,
unsigned int *ClusterSize, unsigned int *dgOldBlock,
unsigned int *thOldBlock, unsigned int *ws )
{
int i,k;
float th;
float dh;
int nc;
int max, kmax;
th = threshold * ncy;
dh = th/20;
for(i=0; i< NK.n; i++)
for(k = 0; k<NK.c[i];k++)
if ((th < Corr.p[i][k]) &&
(thOldBlock[i] == thOldBlock[NK.p[i][k]])) {
Bond.p[i][k] = 1;
}
else Bond.p[i][k] = 0;
for(i=0; i< NK.n; i++){
max = 0;
for(k = 0; k<NK.c[i]; k++)
if( max < Corr.p[i][k] ){
max = Corr.p[i][k];
kmax = k;
}
if(max > dh){
if ( dgOldBlock[i] == dgOldBlock[ NK.p[i][kmax] ] ) {
Bond.p[i][kmax] = 1;
Bond.p[ NK.p[i][kmax] ][ KN.p[i][kmax] ] = 1;
}
}
}
nc = Coarsening(Bond,Block,NK,ClusterSize,ws);
OrderingClusters(NK.n,nc,Block,ClusterSize,ws);
return(nc);
}