VTK  9.7.1
vtkKMeansStatistics.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2010 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
84 #ifndef vtkKMeansStatistics_h
85 #define vtkKMeansStatistics_h
86 
87 #include "vtkFiltersStatisticsModule.h" // For export macro
88 #include "vtkStatisticsAlgorithm.h"
89 
90 VTK_ABI_NAMESPACE_BEGIN
91 class vtkIdTypeArray;
92 class vtkIntArray;
93 class vtkDoubleArray;
96 
97 class VTKFILTERSSTATISTICS_EXPORT vtkKMeansStatistics : public vtkStatisticsAlgorithm
98 {
99 public:
101  void PrintSelf(ostream& os, vtkIndent indent) override;
102  static vtkKMeansStatistics* New();
103 
105 
108  virtual void SetDistanceFunctor(vtkKMeansDistanceFunctor*);
109  vtkGetObjectMacro(DistanceFunctor, vtkKMeansDistanceFunctor);
111 
113 
116  vtkSetMacro(DefaultNumberOfClusters, int);
117  vtkGetMacro(DefaultNumberOfClusters, int);
119 
121 
124  vtkSetStringMacro(KValuesArrayName);
125  vtkGetStringMacro(KValuesArrayName);
127 
129 
133  vtkSetMacro(MaxNumIterations, int);
134  vtkGetMacro(MaxNumIterations, int);
136 
138 
142  vtkSetMacro(Tolerance, double);
143  vtkGetMacro(Tolerance, double);
145 
150  bool Aggregate(vtkDataObjectCollection*, vtkStatisticalModel*) override { return false; }
151 
155  bool SetParameter(const char* parameter, int index, vtkVariant value) override;
156 
158  void AppendAlgorithmParameters(std::string& algorithmParameters) const override;
159 
161  std::size_t ConsumeNextAlgorithmParameter(
162  vtkStringToken parameterName, const std::string& algorithmParameters) override;
163 
164 protected:
166  ~vtkKMeansStatistics() override;
167 
171  void Learn(vtkTable*, vtkTable*, vtkStatisticalModel*) override;
172 
176  void Derive(vtkStatisticalModel*) override;
177 
181  void Assess(vtkTable*, vtkStatisticalModel*, vtkTable*) override;
182 
186  void Test(vtkTable*, vtkStatisticalModel*, vtkTable*) override {}
187 
191  void SelectAssessFunctor(vtkTable* inData, vtkDataObject* inMeta, vtkStringArray* rowNames,
192  AssessFunctor*& dfunc) override;
193 
199  virtual void UpdateClusterCenters(vtkTable* newClusterElements, vtkTable* curClusterElements,
200  vtkIdTypeArray* numMembershipChanges, vtkIdTypeArray* numDataElementsInCluster,
201  vtkDoubleArray* error, vtkIdTypeArray* startRunID, vtkIdTypeArray* endRunID,
202  vtkIntArray* computeRun);
203 
209  virtual vtkIdType GetTotalNumberOfObservations(vtkIdType numObservations);
210 
217  int InitializeDataAndClusterCenters(vtkTable* inParameters, vtkTable* inData,
218  vtkTable* dataElements, vtkIdTypeArray* numberOfClusters, vtkTable* curClusterElements,
219  vtkTable* newClusterElements, vtkIdTypeArray* startRunID, vtkIdTypeArray* endRunID);
220 
226  virtual void CreateInitialClusterCenters(vtkIdType numToAllocate,
227  vtkIdTypeArray* numberOfClusters, vtkTable* inData, vtkTable* curClusterElements,
228  vtkTable* newClusterElements);
229 
248  double Tolerance;
254 
255 private:
256  vtkKMeansStatistics(const vtkKMeansStatistics&) = delete;
257  void operator=(const vtkKMeansStatistics&) = delete;
258 };
259 
260 VTK_ABI_NAMESPACE_END
261 #endif
bool Aggregate(vtkDataObjectCollection *, vtkStatisticalModel *) override
Given a collection of models, calculate aggregate model NB: not implemented.
int MaxNumIterations
This is the maximum number of iterations allowed if the new cluster centers have not yet converged...
a base class for statistical modeling of other data
virtual std::size_t ConsumeNextAlgorithmParameter(vtkStringToken parameterName, const std::string &algorithmParameters)
Consume a single parameter value, setting the value on this instance of the class.
static vtkTableAlgorithm * New()
maintain an unordered list of data objects
vtkKMeansDistanceFunctor * DistanceFunctor
This is the Distance functor.
int DefaultNumberOfClusters
This is the default number of clusters used when the user does not provide initial cluster centers...
char * KValuesArrayName
This is the name of the column that specifies the number of clusters in each run. ...
virtual void AppendAlgorithmParameters(std::string &algorithmParameters) const
Subclasses must override this method if they have any internal ivars that affect the behavior of Requ...
virtual void Assess(vtkTable *, vtkStatisticalModel *, vtkTable *)=0
Execute the calculations required by the Assess option.
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:363
A type representing the union of many types.
Definition: vtkVariant.h:52
dynamic, self-adjusting array of double
virtual void Learn(vtkTable *, vtkTable *, vtkStatisticalModel *)=0
Execute the calculations required by the Learn option, given some input Data.
Base class for statistics algorithms.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:35
double Tolerance
This is the percentage of data elements that swap cluster IDs.
a simple class to control print indentation
Definition: vtkIndent.h:28
A class for KMeans clustering.
virtual void Derive(vtkStatisticalModel *)=0
Execute the calculations required by the Derive option.
Represent a string by its integer hash.
void Test(vtkTable *, vtkStatisticalModel *, vtkTable *) override
Execute the calculations required by the Test option.
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
virtual bool SetParameter(const char *parameter, int index, vtkVariant value)
A convenience method (in particular for access from other applications) to set parameter values of Le...
virtual void SelectAssessFunctor(vtkTable *outData, vtkDataObject *inMeta, vtkStringArray *rowNames, AssessFunctor *&dfunc)=0
A pure virtual method to select the appropriate assessment functor.
general representation of visualization data
Definition: vtkDataObject.h:55
measure distance from k-means cluster centers
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.