decodable-mapped.h
Go to the documentation of this file.
1 // decoder/decodable-mapped.h
2 
3 // Copyright 2009-2011 Saarland University; Microsoft Corporation;
4 // Lukas Burget
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #ifndef KALDI_DECODER_DECODABLE_MAPPED_H_
22 #define KALDI_DECODER_DECODABLE_MAPPED_H_
23 
24 #include <vector>
25 
26 #include "base/kaldi-common.h"
27 #include "itf/decodable-itf.h"
28 
29 namespace kaldi {
30 
31 // The DecodableMapped object is initialized by a normal decodable object,
32 // and a vector that maps indices. The "pdf index" into this decodable object
33 // is the index into the vector, and the value it finds there is used
34 // to index into the base decodable object.
35 
37  public:
38  DecodableMapped(const std::vector<int32> &index_map, DecodableInterface *d):
39  index_map_(index_map), decodable_(d) { }
40 
41  // Note, frames are numbered from zero. But state_index is numbered
42  // from one (this routine is called by FSTs).
43  virtual BaseFloat LogLikelihood(int32 frame, int32 state_index) {
44  KALDI_ASSERT(static_cast<size_t>(state_index) < index_map_.size());
45  return decodable_->LogLikelihood(frame, index_map_[state_index]);
46  }
47 
48  // note: indices are assumed to be numbered from one, so
49  // NumIndices() will be the same as the largest index.
50  virtual int32 NumIndices() const { return static_cast<int32>(index_map_.size()) - 1; }
51 
52  virtual bool IsLastFrame(int32 frame) const {
53  // We require all the decodables have the same #frames. We don't check this though.
54  return decodable_->IsLastFrame(frame);
55  }
56 
57  private:
58  std::vector<int32> index_map_;
60 
62 };
63 
64 
65 
66 } // namespace kaldi
67 
68 #endif // KALDI_DECODER_DECODABLE_MAPPED_H_
69 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and th...
Definition: decodable-itf.h:82
virtual bool IsLastFrame(int32 frame) const
Returns true if this is the last frame.
DecodableMapped(const std::vector< int32 > &index_map, DecodableInterface *d)
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
kaldi::int32 int32
KALDI_DISALLOW_COPY_AND_ASSIGN(DecodableMapped)
DecodableInterface * decodable_
virtual int32 NumIndices() const
Returns the number of states in the acoustic model (they will be indexed one-based, i.e.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual BaseFloat LogLikelihood(int32 frame, int32 index)=0
Returns the log likelihood, which will be negated in the decoder.
std::vector< int32 > index_map_
virtual BaseFloat LogLikelihood(int32 frame, int32 state_index)
Returns the log likelihood, which will be negated in the decoder.