VTK
vtkKMeansStatistics.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkKMeansStatistics.h
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2010 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19  -------------------------------------------------------------------------*/
100 #ifndef __vtkKMeansStatistics_h
101 #define __vtkKMeansStatistics_h
102 
103 #include "vtkStatisticsAlgorithm.h"
104 
105 class vtkIdTypeArray;
106 class vtkIntArray;
107 class vtkDoubleArray;
110 
112 {
113 public:
115  virtual void PrintSelf( ostream& os, vtkIndent indent );
116  static vtkKMeansStatistics* New();
117 
119 
120  virtual void SetDistanceFunctor( vtkKMeansDistanceFunctor* );
121  vtkGetObjectMacro(DistanceFunctor,vtkKMeansDistanceFunctor);
123 
125 
127  vtkSetMacro(DefaultNumberOfClusters, int);
128  vtkGetMacro(DefaultNumberOfClusters, int);
130 
132 
133  vtkSetStringMacro(KValuesArrayName);
134  vtkGetStringMacro(KValuesArrayName);
136 
138 
140  vtkSetMacro( MaxNumIterations, int );
141  vtkGetMacro( MaxNumIterations, int );
143 
145 
147  vtkSetMacro( Tolerance, double );
148  vtkGetMacro( Tolerance, double );
150 
152 
155  vtkMultiBlockDataSet* ) { return; };
157 
158  //BTX
160 
161  virtual bool SetParameter(
162  const char* parameter, int index, vtkVariant value );
163  //ETX
165 
166 protected:
169 
171 
172  virtual void Learn( vtkTable* inData,
173  vtkTable* inParameters,
174  vtkMultiBlockDataSet* outMeta );
176 
178  virtual void Derive( vtkMultiBlockDataSet* );
179 
181 
182  virtual void Assess( vtkTable*,
184  vtkTable* );
186 
188 
189  virtual void Test( vtkTable*,
191  vtkTable* ) { return; };
193 
194  //BTX
196 
197  virtual void SelectAssessFunctor( vtkTable* inData,
198  vtkDataObject* inMeta,
199  vtkStringArray* rowNames,
200  AssessFunctor*& dfunc );
201  //ETX
202  // Description:
203  // Subroutine to update new cluster centers from the old centers.
204  // Called from within Learn (and will be overridden by vtkPKMeansStatistics
205  // to handle distributed datasets).
206  virtual void UpdateClusterCenters( vtkTable* newClusterElements,
207  vtkTable* curClusterElements,
208  vtkIdTypeArray* numMembershipChanges,
209  vtkIdTypeArray* numElementsInCluster,
210  vtkDoubleArray* error,
211  vtkIdTypeArray* startRunID,
212  vtkIdTypeArray* endRunID,
213  vtkIntArray *computeRun );
215 
219  virtual vtkIdType GetTotalNumberOfObservations( vtkIdType numObservations );
220 
222 
226  int InitializeDataAndClusterCenters(vtkTable* inParameters,
227  vtkTable* inData,
228  vtkTable* dataElements,
229  vtkIdTypeArray* numberOfClusters,
230  vtkTable* curClusterElements,
231  vtkTable* newClusterElements,
232  vtkIdTypeArray* startRunID,
233  vtkIdTypeArray* endRunID);
235 
237 
240  virtual void CreateInitialClusterCenters(vtkIdType numToAllocate,
241  vtkIdTypeArray* numberOfClusters,
242  vtkTable* inData,
243  vtkTable* curClusterElements,
244  vtkTable* newClusterElements);
246 
247 
249 
252  // Description:
253  // This is the name of the column that specifies the number of clusters in each run.
254  // This is only used if the user has not specified initial clusters.
256  // Description:
257  // This is the maximum number of iterations allowed if the new cluster centers have not yet converged.
259  // Description:
260  // This is the percentage of data elements that swap cluster IDs
261  double Tolerance;
262  // Description:
263  // This is the Distance functor. The default is Euclidean distance, however this can be overridden.
266 
267 private:
268  vtkKMeansStatistics( const vtkKMeansStatistics& ); // Not implemented
269  void operator=( const vtkKMeansStatistics& ); // Not implemented
270 };
271 
272 #endif