Commit bc21cc6f authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

revert to using fixed RNG in EM, otherwise the algorithm becomes…

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.
parent e6aba3e5
......@@ -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 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment