kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
feature-cmvn.h
Go to the documentation of this file.
1
2//
3// Copyright 2009-2013 Microsoft Corporation
4// Johns Hopkins University (author: Daniel Povey)
5// Copyright (c) 2026 Xiaomi Corporation
6//
7// This file is copied/modified from kaldi/src/transform/cmvn.h
8//
10//
11// See ../../LICENSE for more information
12
33
34#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_CMVN_H_
35#define KALDI_NATIVE_FBANK_CSRC_FEATURE_CMVN_H_
36
37#include <stdint.h>
38
39#include "Eigen/Core"
41
42namespace knf {
43
54 bool norm_vars = false;
55
59 bool reverse = false;
60};
61
98void InitCmvnStats(int32_t dim, MatrixD *stats);
99
129void AccCmvnStats(const float *feat, int32_t dim, float weight, MatrixD *stats);
130
142void AccCmvnStats(const MatrixF &feats, MatrixD *stats);
143
156
195void ApplyCmvn(const MatrixD &stats, const CmvnOptions &opts, MatrixF *feats);
196
206void ApplyCmvn(const MatrixD &stats, const CmvnOptions &opts,
207 Eigen::Ref<MatrixF> feats);
208
221MatrixF ApplyCmvn(const MatrixD &stats, const CmvnOptions &opts,
222 const MatrixF &feats);
223
236 public:
241 explicit CmvnAccumulator(int32_t dim = 0);
242
245 void Accumulate(const MatrixF &feats);
246
254 void Add(int32_t dim, const float *frame, float weight = 1.0f);
255
258 const MatrixD &Stats() const { return stats_; }
259
260 private:
261 MatrixD stats_;
262};
263
264} // namespace knf
265
266#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_CMVN_H_
CmvnAccumulator(int32_t dim=0)
Construct an accumulator for features of dimension dim.
void Add(int32_t dim, const float *frame, float weight=1.0f)
Accumulate stats for one frame of dimension dim, applying the same updates as the free function AccCm...
void Accumulate(const MatrixF &feats)
Accumulate stats for a feature matrix (rows = frames); equivalent to calling Add() for each row with ...
const MatrixD & Stats() const
Return the accumulated 2-row stats: row 0 = [sums, count], row 1 = [sumsq, (unused)]; see InitCmvnSta...
Definition feature-cmvn.h:258
kaldi-native-fbank/kaldi-native-fbank/csrc/feature-matrix.h
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
void InitCmvnStats(int32_t dim, MatrixD *stats)
Initialize cmvn stats to zeros in the FULL 2-row layout.
void ApplyCmvn(const MatrixD &stats, const CmvnOptions &opts, MatrixF *feats)
Apply cmvn to feats in place (kaldi ApplyCmvn / ApplyCmvnReverse).
MatrixD ComputeCmvnStats(const MatrixF &feats)
Compute full 2-row cmvn stats for a whole matrix.
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixF
Row-major feature matrix: rows are frames, columns are features.
Definition feature-matrix.h:26
void AccCmvnStats(const float *feat, int32_t dim, float weight, MatrixD *stats)
Accumulate stats for one frame (kaldi AccCmvnStats, same op order).
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixD
Double-precision accumulator/statistics matrix (e.g.
Definition feature-matrix.h:31
Options matching kaldi's apply-cmvn flags.
Definition feature-cmvn.h:50
bool reverse
If true, undo cmvn instead of applying it: the mean is added back and, if norm_vars is true,...
Definition feature-cmvn.h:59
bool norm_vars
If true, normalize the variances as well: after subtracting the mean, each dimension is divided by it...
Definition feature-cmvn.h:54