1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkRRandomTableSource.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 2009 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 -------------------------------------------------------------------------*/
20 
21 // .NAME vtkRRandomTableSource - Generates vtkTables with columns of random numbers using Gnu R.
22 //
23 // .SECTION Description
24 //
25 // Note - An installation of Gnu R is required to build and use this class.
26 //
27 // vtkRRandomTableSource uses the Gnu R math C language API for statistical distributions to generate
28 // vtkTables with columns of random numbers selected from a chosen distribution. The available
29 // distributions are as follows:
30 //
31 //   Normal, Cauchy, F, Student T, Poisson, Chi-Square, Exponential, Binomial, Beta, Geometric,
32 //   Uniform, Gamma, Log-Normal, Logistic, Hyper-Geometric, Weibull, Negative Binomial, Wilcox
33 //
34 // The default output for the class is a table of one column with ten rows of random numbers chosen
35 // from a Normal distribution of mean 0.0 and standard deviation of 1.0.
36 //
37 // Use SetNumberOfRows() to set the number of rows (random numbers) in the output table.
38 //
39 // See comments for SetStatisticalDistributionForColumn() to set the distribution output for a particular
40 // column or all columns in the output table.
41 //
42 // .SECTION See Also
43 // vtkRInterface
44 //
45 // .SECTION Thanks
46 // Developed by Thomas J. Otahal (tjotaha@sandia.gov) at Sandia National Laboratories.
47 //
48 
49 #ifndef vtkRRandomTableSource_h
50 #define vtkRRandomTableSource_h
51 
52 #include "vtkFiltersStatisticsGnuRModule.h" // For export macro
53 #include "vtkTableAlgorithm.h"
54 
55 class vtkRrtsimplementation;
56 
57 class VTKFILTERSSTATISTICSGNUR_EXPORT vtkRRandomTableSource : public vtkTableAlgorithm
58 {
59 
60 public:
61 
62   static vtkRRandomTableSource* New();
63   vtkTypeMacro(vtkRRandomTableSource,vtkTableAlgorithm);
64   void PrintSelf(ostream& os, vtkIndent indent);
65 
66   // Description:
67   // Set and Get the number of rows in the output table (random numbers).
68   void SetNumberOfRows(int nrows);
69   int GetNumberOfRows();
70 
71   // Description:
72   // Returns number of columns in the output table.
73   int GetNumberOfColumns();
74 
75   // Description:
76   // Clears table output to zero output columns.  Number of table rows
77   // is unchanged.
78   void ClearTableOutput();
79 
80   // Description:
81   // Set the random seed used by Gnu R to generate output.  The default is to use
82   // the random seed provided by Gnu R based on the current time.
83   void SetRandGenSeed(const int seed);
84 
85 //BTX
86   // Description:
87   // Available statistical distribution output types.  Depending on the distribution type, up to three
88   // parameters (param1, param2, param3) must be specified when using SetStatisticalDistributionForColumn().
89   typedef enum
90     {
91 
92     WILCOXONRANKSUM = 0,    // Wilcoxon rank sum
93                             // param1 - number of observations in the first sample
94                             // param2 - number of observations in the second sample
95                             // param3 - not used
96 
97     WILCOXONSIGNEDRANK = 1, // Wilcoxon signed rank
98                             // param1 - number of observations in the sample
99                             // param2 - not used
100                             // param3 - not used
101 
102     LOGISTIC = 2,    // Logistic
103                      // param1 - location parameter (usually 0)
104                      // param2 - scale parameter (usually 1)
105                      // param3 - not used
106 
107     WEIBULL = 3,     // Weibull
108                      // param1 - shape parameter
109                      // param2 - scale parameter (usually 1)
110                      // param3 - not used
111 
112     POISSON = 4,     // Poisson
113                      // param1 - lambda mean
114                      // param2 - not used
115                      // param3 - not used
116 
117     NEGBINOMIAL = 5, // Negative Binomial
118                      // param1 - Dispersion parameter, or number of successful trials
119                      // param2 - Probability of success on each trial
120                      // param3 - not used
121 
122     HYPERGEOM = 6, // Hyper Geometric
123                    // param1 - number of white balls in the urn
124                    // param2 - number of black balls in the urn
125                    // param3 - number of balls drawn from the urn
126 
127     GEOM = 7,      // Geometric
128                    // param1 - rate parameter
129                    // param2 - not used
130                    // param3 - not used
131 
132     EXP = 8,       // Exponential
133                    // param1 - rate parameter
134                    // param2 - not used
135                    // param3 - not used
136 
137     CAUCHY = 9,    // Cauchy
138                    // param1 - location parameter (usually 0)
139                    // param2 - scale parameter (usually 1)
140                    // param3 - not used
141 
142     T = 10,         // Student T
143                     // param1 - degrees of freedom
144                     // param2 - not used
145                     // param3 - not used
146 
147     F = 11,         // F
148                     // param1 - degrees of freedom one
149                     // param2 - degrees of freedom two
150                     // param3 - not used
151 
152     LOGNORMAL = 12, // Log-normal
153                     // param1 - log mean
154                     // param2 - log standard deviation
155                     // param3 - not used
156 
157     GAMMA = 13,     // Gamma
158                     // param1 - shape parameter
159                     // param2 - scale parameter
160                     // param3 - not used
161 
162     UNIF = 14,      // Uniform
163                     // param1 - distribution lower limit
164                     // param2 - distribution upper limit
165                     // param3 - not used
166 
167     BETA = 15,      // Beta
168                     // param1 - shape parameter one.
169                     // param2 - shape parameter two.
170                     // param3 - not used
171 
172     BINOMIAL = 16,  // Binomial
173                     // param1 - number of trials
174                     // param2 - probability of success on each trial
175                     // param3 - not used
176 
177     NORMAL = 17,    // Normal (Gaussian)
178                     // param1 - mean
179                     // param2 - standard deviation
180                     // param3 - not used
181 
182     CHISQUARE = 18, // Chi-square
183                     // param1 - degrees of freedom
184                     // param2 - not used
185                     // param3 - not used
186 
187   } StatDistType;
188 
189   // Description:
190   // Set the statistical distribution to generate random numbers for a particular column or all
191   // columns in the output table.  Use the above documented distribution types, for example
192   // use vtkRRandomTableSource::Normal for a Normal distribution.  Set unused parameter values to 0.0.
193   // For example, a Normal distribution uses only param1 and param2 as the mean and the standard deviation
194   // respectively.  Set param3 to 0.0.
195   // If column_index equals the current number of columns in the output table, a new column will be
196   // added to the output table and initialized with the input distribution parameters.
197   void SetStatisticalDistributionForColumn(vtkRRandomTableSource::StatDistType t,
198                                            double param1,
199                                            double param2,
200                                            double param3,
201                                            const char* ColumnName,
202                                            int column_index);
203 //ETX
204 
205   // Description:
206   // Python wrapped version of above method.  Use integer equivalent of StatDistType.
207   void SetStatisticalDistributionForColumn(int StatDistType,
208                                            double param1,
209                                            double param2,
210                                            double param3,
211                                            const char* ColumnName,
212                                            int column_index);
213 
214 
215 protected:
216   vtkRRandomTableSource();
217   ~vtkRRandomTableSource();
218 
219   int RequestData(
220     vtkInformation*,
221     vtkInformationVector**,
222     vtkInformationVector*);
223 
224 private:
225   vtkRRandomTableSource(const vtkRRandomTableSource&); // Not implemented
226   void operator=(const vtkRRandomTableSource&);   // Not implemented
227 
228   int NumberOfRows;
229 
230   vtkRrtsimplementation *impl;
231 
232 };
233 
234 #endif
235 
236