18 #ifndef NGRAM_NGRAM_HIST_MERGE_H_ 19 #define NGRAM_NGRAM_HIST_MERGE_H_ 24 #include <fst/mutable-fst.h> 35 typedef HistogramArc::Label
Label;
41 Label backoff_label = 0,
double norm_eps =
kNormEps,
42 bool check_consistency =
false)
43 :
NGramMerge(infst1, backoff_label, norm_eps, check_consistency) {}
48 double beta,
bool norm =
false) {
52 NGRAMERROR() <<
"Histogram count merging failed";
60 bool in_fst1,
bool in_fst2)
const override {
61 if (in_fst1 && in_fst2) {
62 return NGramHistMerge::WeightSum(w1, w2);
73 double NormWeight(StateId st,
bool in_fst1,
bool in_fst2)
const override {
74 if (in_fst1 && in_fst2) {
75 return -NegLogSum(alpha_, beta_);
90 return (in_fst1) ? (alpha_ != 0.0) : (beta_ != 0.0);
100 std::array<fst::TropicalWeight, kHistogramBins> v;
101 v.fill(fst::TropicalWeight::Zero());
102 v[0] = NegLogSum(w1.Value(0).Value(), w2.Value(0).Value());
104 for (
int k = 0; k < v.size() - 1; k++) {
105 for (
int j = 0; j <= k; j++) {
106 v[k + 1] = NegLogSum(v[k + 1].Value(), w1.Value(j + 1).Value() +
107 w2.Value(k - j + 1).Value());
110 return fst::PowerWeight<fst::TropicalWeight, kHistogramBins>(
120 #endif // NGRAM_NGRAM_HIST_MERGE_H_ bool MergeUnshared(bool in_fst1) const override
HistogramArc::Weight Weight
NGramHistMerge(fst::MutableFst< HistogramArc > *infst1, Label backoff_label=0, double norm_eps=kNormEps, bool check_consistency=false)
bool MergeNGramModels(const fst::Fst< Arc > &infst2, bool norm=false, int max_order=-1)
HistogramArc::Label Label
void MergeNGramModels(const fst::Fst< HistogramArc > &infst2, double alpha, double beta, bool norm=false)
Weight MergeWeights(StateId s1, StateId s2, Label Label, Weight w1, Weight w2, bool in_fst1, bool in_fst2) const override
HistogramArc::StateId StateId
double NormWeight(StateId st, bool in_fst1, bool in_fst2) const override