VTK
dox/Infovis/vtkKMeansStatistics.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Visualization Toolkit
00004 Module:    vtkKMeansStatistics.h
00005 
00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007 All rights reserved.
00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010 This software is distributed WITHOUT ANY WARRANTY; without even
00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012 PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 /*-------------------------------------------------------------------------
00016   Copyright 2008 Sandia Corporation.
00017   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00018   the U.S. Government retains certain rights in this software.
00019   -------------------------------------------------------------------------*/
00100 #ifndef __vtkKMeansStatistics_h
00101 #define __vtkKMeansStatistics_h
00102 
00103 #include "vtkStatisticsAlgorithm.h"
00104 
00105 class vtkIdTypeArray;
00106 class vtkIntArray;
00107 class vtkDoubleArray;
00108 class vtkKMeansDistanceFunctor;
00109 
00110 class VTK_INFOVIS_EXPORT vtkKMeansStatistics : public vtkStatisticsAlgorithm
00111 {
00112 public:
00113   vtkTypeMacro(vtkKMeansStatistics, vtkStatisticsAlgorithm);
00114   virtual void PrintSelf( ostream& os, vtkIndent indent );
00115   static vtkKMeansStatistics* New();
00116  
00118 
00119   virtual void SetDistanceFunctor( vtkKMeansDistanceFunctor* );
00120   vtkGetObjectMacro(DistanceFunctor,vtkKMeansDistanceFunctor);
00122 
00124 
00126   vtkSetMacro(DefaultNumberOfClusters, int);
00127   vtkGetMacro(DefaultNumberOfClusters, int);
00129 
00131 
00132   vtkSetStringMacro(KValuesArrayName);
00133   vtkGetStringMacro(KValuesArrayName);
00135 
00137 
00139   vtkSetMacro( MaxNumIterations, int );
00140   vtkGetMacro( MaxNumIterations, int );
00142 
00144 
00146   vtkSetMacro( Tolerance, double );
00147   vtkGetMacro( Tolerance, double );
00149 
00151 
00153   virtual void Aggregate( vtkDataObjectCollection*,
00154                           vtkDataObject* ) { return; };
00156 
00157 protected:
00158   vtkKMeansStatistics();
00159   ~vtkKMeansStatistics();
00160 
00162 
00165   virtual int FillOutputPortInformation( int port, vtkInformation* info );
00166   virtual int FillInputPortInformation( int port, vtkInformation* info );
00168 
00170 
00171   virtual void Learn( vtkTable* inData,
00172                       vtkTable* inParameters,
00173                       vtkDataObject* outMeta );
00175 
00177   virtual void Derive( vtkDataObject* );
00178 
00180 
00181   virtual void Assess( vtkTable*, 
00182                        vtkDataObject*, 
00183                        vtkTable* );
00185 
00187 
00188   virtual void Test( vtkTable*,
00189                      vtkDataObject*,
00190                      vtkDataObject* ) { return; };
00192 
00193   //BTX  
00195 
00196   virtual void SelectAssessFunctor( vtkTable* inData, 
00197                                     vtkDataObject* inMeta,
00198                                     vtkStringArray* rowNames,
00199                                     AssessFunctor*& dfunc );
00200   //ETX  
00201   // Description:
00202   // Subroutine to update new cluster centers from the old centers.
00203   // Called from within Learn (and will be overridden by vtkPKMeansStatistics
00204   // to handle distributed datasets).
00205   virtual void UpdateClusterCenters( vtkTable* newClusterElements, 
00206                                      vtkTable* curClusterElements, 
00207                                      vtkIdTypeArray* numMembershipChanges,
00208                                      vtkIdTypeArray* numElementsInCluster, 
00209                                      vtkDoubleArray* error,
00210                                      vtkIdTypeArray* startRunID, 
00211                                      vtkIdTypeArray* endRunID, 
00212                                      vtkIntArray *computeRun );
00214 
00218   virtual vtkIdType GetTotalNumberOfObservations( vtkIdType numObservations );
00219 
00221 
00225   int InitializeDataAndClusterCenters(vtkTable* inParameters,
00226                                       vtkTable* inData,
00227                                       vtkTable*  dataElements,
00228                                       vtkIdTypeArray*  numberOfClusters,
00229                                       vtkTable*  curClusterElements,
00230                                       vtkTable*  newClusterElements,
00231                                       vtkIdTypeArray*  startRunID,
00232                                       vtkIdTypeArray*  endRunID);
00234 
00236 
00239   virtual void CreateInitialClusterCenters(vtkIdType numToAllocate, 
00240                                            vtkIdTypeArray* numberOfClusters, 
00241                                            vtkTable* inData, 
00242                                            vtkTable* curClusterElements, 
00243                                            vtkTable* newClusterElements);
00245 
00246 
00248 
00250   int DefaultNumberOfClusters;
00251   // Description:
00252   // This is the name of the column that specifies the number of clusters in each run. 
00253   // This is only used if the user has not specified initial clusters.
00254   char* KValuesArrayName;
00255   // Description:
00256   // This is the maximum number of iterations allowed if the new cluster centers have not yet converged. 
00257   int MaxNumIterations;
00258   // Description:
00259   // This is the percentage of data elements that swap cluster IDs 
00260   double Tolerance;
00261   // Description:
00262   // This is the Distance functor.  The default is Euclidean distance, however this can be overridden.
00263   vtkKMeansDistanceFunctor* DistanceFunctor;
00265   
00266 private:
00267   vtkKMeansStatistics( const vtkKMeansStatistics& ); // Not implemented
00268   void operator=( const vtkKMeansStatistics& );  // Not implemented
00269 };
00270 
00271 #endif