mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
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.
This commit is contained in:
parent
e6aba3e51c
commit
bc21cc6fe9
@ -581,7 +581,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels,
|
|||||||
|
|
||||||
__BEGIN__;
|
__BEGIN__;
|
||||||
|
|
||||||
cv::RNG* rng = &cv::theRNG();
|
cv::RNG rng(0xFFFFFFFF);
|
||||||
int i, j, k, nsamples, dims;
|
int i, j, k, nsamples, dims;
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
double max_dist = DBL_MAX;
|
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++ )
|
for( i = 0; i < nsamples; i++ )
|
||||||
labels->data.i[i] = i*nclusters/nsamples;
|
labels->data.i[i] = i*nclusters/nsamples;
|
||||||
cvRandShuffle( labels, &rng->state );
|
cvRandShuffle( labels, &rng.state );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
@ -702,7 +702,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels,
|
|||||||
const float* s;
|
const float* s;
|
||||||
for( j = 0; j < 10; j++ )
|
for( j = 0; j < 10; j++ )
|
||||||
{
|
{
|
||||||
i = (*rng)(nsamples);
|
i = rng(nsamples);
|
||||||
if( counters->data.i[labels->data.i[i]] > 1 )
|
if( counters->data.i[labels->data.i[i]] > 1 )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -738,7 +738,7 @@ void CvEM::kmeans( const CvVectors& train_data, int nclusters, CvMat* labels,
|
|||||||
if( counters->data.i[k] == 0 )
|
if( counters->data.i[k] == 0 )
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
i = (*rng)(nsamples);
|
i = rng(nsamples);
|
||||||
j = labels->data.i[i];
|
j = labels->data.i[i];
|
||||||
if( counters->data.i[j] > 1 )
|
if( counters->data.i[j] > 1 )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user