VTK
|
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 2010 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 class vtkMultiBlockDataSet; 00110 00111 class VTK_INFOVIS_EXPORT vtkKMeansStatistics : public vtkStatisticsAlgorithm 00112 { 00113 public: 00114 vtkTypeMacro(vtkKMeansStatistics, vtkStatisticsAlgorithm); 00115 virtual void PrintSelf( ostream& os, vtkIndent indent ); 00116 static vtkKMeansStatistics* New(); 00117 00119 00120 virtual void SetDistanceFunctor( vtkKMeansDistanceFunctor* ); 00121 vtkGetObjectMacro(DistanceFunctor,vtkKMeansDistanceFunctor); 00123 00125 00127 vtkSetMacro(DefaultNumberOfClusters, int); 00128 vtkGetMacro(DefaultNumberOfClusters, int); 00130 00132 00133 vtkSetStringMacro(KValuesArrayName); 00134 vtkGetStringMacro(KValuesArrayName); 00136 00138 00140 vtkSetMacro( MaxNumIterations, int ); 00141 vtkGetMacro( MaxNumIterations, int ); 00143 00145 00147 vtkSetMacro( Tolerance, double ); 00148 vtkGetMacro( Tolerance, double ); 00150 00152 00154 virtual void Aggregate( vtkDataObjectCollection*, 00155 vtkMultiBlockDataSet* ) { return; }; 00157 00158 //BTX 00160 00161 virtual bool SetParameter( 00162 const char* parameter, int index, vtkVariant value ); 00163 //ETX 00165 00166 protected: 00167 vtkKMeansStatistics(); 00168 ~vtkKMeansStatistics(); 00169 00171 00172 virtual void Learn( vtkTable* inData, 00173 vtkTable* inParameters, 00174 vtkMultiBlockDataSet* outMeta ); 00176 00178 virtual void Derive( vtkMultiBlockDataSet* ); 00179 00181 00182 virtual void Assess( vtkTable*, 00183 vtkMultiBlockDataSet*, 00184 vtkTable* ); 00186 00188 00189 virtual void Test( vtkTable*, 00190 vtkMultiBlockDataSet*, 00191 vtkTable* ) { return; }; 00193 00194 //BTX 00196 00197 virtual void SelectAssessFunctor( vtkTable* inData, 00198 vtkDataObject* inMeta, 00199 vtkStringArray* rowNames, 00200 AssessFunctor*& dfunc ); 00201 //ETX 00202 // Description: 00203 // Subroutine to update new cluster centers from the old centers. 00204 // Called from within Learn (and will be overridden by vtkPKMeansStatistics 00205 // to handle distributed datasets). 00206 virtual void UpdateClusterCenters( vtkTable* newClusterElements, 00207 vtkTable* curClusterElements, 00208 vtkIdTypeArray* numMembershipChanges, 00209 vtkIdTypeArray* numElementsInCluster, 00210 vtkDoubleArray* error, 00211 vtkIdTypeArray* startRunID, 00212 vtkIdTypeArray* endRunID, 00213 vtkIntArray *computeRun ); 00215 00219 virtual vtkIdType GetTotalNumberOfObservations( vtkIdType numObservations ); 00220 00222 00226 int InitializeDataAndClusterCenters(vtkTable* inParameters, 00227 vtkTable* inData, 00228 vtkTable* dataElements, 00229 vtkIdTypeArray* numberOfClusters, 00230 vtkTable* curClusterElements, 00231 vtkTable* newClusterElements, 00232 vtkIdTypeArray* startRunID, 00233 vtkIdTypeArray* endRunID); 00235 00237 00240 virtual void CreateInitialClusterCenters(vtkIdType numToAllocate, 00241 vtkIdTypeArray* numberOfClusters, 00242 vtkTable* inData, 00243 vtkTable* curClusterElements, 00244 vtkTable* newClusterElements); 00246 00247 00249 00251 int DefaultNumberOfClusters; 00252 // Description: 00253 // This is the name of the column that specifies the number of clusters in each run. 00254 // This is only used if the user has not specified initial clusters. 00255 char* KValuesArrayName; 00256 // Description: 00257 // This is the maximum number of iterations allowed if the new cluster centers have not yet converged. 00258 int MaxNumIterations; 00259 // Description: 00260 // This is the percentage of data elements that swap cluster IDs 00261 double Tolerance; 00262 // Description: 00263 // This is the Distance functor. The default is Euclidean distance, however this can be overridden. 00264 vtkKMeansDistanceFunctor* DistanceFunctor; 00266 00267 private: 00268 vtkKMeansStatistics( const vtkKMeansStatistics& ); // Not implemented 00269 void operator=( const vtkKMeansStatistics& ); // Not implemented 00270 }; 00271 00272 #endif