vstat
Functions
-
int main(int argc, char *argv[])
vstat [ option ] [ infile ]
-l int
length of vector \((1 \le L)\)
-m int
order of vector \((0 \le L - 1)\)
-t int
output interval \((1 \le T)\)
-c double
confidence level \((0 < C < 100)\)
-o int
output format
0
mean and covariance1
mean2
covariance3
standard deviation4
correlation5
precision6
mean and lower/upper bounds7
sufficient statistics
-s str
statistics file
-d
output only diagonal elements
-e
use a numerically stable algorithm
infile str
double-type vectors
stdout
double-type statistics
The input of this command is
\[ \begin{array}{c} \underbrace{ \underbrace{x_1(1), \; \ldots, \; x_1(L)}_L, \; \ldots, \; \underbrace{x_T(1), \; \ldots, \; x_T(L)}_L, }_{L \times T} \; \ldots, \end{array} \]and the output format depends on-o
option.If \(O=1\),
\[ \begin{array}{ccc} \underbrace{\mu_{0}(1), \; \ldots, \; \mu_{0}(L)}_L, & \underbrace{\mu_{T}(1), \; \ldots, \; \mu_{T}(L)}_L, & \ldots, \end{array} \]where\[ \mu_t(l) = \frac{1}{T} \sum_{\tau=1}^T x_{t+\tau}(l). \]If \(O=2\),
\[ \begin{array}{cc} \underbrace{\sigma^2_0(1,1), \; \sigma^2_{0}(1,2), \; \ldots, \; \sigma^2_0(L,L)}_{L \times L}, & \ldots, \end{array} \]where\[ \sigma^2_t(k,l) = \frac{1}{T} \sum_{\tau=1}^T (x_{t+\tau}(k) - \mu_t(k)) (x_{t+\tau}(l) - \mu_t(l)). \]If \(O=3\),
\[ \begin{array}{cc} \underbrace{\sigma_{0}(1,1), \; \sigma_{0}(2,2), \; \ldots, \; \sigma_{0}(L,L)}_L, & \ldots. \end{array} \]If \(O=4\),
\[ \begin{array}{cc} \underbrace{r_{0}(1,1), \; r_{0}(1,2), \; \ldots, \; r_{0}(L,L)}_{L \times L}, & \ldots, \end{array} \]where\[ r_t(k,l) = \frac{\sigma^2_t(k,l)}{\sigma_t(k,k) \, \sigma_t(l,l)}. \]If \(O=5\),
\[ \begin{array}{cc} \underbrace{s_{0}(1,1), \; s_{0}(1,2), \; \ldots, \; s_{0}(L,L)}_{L \times L}, & \ldots, \end{array} \]where \(s_t(k,l)\) is the \((k,l)\)-th component of the inverse of the covariance matrix.If \(O=6\),
\[ \begin{array}{cccc} \underbrace{\mu_{0}(1), \; \ldots, \; \mu_{0}(L)}_L, & \underbrace{\ell_{0}(1), \; \ldots, \; \ell_{0}(L)}_L, & \underbrace{u_{0}(1), \; \ldots, \; u_{0}(L)}_L, & \ldots, \end{array} \]where\[\begin{split}\begin{eqnarray} \ell_t(l) &=& \mu_t(l) - p(C, T-1) \sqrt{\frac{\sigma^2_t(l,l)}{T-1}}, \\ u_t(l) &=& \mu_t(l) + p(C, T-1) \sqrt{\frac{\sigma^2_t(l,l)}{T-1}}, \end{eqnarray}\end{split}\]and \(p(C, T-1)\) is the upper \((100-C)/2\)-th percentile of the t-distribution with degrees of freedom \(T-1\).If \(O=7\),
\[ \begin{array}{cccc} \underbrace{T}_1, & \underbrace{m^{(1)}_{0}(1), \; \ldots, \; m^{(1)}_{0}(L)}_L, & \underbrace{m^{(2)}_{0}(1,1), \; m^{(2)}_{0}(1,2), \; \ldots, \; m^{(2)}_{0}(L,L)}_{L \times L}, & \ldots, \end{array} \]where \(m^{(1)}\) is the first-order statistics and \(m^{(2)}\) is the second-order statistics.echo 0 1 2 3 4 5 6 7 8 9 | x2x +ad > data.d vstat -o 1 data.d | x2x +da # 4.5 vstat -o 1 data.d -t 5 | x2x +da # 2, 7
cat data1.d data2.d | vstat -o 7 > data12.stat cat data3.d data4.d | vstat -o 7 > data34.stat echo | vstat -s data12.stat -s data34.stat -o 1 > data.mean # equivalent to the following line cat data?.d | vstat -o 1 > data.mean
- Parameters:
argc – [in] Number of arguments.
argv – [in] Argument vector.
- Returns:
0 on success, 1 on failure.
-
class StatisticsAccumulation
Accumulate statistics.
The input of is an \(M\)-th order vector:
\[ \begin{array}{cccc} x_t(0), & x_t(1), & \ldots, & x_t(M). \end{array} \]After runningRun
\(T\) times, the following statistics are obtained:\[\begin{split}\begin{eqnarray} S_0 &=& T, \\ S_1(m) &=& \sum_{t=0}^{T-1} x_t(m), \\ S_2(m,n) &=& \sum_{t=0}^{T-1} x_t(m) x_t(n). \end{eqnarray}\end{split}\]Then, the moments, e.g., mean and covariance, of the input data can be computed from the accumulated statistics \(\{S_k\}_{k=0}^K\).Public Functions
-
StatisticsAccumulation(int num_order, int num_statistics_order, bool diagonal = false, bool numerically_stable = false)
- Parameters:
num_order – [in] Order of vector, \(M\).
num_statistics_order – [in] Order of statistics, \(K\).
diagonal – [in] If true, only diagonal part is accumulated.
numerically_stable – [in] If true, use a numerically stable algorithm.
-
inline int GetNumOrder() const
- Returns:
Order of vector.
-
inline int GetNumStatisticsOrder() const
- Returns:
Order of statistics.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool GetNumData(const StatisticsAccumulation::Buffer &buffer, int *num_data) const
- Parameters:
buffer – [in] Buffer.
num_data – [out] Number of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetFirst(const StatisticsAccumulation::Buffer &buffer, std::vector<double> *first) const
- Parameters:
buffer – [in] Buffer.
first – [out] First order statistics.
- Returns:
True on success, false on failure.
-
bool GetSecond(const StatisticsAccumulation::Buffer &buffer, SymmetricMatrix *second) const
- Parameters:
buffer – [in] Buffer.
second – [out] Second order statistics.
- Returns:
True on success, false on failure.
-
bool GetSum(const StatisticsAccumulation::Buffer &buffer, std::vector<double> *sum) const
- Parameters:
buffer – [in] Buffer.
sum – [out] Summation of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetMean(const StatisticsAccumulation::Buffer &buffer, std::vector<double> *mean) const
- Parameters:
buffer – [in] Buffer.
mean – [out] Mean of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetDiagonalCovariance(const StatisticsAccumulation::Buffer &buffer, std::vector<double> *variance) const
- Parameters:
buffer – [in] Buffer.
variance – [out] Diagonal covariance of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetStandardDeviation(const StatisticsAccumulation::Buffer &buffer, std::vector<double> *standard_deviation) const
- Parameters:
buffer – [in] Buffer.
standard_deviation – [out] Standard deviation of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetFullCovariance(const StatisticsAccumulation::Buffer &buffer, SymmetricMatrix *full_covariance) const
- Parameters:
buffer – [in] Buffer.
full_covariance – [out] Full covariance of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetUnbiasedCovariance(const StatisticsAccumulation::Buffer &buffer, SymmetricMatrix *unbiased_covariance) const
- Parameters:
buffer – [in] Buffer.
unbiased_covariance – [out] Unbiased covariance of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetCorrelation(const StatisticsAccumulation::Buffer &buffer, SymmetricMatrix *correlation) const
- Parameters:
buffer – [in] Buffer.
correlation – [out] Correlation of accumulated data.
- Returns:
True on success, false on failure.
-
void Clear(StatisticsAccumulation::Buffer *buffer) const
Clear buffer.
- Parameters:
buffer – [inout] Buffer.
-
bool Run(const std::vector<double> &data, StatisticsAccumulation::Buffer *buffer) const
Accumulate statistics.
- Parameters:
data – [in] \(M\)-th order input vector.
buffer – [inout] Buffer.
- Returns:
True on success, false on failure.
-
bool Merge(int num_data, const std::vector<double> &first, const SymmetricMatrix &second, StatisticsAccumulation::Buffer *buffer) const
Merge statistics.
- Parameters:
num_data – [in] Number of data.
first – [in] First order statistics.
second – [in] Second order statistics.
buffer – [inout] Buffer.
- Returns:
True on success, false on failure.
-
class Buffer
Buffer for StatisticsAccumulation class.
-
StatisticsAccumulation(int num_order, int num_statistics_order, bool diagonal = false, bool numerically_stable = false)