vprod
Functions
-
int main(int argc, char *argv[])
vprod [ 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
cumulative mode
infile str
double-type vectors
stdout
double-type product
The input of this command is
\[ \begin{array}{ccc} \underbrace{x_1(1), \; \ldots, \; x_1(L)}_L, & \underbrace{x_2(1), \; \ldots, \; x_2(L)}_L, & \ldots, \end{array} \]and the output is\[ \begin{array}{ccc} \underbrace{p_{0}(1), \; \ldots, \; p_{0}(L)}_L, & \underbrace{p_{T}(1), \; \ldots, \; p_{T}(L)}_L, & \ldots, \end{array} \]where\[ p_t(l) = \prod_{\tau=1}^{T} x_{t+\tau}(l). \]If \(T\) is not given, the product of the whole input is computed.echo 1 2 3 4 5 | x2x +ad | vprod | x2x +da # 120
echo 2 3 4 5 | x2x +ad | vprod -c -t 1 | x2x +da # 2 # 6 # 24 # 120
- Parameters:
argc – [in] Number of arguments.
argv – [in] Argument vector.
- Returns:
0 on success, 1 on failure.
-
class ProductAccumulation
Accumulate product of input vectors.
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} P_0 &=& T, \\ P_1(m) &=& \prod_{t=0}^{T-1} x_t(m). \end{eqnarray}\end{split}\]Public Functions
-
explicit ProductAccumulation(int num_order, bool numerically_stable = false)
- Parameters:
num_order – [in] Order of vector, \(M\).
numerically_stable – [in] If true, use a numerically stable algorithm.
-
inline int GetNumOrder() const
- Returns:
Order of vector.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool GetNumData(const ProductAccumulation::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 GetProduct(const ProductAccumulation::Buffer &buffer, std::vector<double> *product) const
- Parameters:
buffer – [in] Buffer.
product – [out] Product of accumulated data.
- Returns:
True on success, false on failure.
-
bool GetGeometricMean(const ProductAccumulation::Buffer &buffer, std::vector<double> *mean) const
- Parameters:
buffer – [in] Buffer.
mean – [out] Geometric mean of accumulated data.
- Returns:
True on success, false on failure.
-
void Clear(ProductAccumulation::Buffer *buffer) const
Clear buffer.
- Parameters:
buffer – [inout] Buffer.
-
bool Run(const std::vector<double> &data, ProductAccumulation::Buffer *buffer) const
Accumulate product.
- Parameters:
data – [in] \(M\)-th order input vector.
buffer – [inout] Buffer.
- Returns:
True on success, false on failure.
-
class Buffer
Buffer for ProductAccumulation class.
-
explicit ProductAccumulation(int num_order, bool numerically_stable = false)