<div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Doria</b> <span dir="ltr"><<a href="mailto:daviddoria%2Bitk@gmail.com">daviddoria+itk@gmail.com</a>></span><br>
Date: Thu, Jul 23, 2009 at 9:18 AM<br>Subject: KMeans type mismatch<br>To: ITK <<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>><br><br><br>I want to do a KMeans clustering of 3d points. So I setup a 3-vector like this:<br>
<br>
typedef itk::Vector< double, 3 > MeasurementVectorType;<br>
<br>
and fill it with some points that are clearly in 3 clusters:<br>
<br>
MeasurementVectorType p0, p1, p2, p3, p4, p5, p6, p7, p8;<br>
<br>
//cluster 1<br>
p0[0]= 0.0; p0[1]= 0.0; p0[2]= 0.0;<br>
p1[0]= 0.1; p1[1]= 0.0; p1[2]= 0.0;<br>
p2[0]= 0.0; p2[1]= 0.1; p2[2]= 0.0;<br>
<br>
//cluster 2<br>
p3[0]= 5.0; p3[1]= 5.0; p3[2]= 5.0;<br>
p4[0]= 5.1; p4[1]= 5.0; p4[2]= 5.0;<br>
p5[0]= 5.0; p5[1]= 5.1; p5[2]= 5.0;<br>
<br>
//cluster 3<br>
p6[0]= -5.0; p6[1]= -5.0; p6[2]= -5.0;<br>
p7[0]= -5.1; p7[1]= -5.0; p7[2]= -5.0;<br>
p8[0]= -5.0; p8[1]= -5.1; p8[2]= -5.0;<br>
<br>
Then I setup the ListSample for the KdTree:<br>
<br>
typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType;<br>
SampleType::Pointer sample = SampleType::New();<br>
sample->PushBack(p0);<br>
sample->PushBack(p1);<br>
sample->PushBack(p2);<br>
sample->PushBack(p3);<br>
sample->PushBack(p4);<br>
sample->PushBack(p5);<br>
sample->PushBack(p6);<br>
sample->PushBack(p7);<br>
sample->PushBack(p8);<br>
<br>
typedef itk::Statistics::WeightedCentroidKdTreeGenerator< SampleType<br>
> TreeGeneratorType;<br>
//typedef itk::Statistics::KdTreeGenerator< SampleType > TreeGeneratorType;<br>
TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New();<br>
treeGenerator->SetSample( sample );<br>
treeGenerator->SetBucketSize( 3 ); //number of measurement vectors in<br>
a terminal node<br>
treeGenerator->Update();<br>
<br>
Now I want to seed the KMeans algorithm with 3 points in the 3d space:<br>
// Once we have the k-d tree, it is a simple procedure to produce k<br>
mean estimates<br>
<br>
typedef TreeGeneratorType::KdTreeType TreeType;<br>
typedef itk::Statistics::KdTreeBasedKmeansEstimator<TreeType> EstimatorType;<br>
EstimatorType::Pointer estimator = EstimatorType::New();<br>
<br>
MeasurementVectorType InitialMean0, InitialMean1, InitialMean2;<br>
InitialMean0[0] = 1.0;<br>
InitialMean0[1] = 1.0;<br>
InitialMean0[2] = 1.0;<br>
<br>
InitialMean1[0] = -1.0;<br>
InitialMean1[1] = -1.0;<br>
InitialMean1[2] = -1.0;<br>
<br>
InitialMean2[0] = 0.0;<br>
InitialMean2[1] = 0.0;<br>
InitialMean2[2] = 0.0;<br>
<br>
I create a vector of 3d vectors:<br>
unsigned int NumClasses = 3;<br>
EstimatorType::ParametersType initialMeans(NumClasses);<br>
initialMeans[0] = InitialMean0;<br>
initialMeans[1] = InitialMean1;<br>
initialMeans[2] = InitialMean2;<br>
<br>
In hopes to do something like this:<br>
<br>
estimator->SetParameters( initialMeans );<br>
estimator->SetKdTree( treeGenerator->GetOutput() );<br>
estimator->SetMaximumIteration( 200 );<br>
estimator->SetCentroidPositionChangesThreshold(0.0);<br>
estimator->StartOptimization();<br>
<br>
But it complains on these lines:<br>
initialMeans[0] = InitialMean0;<br>
<br>
error: cannot convert 'main()::MeasurementVectorType' to 'double' in assignment<br>
<br>
How would I setup these initial means?<br>
<br>
On a separate note: is there an agglomerative clustering algorithm in<br>
ITK? That is, have it start with the 9 points in a single cluster and<br>
then split the clusters until some "continue splitting" tolerance is<br>
met?<br>
<br>
Thanks,<br>
<font color="#888888"><br>
David<br>
</font></div><br>----------------<br>Anyone know how to fix this type issue?<br><br clear="all">Thanks,<br><br>David<br>