]> git.sesse.net Git - foosball/blob - foosrank.cpp
c3bfc88d459c6b35719feda8b3376451cbfd86c0
[foosball] / foosrank.cpp
1 #include <cstdio>
2 #include <cmath>
3 #include <cassert>
4
5 #include <vector>
6 #include <algorithm>
7
8 #include <complex>
9 #include <fftw3.h>
10
11 #define USE_LOGISTIC_DISTRIBUTION 0
12
13 // step sizes
14 static const double int_step_size = 75.0;
15
16 // rating constant (see below)
17 static const double rating_constant = 455.0;
18
19 #if USE_LOGISTIC_DISTRIBUTION
20 // constant used in the logistic pdf
21 static const double l_const = M_PI / (2.0 * sqrt(3.0));
22 #endif
23
24 using namespace std;
25
26 static double prob_score_real(int k, int a, double binomial, double rd_norm);
27 static double prodai(int k, int a);
28 static double fac(int x);
29
30 #if USE_LOGISTIC_DISTRIBUTION
31 // sech²(x)
32 static double sech2(double x)
33 {
34         double e = exp(2.0 * x);
35         return 4.0 * e / ((e+1.0) * (e+1.0));
36 }
37 #endif
38
39 #if 0
40 // probability of match ending k-a (k>a) when winnerR - loserR = RD
41 //
42 //   +inf  
43 //     / 
44 //    |
45 //    | Poisson[lambda1, t](a) * Erlang[lambda2, k](t) dt
46 //    |
47 //   /
48 // -inf
49 //
50 // where lambda1 = 1.0, lambda2 = 2^(rd/455)
51 //
52 // The constant of 455 is chosen carefully so to match with the
53 // Glicko/Bradley-Terry assumption that a player rated 400 points over
54 // his/her opponent will win with a probability of 10/11 =~ 0.90909. 
55 //
56 static double prob_score(int k, int a, double rd)
57 {
58         return prob_score_real(k, a, prodai(k, a) / fac(k-1), rd/rating_constant);
59 }
60 #endif
61
62 // computes x^a, probably more efficiently than pow(x, a) (but requires that a
63 // is n unsigned integer)
64 static double intpow(double x, unsigned a)
65 {
66         double result = 1.0;
67
68         while (a > 0) {
69                 if (a & 1) {
70                         result *= x;
71                 }
72                 a >>= 1;
73                 x *= x;
74         }
75
76         return result;
77 }
78
79 // Same, but takes in binomial(a+k-1, k-1) as an argument in
80 // addition to a. Faster if you already have that precomputed, and assumes rd
81 // is already divided by 455.
82 static double prob_score_real(int k, int a, double binomial, double rd_norm)
83 {
84         double nom = binomial * intpow(pow(2.0, rd_norm), a); 
85         double denom = intpow(1.0 + pow(2.0, rd_norm), k+a);
86         return nom/denom;
87 }
88
89 // Calculates Product(a+i, i=1..k-1) (see above).
90 static double prodai(int k, int a)
91 {
92         double prod = 1.0;
93         for (int i = 1; i < k; ++i)
94                 prod *= (a+i);
95         return prod;
96 }
97
98 static double fac(int x)
99 {
100         double prod = 1.0;
101         for (int i = 2; i <= x; ++i)
102                 prod *= i;
103         return prod;
104 }
105
106 static void compute_opponent_rating_pdf(int k, int a, double mu2, double sigma2, double winfac, vector<pair<double, double> > &result)
107 {
108         double binomial_precompute = prodai(k, a) / fac(k-1);
109         winfac /= rating_constant;
110
111         int sz = (6000.0 - 0.0) / int_step_size;
112         double h = (6000.0 - 0.0) / sz;
113
114         fftw_plan f1, f2, b;
115         complex<double> *func1, *func2, *res;
116
117         func1 = reinterpret_cast<complex<double> *>(fftw_malloc(sz*2*sizeof(complex<double>)));
118         func2 = reinterpret_cast<complex<double> *>(fftw_malloc(sz*2*sizeof(complex<double>)));
119         res = reinterpret_cast<complex<double> *>(fftw_malloc(sz*2*sizeof(complex<double>)));
120         f1 = fftw_plan_dft_1d(sz*2,
121                 reinterpret_cast<fftw_complex*>(func1),
122                 reinterpret_cast<fftw_complex*>(func1),
123                 FFTW_FORWARD,
124                 FFTW_MEASURE);
125         f2 = fftw_plan_dft_1d(sz*2,
126                 reinterpret_cast<fftw_complex*>(func2),
127                 reinterpret_cast<fftw_complex*>(func2),
128                 FFTW_FORWARD,
129                 FFTW_MEASURE);
130         b = fftw_plan_dft_1d(sz*2,
131                 reinterpret_cast<fftw_complex*>(res),
132                 reinterpret_cast<fftw_complex*>(res),
133                 FFTW_BACKWARD,
134                 FFTW_MEASURE);
135         
136         // start off by zero
137         for (int i = 0; i < sz*2; ++i) {
138                 func1[i].real() = func1[i].imag() = func2[i].real() = func2[i].imag() = 0.0;
139         }
140
141 #if USE_LOGISTIC_DISTRIBUTION
142         double invsigma2 = 1.0 / sigma2;
143 #else
144         double invsq2sigma2 = 1.0 / (sqrt(2.0) * sigma2);
145 #endif
146         for (int i = 0; i < sz; ++i) {
147                 double x1 = 0.0 + h*i;
148
149                 // opponent's pdf
150 #if USE_LOGISTIC_DISTRIBUTION
151                 double z = (x1 - mu2) * invsigma2;
152                 double ch = cosh(l_const * z);
153                 func1[i].real() = 1.0 / (ch * ch);
154 #else
155                 double z = (x1 - mu2) * invsq2sigma2;
156                 func1[i].real() = exp(-z*z);
157 #endif
158
159                 double x2 = -3000.0 + h*i;
160                 func2[(i - sz/2 + sz*2)%(sz*2)].real() = prob_score_real(k, a, binomial_precompute, x2*winfac);
161         }
162
163         result.reserve(sz*2);
164
165         // convolve
166         fftw_execute(f1);
167         fftw_execute(f2);
168         for (int i = 0; i < sz*2; ++i) {
169                 res[i] = func1[i] * func2[i];
170         }
171         fftw_execute(b);
172
173         result.reserve(sz);
174         for (int i = 0; i < sz; ++i) {
175                 double r1 = i*h;
176                 result.push_back(make_pair(r1, abs(res[i])));
177         }
178 }
179
180 // normalize the curve so we know that A ~= 1
181 static void normalize(vector<pair<double, double> > &curve)
182 {
183         double peak = 0.0;
184         for (vector<pair<double, double> >::const_iterator i = curve.begin(); i != curve.end(); ++i) {
185                 peak = max(peak, i->second);
186         }
187
188         double invpeak = 1.0 / peak;
189         for (vector<pair<double, double> >::iterator i = curve.begin(); i != curve.end(); ++i) {
190                 i->second *= invpeak;
191         }
192 }
193
194 // computes matA^T * matB
195 static void mat_mul_trans(double *matA, unsigned ah, unsigned aw,
196                           double *matB, unsigned bh, unsigned bw,
197                           double *result)
198 {
199         assert(ah == bh);
200         for (unsigned y = 0; y < bw; ++y) {
201                 for (unsigned x = 0; x < aw; ++x) {
202                         double sum = 0.0;
203                         for (unsigned c = 0; c < ah; ++c) {
204                                 sum += matA[x*ah + c] * matB[y*bh + c];
205                         }
206                         result[y*bw + x] = sum;
207                 }
208         }
209 }
210
211 // solves Ax = B by Gauss-Jordan elimination, where A is an NxN matrix,
212 // x is a column vector of length N and B is a row vector of length N.
213 // Destroys its input in the process.
214 template<int N>
215 static void solve_matrix(double *A, double *x, double *B)
216 {
217         for (int i = 0; i < N; ++i) {
218                 for (int j = i+1; j < N; ++j) {
219                         // row j -= row i * (a[i,j] / a[i,i])
220                         double f = A[j+i*N] / A[i+i*N];
221
222                         A[j+i*N] = 0.0;
223                         for (int k = i+1; k < N; ++k) {
224                                 A[j+k*N] -= A[i+k*N] * f;
225                         }
226
227                         B[j] -= B[i] * f;
228                 }
229         }
230
231         // back-substitute
232         for (int i = N; i --> 0; ) {
233                 for (int j = i; j --> 0; ) {
234                         // row j -= row i * (a[j,j] / a[j,i])
235                         double f = A[i+j*N] / A[j+j*N];
236                         
237                         // A[j+i*N] = 0.0;
238                         B[j] -= B[i] * f;
239                 }
240         }
241
242         // normalize
243         for (int i = 0; i < N; ++i) {
244                 x[i] = B[i] / A[i+i*N];
245         }
246 }
247
248 // Give an OK starting estimate for the least squares, by numerical integration
249 // of statistical moments.
250 static void estimate_musigma(vector<pair<double, double> > &curve, double &mu_result, double &sigma_result)
251 {
252         double h = (curve.back().first - curve.front().first) / (curve.size() - 1);
253
254         double area = curve.front().second;
255         double ex = curve.front().first * curve.front().second;
256         double ex2 = curve.front().first * curve.front().first * curve.front().second;
257
258         for (unsigned i = 1; i < curve.size() - 1; i += 2) {
259                 double x = curve[i].first;
260                 double y = curve[i].second;
261                 area += 4.0 * y;
262                 ex += 4.0 * x * y;
263                 ex2 += 4.0 * x * x * y;
264         }
265         for (unsigned i = 2; i < curve.size() - 1; i += 2) {
266                 double x = curve[i].first;
267                 double y = curve[i].second;
268                 area += 2.0 * y;
269                 ex += 2.0 * x * y;
270                 ex2 += 2.0 * x * x * y;
271         }
272         
273         area += curve.back().second;
274         ex += curve.back().first * curve.back().second;
275         ex2 += curve.back().first * curve.back().first * curve.back().second;
276
277         area = (h/3.0) * area;
278         ex = (h/3.0) * ex / area;
279         ex2 = (h/3.0) * ex2 / area;
280
281         mu_result = ex;
282         sigma_result = sqrt(ex2 - ex * ex);
283 }
284         
285 // Find best fit of the data in curves to a Gaussian pdf, based on the
286 // given initial estimates. Works by nonlinear least squares, iterating
287 // until we're below a certain threshold.
288 //
289 // Note that the algorithm blows up quite hard if the initial estimate is
290 // not good enough. Use estimate_musigma to get a reasonable starting
291 // estimate.
292 static void least_squares(vector<pair<double, double> > &curve, double mu1, double sigma1, double &mu_result, double &sigma_result)
293 {
294         double A = 1.0;
295         double mu = mu1;
296         double sigma = sigma1;
297
298         // column-major
299         double matA[curve.size() * 3];  // N x 3
300         double dbeta[curve.size()];     // N x 1
301
302         // A^T * A: 3xN * Nx3 = 3x3
303         double matATA[3*3];
304
305         // A^T * dβ: 3xN * Nx1 = 3x1
306         double matATdb[3];
307
308         double dlambda[3];
309
310         for ( ;; ) {
311                 //printf("A=%f mu=%f sigma=%f\n", A, mu, sigma);
312
313                 // fill in A (depends only on x_i, A, mu, sigma -- not y_i)
314                 for (unsigned i = 0; i < curve.size(); ++i) {
315                         double x = curve[i].first;
316
317 #if USE_LOGISTIC_DISTRIBUTION
318                         // df/dA(x_i)
319                         matA[i + 0 * curve.size()] = sech2(l_const * (x-mu)/sigma);
320
321                         // df/dµ(x_i)
322                         matA[i + 1 * curve.size()] = 2.0 * l_const * A * matA[i + 0 * curve.size()]
323                                 * tanh(l_const * (x-mu)/sigma) / sigma;
324
325                         // df/dσ(x_i)
326                         matA[i + 2 * curve.size()] = 
327                                 matA[i + 1 * curve.size()] * (x-mu)/sigma;
328 #else
329                         // df/dA(x_i)
330                         matA[i + 0 * curve.size()] = 
331                                 exp(-(x-mu)*(x-mu)/(2.0*sigma*sigma));
332
333                         // df/dµ(x_i)
334                         matA[i + 1 * curve.size()] =
335                                 A * (x-mu)/(sigma*sigma) * matA[i + 0 * curve.size()];
336
337                         // df/dσ(x_i)
338                         matA[i + 2 * curve.size()] = 
339                                 matA[i + 1 * curve.size()] * (x-mu)/sigma;
340 #endif
341                 }
342
343                 // find dβ
344                 for (unsigned i = 0; i < curve.size(); ++i) {
345                         double x = curve[i].first;
346                         double y = curve[i].second;
347
348 #if USE_LOGISTIC_DISTRIBUTION
349                         dbeta[i] = y - A * sech2(l_const * (x-mu)/sigma);
350 #else
351                         dbeta[i] = y - A * exp(- (x-mu)*(x-mu)/(2.0*sigma*sigma));
352 #endif
353                 }
354
355                 // compute a and b
356                 mat_mul_trans(matA, curve.size(), 3, matA, curve.size(), 3, matATA);
357                 mat_mul_trans(matA, curve.size(), 3, dbeta, curve.size(), 1, matATdb);
358
359                 // solve
360                 solve_matrix<3>(matATA, dlambda, matATdb);
361
362                 A += dlambda[0];
363                 mu += dlambda[1];
364                 sigma += dlambda[2];
365
366                 // terminate when we're down to three digits
367                 if (fabs(dlambda[0]) <= 1e-3 && fabs(dlambda[1]) <= 1e-3 && fabs(dlambda[2]) <= 1e-3)
368                         break;
369         }
370
371         mu_result = mu;
372         sigma_result = sigma;
373 }
374
375 static void compute_new_rating(double mu1, double sigma1, double mu2, double sigma2, int score1, int score2, double &mu, double &sigma, double &probability)
376 {
377         vector<pair<double, double> > curve;
378
379         if (score1 > score2) {
380                 compute_opponent_rating_pdf(score1, score2, mu2, sigma2, -1.0, curve);
381         } else {
382                 compute_opponent_rating_pdf(score2, score1, mu2, sigma2, 1.0, curve);
383         }
384
385         // multiply in the gaussian
386         for (unsigned i = 0; i < curve.size(); ++i) {
387                 double r1 = curve[i].first;
388
389                 // my pdf
390                 double z = (r1 - mu1) / sigma1;
391 #if USE_LOGISTIC_DISTRIBUTION
392                 double ch = cosh(l_const * z);
393                 curve[i].second /= (ch * ch);
394 #else
395                 double gaussian = exp(-(z*z/2.0));
396                 curve[i].second *= gaussian;
397 #endif
398         }
399         
400         // Compute the overall probability of the given result, by integrating
401         // the entire resulting pdf. Note that since we're actually evaluating
402         // a double integral, we'll need to multiply by h² instead of h.
403         {
404                 double h = (curve.back().first - curve.front().first) / (curve.size() - 1);
405                 double sum = curve.front().second;
406                 for (unsigned i = 1; i < curve.size() - 1; i += 2) {
407                         sum += 4.0 * curve[i].second;
408                 }
409                 for (unsigned i = 2; i < curve.size() - 1; i += 2) {
410                         sum += 2.0 * curve[i].second;
411                 }
412                 sum += curve.back().second;
413                 sum *= h * h / 3.0;
414         
415                 // FFT convolution multiplication factor (FFTW computes unnormalized
416                 // transforms)
417                 sum /= (curve.size() * 2);      
418
419                 // pdf normalization factors
420 #if USE_LOGISTIC_DISTRIBUTION
421                 sum *= M_PI / (sigma1 * 4.0 * sqrt(3.0));
422                 sum *= M_PI / (sigma2 * 4.0 * sqrt(3.0));
423 #else
424                 sum /= (sigma1 * sqrt(2.0 * M_PI));
425                 sum /= (sigma2 * sqrt(2.0 * M_PI));
426 #endif
427
428                 probability = sum;
429         }
430
431         double mu_est, sigma_est;
432         normalize(curve);
433         estimate_musigma(curve, mu_est, sigma_est);
434         least_squares(curve, mu_est, sigma_est, mu, sigma);
435 }
436
437 static void compute_new_double_rating(double mu1, double sigma1, double mu2, double sigma2, double mu3, double sigma3, double mu4, double sigma4, int score1, int score2, double &mu, double &sigma, double &probability)
438 {
439         vector<pair<double, double> > curve, newcurve;
440         double mu_t = mu3 + mu4;
441         double sigma_t = sqrt(sigma3*sigma3 + sigma4*sigma4);
442                         
443         if (score1 > score2) {
444                 compute_opponent_rating_pdf(score1, score2, mu_t, sigma_t, -1.0, curve);
445         } else {
446                 compute_opponent_rating_pdf(score2, score1, mu_t, sigma_t, 1.0, curve);
447         }
448
449         newcurve.reserve(curve.size());
450
451         // iterate over r1
452         double h = 3000.0 / curve.size();
453         for (unsigned i = 0; i < curve.size(); ++i) {
454                 double sum = 0.0;
455
456                 // could be anything, but this is a nice start
457                 //double r1 = curve[i].first;
458                 double r1 = i * h;
459
460                 // iterate over r2
461 #if USE_LOGISTIC_DISTRIBUTION
462                 double invsigma2 = 1.0 / sigma2;
463 #else
464                 double invsq2sigma2 = 1.0 / (sqrt(2.0) * sigma2);
465 #endif
466                 for (unsigned j = 0; j < curve.size(); ++j) {
467                         double r1plusr2 = curve[j].first;
468                         double r2 = r1plusr2 - r1;
469
470 #if USE_LOGISTIC_DISTRIBUTION
471                         double z = (r2 - mu2) * invsigma2;
472                         double gaussian = sech2(l_const * z);
473 #else   
474                         double z = (r2 - mu2) * invsq2sigma2;
475                         double gaussian = exp(-z*z);
476 #endif
477                         sum += curve[j].second * gaussian;
478                 }
479
480 #if USE_LOGISTIC_DISTRIBUTION
481                 double z = (r1 - mu1) / sigma1;
482                 double gaussian = sech2(l_const * z);
483 #else
484                 double z = (r1 - mu1) / sigma1;
485                 double gaussian = exp(-(z*z/2.0));
486 #endif
487                 newcurve.push_back(make_pair(r1, gaussian * sum));
488         }
489
490         // Compute the overall probability of the given result, by integrating
491         // the entire resulting pdf. Note that since we're actually evaluating
492         // a triple integral, we'll need to multiply by 4h³ (no idea where the
493         // 4 factor comes from, probably from the 0..6000 range somehow) instead
494         // of h.
495         {
496                 double h = (newcurve.back().first - newcurve.front().first) / (newcurve.size() - 1);
497                 double sum = newcurve.front().second;
498                 for (unsigned i = 1; i < newcurve.size() - 1; i += 2) {
499                         sum += 4.0 * newcurve[i].second;
500                 }
501                 for (unsigned i = 2; i < newcurve.size() - 1; i += 2) {
502                         sum += 2.0 * newcurve[i].second;
503                 }
504                 sum += newcurve.back().second;
505
506                 sum *= 4.0 * h * h * h / 3.0;
507         
508                 // FFT convolution multiplication factor (FFTW computes unnormalized
509                 // transforms)
510                 sum /= (newcurve.size() * 2);   
511
512                 // pdf normalization factors
513 #if USE_LOGISTIC_DISTRIBUTION
514                 sum *= M_PI / (sigma1 * 4.0 * sqrt(3.0));
515                 sum *= M_PI / (sigma2 * 4.0 * sqrt(3.0));
516                 sum *= M_PI / (sigma_t * 4.0 * sqrt(3.0));
517 #else
518                 sum /= (sigma1 * sqrt(2.0 * M_PI));
519                 sum /= (sigma2 * sqrt(2.0 * M_PI));
520                 sum /= (sigma_t * sqrt(2.0 * M_PI));
521 #endif
522
523                 probability = sum;
524         }
525
526         double mu_est, sigma_est;
527         normalize(newcurve);
528         estimate_musigma(newcurve, mu_est, sigma_est);
529         least_squares(newcurve, mu_est, sigma_est, mu, sigma);
530 }
531
532 int main(int argc, char **argv)
533 {
534         FILE *fp = fopen("fftw-wisdom", "rb");
535         if (fp != NULL) {
536                 fftw_import_wisdom_from_file(fp);
537                 fclose(fp);
538         }
539
540         double mu1 = atof(argv[1]);
541         double sigma1 = atof(argv[2]);
542         double mu2 = atof(argv[3]);
543         double sigma2 = atof(argv[4]);
544
545         if (argc > 10) {
546                 double mu3 = atof(argv[5]);
547                 double sigma3 = atof(argv[6]);
548                 double mu4 = atof(argv[7]);
549                 double sigma4 = atof(argv[8]);
550                 int score1 = atoi(argv[9]);
551                 int score2 = atoi(argv[10]);
552                 double mu, sigma, probability;
553                 compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, score1, score2, mu, sigma, probability);
554                 if (score1 > score2) {
555                         printf("%f %f %f\n", mu, sigma, probability);
556                 } else {
557                         printf("%f %f %f\n", mu, sigma, probability);
558                 }
559         } else if (argc > 8) {
560                 double mu3 = atof(argv[5]);
561                 double sigma3 = atof(argv[6]);
562                 double mu4 = atof(argv[7]);
563                 double sigma4 = atof(argv[8]);
564                 int k = atoi(argv[9]);
565
566                 // assess all possible scores
567                 for (int i = 0; i < k; ++i) {
568                         double newmu1_1, newmu1_2, newmu2_1, newmu2_2;
569                         double newsigma1_1, newsigma1_2, newsigma2_1, newsigma2_2;
570                         double probability;
571                         compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, k, i, newmu1_1, newsigma1_1, probability);
572                         compute_new_double_rating(mu2, sigma2, mu1, sigma1, mu3, sigma3, mu4, sigma4, k, i, newmu1_2, newsigma1_2, probability);
573                         compute_new_double_rating(mu3, sigma3, mu4, sigma4, mu1, sigma1, mu2, sigma2, i, k, newmu2_1, newsigma2_1, probability);
574                         compute_new_double_rating(mu4, sigma4, mu3, sigma3, mu1, sigma1, mu2, sigma2, i, k, newmu2_2, newsigma2_2, probability);
575                         printf("%u-%u,%f,%+f,%+f,%+f,%+f\n",
576                                 k, i, probability, newmu1_1-mu1, newmu1_2-mu2,
577                                 newmu2_1-mu3, newmu2_2-mu4);
578                 }
579                 for (int i = k; i --> 0; ) {
580                         double newmu1_1, newmu1_2, newmu2_1, newmu2_2;
581                         double newsigma1_1, newsigma1_2, newsigma2_1, newsigma2_2;
582                         double probability;
583                         compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, k, i, newmu1_1, newsigma1_1, probability);
584                         compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, i, k, newmu1_1, newsigma1_1, probability);
585                         compute_new_double_rating(mu2, sigma2, mu1, sigma1, mu3, sigma3, mu4, sigma4, i, k, newmu1_2, newsigma1_2, probability);
586                         compute_new_double_rating(mu3, sigma3, mu4, sigma4, mu1, sigma1, mu2, sigma2, k, i, newmu2_1, newsigma2_1, probability);
587                         compute_new_double_rating(mu4, sigma4, mu3, sigma3, mu1, sigma1, mu2, sigma2, k, i, newmu2_2, newsigma2_2, probability);
588                         printf("%u-%u,%f,%+f,%+f,%+f,%+f\n",
589                                 i, k, probability, newmu1_1-mu1, newmu1_2-mu2,
590                                 newmu2_1-mu3, newmu2_2-mu4);
591                 }
592         } else if (argc > 6) {
593                 int score1 = atoi(argv[5]);
594                 int score2 = atoi(argv[6]);
595                 double mu, sigma, probability;
596                 compute_new_rating(mu1, sigma1, mu2, sigma2, score1, score2, mu, sigma, probability);
597
598                 if (score1 > score2) {
599                         printf("%f %f %f\n", mu, sigma, probability);
600                 } else {
601                         printf("%f %f %f\n", mu, sigma, probability);
602                 }
603         } else {
604                 int k = atoi(argv[5]);
605
606                 // assess all possible scores
607                 for (int i = 0; i < k; ++i) {
608                         double newmu1, newmu2, newsigma1, newsigma2, probability;
609                         compute_new_rating(mu1, sigma1, mu2, sigma2, k, i, newmu1, newsigma1, probability);
610                         compute_new_rating(mu2, sigma2, mu1, sigma1, i, k, newmu2, newsigma2, probability);
611                         printf("%u-%u,%f,%+f,%+f\n",
612                                 k, i, probability, newmu1-mu1, newmu2-mu2);
613                 }
614                 for (int i = k; i --> 0; ) {
615                         double newmu1, newmu2, newsigma1, newsigma2, probability;
616                         compute_new_rating(mu1, sigma1, mu2, sigma2, i, k, newmu1, newsigma1, probability);
617                         compute_new_rating(mu2, sigma2, mu1, sigma1, k, i, newmu2, newsigma2, probability);
618                         printf("%u-%u,%f,%+f,%+f\n",
619                                 i, k, probability, newmu1-mu1, newmu2-mu2);
620                 }
621         }
622         
623         fp = fopen("fftw-wisdom", "wb");
624         if (fp != NULL) {
625                 fftw_export_wisdom_to_file(fp);
626                 fclose(fp);
627         }
628 }
629