1 /*=========================================================================
2 
3 Program:   Visualization Toolkit
4 Module:    vtkAutoCorrelativeStatistics.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  * @class   vtkAutoCorrelativeStatistics
17  * @brief   A class for univariate auto-correlative statistics
18  *
19  *
20  * Given a selection of columns of interest in an input data table, this
21  * class provides the following functionalities, depending on the chosen
22  * execution options:
23  * * Learn: calculate sample mean and M2 aggregates for each variable w.r.t. itself
24  *   (cf. P. Pebay, Formulas for robust, one-pass parallel computation of covariances
25  *   and Arbitrary-Order Statistical Moments, Sandia Report SAND2008-6212, Sep 2008,
26  *   http://infoserve.sandia.gov/sand_doc/2008/086212.pdf for details)
27  *   for each specified time lag.
28  * * Derive: calculate unbiased autocovariance matrix estimators and its determinant,
29  *   linear regressions, and Pearson correlation coefficient, for each specified
30  *   time lag.
31  * * Assess: given an input data set, two means and a 2x2 covariance matrix,
32  *   mark each datum with corresponding relative deviation (2-dimensional Mahlanobis
33  *   distance).
34  *
35  *
36  * @par Thanks:
37  * This class was written by Philippe Pebay, Kitware SAS 2012
38 */
39 
40 #ifndef vtkAutoCorrelativeStatistics_h
41 #define vtkAutoCorrelativeStatistics_h
42 
43 #include "vtkFiltersStatisticsModule.h" // For export macro
44 #include "vtkStatisticsAlgorithm.h"
45 
46 class vtkMultiBlockDataSet;
47 class vtkStringArray;
48 class vtkTable;
49 class vtkVariant;
50 class vtkDoubleArray;
51 
52 class VTKFILTERSSTATISTICS_EXPORT vtkAutoCorrelativeStatistics : public vtkStatisticsAlgorithm
53 {
54 public:
55   vtkTypeMacro(vtkAutoCorrelativeStatistics, vtkStatisticsAlgorithm);
56   void PrintSelf(ostream& os, vtkIndent indent) override;
57   static vtkAutoCorrelativeStatistics* New();
58 
59   //@{
60   /**
61    * Set/get the cardinality of the data set at given time, i.e., of
62    * any given time slice. It cannot be negative.
63    * The input data set is assumed to have a cardinality which
64    * is a multiple of this value.
65    * The default is 0, meaning that the user must specify a value
66    * that is consistent with the input data set.
67    */
68   vtkSetClampMacro(SliceCardinality,vtkIdType,0,VTK_ID_MAX);
69   vtkGetMacro(SliceCardinality,vtkIdType);
70   //@}
71 
72   /**
73    * Given a collection of models, calculate aggregate model
74    */
75   void Aggregate( vtkDataObjectCollection*,
76                   vtkMultiBlockDataSet* ) override;
77 
78 protected:
79   vtkAutoCorrelativeStatistics();
80   ~vtkAutoCorrelativeStatistics() override;
81 
82   /**
83    * Execute the calculations required by the Learn option, given some input Data
84    * NB: input parameters are unused.
85    */
86   void Learn( vtkTable*,
87               vtkTable*,
88               vtkMultiBlockDataSet* ) override;
89 
90   /**
91    * Execute the calculations required by the Derive option.
92    */
93   void Derive( vtkMultiBlockDataSet* ) override;
94 
95   /**
96    * Execute the calculations required by the Test option.
97    */
Test(vtkTable *,vtkMultiBlockDataSet *,vtkTable *)98   void Test( vtkTable*,
99                      vtkMultiBlockDataSet*,
100                      vtkTable* ) override { return; };
101 
102   /**
103    * Execute the calculations required by the Assess option.
104    */
Assess(vtkTable * inData,vtkMultiBlockDataSet * inMeta,vtkTable * outData)105   void Assess( vtkTable* inData,
106                vtkMultiBlockDataSet* inMeta,
107                vtkTable* outData ) override
108   { this->Superclass::Assess( inData, inMeta, outData, 1 ); }
109 
110   /**
111    * Calculate p-value. This will be overridden using the object factory with an
112    * R implementation if R is present.
113    */
114   virtual vtkDoubleArray* CalculatePValues(vtkDoubleArray*);
115 
116   /**
117    * Provide the appropriate assessment functor.
118    */
119   void SelectAssessFunctor( vtkTable* outData,
120                             vtkDataObject* inMeta,
121                             vtkStringArray* rowNames,
122                             AssessFunctor*& dfunc ) override;
123 
124   vtkIdType SliceCardinality;
125 
126 private:
127   vtkAutoCorrelativeStatistics( const vtkAutoCorrelativeStatistics& ) = delete;
128   void operator = ( const vtkAutoCorrelativeStatistics& ) = delete;
129 };
130 
131 #endif
132