9 static double boundingbox_area(
int n,
double *x){
14 for (i = 0; i < n; i++){
15 xmax =
MAX(xmax, x[2*i]);
16 xmin =
MIN(xmin, x[2*i]);
17 ymax =
MAX(ymax, x[2*i+1]);
18 ymin =
MIN(ymin, x[2*i+1]);
20 return (xmax-xmin)*(ymax-
ymin);
25 #define MINDIST 0.000000001
30 for (k = 0; k < dim; k++) dist += (x[i*dim+k] - x[j*dim + k])*(x[i*dim+k] - x[j*dim + k]);
38 for (k = 0; k < dim; k++) dist += (x[i*dim+k] - x[j*dim + k])*(x[i*dim+k] - x[j*dim + k]);
48 real top = 0, bot = 0, c,
s, f = 0, yy, yx, xxavg = 0, xyavg = 0, yxavg = 0, yyavg = 0;
51 for (i = 0; i < n; i++){
58 for (i = 0; i < n; i++){
61 yx = c*y[2*i] - s*y[2*i+1];
62 yy = s*y[2*i] + c*y[2*i+1];
63 top += (x[2*i] - xxavg)*yx + (x[2*i+1] - xyavg)*yy;
68 *r = top/(bot - yxavg*yxavg/n - yyavg*yyavg/n);
70 *p = yxavg/n*(*r)-xxavg;
71 *q = yyavg/n*(*r)-xyavg;
73 for (i = 0; i < n; i++){
76 yx = c*y[2*i] - s*y[2*i+1];
77 yy = s*y[2*i] + c*y[2*i+1];
78 f += (x[2*i] + *p - (*r)*yx)*(x[2*i] + *p - (*r)*yx)+(x[2*i+1] + *q - (*r)*yy)*(x[2*i+1] + *q - (*r)*yy);
86 real dist = 0, theta, normx = 0, r, d, p, q;
90 dist = get_r(n, x, y, 0., &r, &p, &q);
91 *rmin = r; *pmin = p; *qmin = q;
93 for (i = 0; i < 180; i++){
94 theta = 3.1415626*i/180;
95 d = get_r(n, x, y, theta, &r, &p, &q);
98 *rmin = r; *pmin = p; *qmin = q;
104 for (i = 0; i < n; i++) normx += x[2*i]*x[2*i]+x[2*i+1]*x[2*i+1];
105 return sqrt(dist/normx);
108 int main(
int argc,
char *argv[])
115 int dim = 2, n = 0, i, *ia, *ja, j, k, nz = 0;
116 real *x, *y, mean, dev, ratio, *z, r, theta, p, q, xx;
122 fprintf(stderr,
"Usage: similarity graph layout1 layout2\n");
126 fp = fopen(infile,
"r");
127 while (fscanf(fp,
"%lf %lf\n",&xx, &xx) == 2) n++;
131 fp = fopen(infile,
"r");
133 for (i = 0; i < n; i++){
134 fscanf(fp,
"%lf %lf\n",&(x[2*i]), &(x[2*i+1]));
140 fp = fopen(infile,
"r");
143 for (i = 0; i < n; i++){
144 if (fscanf(fp,
"%lf %lf\n",&(y[2*i]), &(y[2*i+1])) != 2)
goto ERROR;
151 ia = B->
ia; ja = B->
ja;
153 for (i = 0; i < n; i++){
154 for (j = ia[i]; j < ia[i+1]; j++){
156 if (k == i)
continue;
163 for (i = 0; i < nz; i++) mean += z[i];
168 for (i = 0; i < nz; i++) {
169 dev += (z[i]-mean)*(z[i]-mean);
175 ratio = boundingbox_area(n, y);
179 fprintf(stderr,
"mean = %f std = %f disimilarity = %f area = %f badness = %f displacement = %f\n",
180 mean, dev, dev/mean, ratio, (dev/mean+1)*ratio, dispacement(n, x, y, &r, &theta, &p, &q));
181 fprintf(stderr,
"theta = %f scaling = %f, shift = {%f, %f}\n",theta, 1/r, p, q);
184 printf(
"%.2f %.2f %.2f\n",dev/mean, dispacement(n, x, y, &r, &theta, &p, &q),ratio/1000000.);
real distance(real *x, int dim, int i, int j)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix call_tri(int n, int dim, real *x)
double dist(Site *s, Site *t)
real distance_cropped(real *x, int dim, int i, int j)
int main(int argc, char **argv)