<br>Hi David,<br><br>The Parameters Array expected by the Estimator <br>is a linear array of doubles.<br><br><br>Therefore, instead of the code:<br><br> unsigned int NumClasses = 3;<br>
EstimatorType::ParametersType initialMeans(NumClasses);<br>
initialMeans[0] = InitialMean0;<br>
initialMeans[1] = InitialMean1;<br>
initialMeans[2] = InitialMean2;<br>
estimator->SetParameters( initialMeans );<br><br><br>You should do:<br><br> const unsigned int NumClasses = 3;<br> const unsigned int VectorLength = 3;<br>
EstimatorType::ParametersType initialMeans(NumClasses * VectorLength);<br>
initialMeans[0] = InitialMean0[0];<br> initialMeans[1] = InitialMean0[1];<br>
initialMeans[2] = InitialMean0[2];<br>
initialMeans[3] = InitialMean1[0];<br>
initialMeans[4] = InitialMean1[1];<br>
initialMeans[5] = InitialMean1[2];<br> initialMeans[6] = InitialMean2[0];<br>
initialMeans[7] = InitialMean2[1];<br> initialMeans[8] = InitialMean2[2];<br> estimator->SetParameters( initialMeans );<br><br><br>Regards,<br><br><br> Luis<br><br><br><br>---------------------------------------------<br>
<div class="gmail_quote">On Tue, Jul 28, 2009 at 7:52 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bitk@gmail.com">daviddoria+itk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5"><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" target="_blank">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" target="_blank">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></div></div>----------------<br>Anyone know how to fix this type issue?<br><br clear="all">Thanks,<br><font color="#888888"><br>David<br>
</font><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br>