Skip to content

Commit

Permalink
Merge pull request #51 from sp-nitech/vstat
Browse files Browse the repository at this point in the history
Support merge of stats
  • Loading branch information
takenori-y committed Nov 7, 2023
2 parents 9176709 + c265c15 commit 638b091
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ What is SPTK?
Documentation
-------------
- See [this page](https://sp-nitech.github.io/sptk/latest/) for a reference manual.
- Our [paper](https://openreview.net/pdf?id=O9l-6JBLf-) is available on OpenReview.
- Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.


Requirements
Expand Down
2 changes: 1 addition & 1 deletion doc/main/vstat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vstat

.. doxygenfile:: vstat.cc

.. seealso:: :ref:`vsum`
.. seealso:: :ref:`vsum` :ref:`median`

.. doxygenclass:: sptk::StatisticsAccumulation
:members:
36 changes: 35 additions & 1 deletion include/SPTK/math/statistics_accumulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class StatisticsAccumulation {
std::vector<double> first_order_statistics_;
SymmetricMatrix second_order_statistics_;

std::vector<double> delta_;

friend class StatisticsAccumulation;
DISALLOW_COPY_AND_ASSIGN(Buffer);
};
Expand All @@ -76,9 +78,11 @@ class StatisticsAccumulation {
* @param[in] num_order Order of vector, @f$M@f$.
* @param[in] num_statistics_order Order of statistics, @f$K@f$.
* @param[in] diagonal If true, only diagonal part is accumulated.
* @param[in] numerically_stable If true, use a numerically stable algorithm.
*/
StatisticsAccumulation(int num_order, int num_statistics_order,
bool diagonal = false);
bool diagonal = false,
bool numerically_stable = false);

virtual ~StatisticsAccumulation() {
}
Expand Down Expand Up @@ -112,6 +116,22 @@ class StatisticsAccumulation {
bool GetNumData(const StatisticsAccumulation::Buffer& buffer,
int* num_data) const;

/**
* @param[in] buffer Buffer.
* @param[out] first First order statistics.
* @return True on success, false on failure.
*/
bool GetFirst(const StatisticsAccumulation::Buffer& buffer,
std::vector<double>* first) const;

/**
* @param[in] buffer Buffer.
* @param[out] second Second order statistics.
* @return True on success, false on failure.
*/
bool GetSecond(const StatisticsAccumulation::Buffer& buffer,
SymmetricMatrix* second) const;

/**
* @param[in] buffer Buffer.
* @param[out] sum Summation of accumulated data.
Expand Down Expand Up @@ -185,10 +205,24 @@ class StatisticsAccumulation {
bool Run(const std::vector<double>& data,
StatisticsAccumulation::Buffer* buffer) const;

/**
* Merge statistics.
*
* @param[in] num_data Number of data.
* @param[in] first First order statistics.
* @param[in] second Second order statistics.
* @param[in,out] buffer Buffer.
* @return True on success, false on failure.
*/
bool Merge(int num_data, const std::vector<double>& first,
const SymmetricMatrix& second,
StatisticsAccumulation::Buffer* buffer) const;

private:
const int num_order_;
const int num_statistics_order_;
const bool diagonal_;
const bool numerically_stable_;

bool is_valid_;

Expand Down
17 changes: 17 additions & 0 deletions include/SPTK/utils/misc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ bool ComputeFirstOrderRegressionCoefficients(int n,
bool ComputeSecondOrderRegressionCoefficients(
int n, std::vector<double>* coefficients);

/**
* Compute lower and upper bounds.
*
* @param[in] confidence_level Confidence level.
* @param[in] num_data Number of data.
* @param[in] mean Mean vector.
* @param[in] variance Variance vector.
* @param[out] lower_bound Lower bound.
* @param[out] upper_bound Upper bound.
* @return True on success, false on failure.
*/
bool ComputeLowerAndUpperBounds(double confidence_level, int num_data,
const std::vector<double> mean,
const std::vector<double> variance,
std::vector<double>* lower_bound,
std::vector<double>* upper_bound);

} // namespace sptk

#endif // SPTK_UTILS_MISC_UTILS_H_
2 changes: 1 addition & 1 deletion src/main/imsvq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void PrintUsage(std::ostream* stream) {
*/
int main(int argc, char* argv[]) {
int num_order(kDefaultNumOrder);
std::vector<char*> codebook_vectors_file;
std::vector<const char*> codebook_vectors_file;

for (;;) {
const int option_char(getopt_long(argc, argv, "l:m:s:h", NULL, NULL));
Expand Down
2 changes: 1 addition & 1 deletion src/main/msvq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void PrintUsage(std::ostream* stream) {
*/
int main(int argc, char* argv[]) {
int num_order(kDefaultNumOrder);
std::vector<char*> codebook_vectors_file;
std::vector<const char*> codebook_vectors_file;

for (;;) {
const int option_char(getopt_long(argc, argv, "l:m:s:h", NULL, NULL));
Expand Down
Loading

0 comments on commit 638b091

Please sign in to comment.