<div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Doria</b> <span dir="ltr">&lt;<a href="mailto:daviddoria%2Bitk@gmail.com">daviddoria+itk@gmail.com</a>&gt;</span><br>
Date: Thu, Jul 23, 2009 at 9:18 AM<br>Subject: KMeans type mismatch<br>To: ITK &lt;<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>&gt;<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&lt; double, 3 &gt; 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&lt; MeasurementVectorType &gt; SampleType;<br>
        SampleType::Pointer sample = SampleType::New();<br>
        sample-&gt;PushBack(p0);<br>
        sample-&gt;PushBack(p1);<br>
        sample-&gt;PushBack(p2);<br>
        sample-&gt;PushBack(p3);<br>
        sample-&gt;PushBack(p4);<br>
        sample-&gt;PushBack(p5);<br>
        sample-&gt;PushBack(p6);<br>
        sample-&gt;PushBack(p7);<br>
        sample-&gt;PushBack(p8);<br>
<br>
        typedef itk::Statistics::WeightedCentroidKdTreeGenerator&lt; SampleType<br>
&gt; TreeGeneratorType;<br>
        //typedef itk::Statistics::KdTreeGenerator&lt; SampleType &gt; TreeGeneratorType;<br>
        TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New();<br>
        treeGenerator-&gt;SetSample( sample );<br>
        treeGenerator-&gt;SetBucketSize( 3 ); //number of measurement vectors in<br>
a terminal node<br>
        treeGenerator-&gt;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&lt;TreeType&gt; 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-&gt;SetParameters( initialMeans );<br>
        estimator-&gt;SetKdTree( treeGenerator-&gt;GetOutput() );<br>
        estimator-&gt;SetMaximumIteration( 200 );<br>
        estimator-&gt;SetCentroidPositionChangesThreshold(0.0);<br>
        estimator-&gt;StartOptimization();<br>
<br>
But it complains on these lines:<br>
        initialMeans[0] = InitialMean0;<br>
<br>
error: cannot convert &#39;main()::MeasurementVectorType&#39; to &#39;double&#39; 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 &quot;continue splitting&quot; 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>