From bc21cc6fe9bb3525aa212dae7c7249eb0fb2dc50 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Mon, 6 Dec 2010 09:41:28 +0000 Subject: [PATCH] revert to using fixed RNG in EM, otherwise the algorithm becomes non-deterministic and the test fails sometimes. in the meantime, EM needs to switch to more robust cv::kmeans instead of CvEM::kmeans. --- modules/ml/src/em.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ml/src/em.cpp b/modules/ml/src/em.cpp index 9c24750790..04c05f1c10 100644 --- a/modules/ml/src/em.cpp +++ b/modules/ml/src/em.cpp @@ -581,7 +581,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels, __BEGIN__; - cv::RNG* rng = &cv::theRNG(); + cv::RNG rng(0xFFFFFFFF); int i, j, k, nsamples, dims; int iter = 0; double max_dist = DBL_MAX; @@ -605,7 +605,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels, { for( i = 0; i < nsamples; i++ ) labels->data.i[i] = i*nclusters/nsamples; - cvRandShuffle( labels, &rng->state ); + cvRandShuffle( labels, &rng.state ); } for( ;; ) @@ -702,7 +702,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels, const float* s; for( j = 0; j < 10; j++ ) { - i = (*rng)(nsamples); + i = rng(nsamples); if( counters->data.i[labels->data.i[i]] > 1 ) break; } @@ -738,7 +738,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels, if( counters->data.i[k] == 0 ) for(;;) { - i = (*rng)(nsamples); + i = rng(nsamples); j = labels->data.i[i]; if( counters->data.i[j] > 1 ) {