[vtkusers] vtkPCAStatistics for vectors

gregthom gregthom99 at yahoo.com
Fri Jul 17 13:24:31 EDT 2009


Thanks for your answers Wes, They were quite helpful

Regards

GT



Wes Turner wrote:
> 
> On Thu, Jul 16, 2009 at 5:22 AM, gregthom <gregthom99 at yahoo.com> wrote:
> 
>>
>> Hi Wes, thanks for pointing out the vtkPCAAnalysis filter. It looks
>> indeed
>> more like what I want to achieve however I have two question.
>> !) How exactly do I use GetParameterisedShape method for my case ? say I
>> want to generate 100 new shapes. What b should I use ?
> 
> 
> There may be multiple ways, but a simple way would be:
> 
> vtkPolyData *temp
> while (need more examples)
> {
>   temp = vtkPolyData::New();
>   temp ->DeepCopy( firstInputPolydataJusttoGetSize );
>   PCA->GetParametrisedShape(shapevector, temp);
>   // Add temp to the list of things you are maintaining .....
> }
> 
> You will need to appropriately manage releasing the memory for temp.
> 
> 
>> 2) concerning my last post, does doing PCA on the n polydatas themselfs
>> differ from doing PCA on the differences (vectors) of all n-1 polydatas
>> with
>> respect to one reference polydata ?
>>
> 
> Moderately.  The PCA on the n polydatas will give you the mean polydata
> and
> a set of eignvectors describing the modes of variation from the mean
> shape.
>  PCA on the difference vectors will give you the mean variation from the
> chosen exemplar and a set of eigenvectors describing the variation of the
> difference vector.  Both can be used to generate additional members of the
> set, but my suspicion is that the first is more stable unless you have a
> specific reason for preferring one of the polydatas (such as it is the
> "correct" answer and it is the deviations from it that are important
> rather
> than an analysis of the population as a whole.)
> 
>>
>> Thank you
>>
>> G
>>
>>
>> Wes Turner wrote:
>> >
>> > Greg,
>> > It looks like you are trying to calculate positional variation from a
>> set
>> > of
>> > polydatas and synthesize other members of the family.  Look at
>> > vtkPCAAnalysis filter.
>> >
>> > - Wes
>> >
>> > On Tue, Jul 14, 2009 at 10:26 AM, gregthom <gregthom99 at yahoo.com>
>> wrote:
>> >
>> >>
>> >> Hello VTK users
>> >>
>> >> I was wondering if vtkPCAStatistics can be used for vectors instead of
>> >> scalars as in the example at:
>> >>
>> >> TestPCAStatistics.cxx.
>> >>
>> >> When looking at this example I see that scalar datas are added to a
>> table
>> >> before adding to the pca filter, ie
>> >>
>> >> const char m0Name[] = "M0";
>> >>  vtkDoubleArray* dataset1Arr = vtkDoubleArray::New();
>> >>  dataset1Arr->SetNumberOfComponents( 1 );
>> >>  dataset1Arr->SetName( m0Name );
>> >>
>> >>  const char m1Name[] = "M1";
>> >>  vtkDoubleArray* dataset2Arr = vtkDoubleArray::New();
>> >>  dataset2Arr->SetNumberOfComponents( 1 );
>> >>  dataset2Arr->SetName( m1Name );
>> >>
>> >>  const char m2Name[] = "M2";
>> >>  vtkDoubleArray* dataset3Arr = vtkDoubleArray::New();
>> >>  dataset3Arr->SetNumberOfComponents( 1 );
>> >>  dataset3Arr->SetName( m2Name );
>> >>
>> >>  for ( int i = 0; i < nVals; ++ i )
>> >>    {
>> >>    int ti = i << 1;
>> >>    dataset1Arr->InsertNextValue( mingledData[ti] );
>> >>    dataset2Arr->InsertNextValue( mingledData[ti + 1] );
>> >>    dataset3Arr->InsertNextValue( i != 12 ? -1. : -1.001 );
>> >>    }
>> >>
>> >>  vtkTable* datasetTable = vtkTable::New();
>> >>  datasetTable->AddColumn( dataset1Arr );
>> >>  dataset1Arr->Delete();
>> >>  datasetTable->AddColumn( dataset2Arr );
>> >>  dataset2Arr->Delete();
>> >>  datasetTable->AddColumn( dataset3Arr );
>> >>  dataset3Arr->Delete();
>> >>
>> >>  vtkPCAStatistics* pcas = vtkPCAStatistics::New();
>> >>  pcas->SetInput( vtkStatisticsAlgorithm::INPUT_DATA, datasetTable );
>> >>  pcas->SetNormalizationSchemeByName( normScheme );
>> >>  pcas->SetBasisSchemeByName( "FixedBasisEnergy" );
>> >>  pcas->SetFixedBasisEnergy( 1. - 1e-8 );
>> >>
>> >>
>> >> In my case, I have 10 polydata sets and I want to do PCA on these
>> >> polydata
>> >> with the end result of producing other polydatas by taking linea
>> >> combinations of the eigen vectors from PCA analysis.
>> >>
>> >> Here is my approach,
>> >>
>> >>
>> >> 1) use one polydata as reference (P0)
>> >> 2) get differences between the points of P0 and each of the other 9
>> >> polydatas
>> >>    these vectors are stored as
>> >>    vtkDoubleArray* vectorsP0toP1array = vtkDoubleArray::New();
>> >>    vectorsP0toP1array->SetNumberOfComponents( 3 );
>> >>    vectorsP0toP1array->SetName( "vectorsP0toP1" );
>> >>
>> >>    (...)
>> >>
>> >>   vtkDoubleArray* vectorsP0toP9array = vtkDoubleArray::New();
>> >>    vectorsP0toP9array->SetNumberOfComponents( 3 );
>> >>    vectorsP0toP9array->SetName( "vectorsP0toP9" );
>> >>
>> >> 3) run PCA on the vectors
>> >>
>> >> 4) obtain a new vector by taking combinations of the PCA eigen vectors
>> >>    Add new vector to P0 polydata points to obtain a new polydata model
>> >>
>> >> Does anyone with experience think this will work ? Could you also
>> please
>> >> help with pseudocode for 3) and 4) ? That is where I am stuck right
>> now.
>> >> Will adding the vectors columns in a table as in the example work ?
>> >>
>> >> ie
>> >>  vtkTable* datasetTable = vtkTable::New();
>> >>  datasetTable->AddColumn( vectorsP0toP1array );
>> >>  ...
>> >>  datasetTable->AddColumn( vectorsP0toP9array );
>> >>
>> >> then
>> >>  vtkPCAStatistics* pcas = vtkPCAStatistics::New();
>> >>  pcas->SetInput( vtkStatisticsAlgorithm::INPUT_DATA, datasetTable );
>> >> ????
>> >>
>> >>
>> >>
>> >> Thanks for your help in advance
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/vtkPCAStatistics-for-vectors-tp24480622p24480622.html
>> >> Sent from the VTK - Users mailing list archive at Nabble.com.
>> >>
>> >> _______________________________________________
>> >> Powered by www.kitware.com
>> >>
>> >> Visit other Kitware open-source projects at
>> >> http://www.kitware.com/opensource/opensource.html
>> >>
>> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >>
>> >> Follow this link to subscribe/unsubscribe:
>> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >>
>> >
>> >
>> >
>> > --
>> > Wesley D. Turner, Ph.D.
>> > Kitware, Inc.
>> > R&D Engineer
>> > 28 Corporate Drive
>> > Clifton Park, NY 12065-8662
>> > Phone: 518-371-3971 x120
>> >
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Please keep messages on-topic and check the VTK FAQ at:
>> > http://www.vtk.org/Wiki/VTK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.vtk.org/mailman/listinfo/vtkusers
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/vtkPCAStatistics-for-vectors-tp24480622p24513104.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
> 
> 
> 
> -- 
> Wesley D. Turner, Ph.D.
> Kitware, Inc.
> R&D Engineer
> 28 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-371-3971 x120
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://www.nabble.com/vtkPCAStatistics-for-vectors-tp24480622p24538521.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list