kaldi Namespace Reference

This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference: More...

Namespaces

 cu
 
 decoder
 
 differentiable_transform
 
 discriminative
 
 internal
 
 kws_internal
 
 nnet1
 
 nnet2
 
 nnet3
 
 sparse_vector_utils
 
 unittest
 

Classes

class  AccumAmDiagGmm
 
class  AccumDiagGmm
 
class  AccumFullGmm
 Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model. More...
 
class  AccumulateMultiThreadedClass
 
struct  AccumulateTreeStatsInfo
 
struct  AccumulateTreeStatsOptions
 
struct  ActivePath
 
class  AffineXformStats
 
class  AgglomerativeClusterer
 The AgglomerativeClusterer class contains the necessary mechanisms for the actual clustering algorithm. More...
 
struct  AhcCluster
 AhcCluster is the cluster object for the agglomerative clustering. More...
 
struct  AlignConfig
 
struct  AlignedTermsPair
 
class  AmDiagGmm
 
class  AmSgmm2
 Class for definition of the subspace Gmm acoustic model. More...
 
class  ArbitraryResample
 Class ArbitraryResample allows you to resample a signal (assumed zero outside the sample region, not periodic) at arbitrary specified time values, which don't have to be linearly spaced. More...
 
class  ArcPosteriorComputer
 
class  ArpaFileParser
 ArpaFileParser is an abstract base class for ARPA LM file conversion. More...
 
struct  ArpaLine
 
class  ArpaLmCompiler
 
class  ArpaLmCompilerImpl
 
class  ArpaLmCompilerImplInterface
 
struct  ArpaParseOptions
 Options that control ArpaFileParser. More...
 
class  basic_filebuf
 
class  basic_pipebuf
 
class  BasicHolder
 BasicHolder is valid for float, double, bool, and integer types. More...
 
class  BasicPairVectorHolder
 BasicPairVectorHolder is a Holder for a vector of pairs of a basic type, e.g. More...
 
class  BasicVectorHolder
 A Holder for a vector of basic types, e.g. More...
 
class  BasicVectorVectorHolder
 BasicVectorVectorHolder is a Holder for a vector of vector of a basic type, e.g. More...
 
class  BasisFmllrAccus
 Stats for fMLLR subspace estimation. More...
 
class  BasisFmllrEstimate
 Estimation functions for basis fMLLR. More...
 
struct  BasisFmllrOptions
 
class  BiglmFasterDecoder
 This is as FasterDecoder, but does online composition between HCLG and the "difference language model", which is a deterministic FST that represents the difference between the language model you want and the language model you compiled HCLG with. More...
 
struct  BiglmFasterDecoderOptions
 
class  BottomUpClusterer
 
struct  ClatRescoreTuple
 
class  Clusterable
 
struct  ClusterKMeansOptions
 
class  CompactLatticeHolder
 
class  CompactLatticeToKwsProductFstMapper
 
struct  CompareFirstMemberOfPair
 Comparator object for pairs that compares only the first pair. More...
 
struct  ComparePosteriorByPdfs
 
struct  CompareReverseSecond
 
class  CompartmentalizedBottomUpClusterer
 
struct  CompBotClustElem
 
struct  ComposeLatticePrunedOptions
 
class  CompressedAffineXformStats
 
class  CompressedMatrix
 
class  ComputeNormalizersClass
 
class  ConfigLine
 This class is responsible for parsing input like hi-there xx=yyy a=b c empty= f-oo=Append(bar, sss) ba_z=123 bing='a b c' baz="a b c d='a b' e" and giving you access to the fields, in this case. More...
 
class  ConstantEventMap
 
class  ConstArpaLm
 
class  ConstArpaLmBuilder
 
class  ConstArpaLmDeterministicFst
 This class wraps a ConstArpaLm format language model with the interface defined in DeterministicOnDemandFst. More...
 
class  ConstIntegerSet
 
class  ContextDependency
 
class  ContextDependencyInterface
 context-dep-itf.h provides a link between the tree-building code in ../tree/, and the FST code in ../fstext/ (particularly, ../fstext/context-dep.h). More...
 
struct  CountStats
 
class  CovarianceStats
 
struct  CuAllocatorOptions
 
class  CuArray
 Class CuArray represents a vector of an integer or struct of type T. More...
 
class  CuArrayBase
 Class CuArrayBase, CuSubArray and CuArray are analogues of classes CuVectorBase, CuSubVector and CuVector, except that they are intended to store things other than float/double: they are intended to store integers or small structs. More...
 
class  CuBlockMatrix
 The class CuBlockMatrix holds a vector of objects of type CuMatrix, say, M_1, M_2, . More...
 
class  CuCompressedMatrix
 Class CuCompressedMatrix, templated on an integer type (expected to be one of: int8, uint8, int16, uint16), this provides a way to approximate a CuMatrix in a more memory-efficient format. More...
 
class  CuCompressedMatrixBase
 Class CuCompressedMatrixBase is an abstract base class that allows you to compress a matrix of type CuMatrix<BaseFloat>. More...
 
class  CuMatrix
 This class represents a matrix that's stored on the GPU if we have one, and in memory if not. More...
 
class  CuMatrixBase
 Matrix for CUDA computing. More...
 
class  CuPackedMatrix
 Matrix for CUDA computing. More...
 
class  CuRand
 
class  CuSparseMatrix
 
class  CuSpMatrix
 
class  CuSubArray
 
class  CuSubMatrix
 This class is used for a piece of a CuMatrix. More...
 
class  CuSubVector
 
class  CuTpMatrix
 
class  CuValue
 The following class is used to simulate non-const references to Real, e.g. More...
 
class  CuVector
 
class  CuVectorBase
 Vector for CUDA computing. More...
 
class  DecisionTreeSplitter
 
class  DecodableAmDiagGmm
 
class  DecodableAmDiagGmmRegtreeFmllr
 
class  DecodableAmDiagGmmRegtreeMllr
 
class  DecodableAmDiagGmmScaled
 
class  DecodableAmDiagGmmUnmapped
 DecodableAmDiagGmmUnmapped is a decodable object that takes indices that correspond to pdf-id's plus one. More...
 
class  DecodableAmSgmm2
 
class  DecodableAmSgmm2Scaled
 
class  DecodableDiagGmmScaledOnline
 
class  DecodableInterface
 DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and the decoder. More...
 
class  DecodableMapped
 
class  DecodableMatrixMapped
 This is like DecodableMatrixScaledMapped, but it doesn't support an acoustic scale, and it does support a frame offset, whereby you can state that the first row of 'likes' is actually the n'th row of the matrix of available log-likelihoods. More...
 
class  DecodableMatrixMappedOffset
 This decodable class returns log-likes stored in a matrix; it supports repeatedly writing to the matrix and setting a time-offset representing the frame-index of the first row of the matrix. More...
 
class  DecodableMatrixScaled
 
class  DecodableMatrixScaledMapped
 
class  DecodableSum
 
class  DecodableSumScaled
 
class  DecodeUtteranceLatticeFasterClass
 This class basically does the same job as the function DecodeUtteranceLatticeFaster, but in a way that allows us to build a multi-threaded command line program more easily. More...
 
class  DeltaFeatures
 
struct  DeltaFeaturesOptions
 
class  DeterminizeLatticeTask
 
class  DiagGmm
 Definition for Gaussian Mixture Model with diagonal covariances. More...
 
class  DiagGmmNormal
 Definition for Gaussian Mixture Model with diagonal covariances in normal mode: where the parameters are stored as means and variances (instead of the exponential form that the DiagGmm class is stored as). More...
 
struct  DummyOptions
 
struct  EbwAmSgmm2Options
 This header implements a form of Extended Baum-Welch training for SGMMs. More...
 
class  EbwAmSgmm2Updater
 
struct  EbwOptions
 
class  EbwUpdatePhoneVectorsClass
 
struct  EbwWeightOptions
 
class  EigenvalueDecomposition
 
struct  error_stats
 
class  EventMap
 A class that is capable of representing a generic mapping from EventType (which is a vector of (key, value) pairs) to EventAnswerType which is just an integer. More...
 
struct  EventMapVectorEqual
 
struct  EventMapVectorHash
 
class  ExampleClass
 
class  ExampleFeatureComputer
 This class is only added for documentation, it is not intended to ever be used. More...
 
struct  ExampleFeatureComputerOptions
 This class is only added for documentation, it is not intended to ever be used. More...
 
class  FasterDecoder
 
struct  FasterDecoderOptions
 
class  FbankComputer
 Class for computing mel-filterbank features; see Computing MFCC features for more information. More...
 
struct  FbankOptions
 FbankOptions contains basic options for computing filterbank features. More...
 
class  FeatureTransformEstimate
 Class for computing a feature transform used for preconditioning of the training data in neural-networks. More...
 
class  FeatureTransformEstimateMulti
 
struct  FeatureTransformEstimateOptions
 
struct  FeatureWindowFunction
 
class  FileInputImpl
 
class  FileOutputImpl
 
class  FmllrDiagGmmAccs
 This does not work with multiple feature transforms. More...
 
struct  FmllrOptions
 
class  FmllrRawAccs
 
struct  FmllrRawOptions
 
class  FmllrSgmm2Accs
 Class for computing the accumulators needed for the maximum-likelihood estimate of FMLLR transforms for a subspace GMM acoustic model. More...
 
class  Fmpe
 
struct  FmpeOptions
 
struct  FmpeStats
 
struct  FmpeUpdateOptions
 
struct  FrameExtractionOptions
 
class  FullGmm
 Definition for Gaussian Mixture Model with full covariances. More...
 
class  FullGmmNormal
 Definition for Gaussian Mixture Model with full covariances in normal mode: where the parameters are stored as means and variances (instead of the exponential form that the FullGmm class is stored as). More...
 
class  GaussClusterable
 GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms. More...
 
struct  GaussInfo
 
class  GaussPostHolder
 
class  GeneralMatrix
 This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<BaseFloat>, or a CompressedMatrix, or a SparseMatrix<BaseFloat>. More...
 
class  GenericHolder
 GenericHolder serves to document the requirements of the Holder interface; it's not intended to be used. More...
 
class  HashList
 
struct  HmmCacheHash
 
class  HmmTopology
 A class for storing topology information for phones. More...
 
struct  HtkHeader
 A structure containing the HTK header. More...
 
class  HtkMatrixHolder
 
struct  HTransducerConfig
 Configuration class for the GetHTransducer() function; see The HTransducerConfig configuration class for context. More...
 
class  Input
 
class  InputImplBase
 
union  Int32AndFloat
 
struct  Int32IsZero
 
class  Interval
 
struct  IvectorEstimationOptions
 
class  IvectorExtractor
 
class  IvectorExtractorComputeDerivedVarsClass
 
struct  IvectorExtractorEstimationOptions
 Options for training the IvectorExtractor, e.g. variance flooring. More...
 
struct  IvectorExtractorOptions
 
class  IvectorExtractorStats
 IvectorExtractorStats is a class used to update the parameters of the ivector extractor. More...
 
struct  IvectorExtractorStatsOptions
 Options for IvectorExtractorStats, which is used to update the parameters of IvectorExtractor. More...
 
class  IvectorExtractorUpdateProjectionClass
 
class  IvectorExtractorUpdateWeightClass
 
class  IvectorExtractorUtteranceStats
 These are the stats for a particular utterance, i.e. More...
 
class  IvectorExtractTask
 
class  IvectorTask
 
class  KaldiFatalError
 Kaldi fatal runtime error exception. More...
 
class  KaldiObjectHolder
 KaldiObjectHolder works for Kaldi objects that have the "standard" Read and Write functions, and a copy constructor. More...
 
class  KaldiRnnlmWrapper
 
struct  KaldiRnnlmWrapperOpts
 
class  KwsAlignment
 
class  KwsProductFstToKwsLexicographicFstMapper
 
class  KwsTerm
 
class  KwsTermsAligner
 
struct  KwsTermsAlignerOptions
 
struct  LatticeArcRecord
 This is used in CompactLatticeLimitDepth. More...
 
class  LatticeBiglmFasterDecoder
 This is as LatticeFasterDecoder, but does online composition between HCLG and the "difference language model", which is a deterministic FST that represents the difference between the language model you want and the language model you compiled HCLG with. More...
 
struct  LatticeFasterDecoderConfig
 
class  LatticeFasterDecoderTpl
 This is the "normal" lattice-generating decoder. More...
 
class  LatticeFasterOnlineDecoderTpl
 LatticeFasterOnlineDecoderTpl is as LatticeFasterDecoderTpl but also supports an efficient way to get the best path (see the function BestPathEnd()), which is useful in endpointing and in situations where you might want to frequently access the best path. More...
 
class  LatticeHolder
 
struct  LatticeIncrementalDecoderConfig
 The normal decoder, lattice-faster-decoder.h, sometimes has an issue when doing real-time applications with long utterances, that each time you get the lattice the lattice determinization can take a considerable amount of time; this introduces latency. More...
 
class  LatticeIncrementalDecoderTpl
 This is an extention to the "normal" lattice-generating decoder. More...
 
class  LatticeIncrementalDeterminizer
 This class is used inside LatticeIncrementalDecoderTpl; it handles some of the details of incremental determinization. More...
 
class  LatticeIncrementalOnlineDecoderTpl
 LatticeIncrementalOnlineDecoderTpl is as LatticeIncrementalDecoderTpl but also supports an efficient way to get the best path (see the function BestPathEnd()), which is useful in endpointing and in situations where you might want to frequently access the best path. More...
 
class  LatticeLexiconWordAligner
 
class  LatticePhoneAligner
 
class  LatticeReader
 LatticeReader provides (static) functions for reading both Lattice and CompactLattice, in text form. More...
 
class  LatticeSimpleDecoder
 Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly optimized decoders. More...
 
struct  LatticeSimpleDecoderConfig
 
class  LatticeWordAligner
 
struct  LbfgsOptions
 This is an implementation of L-BFGS. More...
 
class  LdaEstimate
 Class for computing linear discriminant analysis (LDA) transform. More...
 
struct  LdaEstimateOptions
 
struct  LinearCgdOptions
 
class  LinearResample
 LinearResample is a special case of ArbitraryResample, where we want to resample a signal at linearly spaced intervals (this means we want to upsample or downsample the signal). More...
 
class  LinearVtln
 
class  LmState
 
class  LogisticRegression
 
struct  LogisticRegressionConfig
 
struct  LogMessageEnvelope
 Log message severity and source location info. More...
 
struct  MapDiagGmmOptions
 Configuration variables for Maximum A Posteriori (MAP) update. More...
 
struct  MapTransitionUpdateConfig
 
class  Matrix
 A class for storing matrices. More...
 
class  MatrixBase
 Base class which provides matrix operations not involving resizing or allocation. More...
 
class  MelBanks
 
struct  MelBanksOptions
 
class  MessageLogger
 
class  MfccComputer
 
struct  MfccOptions
 MfccOptions contains basic options for computing MFCC features. More...
 
class  MinimumBayesRisk
 This class does the word-level Minimum Bayes Risk computation, and gives you either the 1-best MBR output together with the expected Bayes Risk, or a sausage-like structure. More...
 
struct  MinimumBayesRiskOptions
 The implementation of the Minimum Bayes Risk decoding method described in "Minimum Bayes Risk decoding and system combination based on a recursion for edit distance", Haihua Xu, Daniel Povey, Lidia Mangu and Jie Zhu, Computer Speech and Language, 2011 This is a slightly more principled way to do Minimum Bayes Risk (MBR) decoding than the standard "Confusion Network" method. More...
 
class  MleAmSgmm2Accs
 Class for the accumulators associated with the phonetic-subspace model parameters. More...
 
struct  MleAmSgmm2Options
 Configuration variables needed in the SGMM estimation process. More...
 
class  MleAmSgmm2Updater
 
struct  MleDiagGmmOptions
 Configuration variables like variance floor, minimum occupancy, etc. More...
 
struct  MleFullGmmOptions
 Configuration variables like variance floor, minimum occupancy, etc. More...
 
class  MleSgmm2SpeakerAccs
 Class for the accumulators required to update the speaker vectors v_s. More...
 
struct  MleTransitionUpdateConfig
 
class  MlltAccs
 A class for estimating Maximum Likelihood Linear Transform, also known as global Semi-tied Covariance (STC), for GMMs. More...
 
class  MultiThreadable
 
class  MultiThreader
 
class  MyTaskClass
 
class  MyThreadClass
 
struct  NccfInfo
 
struct  NGram
 A parsed n-gram from ARPA LM file. More...
 
class  NumberIstream
 
class  OfflineFeatureTpl
 This templated class is intended for offline feature extraction, i.e. More...
 
class  OffsetFileInputImpl
 
class  OnlineAppendFeature
 This online-feature class implements combination of two feature streams (such as pitch, plp) into one stream. More...
 
class  OnlineAudioSourceItf
 
class  OnlineBaseFeature
 Add a virtual class for "source" features such as MFCC or PLP or pitch features. More...
 
class  OnlineCacheFeature
 This feature type can be used to cache its input, to avoid repetition of computation in a multi-pass decoding context. More...
 
class  OnlineCacheInput
 
class  OnlineCmnInput
 
class  OnlineCmvn
 This class does an online version of the cepstral mean and [optionally] variance, but note that this is not equivalent to the offline version. More...
 
struct  OnlineCmvnOptions
 
struct  OnlineCmvnState
 Struct OnlineCmvnState stores the state of CMVN adaptation between utterances (but not the state of the computation within an utterance). More...
 
class  OnlineDecodableDiagGmmScaled
 
class  OnlineDeltaFeature
 
class  OnlineDeltaInput
 
struct  OnlineEndpointConfig
 
struct  OnlineEndpointRule
 This header contains a simple facility for endpointing, that should be used in conjunction with the "online2" online decoding code; see ../online2bin/online2-wav-gmm-latgen-faster-endpoint.cc. More...
 
class  OnlineFasterDecoder
 
struct  OnlineFasterDecoderOpts
 
class  OnlineFeatInputItf
 
class  OnlineFeatureInterface
 OnlineFeatureInterface is an interface for online feature processing (it is also usable in the offline setting, but currently we're not using it for that). More...
 
class  OnlineFeatureMatrix
 
struct  OnlineFeatureMatrixOptions
 
class  OnlineFeaturePipeline
 OnlineFeaturePipeline is a class that's responsible for putting together the various stages of the feature-processing pipeline, in an online setting. More...
 
struct  OnlineFeaturePipelineCommandLineConfig
 This configuration class is to set up OnlineFeaturePipelineConfig, which in turn is the configuration class for OnlineFeaturePipeline. More...
 
struct  OnlineFeaturePipelineConfig
 This configuration class is responsible for storing the configuration options for OnlineFeaturePipeline, but it does not set them. More...
 
class  OnlineFeInput
 
class  OnlineGenericBaseFeature
 This is a templated class for online feature extraction; it's templated on a class like MfccComputer or PlpComputer that does the basic feature extraction. More...
 
struct  OnlineGmmAdaptationState
 
struct  OnlineGmmDecodingAdaptationPolicyConfig
 This configuration class controls when to re-estimate the basis-fMLLR during online decoding. More...
 
struct  OnlineGmmDecodingConfig
 
class  OnlineGmmDecodingModels
 This class is used to read, store and give access to the models used for 3 phases of decoding (first-pass with online-CMN features; the ML models used for estimating transforms; and the discriminatively trained models). More...
 
class  OnlineIvectorEstimationStats
 This class helps us to efficiently estimate iVectors in situations where the data is coming in frame by frame. More...
 
struct  OnlineIvectorExtractionConfig
 This class includes configuration variables relating to the online iVector extraction, but not including configuration for the "base feature", i.e. More...
 
struct  OnlineIvectorExtractionInfo
 This struct contains various things that are needed (as const references) by class OnlineIvectorExtractor. More...
 
struct  OnlineIvectorExtractorAdaptationState
 This class stores the adaptation state from the online iVector extractor, which can help you to initialize the adaptation state for the next utterance of the same speaker in a more informed way. More...
 
class  OnlineIvectorFeature
 OnlineIvectorFeature is an online feature-extraction class that's responsible for extracting iVectors from raw features such as MFCC, PLP or filterbank. More...
 
class  OnlineLdaInput
 
class  OnlineMatrixFeature
 This class takes a Matrix<BaseFloat> and wraps it as an OnlineFeatureInterface: this can be useful where some earlier stage of feature processing has been done offline but you want to use part of the online pipeline. More...
 
class  OnlineMatrixInput
 
struct  OnlineNnet2DecodingConfig
 
struct  OnlineNnet2DecodingThreadedConfig
 
class  OnlineNnet2FeaturePipeline
 OnlineNnet2FeaturePipeline is a class that's responsible for putting together the various parts of the feature-processing pipeline for neural networks, in an online setting. More...
 
struct  OnlineNnet2FeaturePipelineConfig
 This configuration class is to set up OnlineNnet2FeaturePipelineInfo, which in turn is the configuration class for OnlineNnet2FeaturePipeline. More...
 
struct  OnlineNnet2FeaturePipelineInfo
 This class is responsible for storing configuration variables, objects and options for OnlineNnet2FeaturePipeline (including the actual LDA and CMVN-stats matrices, and the iVector extractor, which is a member of ivector_extractor_info. More...
 
class  OnlinePaSource
 
class  OnlinePitchFeature
 
class  OnlinePitchFeatureImpl
 
class  OnlineProcessPitch
 This online-feature class implements post processing of pitch features. More...
 
class  OnlineSilenceWeighting
 
struct  OnlineSilenceWeightingConfig
 
class  OnlineSpeexDecoder
 
class  OnlineSpeexEncoder
 
class  OnlineSpliceFrames
 
struct  OnlineSpliceOptions
 
class  OnlineTcpVectorSource
 
class  OnlineTimer
 class OnlineTimer is used to test real-time decoding algorithms and evaluate how long the decoding of a particular utterance would take. More...
 
class  OnlineTimingStats
 class OnlineTimingStats stores statistics from timing of online decoding, which will enable the Print() function to print out the average real-time factor and average delay per utterance. More...
 
class  OnlineTransform
 This online-feature class implements any affine or linear transform. More...
 
class  OnlineUdpInput
 
class  OnlineVectorSource
 
class  OptimizableInterface
 OptimizableInterface provides a virtual class for optimizable objects. More...
 
class  OptimizeLbfgs
 
class  OptionsItf
 
class  OtherReal
 This class provides a way for switching between double and float types. More...
 
class  OtherReal< double >
 A specialized class for switching from double to float. More...
 
class  OtherReal< float >
 A specialized class for switching from float to double. More...
 
class  Output
 
class  OutputImplBase
 
class  PackedMatrix
 Packed matrix: base class for triangular and symmetric matrices. More...
 
struct  PairHasher
 A hashing function-object for pairs of ints. More...
 
class  ParseOptions
 The class ParseOptions is for parsing command-line options; see Parsing command-line options for more documentation. More...
 
struct  PhoneAlignLatticeOptions
 
class  PipeInputImpl
 
class  PipeOutputImpl
 
struct  PitchExtractionOptions
 
class  PitchFrameInfo
 
class  PitchInterpolator
 
struct  PitchInterpolatorOptions
 
struct  PitchInterpolatorStats
 
class  Plda
 
struct  PldaConfig
 
struct  PldaEstimationConfig
 
class  PldaEstimator
 
class  PldaStats
 
class  PldaUnsupervisedAdaptor
 This class takes unlabeled iVectors from the domain of interest and uses their mean and variance to adapt your PLDA matrices to a new domain. More...
 
struct  PldaUnsupervisedAdaptorConfig
 
class  PlpComputer
 This is the new-style interface to the PLP computation. More...
 
struct  PlpOptions
 PlpOptions contains basic options for computing PLP features. More...
 
class  PosteriorHolder
 
struct  ProcessPitchOptions
 
class  Profiler
 
class  ProfileStats
 
class  PrunedCompactLatticeComposer
 PrunedCompactLatticeComposer implements an algorithm for pruned composition. More...
 
class  Questions
 This class defines, for each EventKeyType, a set of initial questions that it tries and also a number of iterations for which to refine the questions to increase likelihood. More...
 
struct  QuestionsForKey
 QuestionsForKey is a class used to define the questions for a key, and also options that allow us to refine the question during tree-building (i.e. More...
 
class  RandomAccessTableReader
 Allows random access to a collection of objects in an archive or script file; see The Table concept. More...
 
class  RandomAccessTableReaderArchiveImplBase
 
class  RandomAccessTableReaderDSortedArchiveImpl
 
class  RandomAccessTableReaderImplBase
 
class  RandomAccessTableReaderMapped
 This class is for when you are reading something in random access, but it may actually be stored per-speaker (or something similar) but the keys you're using are per utterance. More...
 
class  RandomAccessTableReaderScriptImpl
 
class  RandomAccessTableReaderSortedArchiveImpl
 
class  RandomAccessTableReaderUnsortedArchiveImpl
 
struct  RandomState
 
struct  RecognizedWord
 
class  RecyclingVector
 This class serves as a storage for feature vectors with an option to limit the memory usage by removing old elements. More...
 
class  RefineClusterer
 
struct  RefineClustersOptions
 
class  RegressionTree
 A regression tree is a clustering of Gaussian densities in an acoustic model, such that the group of Gaussians at each node of the tree are transformed by the same transform. More...
 
class  RegtreeFmllrDiagGmm
 An FMLLR (feature-space MLLR) transformation, also called CMLLR (constrained MLLR) is an affine transformation of the feature vectors. More...
 
class  RegtreeFmllrDiagGmmAccs
 Class for computing the accumulators needed for the maximum-likelihood estimate of FMLLR transforms for an acoustic model that uses diagonal Gaussian mixture models as emission densities. More...
 
struct  RegtreeFmllrOptions
 Configuration variables for FMLLR transforms. More...
 
class  RegtreeMllrDiagGmm
 An MLLR mean transformation is an affine transformation of Gaussian means. More...
 
class  RegtreeMllrDiagGmmAccs
 Class for computing the maximum-likelihood estimates of the parameters of an acoustic model that uses diagonal Gaussian mixture models as emission densities. More...
 
struct  RegtreeMllrOptions
 Configuration variables for FMLLR transforms. More...
 
class  RnnlmDeterministicFst
 
struct  RspecifierOptions
 
class  ScalarClusterable
 ScalarClusterable clusters scalars with x^2 loss. More...
 
class  Semaphore
 
class  SequentialTableReader
 A templated class for reading objects sequentially from an archive or script file; see The Table concept. More...
 
class  SequentialTableReaderArchiveImpl
 
class  SequentialTableReaderBackgroundImpl
 
class  SequentialTableReaderImplBase
 
class  SequentialTableReaderScriptImpl
 
struct  Sgmm2FmllrConfig
 Configuration variables needed in the estimation of FMLLR for SGMMs. More...
 
class  Sgmm2FmllrGlobalParams
 Global adaptation parameters. More...
 
class  Sgmm2GauPost
 indexed by time. More...
 
struct  Sgmm2GauPostElement
 This is the entry for a single time. More...
 
struct  Sgmm2GselectConfig
 
struct  Sgmm2LikelihoodCache
 Sgmm2LikelihoodCache caches SGMM likelihoods at two levels: the final pdf likelihoods, and the sub-state level likelihoods, which means that with the SCTM system we can avoid redundant computation. More...
 
struct  Sgmm2PerFrameDerivedVars
 Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf. More...
 
class  Sgmm2PerSpkDerivedVars
 
class  Sgmm2Project
 
struct  Sgmm2SplitSubstatesConfig
 
class  ShiftedDeltaFeatures
 
struct  ShiftedDeltaFeaturesOptions
 
class  SimpleDecoder
 Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly optimized decoders. More...
 
class  SimpleOptions
 The class SimpleOptions is an implementation of OptionsItf that allows setting and getting option values programmatically, i.e., via getter and setter methods. More...
 
class  SingleUtteranceGmmDecoder
 You will instantiate this class when you want to decode a single utterance using the online-decoding setup. More...
 
class  SingleUtteranceNnet2Decoder
 You will instantiate this class when you want to decode a single utterance using the online-decoding setup for neural nets. More...
 
class  SingleUtteranceNnet2DecoderThreaded
 You will instantiate this class when you want to decode a single utterance using the online-decoding setup for neural nets. More...
 
class  SingleUtteranceNnet3DecoderTpl
 You will instantiate this class when you want to decode a single utterance using the online-decoding setup for neural nets. More...
 
class  SingleUtteranceNnet3IncrementalDecoderTpl
 You will instantiate this class when you want to decode a single utterance using the online-decoding setup for neural nets. More...
 
struct  SlidingWindowCmnOptions
 
struct  SolverOptions
 This class describes the options for maximizing various quadratic objective functions. More...
 
class  SparseMatrix
 
class  SparseVector
 
class  SpectrogramComputer
 Class for computing spectrogram features. More...
 
struct  SpectrogramOptions
 SpectrogramOptions contains basic options for computing spectrogram features. More...
 
struct  SpeexOptions
 
class  SphinxMatrixHolder
 A class for reading/writing Sphinx format matrices. More...
 
class  SplitEventMap
 
class  SplitRadixComplexFft
 
class  SplitRadixRealFft
 
class  SpMatrix
 Packed symetric matrix class. More...
 
class  StandardInputImpl
 
class  StandardOutputImpl
 
struct  StringHasher
 A hashing function object for strings. More...
 
class  SubMatrix
 Sub-matrix representation. More...
 
class  SubVector
 Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vector [or as the row of a matrix]. More...
 
class  TableEventMap
 
class  TableWriter
 A templated class for writing objects to an archive or script file; see The Table concept. More...
 
class  TableWriterArchiveImpl
 
class  TableWriterBothImpl
 
class  TableWriterImplBase
 
class  TableWriterScriptImpl
 
class  TaskSequencer
 
struct  TaskSequencerConfig
 
class  TcpServer
 
class  ThreadSynchronizer
 class ThreadSynchronizer acts to guard an arbitrary type of buffer between a producing and a consuming thread (note: it's all symmetric between the two thread types). More...
 
class  TidToTstateMapper
 
class  Timer
 
class  TokenHolder
 
class  TokenVectorHolder
 
class  TpMatrix
 Packed symetric matrix class. More...
 
class  TrainingGraphCompiler
 
struct  TrainingGraphCompilerOptions
 
class  TransitionModel
 
class  TreeClusterer
 
struct  TreeClusterOptions
 
class  TreeRenderer
 
class  TwvMetrics
 
struct  TwvMetricsOptions
 
class  TwvMetricsStats
 
struct  UbmClusteringOptions
 
class  UpdatePhoneVectorsClass
 
class  UpdateWClass
 
struct  VadEnergyOptions
 
class  Vector
 A class representing a vector. More...
 
class  VectorBase
 Provides a vector abstraction class. More...
 
class  VectorClusterable
 VectorClusterable wraps vectors in a form accessible to generic clustering algorithms. More...
 
class  VectorFstToKwsLexicographicFstMapper
 
struct  VectorHasher
 A hashing function-object for vectors. More...
 
class  WaveData
 This class's purpose is to read in Wave files. More...
 
struct  WaveHeaderReadGofer
 
class  WaveHolder
 
class  WaveInfo
 This class reads and hold wave file header information. More...
 
class  WaveInfoHolder
 
class  WordAlignedLatticeTester
 
class  WordAlignLatticeLexiconInfo
 This class extracts some information from the lexicon and stores it in a suitable form for the word-alignment code to use. More...
 
struct  WordAlignLatticeLexiconOpts
 
struct  WordBoundaryInfo
 
struct  WordBoundaryInfoNewOpts
 
struct  WordBoundaryInfoOpts
 
struct  WspecifierOptions
 

Typedefs

typedef void(* LogHandler) (const LogMessageEnvelope &envelope, const char *message)
 Type of third-party logging function. More...
 
typedef float BaseFloat
 
typedef float float32
 
typedef double double64
 
typedef int32 MatrixIndexT
 
typedef int32 SignedMatrixIndexT
 
typedef uint32 UnsignedMatrixIndexT
 
typedef basic_pipebuf< char > PipebufType
 
typedef std::vector< std::string > KeyList
 
typedef TableWriter< KaldiObjectHolder< MatrixBase< BaseFloat > > > BaseFloatMatrixWriter
 
typedef SequentialTableReader< KaldiObjectHolder< Matrix< BaseFloat > > > SequentialBaseFloatMatrixReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< Matrix< BaseFloat > > > RandomAccessBaseFloatMatrixReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< Matrix< BaseFloat > > > RandomAccessBaseFloatMatrixReaderMapped
 
typedef TableWriter< KaldiObjectHolder< MatrixBase< double > > > DoubleMatrixWriter
 
typedef SequentialTableReader< KaldiObjectHolder< Matrix< double > > > SequentialDoubleMatrixReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< Matrix< double > > > RandomAccessDoubleMatrixReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< Matrix< double > > > RandomAccessDoubleMatrixReaderMapped
 
typedef TableWriter< KaldiObjectHolder< CompressedMatrix > > CompressedMatrixWriter
 
typedef TableWriter< KaldiObjectHolder< VectorBase< BaseFloat > > > BaseFloatVectorWriter
 
typedef SequentialTableReader< KaldiObjectHolder< Vector< BaseFloat > > > SequentialBaseFloatVectorReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< Vector< BaseFloat > > > RandomAccessBaseFloatVectorReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< Vector< BaseFloat > > > RandomAccessBaseFloatVectorReaderMapped
 
typedef TableWriter< KaldiObjectHolder< VectorBase< double > > > DoubleVectorWriter
 
typedef SequentialTableReader< KaldiObjectHolder< Vector< double > > > SequentialDoubleVectorReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< Vector< double > > > RandomAccessDoubleVectorReader
 
typedef TableWriter< KaldiObjectHolder< CuMatrix< BaseFloat > > > BaseFloatCuMatrixWriter
 
typedef SequentialTableReader< KaldiObjectHolder< CuMatrix< BaseFloat > > > SequentialBaseFloatCuMatrixReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< CuMatrix< BaseFloat > > > RandomAccessBaseFloatCuMatrixReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< CuMatrix< BaseFloat > > > RandomAccessBaseFloatCuMatrixReaderMapped
 
typedef TableWriter< KaldiObjectHolder< CuMatrix< double > > > DoubleCuMatrixWriter
 
typedef SequentialTableReader< KaldiObjectHolder< CuMatrix< double > > > SequentialDoubleCuMatrixReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< CuMatrix< double > > > RandomAccessDoubleCuMatrixReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< CuMatrix< double > > > RandomAccessDoubleCuMatrixReaderMapped
 
typedef TableWriter< KaldiObjectHolder< CuVector< BaseFloat > > > BaseFloatCuVectorWriter
 
typedef SequentialTableReader< KaldiObjectHolder< CuVector< BaseFloat > > > SequentialBaseFloatCuVectorReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< CuVector< BaseFloat > > > RandomAccessBaseFloatCuVectorReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< CuVector< BaseFloat > > > RandomAccessBaseFloatCuVectorReaderMapped
 
typedef TableWriter< KaldiObjectHolder< CuVector< double > > > DoubleCuVectorWriter
 
typedef SequentialTableReader< KaldiObjectHolder< CuVector< double > > > SequentialDoubleCuVectorReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< CuVector< double > > > RandomAccessDoubleCuVectorReader
 
typedef TableWriter< BasicHolder< int32 > > Int32Writer
 
typedef SequentialTableReader< BasicHolder< int32 > > SequentialInt32Reader
 
typedef RandomAccessTableReader< BasicHolder< int32 > > RandomAccessInt32Reader
 
typedef TableWriter< BasicVectorHolder< int32 > > Int32VectorWriter
 
typedef SequentialTableReader< BasicVectorHolder< int32 > > SequentialInt32VectorReader
 
typedef RandomAccessTableReader< BasicVectorHolder< int32 > > RandomAccessInt32VectorReader
 
typedef TableWriter< BasicVectorVectorHolder< int32 > > Int32VectorVectorWriter
 
typedef SequentialTableReader< BasicVectorVectorHolder< int32 > > SequentialInt32VectorVectorReader
 
typedef RandomAccessTableReader< BasicVectorVectorHolder< int32 > > RandomAccessInt32VectorVectorReader
 
typedef TableWriter< BasicPairVectorHolder< int32 > > Int32PairVectorWriter
 
typedef SequentialTableReader< BasicPairVectorHolder< int32 > > SequentialInt32PairVectorReader
 
typedef RandomAccessTableReader< BasicPairVectorHolder< int32 > > RandomAccessInt32PairVectorReader
 
typedef TableWriter< BasicPairVectorHolder< BaseFloat > > BaseFloatPairVectorWriter
 
typedef SequentialTableReader< BasicPairVectorHolder< BaseFloat > > SequentialBaseFloatPairVectorReader
 
typedef RandomAccessTableReader< BasicPairVectorHolder< BaseFloat > > RandomAccessBaseFloatPairVectorReader
 
typedef TableWriter< BasicHolder< BaseFloat > > BaseFloatWriter
 
typedef SequentialTableReader< BasicHolder< BaseFloat > > SequentialBaseFloatReader
 
typedef RandomAccessTableReader< BasicHolder< BaseFloat > > RandomAccessBaseFloatReader
 
typedef RandomAccessTableReaderMapped< BasicHolder< BaseFloat > > RandomAccessBaseFloatReaderMapped
 
typedef TableWriter< BasicHolder< double > > DoubleWriter
 
typedef SequentialTableReader< BasicHolder< double > > SequentialDoubleReader
 
typedef RandomAccessTableReader< BasicHolder< double > > RandomAccessDoubleReader
 
typedef TableWriter< BasicHolder< bool > > BoolWriter
 
typedef SequentialTableReader< BasicHolder< bool > > SequentialBoolReader
 
typedef RandomAccessTableReader< BasicHolder< bool > > RandomAccessBoolReader
 
typedef TableWriter< TokenHolderTokenWriter
 TokenWriter is a writer specialized for std::string where the strings are nonempty and whitespace-free. More...
 
typedef SequentialTableReader< TokenHolderSequentialTokenReader
 
typedef RandomAccessTableReader< TokenHolderRandomAccessTokenReader
 
typedef TableWriter< TokenVectorHolderTokenVectorWriter
 TokenVectorWriter is a writer specialized for sequences of std::string where the strings are nonempty and whitespace-free. More...
 
typedef SequentialTableReader< TokenVectorHolderSequentialTokenVectorReader
 
typedef RandomAccessTableReader< TokenVectorHolderRandomAccessTokenVectorReader
 
typedef TableWriter< KaldiObjectHolder< GeneralMatrix > > GeneralMatrixWriter
 
typedef SequentialTableReader< KaldiObjectHolder< GeneralMatrix > > SequentialGeneralMatrixReader
 
typedef RandomAccessTableReader< KaldiObjectHolder< GeneralMatrix > > RandomAccessGeneralMatrixReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< GeneralMatrix > > RandomAccessGeneralMatrixReaderMapped
 
typedef OfflineFeatureTpl< FbankComputerFbank
 
typedef OfflineFeatureTpl< MfccComputerMfcc
 
typedef OfflineFeatureTpl< PlpComputerPlp
 
typedef OfflineFeatureTpl< SpectrogramComputerSpectrogram
 
typedef OnlineGenericBaseFeature< MfccComputerOnlineMfcc
 
typedef OnlineGenericBaseFeature< PlpComputerOnlinePlp
 
typedef OnlineGenericBaseFeature< FbankComputerOnlineFbank
 
typedef std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
 
typedef uint16 uint_smaller
 
typedef int16 int_smaller
 
typedef int32 EventKeyType
 Things of type EventKeyType can take any value. More...
 
typedef int32 EventValueType
 Given current code, things of type EventValueType should generally be nonnegative and in a reasonably small range (e.g. More...
 
typedef int32 EventAnswerType
 As far as the event-map code itself is concerned, things of type EventAnswerType may take any value except kNoAnswer (== -1). More...
 
typedef std::vector< std::pair< EventKeyType, EventValueType > > EventType
 
typedef TableWriter< KaldiObjectHolder< AmDiagGmm > > MapAmDiagGmmWriter
 
typedef RandomAccessTableReader< KaldiObjectHolder< AmDiagGmm > > RandomAccessMapAmDiagGmmReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< AmDiagGmm > > RandomAccessMapAmDiagGmmReaderMapped
 
typedef SequentialTableReader< KaldiObjectHolder< AmDiagGmm > > MapAmDiagGmmSeqReader
 
typedef uint16 GmmFlagsType
 Bitwise OR of the above flags. More...
 
typedef uint16 SgmmUpdateFlagsType
 Bitwise OR of the above flags. More...
 
typedef uint16 SgmmWriteFlagsType
 Bitwise OR of the above flags. More...
 
typedef TableWriter< KaldiObjectHolder< RegtreeFmllrDiagGmm > > RegtreeFmllrDiagGmmWriter
 
typedef RandomAccessTableReader< KaldiObjectHolder< RegtreeFmllrDiagGmm > > RandomAccessRegtreeFmllrDiagGmmReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< RegtreeFmllrDiagGmm > > RandomAccessRegtreeFmllrDiagGmmReaderMapped
 
typedef SequentialTableReader< KaldiObjectHolder< RegtreeFmllrDiagGmm > > RegtreeFmllrDiagGmmSeqReader
 
typedef TableWriter< KaldiObjectHolder< RegtreeMllrDiagGmm > > RegtreeMllrDiagGmmWriter
 
typedef RandomAccessTableReader< KaldiObjectHolder< RegtreeMllrDiagGmm > > RandomAccessRegtreeMllrDiagGmmReader
 
typedef RandomAccessTableReaderMapped< KaldiObjectHolder< RegtreeMllrDiagGmm > > RandomAccessRegtreeMllrDiagGmmReaderMapped
 
typedef SequentialTableReader< KaldiObjectHolder< RegtreeMllrDiagGmm > > RegtreeMllrDiagGmmSeqReader
 
typedef unordered_map< std::pair< int32, std::vector< int32 > >, fst::VectorFst< fst::StdArc > *, HmmCacheHashHmmCacheType
 HmmCacheType is a map from (central-phone, sequence of pdf-ids) to FST, used as cache in GetHmmAsFsa, as an optimization. More...
 
typedef std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
 Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an utterance. More...
 
typedef std::vector< std::vector< std::pair< int32, Vector< BaseFloat > > > > GaussPost
 GaussPost is a typedef for storing Gaussian-level posteriors for an utterance. More...
 
typedef TableWriter< PosteriorHolderPosteriorWriter
 
typedef SequentialTableReader< PosteriorHolderSequentialPosteriorReader
 
typedef RandomAccessTableReader< PosteriorHolderRandomAccessPosteriorReader
 
typedef TableWriter< GaussPostHolderGaussPostWriter
 
typedef SequentialTableReader< GaussPostHolderSequentialGaussPostReader
 
typedef RandomAccessTableReader< GaussPostHolderRandomAccessGaussPostReader
 
typedef LatticeFasterDecoderConfig LatticeBiglmFasterDecoderConfig
 
typedef LatticeFasterDecoderTpl< fst::StdFst, decoder::StdTokenLatticeFasterDecoder
 
typedef LatticeFasterOnlineDecoderTpl< fst::StdFst > LatticeFasterOnlineDecoder
 
typedef LatticeIncrementalDecoderTpl< fst::StdFst, decoder::StdTokenLatticeIncrementalDecoder
 
typedef LatticeIncrementalOnlineDecoderTpl< fst::StdFst > LatticeIncrementalOnlineDecoder
 
typedef fst::LatticeWeightTpl< BaseFloatLatticeWeight
 
typedef fst::CompactLatticeWeightTpl< LatticeWeight, int32CompactLatticeWeight
 
typedef fst::CompactLatticeWeightCommonDivisorTpl< LatticeWeight, int32CompactLatticeWeightCommonDivisor
 
typedef fst::ArcTpl< LatticeWeightLatticeArc
 
typedef fst::ArcTpl< CompactLatticeWeightCompactLatticeArc
 
typedef fst::VectorFst< LatticeArcLattice
 
typedef fst::VectorFst< CompactLatticeArcCompactLattice
 
typedef TableWriter< LatticeHolderLatticeWriter
 
typedef SequentialTableReader< LatticeHolderSequentialLatticeReader
 
typedef RandomAccessTableReader< LatticeHolderRandomAccessLatticeReader
 
typedef TableWriter< CompactLatticeHolderCompactLatticeWriter
 
typedef SequentialTableReader< CompactLatticeHolderSequentialCompactLatticeReader
 
typedef RandomAccessTableReader< CompactLatticeHolderRandomAccessCompactLatticeReader
 
typedef Lattice::StateId StateId
 
typedef Lattice::Arc Arc
 
typedef fst::StdArc::Label Label
 
typedef std::vector< std::pair< Label, Label > > LabelPairVector
 
typedef KaldiObjectHolder< Sgmm2GauPostSgmm2GauPostHolder
 
typedef RandomAccessTableReader< Sgmm2GauPostHolderRandomAccessSgmm2GauPostReader
 
typedef SequentialTableReader< Sgmm2GauPostHolderSequentialSgmm2GauPostReader
 
typedef TableWriter< Sgmm2GauPostHolderSgmm2GauPostWriter
 
typedef fst::LexicographicWeight< TropicalWeight, TropicalWeight > StdLStdWeight
 
typedef fst::LexicographicWeight< TropicalWeight, StdLStdWeightStdLStdLStdWeight
 
typedef fst::ArcTpl< StdLStdLStdWeightStdLStdLStdArc
 
typedef fst::ProductWeight< TropicalWeight, ArcticWeightStdXStdprimeWeight
 
typedef fst::ProductWeight< LogWeight, StdXStdprimeWeightLogXStdXStdprimeWeight
 
typedef fst::ArcTpl< LogXStdXStdprimeWeightLogXStdXStdprimeArc
 
typedef StdLStdLStdWeight KwsLexicographicWeight
 
typedef StdLStdLStdArc KwsLexicographicArc
 
typedef fst::VectorFst< KwsLexicographicArcKwsLexicographicFst
 
typedef LogXStdXStdprimeWeight KwsProductWeight
 
typedef LogXStdXStdprimeArc KwsProductArc
 
typedef fst::VectorFst< KwsProductArcKwsProductFst
 
typedef Arc::Weight Weight
 
typedef kaldi::int32 int32
 
typedef SingleUtteranceNnet3DecoderTpl< fst::Fst< fst::StdArc > > SingleUtteranceNnet3Decoder
 
typedef SingleUtteranceNnet3IncrementalDecoderTpl< fst::Fst< fst::StdArc > > SingleUtteranceNnet3IncrementalDecoder
 

Enumerations

enum  CompressionMethod {
  kAutomaticMethod = 1, kSpeechFeature = 2, kTwoByteAuto = 3, kTwoByteSignedInteger = 4,
  kOneByteAuto = 5, kOneByteUnsignedInteger = 6, kOneByteZeroOne = 7
}
 
enum  MatrixTransposeType { kTrans = 112, kNoTrans = 111 }
 
enum  MatrixResizeType { kSetZero, kUndefined, kCopyData }
 
enum  MatrixStrideType { kDefaultStride, kStrideEqualNumCols }
 
enum  SpCopyType { kTakeLower, kTakeUpper, kTakeMean, kTakeMeanAndCheck }
 
enum  GeneralMatrixType { kFullMatrix, kCompressedMatrix, kSparseMatrix }
 
enum  OutputType { kNoOutput, kFileOutput, kStandardOutput, kPipeOutput }
 
enum  InputType {
  kNoInput, kFileInput, kStandardInput, kOffsetFileInput,
  kPipeInput
}
 
enum  WspecifierType { kNoWspecifier, kArchiveWspecifier, kScriptWspecifier, kBothWspecifier }
 
enum  RspecifierType { kNoRspecifier, kArchiveRspecifier, kScriptRspecifier }
 
enum  ShellType { kBash = 0 }
 
enum  AllKeysType { kAllKeysInsistIdentical, kAllKeysIntersection, kAllKeysUnion }
 Typedef used when we get "all keys" from a set of stats– used in specifying which kinds of questions to ask. More...
 
enum  GmmUpdateFlags {
  kGmmMeans = 0x001, kGmmVariances = 0x002, kGmmWeights = 0x004, kGmmTransitions = 0x008,
  kGmmAll = 0x00F
}
 
enum  SgmmUpdateFlags {
  kSgmmPhoneVectors = 0x001, kSgmmPhoneProjections = 0x002, kSgmmPhoneWeightProjections = 0x004, kSgmmCovarianceMatrix = 0x008,
  kSgmmSubstateWeights = 0x010, kSgmmSpeakerProjections = 0x020, kSgmmTransitions = 0x040, kSgmmSpeakerWeightProjections = 0x080,
  kSgmmAll = 0x0FF
}
 
enum  SgmmWriteFlags {
  kSgmmGlobalParams = 0x001, kSgmmStateParams = 0x002, kSgmmNormalizers = 0x004, kSgmmBackgroundGmms = 0x008,
  kSgmmWriteAll = 0x00F
}
 
enum  cova_type { full, diag }
 Generate features for a certain covariance type covariance_type == 0: full covariance covariance_type == 1: diagonal covariance. More...
 
enum  { kEps = 0, kDisambig, kBos, kEos }
 
enum  CuCompressedMatrixType { kCompressedMatrixInt8 = 1, kCompressedMatrixUint8 = 2, kCompressedMatrixInt16 = 3, kCompressedMatrixUint16 = 4 }
 
enum  DetectionDecision {
  kKwsFalseAlarm, kKwsMiss, kKwsCorr, kKwsCorrUndetected,
  kKwsUnseen
}
 

Functions

template<class T >
void WriteBasicType (std::ostream &os, bool binary, T t)
 WriteBasicType is the name of the write function for bool, integer types, and floating-point types. More...
 
template<class T >
void ReadBasicType (std::istream &is, bool binary, T *t)
 ReadBasicType is the name of the read function for bool, integer types, and floating-point types. More...
 
template<class T >
void WriteIntegerPairVector (std::ostream &os, bool binary, const std::vector< std::pair< T, T > > &v)
 Function for writing STL vectors of pairs of integer types. More...
 
template<class T >
void ReadIntegerPairVector (std::istream &is, bool binary, std::vector< std::pair< T, T > > *v)
 Function for reading STL vector of pairs of integer types. More...
 
template<class T >
void WriteIntegerVector (std::ostream &os, bool binary, const std::vector< T > &v)
 Function for writing STL vectors of integer types. More...
 
template<class T >
void ReadIntegerVector (std::istream &is, bool binary, std::vector< T > *v)
 Function for reading STL vector of integer types. More...
 
void InitKaldiOutputStream (std::ostream &os, bool binary)
 InitKaldiOutputStream initializes an opened stream for writing by writing an optional binary header and modifying the floating-point precision; it will typically not be called by users directly. More...
 
bool InitKaldiInputStream (std::istream &is, bool *binary)
 Initialize an opened stream for reading by detecting the binary header and. More...
 
void UnitTestIo (bool binary)
 
template<>
void WriteBasicType< bool > (std::ostream &os, bool binary, bool b)
 
template<>
void ReadBasicType< bool > (std::istream &is, bool binary, bool *b)
 
template<>
void WriteBasicType< float > (std::ostream &os, bool binary, float f)
 
template<>
void WriteBasicType< double > (std::ostream &os, bool binary, double f)
 
template<>
void ReadBasicType< float > (std::istream &is, bool binary, float *f)
 
template<>
void ReadBasicType< double > (std::istream &is, bool binary, double *d)
 
void CheckToken (const char *token)
 
void WriteToken (std::ostream &os, bool binary, const char *token)
 The WriteToken functions are for writing nonempty sequences of non-space characters. More...
 
int Peek (std::istream &is, bool binary)
 Peek consumes whitespace (if binary == false) and then returns the peek() value of the stream. More...
 
void WriteToken (std::ostream &os, bool binary, const std::string &token)
 
void ReadToken (std::istream &is, bool binary, std::string *token)
 ReadToken gets the next token and puts it in str (exception on failure). More...
 
int PeekToken (std::istream &is, bool binary)
 PeekToken will return the first character of the next token, or -1 if end of file. More...
 
void ExpectToken (std::istream &is, bool binary, const char *token)
 ExpectToken tries to read in the given token, and throws an exception on failure. More...
 
void ExpectToken (std::istream &is, bool binary, const std::string &token)
 
template<class T >
void ReadBasicType (std::istream &is, bool binary, T *t, bool add)
 
void ExpectPretty (std::istream &is, bool binary, const char *token)
 ExpectPretty attempts to read the text in "token", but only in non-binary mode. More...
 
void ExpectPretty (std::istream &is, bool binary, const std::string &token)
 
void MyFunction2 ()
 
void MyFunction1 ()
 
void UnitTestError ()
 
void VerifySymbolRange (const std::string &trace, const bool want_found, const std::string &want_symbol)
 
void TestLocateSymbolRange ()
 
void SetProgramName (const char *basename)
 Called by ParseOptions to set base name (no directory) of the executing program. More...
 
static const char * GetShortFileName (const char *path)
 
static std::string KaldiGetStackTrace ()
 
void KaldiAssertFailure_ (const char *func, const char *file, int32 line, const char *cond_str)
 
LogHandler SetLogHandler (LogHandler)
 Set logging handler. More...
 
int32 GetVerboseLevel ()
 Get verbosity level, usually set via command line '–verbose=' switch. More...
 
void SetVerboseLevel (int32 i)
 This should be rarely used, except by programs using Kaldi as library; command-line programs set the verbose level automatically from ParseOptions. More...
 
template<class I >
void UnitTestGcdLcmTpl ()
 
void UnitTestRoundUpToNearestPowerOfTwo ()
 
void UnitTestDivideRoundingDown ()
 
void UnitTestGcdLcm ()
 
void UnitTestRand ()
 
void UnitTestLogAddSub ()
 
void UnitTestDefines ()
 
void UnitTestAssertFunc ()
 
template<class I >
void UnitTestFactorizeTpl ()
 
void UnitTestFactorize ()
 
void UnitTestApproxEqual ()
 
template<class Real >
void UnitTestExpSpeed ()
 
template<class Real >
void UnitTestLogSpeed ()
 
int32 RoundUpToNearestPowerOfTwo (int32 n)
 
int Rand (struct RandomState *state)
 
bool WithProb (BaseFloat prob, struct RandomState *state)
 
int32 RandInt (int32 min_val, int32 max_val, struct RandomState *state)
 
int32 RandPoisson (float lambda, struct RandomState *state)
 
void RandGauss2 (float *a, float *b, RandomState *state)
 
void RandGauss2 (double *a, double *b, RandomState *state)
 
double Exp (double x)
 
float Exp (float x)
 
double Log (double x)
 
float Log (float x)
 
double Log1p (double x)
 
float Log1p (float x)
 
float RandUniform (struct RandomState *state=NULL)
 Returns a random number strictly between 0 and 1. More...
 
float RandGauss (struct RandomState *state=NULL)
 
template<class Float >
Float RandPrune (Float post, BaseFloat prune_thresh, struct RandomState *state=NULL)
 
double LogAdd (double x, double y)
 
float LogAdd (float x, float y)
 
double LogSub (double x, double y)
 
float LogSub (float x, float y)
 
static bool ApproxEqual (float a, float b, float relative_tolerance=0.001)
 return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)). More...
 
static void AssertEqual (float a, float b, float relative_tolerance=0.001)
 assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b)) More...
 
static int32 DivideRoundingDown (int32 a, int32 b)
 Returns a / b, rounding towards negative infinity in all cases. More...
 
template<class I >
Gcd (I m, I n)
 
template<class I >
Lcm (I m, I n)
 Returns the least common multiple of two integers. More...
 
template<class I >
void Factorize (I m, std::vector< I > *factors)
 
double Hypot (double x, double y)
 
float Hypot (float x, float y)
 
std::string CharToString (const char &c)
 
void Sleep (float seconds)
 
int MachineIsLittleEndian ()
 
void TimerTest ()
 
void cblas_Xcopy (const int N, const float *X, const int incX, float *Y, const int incY)
 
void cblas_Xcopy (const int N, const double *X, const int incX, double *Y, const int incY)
 
float cblas_Xasum (const int N, const float *X, const int incX)
 
double cblas_Xasum (const int N, const double *X, const int incX)
 
void cblas_Xrot (const int N, float *X, const int incX, float *Y, const int incY, const float c, const float s)
 
void cblas_Xrot (const int N, double *X, const int incX, double *Y, const int incY, const double c, const double s)
 
float cblas_Xdot (const int N, const float *const X, const int incX, const float *const Y, const int incY)
 
double cblas_Xdot (const int N, const double *const X, const int incX, const double *const Y, const int incY)
 
void cblas_Xaxpy (const int N, const float alpha, const float *X, const int incX, float *Y, const int incY)
 
void cblas_Xaxpy (const int N, const double alpha, const double *X, const int incX, double *Y, const int incY)
 
void cblas_Xscal (const int N, const float alpha, float *data, const int inc)
 
void cblas_Xscal (const int N, const double alpha, double *data, const int inc)
 
void cblas_Xspmv (const float alpha, const int num_rows, const float *Mdata, const float *v, const int v_inc, const float beta, float *y, const int y_inc)
 
void cblas_Xspmv (const double alpha, const int num_rows, const double *Mdata, const double *v, const int v_inc, const double beta, double *y, const int y_inc)
 
void cblas_Xtpmv (MatrixTransposeType trans, const float *Mdata, const int num_rows, float *y, const int y_inc)
 
void cblas_Xtpmv (MatrixTransposeType trans, const double *Mdata, const int num_rows, double *y, const int y_inc)
 
void cblas_Xtpsv (MatrixTransposeType trans, const float *Mdata, const int num_rows, float *y, const int y_inc)
 
void cblas_Xtpsv (MatrixTransposeType trans, const double *Mdata, const int num_rows, double *y, const int y_inc)
 
void cblas_Xspmv (MatrixIndexT dim, float alpha, const float *Mdata, const float *ydata, MatrixIndexT ystride, float beta, float *xdata, MatrixIndexT xstride)
 
void cblas_Xspmv (MatrixIndexT dim, double alpha, const double *Mdata, const double *ydata, MatrixIndexT ystride, double beta, double *xdata, MatrixIndexT xstride)
 
void cblas_Xspr2 (MatrixIndexT dim, float alpha, const float *Xdata, MatrixIndexT incX, const float *Ydata, MatrixIndexT incY, float *Adata)
 
void cblas_Xspr2 (MatrixIndexT dim, double alpha, const double *Xdata, MatrixIndexT incX, const double *Ydata, MatrixIndexT incY, double *Adata)
 
void cblas_Xspr (MatrixIndexT dim, float alpha, const float *Xdata, MatrixIndexT incX, float *Adata)
 
void cblas_Xspr (MatrixIndexT dim, double alpha, const double *Xdata, MatrixIndexT incX, double *Adata)
 
void cblas_Xgemv (MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, float alpha, const float *Mdata, MatrixIndexT stride, const float *xdata, MatrixIndexT incX, float beta, float *ydata, MatrixIndexT incY)
 
void cblas_Xgemv (MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, double alpha, const double *Mdata, MatrixIndexT stride, const double *xdata, MatrixIndexT incX, double beta, double *ydata, MatrixIndexT incY)
 
void cblas_Xgbmv (MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT num_below, MatrixIndexT num_above, float alpha, const float *Mdata, MatrixIndexT stride, const float *xdata, MatrixIndexT incX, float beta, float *ydata, MatrixIndexT incY)
 
void cblas_Xgbmv (MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT num_below, MatrixIndexT num_above, double alpha, const double *Mdata, MatrixIndexT stride, const double *xdata, MatrixIndexT incX, double beta, double *ydata, MatrixIndexT incY)
 
template<typename Real >
void Xgemv_sparsevec (MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, Real alpha, const Real *Mdata, MatrixIndexT stride, const Real *xdata, MatrixIndexT incX, Real beta, Real *ydata, MatrixIndexT incY)
 
void cblas_Xgemm (const float alpha, MatrixTransposeType transA, const float *Adata, MatrixIndexT a_num_rows, MatrixIndexT a_num_cols, MatrixIndexT a_stride, MatrixTransposeType transB, const float *Bdata, MatrixIndexT b_stride, const float beta, float *Mdata, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT stride)
 
void cblas_Xgemm (const double alpha, MatrixTransposeType transA, const double *Adata, MatrixIndexT a_num_rows, MatrixIndexT a_num_cols, MatrixIndexT a_stride, MatrixTransposeType transB, const double *Bdata, MatrixIndexT b_stride, const double beta, double *Mdata, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT stride)
 
void cblas_Xsymm (const float alpha, MatrixIndexT sz, const float *Adata, MatrixIndexT a_stride, const float *Bdata, MatrixIndexT b_stride, const float beta, float *Mdata, MatrixIndexT stride)
 
void cblas_Xsymm (const double alpha, MatrixIndexT sz, const double *Adata, MatrixIndexT a_stride, const double *Bdata, MatrixIndexT b_stride, const double beta, double *Mdata, MatrixIndexT stride)
 
void cblas_Xger (MatrixIndexT num_rows, MatrixIndexT num_cols, float alpha, const float *xdata, MatrixIndexT incX, const float *ydata, MatrixIndexT incY, float *Mdata, MatrixIndexT stride)
 
void cblas_Xger (MatrixIndexT num_rows, MatrixIndexT num_cols, double alpha, const double *xdata, MatrixIndexT incX, const double *ydata, MatrixIndexT incY, double *Mdata, MatrixIndexT stride)
 
void cblas_Xsyrk (const MatrixTransposeType trans, const MatrixIndexT dim_c, const MatrixIndexT other_dim_a, const float alpha, const float *A, const MatrixIndexT a_stride, const float beta, float *C, const MatrixIndexT c_stride)
 
void cblas_Xsyrk (const MatrixTransposeType trans, const MatrixIndexT dim_c, const MatrixIndexT other_dim_a, const double alpha, const double *A, const MatrixIndexT a_stride, const double beta, double *C, const MatrixIndexT c_stride)
 
void cblas_Xsbmv1 (const MatrixIndexT dim, const double *A, const double alpha, const double *x, const double beta, double *y)
 matrix-vector multiply using a banded matrix; we always call this with b = 1 meaning we're multiplying by a diagonal matrix. More...
 
void cblas_Xsbmv1 (const MatrixIndexT dim, const float *A, const float alpha, const float *x, const float beta, float *y)
 
void mul_elements (const MatrixIndexT dim, const double *a, double *b)
 This is not really a wrapper for CBLAS as CBLAS does not have this; in future we could extend this somehow. More...
 
void mul_elements (const MatrixIndexT dim, const float *a, float *b)
 
void clapack_Xtptri (KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *result)
 
void clapack_Xtptri (KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *result)
 
void clapack_Xgetrf2 (KaldiBlasInt *num_rows, KaldiBlasInt *num_cols, float *Mdata, KaldiBlasInt *stride, KaldiBlasInt *pivot, KaldiBlasInt *result)
 
void clapack_Xgetrf2 (KaldiBlasInt *num_rows, KaldiBlasInt *num_cols, double *Mdata, KaldiBlasInt *stride, KaldiBlasInt *pivot, KaldiBlasInt *result)
 
void clapack_Xgetri2 (KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *stride, KaldiBlasInt *pivot, float *p_work, KaldiBlasInt *l_work, KaldiBlasInt *result)
 
void clapack_Xgetri2 (KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *stride, KaldiBlasInt *pivot, double *p_work, KaldiBlasInt *l_work, KaldiBlasInt *result)
 
void clapack_Xgesvd (char *v, char *u, KaldiBlasInt *num_cols, KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *stride, float *sv, float *Vdata, KaldiBlasInt *vstride, float *Udata, KaldiBlasInt *ustride, float *p_work, KaldiBlasInt *l_work, KaldiBlasInt *result)
 
void clapack_Xgesvd (char *v, char *u, KaldiBlasInt *num_cols, KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *stride, double *sv, double *Vdata, KaldiBlasInt *vstride, double *Udata, KaldiBlasInt *ustride, double *p_work, KaldiBlasInt *l_work, KaldiBlasInt *result)
 
void clapack_Xsptri (KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *ipiv, float *work, KaldiBlasInt *result)
 
void clapack_Xsptri (KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *ipiv, double *work, KaldiBlasInt *result)
 
void clapack_Xsptrf (KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *ipiv, KaldiBlasInt *result)
 
void clapack_Xsptrf (KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *ipiv, KaldiBlasInt *result)
 
template<typename Real >
std::ostream & operator<< (std::ostream &os, const MatrixBase< Real > &M)
 
template<typename Real >
std::istream & operator>> (std::istream &is, Matrix< Real > &M)
 
template<typename Real >
std::istream & operator>> (std::istream &is, MatrixBase< Real > &M)
 
template<typename Real >
bool ReadHtk (std::istream &is, Matrix< Real > *M_ptr, HtkHeader *header_ptr)
 Extension of the HTK header. More...
 
template bool ReadHtk (std::istream &is, Matrix< float > *M, HtkHeader *header_ptr)
 
template bool ReadHtk (std::istream &is, Matrix< double > *M, HtkHeader *header_ptr)
 
template<typename Real >
bool WriteHtk (std::ostream &os, const MatrixBase< Real > &M, HtkHeader htk_hdr)
 
template bool WriteHtk (std::ostream &os, const MatrixBase< float > &M, HtkHeader htk_hdr)
 
template bool WriteHtk (std::ostream &os, const MatrixBase< double > &M, HtkHeader htk_hdr)
 
template<class Real >
bool WriteSphinx (std::ostream &os, const MatrixBase< Real > &M)
 
template bool WriteSphinx (std::ostream &os, const MatrixBase< float > &M)
 
template bool WriteSphinx (std::ostream &os, const MatrixBase< double > &M)
 
template<typename Real >
Real TraceMatMatMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const MatrixBase< Real > &C, MatrixTransposeType transC)
 Returns tr(A B C) More...
 
template float TraceMatMatMat (const MatrixBase< float > &A, MatrixTransposeType transA, const MatrixBase< float > &B, MatrixTransposeType transB, const MatrixBase< float > &C, MatrixTransposeType transC)
 
template double TraceMatMatMat (const MatrixBase< double > &A, MatrixTransposeType transA, const MatrixBase< double > &B, MatrixTransposeType transB, const MatrixBase< double > &C, MatrixTransposeType transC)
 
template<typename Real >
Real TraceMatMatMatMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const MatrixBase< Real > &C, MatrixTransposeType transC, const MatrixBase< Real > &D, MatrixTransposeType transD)
 Returns tr(A B C D) More...
 
template float TraceMatMatMatMat (const MatrixBase< float > &A, MatrixTransposeType transA, const MatrixBase< float > &B, MatrixTransposeType transB, const MatrixBase< float > &C, MatrixTransposeType transC, const MatrixBase< float > &D, MatrixTransposeType transD)
 
template double TraceMatMatMatMat (const MatrixBase< double > &A, MatrixTransposeType transA, const MatrixBase< double > &B, MatrixTransposeType transB, const MatrixBase< double > &C, MatrixTransposeType transC, const MatrixBase< double > &D, MatrixTransposeType transD)
 
template<typename Real >
void SortSvd (VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt=NULL, bool sort_on_absolute_value=true)
 Function to ensure that SVD is sorted. More...
 
template void SortSvd (VectorBase< float > *s, MatrixBase< float > *U, MatrixBase< float > *Vt, bool)
 
template void SortSvd (VectorBase< double > *s, MatrixBase< double > *U, MatrixBase< double > *Vt, bool)
 
template<typename Real >
void CreateEigenvalueMatrix (const VectorBase< Real > &real, const VectorBase< Real > &imag, MatrixBase< Real > *D)
 Creates the eigenvalue matrix D that is part of the decomposition used Matrix::Eig. More...
 
template void CreateEigenvalueMatrix (const VectorBase< float > &re, const VectorBase< float > &im, MatrixBase< float > *D)
 
template void CreateEigenvalueMatrix (const VectorBase< double > &re, const VectorBase< double > &im, MatrixBase< double > *D)
 
template<typename Real >
bool AttemptComplexPower (Real *x_re, Real *x_im, Real power)
 The following function is used in Matrix::Power, and separately tested, so we declare it here mainly for the testing code to see. More...
 
template bool AttemptComplexPower (float *x_re, float *x_im, float power)
 
template bool AttemptComplexPower (double *x_re, double *x_im, double power)
 
template float TraceMatMat (const MatrixBase< float > &A, const MatrixBase< float > &B, MatrixTransposeType trans)
 
template double TraceMatMat (const MatrixBase< double > &A, const MatrixBase< double > &B, MatrixTransposeType trans)
 
template<typename Real >
bool ApproxEqual (const MatrixBase< Real > &A, const MatrixBase< Real > &B, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const MatrixBase< Real > &A, const MatrixBase< Real > &B, float tol=0.01)
 
template<typename Real >
double TraceMat (const MatrixBase< Real > &A)
 Returns trace of matrix. More...
 
template<typename Real >
bool SameDim (const MatrixBase< Real > &M, const MatrixBase< Real > &N)
 
template<typename Real >
std::ostream & operator<< (std::ostream &os, const VectorBase< Real > &rv)
 
template<typename Real >
std::istream & operator>> (std::istream &in, VectorBase< Real > &v)
 Input from a C++ stream. More...
 
template<typename Real >
std::istream & operator>> (std::istream &in, Vector< Real > &v)
 Input from a C++ stream. More...
 
template<typename Real >
Real VecVec (const VectorBase< Real > &v1, const VectorBase< Real > &v2)
 Returns dot product between v1 and v2. More...
 
template float VecVec (const VectorBase< float > &a, const VectorBase< float > &b)
 
template double VecVec (const VectorBase< double > &a, const VectorBase< double > &b)
 
template<typename Real , typename OtherReal >
Real VecVec (const VectorBase< Real > &ra, const VectorBase< OtherReal > &rb)
 
template float VecVec (const VectorBase< float > &ra, const VectorBase< double > &rb)
 
template double VecVec (const VectorBase< double > &ra, const VectorBase< float > &rb)
 
template<typename Real >
Real VecMatVec (const VectorBase< Real > &v1, const MatrixBase< Real > &M, const VectorBase< Real > &v2)
 Returns $ v_1^T M v_2 $ . More...
 
template float VecMatVec (const VectorBase< float > &v1, const MatrixBase< float > &M, const VectorBase< float > &v2)
 
template double VecMatVec (const VectorBase< double > &v1, const MatrixBase< double > &M, const VectorBase< double > &v2)
 
template<typename Real >
bool ApproxEqual (const VectorBase< Real > &a, const VectorBase< Real > &b, Real tol=0.01)
 
template<typename Real >
void AssertEqual (VectorBase< Real > &a, VectorBase< Real > &b, float tol=0.01)
 
template<typename Real >
void ComplexMul (const Real &a_re, const Real &a_im, Real *b_re, Real *b_im)
 ComplexMul implements, inline, the complex multiplication b *= a. More...
 
template<typename Real >
void ComplexAddProduct (const Real &a_re, const Real &a_im, const Real &b_re, const Real &b_im, Real *c_re, Real *c_im)
 ComplexMul implements, inline, the complex operation c += (a * b). More...
 
template<typename Real >
void ComplexImExp (Real x, Real *a_re, Real *a_im)
 ComplexImExp implements a <– exp(i x), inline. More...
 
template<typename Real >
void ComplexFt (const VectorBase< Real > &in, VectorBase< Real > *out, bool forward)
 ComplexFt is the same as ComplexFft but it implements the Fourier transform in an inefficient way. More...
 
template void ComplexFt (const VectorBase< float > &in, VectorBase< float > *out, bool forward)
 
template void ComplexFt (const VectorBase< double > &in, VectorBase< double > *out, bool forward)
 
template<typename Real >
void ComplexFftRecursive (Real *data, int nffts, int N, const int *factor_begin, const int *factor_end, bool forward, Vector< Real > *tmp_vec)
 ComplexFftRecursive is a recursive function that computes the complex FFT of size N. More...
 
template<typename Real >
void ComplexFft (VectorBase< Real > *v, bool forward, Vector< Real > *tmp_work=NULL)
 The function ComplexFft does an Fft on the vector argument v. More...
 
template<typename Real >
void RealFftInefficient (VectorBase< Real > *v, bool forward)
 Inefficient version of Fourier transform, for testing purposes. More...
 
template void RealFftInefficient (VectorBase< float > *v, bool forward)
 
template void RealFftInefficient (VectorBase< double > *v, bool forward)
 
template void ComplexFft (VectorBase< float > *v, bool forward, Vector< float > *tmp_in)
 
template void ComplexFft (VectorBase< double > *v, bool forward, Vector< double > *tmp_in)
 
template<typename Real >
void RealFft (VectorBase< Real > *v, bool forward)
 RealFft is a fourier transform of real inputs. More...
 
template void RealFft (VectorBase< float > *v, bool forward)
 
template void RealFft (VectorBase< double > *v, bool forward)
 
template<typename Real >
void ComputeDctMatrix (Matrix< Real > *M)
 ComputeDctMatrix computes a matrix corresponding to the DCT, such that M * v equals the DCT of vector v. More...
 
template void ComputeDctMatrix (Matrix< float > *M)
 
template void ComputeDctMatrix (Matrix< double > *M)
 
template<typename Real >
void ComputePca (const MatrixBase< Real > &X, MatrixBase< Real > *U, MatrixBase< Real > *A, bool print_eigs=false, bool exact=true)
 ComputePCA does a PCA computation, using either outer products or inner products, whichever is more efficient. More...
 
template void ComputePca (const MatrixBase< float > &X, MatrixBase< float > *U, MatrixBase< float > *A, bool print_eigs, bool exact)
 
template void ComputePca (const MatrixBase< double > &X, MatrixBase< double > *U, MatrixBase< double > *A, bool print_eigs, bool exact)
 
template<typename Real >
void AddOuterProductPlusMinus (Real alpha, const VectorBase< Real > &a, const VectorBase< Real > &b, MatrixBase< Real > *plus, MatrixBase< Real > *minus)
 
template void AddOuterProductPlusMinus< float > (float alpha, const VectorBase< float > &a, const VectorBase< float > &b, MatrixBase< float > *plus, MatrixBase< float > *minus)
 
template void AddOuterProductPlusMinus< double > (double alpha, const VectorBase< double > &a, const VectorBase< double > &b, MatrixBase< double > *plus, MatrixBase< double > *minus)
 
template<typename Real1 , typename Real2 >
void AssertSameDim (const MatrixBase< Real1 > &mat1, const MatrixBase< Real2 > &mat2)
 
template<typename Real >
std::string NameOf ()
 
template<typename Real >
static void CsvResult (std::string test, int dim, BaseFloat measure, std::string units)
 
template<typename Real >
static void UnitTestRealFftSpeed ()
 
template<typename Real >
static void UnitTestSplitRadixRealFftSpeed ()
 
template<typename Real >
static void UnitTestSvdSpeed ()
 
template<typename Real >
static void UnitTestAddMatMatSpeed ()
 
template<typename Real >
static void UnitTestAddRowSumMatSpeed ()
 
template<typename Real >
static void UnitTestAddColSumMatSpeed ()
 
template<typename Real >
static void UnitTestAddVecToRowsSpeed ()
 
template<typename Real >
static void UnitTestAddVecToColsSpeed ()
 
template<typename Real >
static void MatrixUnitSpeedTest ()
 
template<typename Real >
void RandPosdefSpMatrix (MatrixIndexT dim, SpMatrix< Real > *matrix)
 
template<typename Real >
static void InitRandNonsingular (MatrixBase< Real > *M)
 
template<typename Real >
static void InitRandNonsingular (SpMatrix< Real > *M)
 
template<typename Real >
static void CholeskyUnitTestTr ()
 
template<typename Real >
static void SlowMatMul ()
 
template<typename Real >
static void UnitTestAddToDiagMatrix ()
 
template<typename Real >
static void UnitTestAddDiagVecMat ()
 
template<typename Real >
static void UnitTestAddMatDiagVec ()
 
template<typename Real >
static void UnitTestAddMatMatElements ()
 
template<typename Real >
static void UnitTestAddSp ()
 
template<typename Real , typename OtherReal >
static void UnitTestSpAddDiagVec ()
 
template<typename Real >
static void UnitTestSpAddVecVec ()
 
template<typename Real >
static void UnitTestCopyRowsAndCols ()
 
template<typename Real >
static void UnitTestSpliceRows ()
 
template<typename Real >
static void UnitTestRemoveRow ()
 
template<typename Real >
static void UnitTestSubvector ()
 
static int32 DoubleFactorial (int32 i)
 
template<typename Real >
static void UnitTestSetRandn ()
 
template<typename Real >
static void UnitTestSetRandUniform ()
 
template<typename Real >
static void UnitTestSimpleForVec ()
 
template<typename Real >
static void UnitTestVectorMax ()
 
template<typename Real >
static void UnitTestVectorMin ()
 
template<typename Real >
static void UnitTestReplaceValue ()
 
template<typename Real >
static void UnitTestNorm ()
 
template<typename Real >
static void UnitTestCopyRows ()
 
template<typename Real >
static void UnitTestCopyToRows ()
 
template<typename Real >
static void UnitTestAddRows ()
 
template<typename Real >
static void UnitTestAddToRows ()
 
template<typename Real >
static void UnitTestCopyCols ()
 
template<typename Real >
static void UnitTestSimpleForMat ()
 
template<typename Real >
static void UnitTestRow ()
 
template<typename Real >
static void UnitTestAxpy ()
 
template<typename Real >
static void UnitTestCopySp ()
 
template<typename Real >
static void UnitTestPower ()
 
template<typename Real >
static void UnitTestPowerAbs ()
 
template<typename Real >
static void UnitTestHeaviside ()
 
template<typename Real >
static void UnitTestAddOuterProductPlusMinus ()
 
template<typename Real >
static void UnitTestSger ()
 
template<typename Real >
static void UnitTestDeterminant ()
 
template<typename Real >
static void UnitTestDeterminantSign ()
 
template<typename Real >
static void UnitTestSpVec ()
 
template<typename Real >
static void UnitTestTraceProduct ()
 
template<typename Real >
static void UnitTestSvd ()
 
template<typename Real >
static void UnitTestSvdBad ()
 
template<typename Real >
static void UnitTestSvdZero ()
 
template<typename Real >
static void UnitTestSvdNodestroy ()
 
template<typename Real >
static void UnitTestSvdJustvec ()
 
template<typename Real >
static void UnitTestEigSymmetric ()
 
template<typename Real >
static void UnitTestEig ()
 
template<typename Real >
static void UnitTestEigSp ()
 
template<typename Real >
static Real NonOrthogonality (const MatrixBase< Real > &M, MatrixTransposeType transM)
 
template<typename Real >
static Real NonDiagonalness (const SpMatrix< Real > &S)
 
template<typename Real >
static Real NonUnitness (const SpMatrix< Real > &S)
 
template<typename Real >
static void UnitTestTridiagonalize ()
 
template<typename Real >
static void UnitTestTridiagonalizeAndQr ()
 
template<typename Real >
static void UnitTestMmul ()
 
template<typename Real >
static void UnitTestMmulSym ()
 
template<typename Real >
static void UnitTestAddVecVec ()
 
template<typename Real >
static void UnitTestVecmul ()
 
template<typename Real >
static void UnitTestInverse ()
 
template<typename Real >
static void UnitTestMulElements ()
 
template<typename Real >
static void UnitTestDotprod ()
 
template<class Real >
void PlaceNansInGaps (Matrix< Real > *mat)
 
template<typename Real >
static void UnitTestResizeCopyDataDifferentStrideType ()
 Make sure that when Resize() is called with resize_type = kCopyData and a stride_type different from this's stride_type, the resized matrix is equivalent to the original matrix (modulo the stride). More...
 
template<typename Real >
static void UnitTestResize ()
 
template<typename Real >
static void UnitTestTp2Sp ()
 
template<typename Real >
static void UnitTestTp2 ()
 
template<typename Real >
static void UnitTestAddDiagMat2 ()
 
template<typename Real >
static void UnitTestAddDiagMatMat ()
 
template<typename Real >
static void UnitTestOrthogonalizeRows ()
 
template<typename Real >
static void UnitTestTransposeScatter ()
 
template<typename Real >
static void UnitTestRankNUpdate ()
 
template<typename Real >
static void UnitTestSpInvert ()
 
template<typename Real >
static void UnitTestTpInvert ()
 
template<typename Real >
static void UnitTestLimitCondInvert ()
 
template<typename Real >
static void UnitTestFloorChol ()
 
template<typename Real >
static void UnitTestFloorUnit ()
 
template<typename Real >
static void UnitTestFloorCeiling ()
 
template<typename Real >
static void UnitTestMat2Vec ()
 
template<typename Real >
static void UnitTestLimitCond ()
 
template<typename Real >
static void UnitTestTanh ()
 
template<typename Real >
static void UnitTestSigmoid ()
 
template<typename Real >
static void UnitTestSoftHinge ()
 
template<typename Real >
static void UnitTestSimple ()
 
template<typename Real >
static void UnitTestIo ()
 
template<typename Real >
static void UnitTestIoCross ()
 
template<typename Real >
static void UnitTestHtkIo ()
 
template<typename Real >
static void UnitTestRange ()
 
template<typename Real >
static void UnitTestScale ()
 
template<typename Real >
static void UnitTestMul ()
 
template<typename Real >
static void UnitTestApplyExpSpecial ()
 
template<typename Real >
static void UnitTestInnerProd ()
 
template<typename Real >
static void UnitTestAddToDiag ()
 
template<typename Real >
static void UnitTestScaleDiag ()
 
template<typename Real >
static void UnitTestSetDiag ()
 
template<typename Real >
static void UnitTestTraceSpSpLower ()
 
template<typename Real >
static void UnitTestAddMatSmat ()
 
template<typename Real >
static void UnitTestAddMat2Sp ()
 
template<typename Real >
static void UnitTestAddMatSelf ()
 
template<typename Real >
static void UnitTestAddMat2 ()
 
template<typename Real >
static void UnitTestSymAddMat2 ()
 
template<typename Real >
static void UnitTestSolve ()
 
template<typename Real >
static void UnitTestMax2 ()
 
template<typename Real >
static void UnitTestMaxAbsEig ()
 
template<typename Real >
static void UnitTestLbfgs ()
 
template<typename Real >
static void UnitTestLinearCgd ()
 
template<typename Real >
static void UnitTestMaxMin ()
 
template<typename Real >
static bool approx_equal (Real a, Real b)
 
template<typename Real >
static void UnitTestTrace ()
 
template<typename Real >
static void UnitTestComplexFt ()
 
template<typename Real >
static void UnitTestDct ()
 
template<typename Real >
static void UnitTestComplexFft ()
 
template<typename Real >
static void UnitTestSplitRadixComplexFft ()
 
template<typename Real >
static void UnitTestTranspose ()
 
template<typename Real >
static void UnitTestAddVecToRows ()
 
template<typename Real >
static void UnitTestAddVec2Sp ()
 
template<typename Real >
static void UnitTestAddVecToCols ()
 
template<typename Real >
static void UnitTestComplexFft2 ()
 
template<typename Real >
static void UnitTestSplitRadixComplexFft2 ()
 
template<typename Real >
static void UnitTestRealFft ()
 
template<typename Real >
static void UnitTestSplitRadixRealFft ()
 
template<typename Real >
static void UnitTestRealFftSpeed ()
 
template<typename Real >
static void UnitTestSplitRadixRealFftSpeed ()
 
template<typename Real >
void UnitTestComplexPower ()
 
template<typename Real >
void UnitTestNonsymmetricPower ()
 
void UnitTestAddVecCross ()
 
template<typename Real >
static void UnitTestPca (bool full_test)
 
template<typename Real >
static void UnitTestPca2 (bool full_test)
 
template<typename Real >
static void UnitTestSvdSpeed ()
 
template<typename Real >
static void UnitTestCompressedMatrix2 ()
 
template<typename Real >
static void UnitTestCompressedMatrix ()
 
template<typename Real >
static void UnitTestGeneralMatrix ()
 
template<typename Real >
static void UnitTestExtractCompressedMatrix ()
 
template<typename Real >
static void UnitTestTridiag ()
 
template<typename Real >
static void UnitTestRandCategorical ()
 
template<class Real >
static void UnitTestAddMatMatNans ()
 
template<class Real >
static void UnitTestTopEigs ()
 
template<typename Real >
static void UnitTestTriVecSolver ()
 
template<typename Real >
static void MatrixUnitTest (bool full_test)
 
template<class Real >
int32 LinearCgd (const LinearCgdOptions &opts, const SpMatrix< Real > &A, const VectorBase< Real > &b, VectorBase< Real > *x)
 
template int32 LinearCgd< float > (const LinearCgdOptions &opts, const SpMatrix< float > &A, const VectorBase< float > &b, VectorBase< float > *x)
 
template int32 LinearCgd< double > (const LinearCgdOptions &opts, const SpMatrix< double > &A, const VectorBase< double > &b, VectorBase< double > *x)
 
template<typename Real >
std::ostream & operator<< (std::ostream &out, const PackedMatrix< Real > &M)
 
template<typename Real >
std::istream & operator>> (std::istream &is, PackedMatrix< Real > &M)
 
template<typename Real >
void HouseBackward (MatrixIndexT dim, const Real *x, Real *v, Real *beta)
 
template<typename Real >
void Givens (Real a, Real b, Real *c, Real *s)
 Create Givens rotations, as in Golub and Van Loan 3rd ed., page 216. More...
 
template<typename Real >
void QrStep (MatrixIndexT n, Real *diag, Real *off_diag, MatrixBase< Real > *Q)
 
template<typename Real >
void QrInternal (MatrixIndexT n, Real *diag, Real *off_diag, MatrixBase< Real > *Q)
 
template<>
double SolveQuadraticProblem (const SpMatrix< double > &H, const VectorBase< double > &g, const SolverOptions &opts, VectorBase< double > *x)
 
template<>
float SolveQuadraticProblem (const SpMatrix< float > &H, const VectorBase< float > &g, const SolverOptions &opts, VectorBase< float > *x)
 
double TraceSpSp (const SpMatrix< double > &A, const SpMatrix< double > &B)
 
float TraceSpSp (const SpMatrix< float > &A, const SpMatrix< float > &B)
 Returns tr(A B). More...
 
template<typename Real , typename OtherReal >
Real TraceSpSp (const SpMatrix< Real > &A, const SpMatrix< OtherReal > &B)
 Returns tr(A B). More...
 
template float TraceSpSp< float, double > (const SpMatrix< float > &A, const SpMatrix< double > &B)
 
template double TraceSpSp< double, float > (const SpMatrix< double > &A, const SpMatrix< float > &B)
 
template<typename Real >
Real TraceSpMat (const SpMatrix< Real > &A, const MatrixBase< Real > &B)
 Returns tr(A B). More...
 
template float TraceSpMat (const SpMatrix< float > &A, const MatrixBase< float > &B)
 
template double TraceSpMat (const SpMatrix< double > &A, const MatrixBase< double > &B)
 
template<typename Real >
Real TraceMatSpMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const MatrixBase< Real > &C, MatrixTransposeType transC)
 Returns tr(A B C) (A and C may be transposed as specified by transA and transC). More...
 
template float TraceMatSpMat (const MatrixBase< float > &A, MatrixTransposeType transA, const SpMatrix< float > &B, const MatrixBase< float > &C, MatrixTransposeType transC)
 
template double TraceMatSpMat (const MatrixBase< double > &A, MatrixTransposeType transA, const SpMatrix< double > &B, const MatrixBase< double > &C, MatrixTransposeType transC)
 
template<typename Real >
Real TraceMatSpMatSp (const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const MatrixBase< Real > &C, MatrixTransposeType transC, const SpMatrix< Real > &D)
 Returns tr (A B C D) (A and C may be transposed as specified by transA and transB). More...
 
template float TraceMatSpMatSp (const MatrixBase< float > &A, MatrixTransposeType transA, const SpMatrix< float > &B, const MatrixBase< float > &C, MatrixTransposeType transC, const SpMatrix< float > &D)
 
template double TraceMatSpMatSp (const MatrixBase< double > &A, MatrixTransposeType transA, const SpMatrix< double > &B, const MatrixBase< double > &C, MatrixTransposeType transC, const SpMatrix< double > &D)
 
template<typename Real >
Real SolveQuadraticMatrixProblem (const SpMatrix< Real > &Q, const MatrixBase< Real > &Y, const SpMatrix< Real > &P, const SolverOptions &opts, MatrixBase< Real > *M)
 Maximizes the auxiliary function :

\[ Q(x) = tr(M^T P Y) - 0.5 tr(P M Q M^T) \]

Like a numerically stable version of $ M := Y Q^{-1} $. More...

 
template<typename Real >
Real SolveDoubleQuadraticMatrixProblem (const MatrixBase< Real > &G, const SpMatrix< Real > &P1, const SpMatrix< Real > &P2, const SpMatrix< Real > &Q1, const SpMatrix< Real > &Q2, const SolverOptions &opts, MatrixBase< Real > *M)
 Maximizes the auxiliary function :

\[ Q(M) = tr(M^T G) -0.5 tr(P_1 M Q_1 M^T) -0.5 tr(P_2 M Q_2 M^T). \]

Encountered in matrix update with a prior. More...

 
template<typename Real >
Real VecSpVec (const VectorBase< Real > &v1, const SpMatrix< Real > &M, const VectorBase< Real > &v2)
 Computes v1^T * M * v2. More...
 
template float VecSpVec (const VectorBase< float > &v1, const SpMatrix< float > &M, const VectorBase< float > &v2)
 
template double VecSpVec (const VectorBase< double > &v1, const SpMatrix< double > &M, const VectorBase< double > &v2)
 
template<typename Real >
Real TraceSpSpLower (const SpMatrix< Real > &A, const SpMatrix< Real > &B)
 
template double TraceSpSpLower (const SpMatrix< double > &A, const SpMatrix< double > &B)
 
template float TraceSpSpLower (const SpMatrix< float > &A, const SpMatrix< float > &B)
 
template float SolveQuadraticMatrixProblem (const SpMatrix< float > &Q, const MatrixBase< float > &Y, const SpMatrix< float > &SigmaInv, const SolverOptions &opts, MatrixBase< float > *M)
 
template double SolveQuadraticMatrixProblem (const SpMatrix< double > &Q, const MatrixBase< double > &Y, const SpMatrix< double > &SigmaInv, const SolverOptions &opts, MatrixBase< double > *M)
 
template float SolveDoubleQuadraticMatrixProblem (const MatrixBase< float > &G, const SpMatrix< float > &P1, const SpMatrix< float > &P2, const SpMatrix< float > &Q1, const SpMatrix< float > &Q2, const SolverOptions &opts, MatrixBase< float > *M)
 
template double SolveDoubleQuadraticMatrixProblem (const MatrixBase< double > &G, const SpMatrix< double > &P1, const SpMatrix< double > &P2, const SpMatrix< double > &Q1, const SpMatrix< double > &Q2, const SolverOptions &opts, MatrixBase< double > *M)
 
template<typename Real >
bool ApproxEqual (const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
 
template<typename Real >
Real SolveQuadraticProblem (const SpMatrix< Real > &H, const VectorBase< Real > &g, const SolverOptions &opts, VectorBase< Real > *x)
 Maximizes the auxiliary function

\[ Q(x) = x.g - 0.5 x^T H x \]

using a numerically stable method. More...

 
template<typename Real >
void UnitTestSparseVectorSum ()
 
template<typename Real >
void UnitTestSparseVectorAddToVec ()
 
template<typename Real >
void UnitTestSparseVectorMax ()
 
template<typename Real >
void UnitTestSparseVectorVecSvec ()
 
template<typename Real >
void UnitTestSparseMatrixSum ()
 
template<typename Real >
void UnitTestSparseMatrixFrobeniusNorm ()
 
template<typename Real >
void UnitTestSparseMatrixAddToMat ()
 
template<typename Real >
void UnitTestSparseMatrixConstructor ()
 
template<typename Real >
void UnitTestSparseMatrixTraceMatSmat ()
 
template<typename Real >
void UnitTestMatrixAddMatSmat ()
 
template<typename Real >
void UnitTestMatrixAddSmatMat ()
 
template<typename Real >
void SparseMatrixUnitTest ()
 
template<typename Real >
Real VecSvec (const VectorBase< Real > &vec, const SparseVector< Real > &svec)
 
template float VecSvec (const VectorBase< float > &vec, const SparseVector< float > &svec)
 
template double VecSvec (const VectorBase< double > &vec, const SparseVector< double > &svec)
 
template<typename Real >
Real TraceMatSmat (const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType trans)
 
template float TraceMatSmat (const MatrixBase< float > &A, const SparseMatrix< float > &B, MatrixTransposeType trans)
 
template double TraceMatSmat (const MatrixBase< double > &A, const SparseMatrix< double > &B, MatrixTransposeType trans)
 
void AppendGeneralMatrixRows (const std::vector< const GeneralMatrix * > &src, GeneralMatrix *mat)
 Appends all the matrix rows of a list of GeneralMatrixes, to get a single GeneralMatrix. More...
 
void FilterCompressedMatrixRows (const CompressedMatrix &in, const std::vector< bool > &keep_rows, Matrix< BaseFloat > *out)
 Outputs a Matrix<Real> containing only the rows r of "in" such that keep_rows[r] == true. More...
 
template<typename Real >
void FilterMatrixRows (const Matrix< Real > &in, const std::vector< bool > &keep_rows, Matrix< Real > *out)
 Outputs a Matrix<Real> containing only the rows r of "in" such that keep_keep_rows[r] == true. More...
 
template void FilterMatrixRows (const Matrix< float > &in, const std::vector< bool > &keep_rows, Matrix< float > *out)
 
template void FilterMatrixRows (const Matrix< double > &in, const std::vector< bool > &keep_rows, Matrix< double > *out)
 
template<typename Real >
void FilterSparseMatrixRows (const SparseMatrix< Real > &in, const std::vector< bool > &keep_rows, SparseMatrix< Real > *out)
 Outputs a SparseMatrix<Real> containing only the rows r of "in" such that keep_rows[r] == true. More...
 
template void FilterSparseMatrixRows (const SparseMatrix< float > &in, const std::vector< bool > &keep_rows, SparseMatrix< float > *out)
 
template void FilterSparseMatrixRows (const SparseMatrix< double > &in, const std::vector< bool > &keep_rows, SparseMatrix< double > *out)
 
void FilterGeneralMatrixRows (const GeneralMatrix &in, const std::vector< bool > &keep_rows, GeneralMatrix *out)
 Outputs a GeneralMatrix containing only the rows r of "in" such that keep_rows[r] == true. More...
 
void ExtractRowRangeWithPadding (const GeneralMatrix &in, int32 row_offset, int32 num_rows, GeneralMatrix *out)
 This function extracts a row-range of a GeneralMatrix and writes as a GeneralMatrix containing the same type of underlying matrix. More...
 
template<class CharT , class Traits >
void swap (basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
 
template<class Int >
void TestSetOfNumbers (bool binary)
 
template<class T >
int32 LevenshteinEditDistance (const std::vector< T > &a, const std::vector< T > &b)
 
template<class T >
int32 LevenshteinEditDistance (const std::vector< T > &ref, const std::vector< T > &hyp, int32 *ins, int32 *del, int32 *sub)
 
template<class T >
int32 LevenshteinAlignment (const std::vector< T > &a, const std::vector< T > &b, T eps_symbol, std::vector< std::pair< T, T > > *output)
 
void TestEditDistance ()
 
void TestEditDistanceString ()
 
void TestEditDistance2 ()
 
void TestEditDistance2String ()
 
void TestLevenshteinAlignment ()
 
template<class Int , class T >
void TestHashList ()
 
static bool prefixp (const std::string &pfx, const std::string &str)
 
static std::string cygprefix ("/cygdrive/")
 
static std::string MapCygwinPathNoTmp (const std::string &filename)
 
std::string MapCygwinPath (const std::string &filename)
 
static FILE * CygwinCompatPopen (const char *command, const char *mode)
 
bool ParseMatrixRangeSpecifier (const std::string &range, const int rows, const int cols, std::vector< int32 > *row_range, std::vector< int32 > *col_range)
 
bool ExtractObjectRange (const GeneralMatrix &input, const std::string &range, GeneralMatrix *output)
 GeneralMatrix is always of type BaseFloat. More...
 
template<class Real >
bool ExtractObjectRange (const CompressedMatrix &input, const std::string &range, Matrix< Real > *output)
 CompressedMatrix is always of the type BaseFloat but it is more efficient to provide template as it uses CompressedMatrix's own conversion to Matrix<Real> More...
 
template bool ExtractObjectRange (const CompressedMatrix &, const std::string &, Matrix< float > *)
 
template bool ExtractObjectRange (const CompressedMatrix &, const std::string &, Matrix< double > *)
 
template<class Real >
bool ExtractObjectRange (const Matrix< Real > &input, const std::string &range, Matrix< Real > *output)
 The template is specialized with a version that actually does something, for types Matrix<float> and Matrix<double>. More...
 
template bool ExtractObjectRange (const Matrix< double > &, const std::string &, Matrix< double > *)
 
template bool ExtractObjectRange (const Matrix< float > &, const std::string &, Matrix< float > *)
 
template<class Real >
bool ExtractObjectRange (const Vector< Real > &input, const std::string &range, Vector< Real > *output)
 The template is specialized types Vector<float> and Vector<double>. More...
 
template bool ExtractObjectRange (const Vector< double > &, const std::string &, Vector< double > *)
 
template bool ExtractObjectRange (const Vector< float > &, const std::string &, Vector< float > *)
 
bool ExtractRangeSpecifier (const std::string &rxfilename_with_range, std::string *data_rxfilename, std::string *range)
 
template<class T >
bool ExtractObjectRange (const T &input, const std::string &range, T *output)
 This templated function exists so that we can write .scp files with 'object ranges' specified: the canonical example is a [first:last] range of rows of a matrix, or [first-row:last-row,first-column,last-column] of a matrix. More...
 
void UnitTestClassifyRxfilename ()
 
void UnitTestClassifyWxfilename ()
 
void UnitTestIoNew (bool binary)
 
void UnitTestIoPipe (bool binary)
 
void UnitTestIoStandard ()
 
void UnitTestNativeFilename ()
 
std::string PrintableRxfilename (const std::string &rxfilename)
 PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting, i.e. More...
 
std::string PrintableWxfilename (const std::string &wxfilename)
 PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting, i.e. More...
 
OutputType ClassifyWxfilename (const std::string &wxfilename)
 ClassifyWxfilename interprets filenames as follows: More...
 
InputType ClassifyRxfilename (const std::string &rxfilename)
 ClassifyRxfilenames interprets filenames for reading as follows: More...
 
template<>
void ReadKaldiObject (const std::string &filename, Matrix< float > *m)
 
template<>
void ReadKaldiObject (const std::string &filename, Matrix< double > *m)
 
template<class C >
void ReadKaldiObject (const std::string &filename, C *c)
 
template<class C >
void WriteKaldiObject (const C &c, const std::string &filename, bool binary)
 
void UnitTestReadScriptFile ()
 
void UnitTestClassifyWspecifier ()
 
void UnitTestClassifyRspecifier ()
 
void UnitTestTableSequentialInt32 (bool binary)
 
void UnitTestTableSequentialBool (bool binary)
 
void UnitTestTableSequentialDouble (bool binary)
 
void UnitTestTableSequentialDoubleBoth (bool binary, bool read_scp)
 
void UnitTestTableSequentialInt32VectorBoth (bool binary, bool read_scp)
 
void UnitTestTableSequentialInt32PairVectorBoth (bool binary, bool read_scp)
 
void UnitTestTableSequentialInt32VectorVectorBoth (bool binary, bool read_scp)
 
void UnitTestTableSequentialInt32Script (bool binary)
 
void UnitTestTableSequentialDoubleMatrixBoth (bool binary, bool read_scp)
 
void UnitTestTableSequentialBaseFloatVectorBoth (bool binary, bool read_scp)
 
template<class T >
void RandomizeVector (std::vector< T > *v)
 
void UnitTestTableRandomBothDouble (bool binary, bool read_scp, bool sorted, bool called_sorted, bool once)
 
void UnitTestRangesMatrix (bool binary)
 
void UnitTestTableRandomBothDoubleMatrix (bool binary, bool read_scp, bool sorted, bool called_sorted, bool once)
 
bool ReadScriptFile (const std::string &rxfilename, bool warn, std::vector< std::pair< std::string, std::string > > *script_out)
 
bool ReadScriptFile (std::istream &is, bool warn, std::vector< std::pair< std::string, std::string > > *script_out)
 
bool WriteScriptFile (std::ostream &os, const std::vector< std::pair< std::string, std::string > > &script)
 
bool WriteScriptFile (const std::string &wxfilename, const std::vector< std::pair< std::string, std::string > > &script)
 
WspecifierType ClassifyWspecifier (const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
 
RspecifierType ClassifyRspecifier (const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
 
void TestThreads ()
 
void TestTaskSequencer ()
 
template<class C >
void RunMultiThreaded (const C &c_in)
 Here, class C should inherit from MultiThreadable. More...
 
void UnitTestParseOptions ()
 
static bool MustBeQuoted (const std::string &str, ShellType st)
 
static std::string QuoteAndEscape (const std::string &str, ShellType st)
 
template<class C >
void ReadConfigFromFile (const std::string &config_filename, C *c)
 This template is provided for convenience in reading config classes from files; this is not the standard way to read configuration options, but may occasionally be needed. More...
 
template<class C1 , class C2 >
void ReadConfigsFromFile (const std::string &conf, C1 *c1, C2 *c2)
 This variant of the template ReadConfigFromFile is for if you need to read two config classes from the same file. More...
 
bool WriteIntegerVectorSimple (const std::string &wxfilename, const std::vector< int32 > &v)
 WriteToList attempts to write this list of integers, one per line, to the given file, in text format. More...
 
bool ReadIntegerVectorSimple (const std::string &rxfilename, std::vector< int32 > *v)
 ReadFromList attempts to read this list of integers, one per line, from the given file, in text format. More...
 
bool WriteIntegerVectorVectorSimple (const std::string &wxfilename, const std::vector< std::vector< int32 > > &list)
 
bool ReadIntegerVectorVectorSimple (const std::string &rxfilename, std::vector< std::vector< int32 > > *list)
 
void UnitTestSimpleOptions ()
 
template<typename T >
static bool SetOptionImpl (const std::string &key, const T &value, std::map< std::string, T *> &some_map)
 
template<typename T >
static bool GetOptionImpl (const std::string &key, T *value, std::map< std::string, T *> &some_map)
 
static void TestIsSorted ()
 
static void TestIsSortedAndUniq ()
 
static void TestUniq ()
 
static void TestSortAndUniq ()
 
void TestCopySetToVector ()
 
void TestCopyMapToVector ()
 
void TestCopyMapKeysToVector ()
 
void TestCopyMapValuesToVector ()
 
void TestCopyMapKeysToSet ()
 
void TestCopyMapValuesToSet ()
 
void TestContainsNullPointers ()
 
void TestReverseVector ()
 
void TestMergePairVectorSumming ()
 
template<typename T >
void SortAndUniq (std::vector< T > *vec)
 Sorts and uniq's (removes duplicates) from a vector. More...
 
template<typename T >
bool IsSorted (const std::vector< T > &vec)
 Returns true if the vector is sorted. More...
 
template<typename T >
bool IsSortedAndUniq (const std::vector< T > &vec)
 Returns true if the vector is sorted and contains each element only once. More...
 
template<typename T >
void Uniq (std::vector< T > *vec)
 Removes duplicate elements from a sorted list. More...
 
template<class T >
void CopySetToVector (const std::set< T > &s, std::vector< T > *v)
 Copies the elements of a set to a vector. More...
 
template<class T >
void CopySetToVector (const unordered_set< T > &s, std::vector< T > *v)
 
template<class A , class B >
void CopyMapToVector (const std::map< A, B > &m, std::vector< std::pair< A, B > > *v)
 Copies the (key, value) pairs in a map to a vector of pairs. More...
 
template<class A , class B >
void CopyMapKeysToVector (const std::map< A, B > &m, std::vector< A > *v)
 Copies the keys in a map to a vector. More...
 
template<class A , class B >
void CopyMapValuesToVector (const std::map< A, B > &m, std::vector< B > *v)
 Copies the values in a map to a vector. More...
 
template<class A , class B >
void CopyMapKeysToSet (const std::map< A, B > &m, std::set< A > *s)
 Copies the keys in a map to a set. More...
 
template<class A , class B >
void CopyMapValuesToSet (const std::map< A, B > &m, std::set< B > *s)
 Copies the values in a map to a set. More...
 
template<class A >
void CopyVectorToSet (const std::vector< A > &v, std::set< A > *s)
 Copies the contents of a vector to a set. More...
 
template<class A >
void DeletePointers (std::vector< A *> *v)
 Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL. More...
 
template<class A >
bool ContainsNullPointers (const std::vector< A *> &v)
 Returns true if the vector of pointers contains NULL pointers. More...
 
template<typename A , typename B >
void CopyVectorToVector (const std::vector< A > &vec_in, std::vector< B > *vec_out)
 Copies the contents a vector of one type to a vector of another type. More...
 
template<typename T >
void ReverseVector (std::vector< T > *vec)
 Reverses the contents of a vector. More...
 
template<typename I , typename F >
void MergePairVectorSumming (std::vector< std::pair< I, F > > *vec)
 For a vector of pair<I, F> where I is an integer and F a floating-point or integer type, this function sorts a vector of type vector<pair<I, F> > on the I value and then merges elements with equal I values, summing these over the F component and then removing any F component with zero value. More...
 
char GetRandChar ()
 
char GetRandDelim ()
 
void TestSplitStringToVector ()
 
void TestSplitStringToIntegers ()
 
void TestSplitStringToFloats ()
 
void TestConvertStringToInteger ()
 
template<class Real >
void TestConvertStringToReal ()
 
template<class Real >
void TestNan ()
 
template<class Real >
void TestInf ()
 
std::string TrimTmp (std::string s)
 
void TestTrim ()
 
void TestSplitStringOnFirstSpace ()
 
void TestIsToken ()
 
void TestIsLine ()
 
void TestStringsApproxEqual ()
 
void UnitTestConfigLineParse ()
 
void UnitTestReadConfig ()
 
template<class F >
bool SplitStringToFloats (const std::string &full, const char *delim, bool omit_empty_strings, std::vector< F > *out)
 
template bool SplitStringToFloats (const std::string &full, const char *delim, bool omit_empty_strings, std::vector< float > *out)
 
template bool SplitStringToFloats (const std::string &full, const char *delim, bool omit_empty_strings, std::vector< double > *out)
 
void SplitStringToVector (const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
 Split a string using any of the single character delimiters. More...
 
void JoinVectorToString (const std::vector< std::string > &vec_in, const char *delim, bool omit_empty_strings, std::string *str_out)
 Joins the elements of a vector of strings into a single string using "delim" as the delimiter. More...
 
void Trim (std::string *str)
 Removes the beginning and trailing whitespaces from a string. More...
 
bool IsToken (const std::string &token)
 Returns true if "token" is nonempty, and all characters are printable and whitespace-free. More...
 
void SplitStringOnFirstSpace (const std::string &line, std::string *first, std::string *rest)
 Removes leading and trailing white space from the string, then splits on the first section of whitespace found (if present), putting the part before the whitespace in "first" and the rest in "rest". More...
 
bool IsLine (const std::string &line)
 Returns true if "line" is free of
characters and unprintable characters, and does not contain leading or trailing whitespace. More...
 
template<typename T >
bool ConvertStringToReal (const std::string &str, T *out)
 ConvertStringToReal converts a string into either float or double and returns false if there was any kind of problem (i.e. More...
 
template bool ConvertStringToReal (const std::string &str, float *out)
 
template bool ConvertStringToReal (const std::string &str, double *out)
 
bool StringsApproxEqualInternal (const char *a, const char *b, int32 decimal_places_tolerance, int32 places_into_number)
 
bool StringsApproxEqual (const std::string &a, const std::string &b, int32 decimal_places_check=2)
 This function returns true when two text strings are approximately equal, and false when they are not. More...
 
void ExpectOneOrTwoTokens (std::istream &is, bool binary, const std::string &token1, const std::string &token2)
 This function is like ExpectToken but for two tokens, and it will either accept token1 and then token2, or just token2. More...
 
bool IsValidName (const std::string &name)
 Returns true if 'name' would be a valid name for a component or node in a nnet3Nnet. More...
 
void ReadConfigLines (std::istream &is, std::vector< std::string > *lines)
 This function reads in a config file and *appends* its contents to a vector of lines; it is responsible for removing comments (anything after '#') and stripping out any lines that contain only whitespace after comment removal. More...
 
void ParseConfigLines (const std::vector< std::string > &lines, std::vector< ConfigLine > *config_lines)
 This function converts config-lines from a simple sequence of strings as output by ReadConfigLines(), into a sequence of first-tokens and name-value pairs. More...
 
template<class I >
bool SplitStringToIntegers (const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
 Split a string (e.g. More...
 
template<class Int >
bool ConvertStringToInteger (const std::string &str, Int *out)
 Converts a string into an integer via strtoll and returns false if there was any kind of problem (i.e. More...
 
void UnitTestOnlineCmvn ()
 
void ComputePowerSpectrum (VectorBase< BaseFloat > *waveform)
 
void ComputeDeltas (const DeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
 
void ComputeShiftedDeltas (const ShiftedDeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
 
void InitIdftBases (int32 n_bases, int32 dimension, Matrix< BaseFloat > *mat_out)
 
void SpliceFrames (const MatrixBase< BaseFloat > &input_features, int32 left_context, int32 right_context, Matrix< BaseFloat > *output_features)
 
void ReverseFrames (const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
 
void SlidingWindowCmnInternal (const SlidingWindowCmnOptions &opts, const MatrixBase< double > &input, MatrixBase< double > *output)
 
void SlidingWindowCmn (const SlidingWindowCmnOptions &opts, const MatrixBase< BaseFloat > &input, MatrixBase< BaseFloat > *output)
 Applies sliding-window cepstral mean and/or variance normalization. More...
 
int64 FirstSampleOfFrame (int32 frame, const FrameExtractionOptions &opts)
 
int32 NumFrames (int64 num_samples, const FrameExtractionOptions &opts, bool flush=true)
 This function returns the number of frames that we can extract from a wave file with the given number of samples in it (assumed to have the same sampling rate as specified in 'opts'). More...
 
void Dither (VectorBase< BaseFloat > *waveform, BaseFloat dither_value)
 
void Preemphasize (VectorBase< BaseFloat > *waveform, BaseFloat preemph_coeff)
 
void ProcessWindow (const FrameExtractionOptions &opts, const FeatureWindowFunction &window_function, VectorBase< BaseFloat > *window, BaseFloat *log_energy_pre_window=NULL)
 This function does all the windowing steps after actually extracting the windowed signal: depending on the configuration, it does dithering, dc offset removal, preemphasis, and multiplication by the windowing function. More...
 
void ExtractWindow (int64 sample_offset, const VectorBase< BaseFloat > &wave, int32 f, const FrameExtractionOptions &opts, const FeatureWindowFunction &window_function, Vector< BaseFloat > *window, BaseFloat *log_energy_pre_window)
 
void ComputeLifterCoeffs (BaseFloat Q, VectorBase< BaseFloat > *coeffs)
 
BaseFloat Durbin (int n, const BaseFloat *pAC, BaseFloat *pLP, BaseFloat *pTmp)
 
void Lpc2Cepstrum (int n, const BaseFloat *pLPC, BaseFloat *pCepst)
 
void GetEqualLoudnessVector (const MelBanks &mel_banks, Vector< BaseFloat > *ans)
 
BaseFloat ComputeLpc (const VectorBase< BaseFloat > &autocorr_in, Vector< BaseFloat > *lpc_out)
 
void GetOutput (OnlineFeatureInterface *a, Matrix< BaseFloat > *output)
 
bool RandomSplit (int32 wav_dim, std::vector< int32 > *piece_dim, int32 num_pieces, int32 trials=5)
 
void TestOnlineMatrixCacheFeature ()
 
void TestOnlineDeltaFeature ()
 
void TestOnlineSpliceFrames ()
 
void TestOnlineMfcc ()
 
void TestOnlinePlp ()
 
void TestOnlineTransform ()
 
void TestOnlineAppendFeature ()
 
void TestRecyclingVector ()
 
std::string ConvertIntToString (const int &number)
 
bool DirExist (const std::string &dirname)
 
static void UnitTestSimple ()
 
static void UnitTestSnipEdges ()
 
static void UnitTestPieces ()
 
static void UnitTestDelay ()
 
static void UnitTestSearch ()
 
static void UnitTestComputeGPE ()
 
static void UnitTestKeele ()
 
static void UnitTestPenaltyFactor ()
 
static void UnitTestKeeleNccfBallast ()
 
static void UnitTestPitchExtractionSpeed ()
 
static void UnitTestPitchExtractorCompareKeele ()
 
void UnitTestDiffSampleRate ()
 
void UnitTestProcess ()
 
static void UnitTestFeatNoKeele ()
 
static void UnitTestFeatWithKeele ()
 
BaseFloat NccfToPovFeature (BaseFloat n)
 This function processes the NCCF n to a POV feature f by applying the formula f = (1.0001 - n)^0.15 - 1.0 This is a nonlinear function designed to make the output reasonably Gaussian distributed. More...
 
BaseFloat NccfToPov (BaseFloat n)
 This function processes the NCCF n to a reasonably accurate probability of voicing p by applying the formula: More...
 
void ComputeCorrelation (const VectorBase< BaseFloat > &wave, int32 first_lag, int32 last_lag, int32 nccf_window_size, VectorBase< BaseFloat > *inner_prod, VectorBase< BaseFloat > *norm_prod)
 This function computes some dot products that are required while computing the NCCF. More...
 
void ComputeNccf (const VectorBase< BaseFloat > &inner_prod, const VectorBase< BaseFloat > &norm_prod, BaseFloat nccf_ballast, VectorBase< BaseFloat > *nccf_vec)
 Computes the NCCF as a fraction of the numerator term (a dot product between two vectors) and a denominator term which equals sqrt(e1*e2 + nccf_ballast) where e1 and e2 are both dot-products of bits of the wave with themselves, and e1*e2 is supplied as "norm_prod". More...
 
void SelectLags (const PitchExtractionOptions &opts, Vector< BaseFloat > *lags)
 This function selects the lags at which we measure the NCCF: we need to select lags from 1/max_f0 to 1/min_f0, in a geometric progression with ratio 1 + d. More...
 
void ComputeLocalCost (const VectorBase< BaseFloat > &nccf_pitch, const VectorBase< BaseFloat > &lags, const PitchExtractionOptions &opts, VectorBase< BaseFloat > *local_cost)
 This function computes the local-cost for the Viterbi computation, see eq. More...
 
void ComputeKaldiPitchFirstPass (const PitchExtractionOptions &opts, const VectorBase< BaseFloat > &wave, Matrix< BaseFloat > *output)
 This function is called from ComputeKaldiPitch when the user specifies opts.simulate_first_pass_online == true. More...
 
void ComputeKaldiPitch (const PitchExtractionOptions &opts, const VectorBase< BaseFloat > &wave, Matrix< BaseFloat > *output)
 This function extracts (pitch, NCCF) per frame, using the pitch extraction method described in "A Pitch Extraction Algorithm Tuned for Automatic Speech Recognition", Pegah Ghahremani, Bagher BabaAli, Daniel Povey, Korbinian Riedhammer, Jan Trmal and Sanjeev Khudanpur, ICASSP 2014. More...
 
template<typename Real >
void AppendVector (const VectorBase< Real > &src, Vector< Real > *dst)
 
void ProcessPitch (const ProcessPitchOptions &opts, const MatrixBase< BaseFloat > &input, Matrix< BaseFloat > *output)
 This function processes the raw (NCCF, pitch) quantities computed by ComputeKaldiPitch, and processes them into features. More...
 
void ComputeAndProcessKaldiPitch (const PitchExtractionOptions &pitch_opts, const ProcessPitchOptions &process_opts, const VectorBase< BaseFloat > &wave, Matrix< BaseFloat > *output)
 This function combines ComputeKaldiPitch and ProcessPitch. More...
 
void ResampleWaveform (BaseFloat orig_freq, const VectorBase< BaseFloat > &wave, BaseFloat new_freq, Vector< BaseFloat > *new_wave)
 Downsample or upsample a waveform. More...
 
void DownsampleWaveForm (BaseFloat orig_freq, const VectorBase< BaseFloat > &wave, BaseFloat new_freq, Vector< BaseFloat > *new_wave)
 This function is deprecated. More...
 
void UnitTestFFTbasedBlockConvolution ()
 
void UnitTestFFTbasedConvolution ()
 
void ElementwiseProductOfFft (const Vector< BaseFloat > &a, Vector< BaseFloat > *b)
 
void ConvolveSignals (const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
 
void FFTbasedConvolveSignals (const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
 
void FFTbasedBlockConvolveSignals (const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
 
static void WriteUint32 (std::ostream &os, int32 i)
 
static void WriteUint16 (std::ostream &os, int16 i)
 
void TestGenRandStats ()
 
void TestBuildTree ()
 
void TestTrivialTree ()
 
void TestPossibleValues ()
 
void TestConvertStats ()
 
void TestSplitStatsByKey ()
 
void TestFindAllKeys ()
 
void TestDoTableSplit ()
 
void TestClusterEventMapGetMappingAndRenumberEventMap ()
 
void TestClusterEventMapGetMappingAndRenumberEventMap2 ()
 
void TestClusterEventMap ()
 
void TestClusterEventMapRestricted ()
 
void TestShareEventMapLeaves ()
 
void TestQuestionsInitRand ()
 
void TestSplitDecisionTree ()
 
void TestBuildTreeStatsIo (bool binary)
 
void WriteBuildTreeStats (std::ostream &os, bool binary, const BuildTreeStatsType &stats)
 Writes BuildTreeStats object. This works even if pointers are NULL. More...
 
void ReadBuildTreeStats (std::istream &is, bool binary, const Clusterable &example, BuildTreeStatsType *stats)
 Reads BuildTreeStats object. More...
 
bool PossibleValues (EventKeyType key, const BuildTreeStatsType &stats, std::vector< EventValueType > *ans)
 Convenience function e.g. More...
 
static void GetEventKeys (const EventType &vec, std::vector< EventKeyType > *keys)
 
void FindAllKeys (const BuildTreeStatsType &stats, AllKeysType keys_type, std::vector< EventKeyType > *keys)
 FindAllKeys puts in *keys the (sorted, unique) list of all key identities in the stats. More...
 
EventMapDoTableSplit (const EventMap &orig, EventKeyType key, const BuildTreeStatsType &stats, int32 *num_leaves)
 DoTableSplit does a complete split on this key (e.g. More...
 
EventMapDoTableSplitMultiple (const EventMap &orig, const std::vector< EventKeyType > &keys, const BuildTreeStatsType &stats, int32 *num_leaves)
 DoTableSplitMultiple does a complete split on all the keys, in order from keys[0], keys[1] and so on. More...
 
void SplitStatsByMap (const BuildTreeStatsType &stats_in, const EventMap &e, std::vector< BuildTreeStatsType > *stats_out)
 Splits stats according to the EventMap, indexing them at output by the leaf type. More...
 
void SplitStatsByKey (const BuildTreeStatsType &stats_in, EventKeyType key, std::vector< BuildTreeStatsType > *stats_out)
 SplitStatsByKey splits stats up according to the value of a particular key, which must be always defined and nonnegative. More...
 
void FilterStatsByKey (const BuildTreeStatsType &stats_in, EventKeyType key, std::vector< EventValueType > &values, bool include_if_present, BuildTreeStatsType *stats_out)
 FilterStatsByKey filters the stats according the value of a specified key. More...
 
ClusterableSumStats (const BuildTreeStatsType &stats_in)
 Sums stats, or returns NULL stats_in has no non-NULL stats. More...
 
BaseFloat SumNormalizer (const BuildTreeStatsType &stats_in)
 Sums the normalizer [typically, data-count] over the stats. More...
 
BaseFloat SumObjf (const BuildTreeStatsType &stats_in)
 Sums the objective function over the stats. More...
 
void SumStatsVec (const std::vector< BuildTreeStatsType > &stats_in, std::vector< Clusterable * > *stats_out)
 Sum a vector of stats. More...
 
BaseFloat ObjfGivenMap (const BuildTreeStatsType &stats_in, const EventMap &e)
 Cluster the stats given the event map return the total objf given those clusters. More...
 
BaseFloat ComputeInitialSplit (const std::vector< Clusterable *> &summed_stats, const Questions &q_opts, EventKeyType key, std::vector< EventValueType > *yes_set)
 
BaseFloat FindBestSplitForKey (const BuildTreeStatsType &stats, const Questions &qcfg, EventKeyType key, std::vector< EventValueType > *yes_set)
 FindBestSplitForKey is a function used in DoDecisionTreeSplit. More...
 
EventMapSplitDecisionTree (const EventMap &orig, const BuildTreeStatsType &stats, Questions &qcfg, BaseFloat thresh, int32 max_leaves, int32 *num_leaves, BaseFloat *objf_impr_out, BaseFloat *smallest_split_change_out)
 Does a decision-tree split at the leaves of an EventMap. More...
 
int ClusterEventMapGetMapping (const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, std::vector< EventMap * > *mapping)
 "ClusterEventMapGetMapping" clusters the leaves of the EventMap, with "thresh" a delta-likelihood threshold to control how many leaves we combine (might be the same as the delta-like threshold used in splitting. More...
 
EventMapRenumberEventMap (const EventMap &e_in, int32 *num_leaves)
 RenumberEventMap [intended to be used after calling ClusterEventMap] renumbers an EventMap so its leaves are consecutive. More...
 
EventMapMapEventMapLeaves (const EventMap &e_in, const std::vector< int32 > &mapping)
 This function remaps the event-map leaves using this mapping, indexed by the number at leaf. More...
 
EventMapClusterEventMap (const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, int32 *num_removed)
 This is as ClusterEventMapGetMapping but a more convenient interface that exposes less of the internals. More...
 
EventMapShareEventMapLeaves (const EventMap &e_in, EventKeyType key, std::vector< std::vector< EventValueType > > &values, int32 *num_leaves)
 ShareEventMapLeaves performs a quite specific function that allows us to generate trees where, for a certain list of phones, and for all states in the phone, all the pdf's are shared. More...
 
void DeleteBuildTreeStats (BuildTreeStatsType *stats)
 This frees the Clusterable* pointers in "stats", where non-NULL, and sets them to NULL. More...
 
EventMapGetToLengthMap (const BuildTreeStatsType &stats, int32 P, const std::vector< EventValueType > *phones, int32 default_length)
 
static int32 ClusterEventMapRestrictedHelper (const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, std::vector< EventKeyType > keys, std::vector< EventMap *> *leaf_mapping)
 
EventMapClusterEventMapRestrictedByKeys (const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, const std::vector< EventKeyType > &keys, int32 *num_removed)
 This is as ClusterEventMap, but first splits the stats on the keys specified in "keys" (e.g. More...
 
EventMapClusterEventMapRestrictedByMap (const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, const EventMap &e_restrict, int32 *num_removed)
 This version of ClusterEventMapRestricted restricts the clustering to only allow things that "e_restrict" maps to the same value to be clustered together. More...
 
EventMapClusterEventMapToNClustersRestrictedByMap (const EventMap &e_in, const BuildTreeStatsType &stats, int32 num_clusters, const EventMap &e_restrict, int32 *num_removed)
 This version of ClusterEventMapRestrictedByMap clusters to get a specific number of clusters as specified by 'num_clusters'. More...
 
EventMapGetStubMap (int32 P, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, int32 *num_leaves)
 GetStubMap is used in tree-building functions to get the initial to-states map, before the decision-tree-building process. More...
 
bool ConvertStats (int32 oldN, int32 oldP, int32 newN, int32 newP, BuildTreeStatsType *stats)
 Converts stats from a given context-window (N) and central-position (P) to a different N and P, by possibly reducing context. More...
 
EventMapTrivialTree (int32 *num_leaves)
 Returns a tree with just one node. More...
 
void CreateRandomQuestions (const BuildTreeStatsType &stats, int32 num_quest, Questions *cfg_out)
 CreateRandomQuestions will initialize a Questions randomly, in a reasonable way [for testing purposes, or when hand-designed questions are not available]. More...
 
void GenRandStats (int32 dim, int32 num_stats, int32 N, int32 P, const std::vector< int32 > &phone_ids, const std::vector< int32 > &hmm_lengths, const std::vector< bool > &is_ctx_dep, bool ensure_all_phones_covered, BuildTreeStatsType *stats_out)
 GenRandStats generates random statistics of the form used by BuildTree. More...
 
EventMapBuildTree (Questions &qopts, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, const std::vector< bool > &do_split, const BuildTreeStatsType &stats, BaseFloat thresh, int32 max_leaves, BaseFloat cluster_thresh, int32 P, bool round_num_leaves=true)
 BuildTree is the normal way to build a set of decision trees. More...
 
static void ComputeTreeMapping (const EventMap &small_tree, const EventMap &big_tree, const BuildTreeStatsType &stats, std::vector< int32 > *leaf_map)
 
EventMapBuildTreeTwoLevel (Questions &qopts, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, const std::vector< bool > &do_split, const BuildTreeStatsType &stats, int32 max_leaves_first, int32 max_leaves_second, bool cluster_leaves, int32 P, std::vector< int32 > *leaf_map)
 BuildTreeTwoLevel builds a two-level tree, useful for example in building tied mixture systems with multiple codebooks. More...
 
void ReadSymbolTableAsIntegers (std::string filename, bool include_eps, std::vector< int32 > *syms)
 included here because it's used in some tree-building calling code. More...
 
static void RemoveDuplicates (std::vector< std::vector< int32 > > *vecs)
 
static void ObtainSetsOfPhones (const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &assignments, const std::vector< int32 > &clust_assignments, int32 num_leaves, std::vector< std::vector< int32 > > *sets_out)
 ObtainSetsOfPhones is called by AutomaticallyObtainQuestions. More...
 
void AutomaticallyObtainQuestions (BuildTreeStatsType &stats, const std::vector< std::vector< int32 > > &phone_sets_in, const std::vector< int32 > &all_pdf_classes_in, int32 P, std::vector< std::vector< int32 > > *questions_out)
 Outputs sets of phones that are reasonable for questions to ask in the tree-building algorithm. More...
 
void KMeansClusterPhones (BuildTreeStatsType &stats, const std::vector< std::vector< int32 > > &phone_sets_in, const std::vector< int32 > &all_pdf_classes_in, int32 P, int32 num_classes, std::vector< std::vector< int32 > > *sets_out)
 This function clusters the phones (or some initially specified sets of phones) into sets of phones, using a k-means algorithm. More...
 
void ReadRootsFile (std::istream &is, std::vector< std::vector< int32 > > *phone_sets, std::vector< bool > *is_shared_root, std::vector< bool > *is_split_root)
 Reads the roots file (throws on error). More...
 
static void TestClusterUtils ()
 
static void TestClusterUtilsVector ()
 
static void TestObjfPlus ()
 
static void TestObjfMinus ()
 
static void TestDistance ()
 
static void TestSumObjfAndSumNormalizer ()
 
static void TestSum ()
 
static void TestEnsureClusterableVectorNotNull ()
 
static void TestAddToClusters ()
 
static void TestAddToClustersOptimized ()
 
static void TestClusterBottomUp ()
 
static void TestRefineClusters ()
 
static void TestClusterKMeans ()
 
static void TestClusterKMeansVector ()
 
static void TestTreeCluster ()
 
static void TestClusterTopDown ()
 
BaseFloat SumClusterableObjf (const std::vector< Clusterable * > &vec)
 Returns the total objective function after adding up all the statistics in the vector (pointers may be NULL). More...
 
BaseFloat SumClusterableNormalizer (const std::vector< Clusterable * > &vec)
 Returns the total normalizer (usually count) of the cluster (pointers may be NULL). More...
 
ClusterableSumClusterable (const std::vector< Clusterable * > &vec)
 Sums stats (ptrs may be NULL). Returns NULL if no non-NULL stats present. More...
 
void EnsureClusterableVectorNotNull (std::vector< Clusterable * > *stats)
 Fills in any (NULL) holes in "stats" vector, with empty stats, because certain algorithms require non-NULL stats. More...
 
void AddToClusters (const std::vector< Clusterable * > &stats, const std::vector< int32 > &assignments, std::vector< Clusterable * > *clusters)
 Given stats and a vector "assignments" of the same size (that maps to cluster indices), sums the stats up into "clusters." It will add to any stats already present in "clusters" (although typically "clusters" will be empty when called), and it will extend with NULL pointers for any unseen indices. More...
 
void AddToClustersOptimized (const std::vector< Clusterable * > &stats, const std::vector< int32 > &assignments, const Clusterable &total, std::vector< Clusterable * > *clusters)
 AddToClustersOptimized does the same as AddToClusters (it sums up the stats within each cluster, except it uses the sum of all the stats ("total") to optimize the computation for speed, if possible. More...
 
BaseFloat ClusterBottomUp (const std::vector< Clusterable * > &points, BaseFloat thresh, int32 min_clust, std::vector< Clusterable * > *clusters_out, std::vector< int32 > *assignments_out)
 A bottom-up clustering algorithm. More...
 
bool operator> (const CompBotClustElem &a, const CompBotClustElem &b)
 
BaseFloat ClusterBottomUpCompartmentalized (const std::vector< std::vector< Clusterable * > > &points, BaseFloat thresh, int32 min_clust, std::vector< std::vector< Clusterable * > > *clusters_out, std::vector< std::vector< int32 > > *assignments_out)
 This is a bottom-up clustering where the points are pre-clustered in a set of compartments, such that only points in the same compartment are clustered together. More...
 
BaseFloat RefineClusters (const std::vector< Clusterable * > &points, std::vector< Clusterable * > *clusters, std::vector< int32 > *assignments, RefineClustersOptions cfg=RefineClustersOptions())
 RefineClusters is mainly used internally by other clustering algorithms. More...
 
BaseFloat ClusterKMeansOnce (const std::vector< Clusterable *> &points, int32 num_clust, std::vector< Clusterable *> *clusters_out, std::vector< int32 > *assignments_out, ClusterKMeansOptions &cfg)
 ClusterKMeansOnce is called internally by ClusterKMeans; it is equivalent to calling ClusterKMeans with cfg.num_tries == 1. More...
 
BaseFloat ClusterKMeans (const std::vector< Clusterable * > &points, int32 num_clust, std::vector< Clusterable * > *clusters_out, std::vector< int32 > *assignments_out, ClusterKMeansOptions cfg=ClusterKMeansOptions())
 ClusterKMeans is a K-means-like clustering algorithm. More...
 
BaseFloat TreeCluster (const std::vector< Clusterable * > &points, int32 max_clust, std::vector< Clusterable * > *clusters_out, std::vector< int32 > *assignments_out, std::vector< int32 > *clust_assignments_out, int32 *num_leaves_out, TreeClusterOptions cfg=TreeClusterOptions())
 TreeCluster is a top-down clustering algorithm, using a binary tree (not necessarily balanced). More...
 
BaseFloat ClusterTopDown (const std::vector< Clusterable * > &points, int32 max_clust, std::vector< Clusterable * > *clusters_out, std::vector< int32 > *assignments_out, TreeClusterOptions cfg=TreeClusterOptions())
 A clustering algorithm that internally uses TreeCluster, but does not give you the information about the structure of the tree. More...
 
void TestContextDep ()
 
void TestMonophoneContextDependency ()
 
void TestGenRandContextDependency ()
 
ContextDependencyGenRandContextDependency (const std::vector< int32 > &phones, bool ensure_all_covered, std::vector< int32 > *num_pdf_classes)
 GenRandContextDependency is mainly of use for debugging. More...
 
ContextDependencyGenRandContextDependencyLarge (const std::vector< int32 > &phones, int N, int P, bool ensure_all_covered, std::vector< int32 > *num_pdf_classes)
 GenRandContextDependencyLarge is like GenRandContextDependency but generates a larger tree with specified N and P for use in "one-time" larger-scale tests. More...
 
ContextDependencyMonophoneContextDependency (const std::vector< int32 > &phones, const std::vector< int32 > &phone2num_pdf_classes)
 
ContextDependencyMonophoneContextDependencyShared (const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes)
 
void TestEventMap ()
 
void TestEventTypeIo (bool binary)
 
EventMapRandomEventMap (const std::vector< EventKeyType > &keys)
 
void TestEventMapIo (bool binary)
 
void TestEventMapPrune ()
 
void TestEventMapMapValues ()
 
void WriteEventType (std::ostream &os, bool binary, const EventType &evec)
 
void ReadEventType (std::istream &is, bool binary, EventType *evec)
 
std::string EventTypeToString (const EventType &evec)
 
static bool IsLeafNode (const EventMap *e)
 
static bool GetTreeStructureInternal (const EventMap &map, std::vector< const EventMap *> *nonleaf_nodes, std::map< const EventMap *, const EventMap *> *nonleaf_parents, std::vector< const EventMap *> *leaf_parents)
 
bool GetTreeStructure (const EventMap &map, int32 *num_leaves, std::vector< int32 > *parents)
 This function gets the tree structure of the EventMap "map" in a convenient form. More...
 
std::pair< EventKeyType, EventValueTypeMakeEventPair (EventKeyType k, EventValueType v)
 
void ClusterGaussiansToUbm (const AmDiagGmm &am, const Vector< BaseFloat > &state_occs, UbmClusteringOptions opts, DiagGmm *ubm_out)
 Clusters the Gaussians in an acoustic model to a single GMM with specified number of components. More...
 
void InitRandomGmm (DiagGmm *gmm_in)
 
void UnitTestDiagGmmGenerate ()
 
void UnitTestDiagGmm ()
 
std::ostream & operator<< (std::ostream &os, const kaldi::DiagGmm &gmm)
 ostream operator that calls DiagGMM::Write() More...
 
std::istream & operator>> (std::istream &is, kaldi::DiagGmm &gmm)
 istream operator that calls DiagGMM::Read() More...
 
void UnitTestEstimateMmieDiagGmm ()
 
static bool EBWUpdateGaussian (BaseFloat D, GmmFlagsType flags, const VectorBase< double > &orig_mean, const VectorBase< double > &orig_var, const VectorBase< double > &x_stats, const VectorBase< double > &x2_stats, double occ, VectorBase< double > *mean, VectorBase< double > *var, double *auxf_impr)
 
void UpdateEbwDiagGmm (const AccumDiagGmm &num_stats, const AccumDiagGmm &den_stats, GmmFlagsType flags, const EbwOptions &opts, DiagGmm *gmm, BaseFloat *auxf_change_out, BaseFloat *count_out, int32 *num_floored_out)
 
void UpdateEbwWeightsDiagGmm (const AccumDiagGmm &num_stats, const AccumDiagGmm &den_stats, const EbwWeightOptions &opts, DiagGmm *gmm, BaseFloat *auxf_change_out, BaseFloat *count_out)
 
void UpdateEbwAmDiagGmm (const AccumAmDiagGmm &num_stats, const AccumAmDiagGmm &den_stats, GmmFlagsType flags, const EbwOptions &opts, AmDiagGmm *am_gmm, BaseFloat *auxf_change_out, BaseFloat *count_out, int32 *num_floored_out)
 
void UpdateEbwWeightsAmDiagGmm (const AccumAmDiagGmm &num_stats, const AccumAmDiagGmm &den_stats, const EbwWeightOptions &opts, AmDiagGmm *am_gmm, BaseFloat *auxf_change_out, BaseFloat *count_out)
 
void IsmoothStatsDiagGmm (const AccumDiagGmm &src_stats, double tau, AccumDiagGmm *dst_stats)
 I-Smooth the stats. src_stats and dst_stats do not have to be different. More...
 
void DiagGmmToStats (const DiagGmm &gmm, GmmFlagsType flags, double state_occ, AccumDiagGmm *dst_stats)
 Creates stats from the GMM. Resizes them as needed. More...
 
void IsmoothStatsAmDiagGmm (const AccumAmDiagGmm &src_stats, double tau, AccumAmDiagGmm *dst_stats)
 Smooth "dst_stats" with "src_stats". More...
 
void IsmoothStatsAmDiagGmmFromModel (const AmDiagGmm &src_model, double tau, AccumAmDiagGmm *dst_stats)
 This version of the I-smoothing function takes a model as input. More...
 
std::ostream & operator<< (std::ostream &rOut, const kaldi::FullGmm &gmm)
 ostream operator that calls FullGmm::Write() More...
 
std::istream & operator>> (std::istream &rIn, kaldi::FullGmm &gmm)
 istream operator that calls FullGmm::Read() More...
 
void GetSingleStatsDerivative (double ml_count, double ml_x_stats, double ml_x2_stats, double disc_count, double disc_x_stats, double disc_x2_stats, double model_mean, double model_var, BaseFloat min_variance, double *ml_x_stats_deriv, double *ml_x2_stats_deriv)
 
void GetStatsDerivative (const DiagGmm &gmm, const AccumDiagGmm &num_acc, const AccumDiagGmm &den_acc, const AccumDiagGmm &ml_acc, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AccumDiagGmm *out_accs)
 
void GetStatsDerivative (const AmDiagGmm &gmm, const AccumAmDiagGmm &num_accs, const AccumAmDiagGmm &den_accs, const AccumAmDiagGmm &ml_accs, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AccumAmDiagGmm *out_accs)
 
void DoRescalingUpdate (const AccumDiagGmm &old_ml_acc, const AccumDiagGmm &new_ml_acc, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, DiagGmm *gmm, double *tot_count, double *tot_divergence)
 
void DoRescalingUpdate (const AccumAmDiagGmm &old_ml_accs, const AccumAmDiagGmm &new_ml_accs, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AmDiagGmm *am_gmm)
 
void ResizeModel (int32 dim, AmDiagGmm *am_gmm)
 
void MleAmDiagGmmUpdate (const MleDiagGmmOptions &config, const AccumAmDiagGmm &amdiaggmm_acc, GmmFlagsType flags, AmDiagGmm *am_gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
 for computing the maximum-likelihood estimates of the parameters of an acoustic model that uses diagonal Gaussian mixture models as emission densities. More...
 
void MapAmDiagGmmUpdate (const MapDiagGmmOptions &config, const AccumAmDiagGmm &diag_gmm_acc, GmmFlagsType flags, AmDiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
 Maximum A Posteriori update. More...
 
BaseFloat MlObjective (const DiagGmm &gmm, const AccumDiagGmm &diaggmm_acc)
 Calc using the DiagGMM exponential form. More...
 
void MleDiagGmmUpdate (const MleDiagGmmOptions &config, const AccumDiagGmm &diag_gmm_acc, GmmFlagsType flags, DiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out, int32 *floored_elements_out=NULL, int32 *floored_gauss_out=NULL, int32 *removed_gauss_out=NULL)
 for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model. More...
 
void MapDiagGmmUpdate (const MapDiagGmmOptions &config, const AccumDiagGmm &diag_gmm_acc, GmmFlagsType flags, DiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
 Maximum A Posteriori estimation of the model. More...
 
GmmFlagsType AugmentGmmFlags (GmmFlagsType f)
 Returns "augmented" version of flags: e.g. More...
 
BaseFloat MlObjective (const FullGmm &gmm, const AccumFullGmm &fullgmm_acc)
 Calc using the DiagGMM exponential form. More...
 
void MleFullGmmUpdate (const MleFullGmmOptions &config, const AccumFullGmm &fullgmm_acc, GmmFlagsType flags, FullGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
 for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model. More...
 
GmmFlagsType StringToGmmFlags (std::string str)
 Convert string which is some subset of "mSwa" to flags. More...
 
std::string GmmFlagsToString (GmmFlagsType gmm_flags)
 Convert GMM flags to string. More...
 
SgmmUpdateFlagsType StringToSgmmUpdateFlags (std::string str)
 
SgmmUpdateFlagsType StringToSgmmWriteFlags (std::string str)
 
void GetSplitTargets (const Vector< BaseFloat > &state_occs, int32 target_components, BaseFloat power, BaseFloat min_count, std::vector< int32 > *targets)
 Get Gaussian-mixture or substate-mixture splitting targets, according to a power rule (e.g. More...
 
static BaseFloat CalBasisFmllrStepSize (const AffineXformStats &spk_stats, const Matrix< BaseFloat > &spk_stats_tmp_K, const std::vector< SpMatrix< BaseFloat > > &spk_stats_tmp_G, const Matrix< BaseFloat > &delta, const Matrix< BaseFloat > &A, const Matrix< BaseFloat > &S, int32 max_iters)
 This function takes the step direction (delta) of fMLLR matrix as argument, and optimize step size using Newton's method. More...
 
void InitCmvnStats (int32 dim, Matrix< double > *stats)
 This function initializes the matrix to dimension 2 by (dim+1); 1st "dim" elements of 1st row are mean stats, 1st "dim" elements of 2nd row are var stats, last element of 1st row is count, last element of 2nd row is zero. More...
 
void AccCmvnStats (const VectorBase< BaseFloat > &feat, BaseFloat weight, MatrixBase< double > *stats)
 Accumulation from a single frame (weighted). More...
 
void AccCmvnStats (const MatrixBase< BaseFloat > &feats, const VectorBase< BaseFloat > *weights, MatrixBase< double > *stats)
 Accumulation from a feature file (possibly weighted– useful in excluding silence). More...
 
void ApplyCmvn (const MatrixBase< double > &stats, bool norm_vars, MatrixBase< BaseFloat > *feats)
 Apply cepstral mean and variance normalization to a matrix of features. More...
 
void ApplyCmvnReverse (const MatrixBase< double > &stats, bool norm_vars, MatrixBase< BaseFloat > *feats)
 This is as ApplyCmvn, but does so in the reverse sense, i.e. More...
 
void FakeStatsForSomeDims (const std::vector< int32 > &dims, MatrixBase< double > *stats)
 Modify the stats so that for some dimensions (specified in "dims"), we replace them with "fake" stats that have zero mean and unit variance; this is done to disable CMVN for those dimensions. More...
 
static void ComputeGconsts (const VectorBase< BaseFloat > &weights, const MatrixBase< BaseFloat > &means, const MatrixBase< BaseFloat > &inv_vars, VectorBase< BaseFloat > *gconsts_out)
 
void UnitTestFmllrDiagGmm ()
 
void UnitTestFmllrDiagGmmDiagonal ()
 
void UnitTestFmllrDiagGmmOffset ()
 
BaseFloat ComputeFmllrMatrixDiagGmm (const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, std::string fmllr_type, int32 num_iters, MatrixBase< BaseFloat > *out_xform)
 This function internally calls ComputeFmllrMatrixDiagGmm{Full, Diagonal, Offset}, depending on "fmllr_type". More...
 
void FmllrInnerUpdate (SpMatrix< double > &inv_G, VectorBase< double > &k, double beta, int32 row, MatrixBase< double > *transform)
 This function does one row of the inner-loop fMLLR transform update. More...
 
BaseFloat ComputeFmllrMatrixDiagGmmFull (const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, int32 num_iters, MatrixBase< BaseFloat > *out_xform)
 Updates the FMLLR matrix using Mark Gales' row-by-row update. More...
 
BaseFloat ComputeFmllrMatrixDiagGmmDiagonal (const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *out_xform)
 This does diagonal fMLLR (i.e. More...
 
BaseFloat ComputeFmllrMatrixDiagGmmOffset (const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *out_xform)
 This does offset-only fMLLR, i.e. it only estimates an offset. More...
 
void ApplyFeatureTransformToStats (const MatrixBase< BaseFloat > &xform, AffineXformStats *stats)
 This function applies a feature-level transform to stats (useful for certain techniques based on fMLLR). More...
 
void ApplyModelTransformToStats (const MatrixBase< BaseFloat > &xform, AffineXformStats *stats)
 ApplyModelTransformToStats takes a transform "xform", which must be diagonal (i.e. More...
 
float FmllrAuxFuncDiagGmm (const MatrixBase< float > &xform, const AffineXformStats &stats)
 Returns the (diagonal-GMM) FMLLR auxiliary function value given the transform and the stats. More...
 
double FmllrAuxFuncDiagGmm (const MatrixBase< double > &xform, const AffineXformStats &stats)
 
BaseFloat FmllrAuxfGradient (const MatrixBase< BaseFloat > &xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *grad_out)
 Returns the (diagonal-GMM) FMLLR auxiliary function value given the transform and the stats. More...
 
void InitFmllr (int32 dim, Matrix< BaseFloat > *out_fmllr)
 
BaseFloat ComputeFmllrDiagGmm (const FmllrDiagGmmAccs &accs, const FmllrOptions &opts, Matrix< BaseFloat > *out_fmllr, BaseFloat *logdet)
 
BaseFloat ComputeFmllrLogDet (const Matrix< BaseFloat > &fmllr_mat)
 
BaseFloat ComputeFmllrMatrixDiagGmmDiagonal2 (const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *out_xform)
 
void UnitTestFmllrRaw (bool use_offset)
 
void GetFeatDeriv (const DiagGmm &gmm, const Matrix< BaseFloat > &feats, Matrix< BaseFloat > *deriv)
 
BaseFloat GetGmmLike (const DiagGmm &gmm, const Matrix< BaseFloat > &feats)
 
void TestFmpe ()
 
BaseFloat ComputeAmGmmFeatureDeriv (const AmDiagGmm &am_gmm, const TransitionModel &trans_model, const Posterior &posterior, const MatrixBase< BaseFloat > &features, Matrix< BaseFloat > *direct_deriv, const AccumAmDiagGmm *model_diff=NULL, Matrix< BaseFloat > *indirect_deriv=NULL)
 Computes derivatives of the likelihood of these states (weighted), w.r.t. More...
 
static bool GetActiveParents (int32 node, const vector< int32 > &parents, const vector< bool > &is_active, vector< int32 > *active_parents_out)
 
static void RandFullCova (Matrix< BaseFloat > *matrix)
 
static void generate_features (cova_type covariance_type, size_t n_gaussians, size_t dim, Matrix< BaseFloat > &trans_mat, size_t frames_per_gaussian, std::vector< Vector< BaseFloat > *> &train_feats, std::vector< Vector< BaseFloat > *> &adapt_feats)
 
void UnitTestRegtreeFmllrDiagGmm (cova_type feature_type, size_t max_bclass)
 
static void ComputeMllrMatrix (const Matrix< double > &K, const vector< SpMatrix< double > > &G, Matrix< BaseFloat > *out)
 
static BaseFloat MllrAuxFunction (const Matrix< BaseFloat > &xform, const AffineXformStats &stats)
 
bool ComposeTransforms (const Matrix< BaseFloat > &a, const Matrix< BaseFloat > &b, bool b_is_affine, Matrix< BaseFloat > *c)
 
void ApplyAffineTransform (const MatrixBase< BaseFloat > &xform, VectorBase< BaseFloat > *vec)
 Applies the affine transform 'xform' to the vector 'vec' and overwrites the contents of 'vec'. More...
 
TransitionModelGenRandTransitionModel (ContextDependency **ctx_dep_out)
 
HmmTopology GetDefaultTopology (const std::vector< int32 > &phones)
 This function returns a HmmTopology object giving a normal 3-state topology, covering all phones in the list "phones". More...
 
HmmTopology GenRandTopology (const std::vector< int32 > &phones, const std::vector< int32 > &num_pdf_classes)
 This method of generating an arbitrary HmmTopology object allows you to specify the number of pdf-classes for each phone separately. More...
 
HmmTopology GenRandTopology ()
 This version of GenRandTopology() generates the phone list and number of pdf classes randomly. More...
 
void GeneratePathThroughHmm (const HmmTopology &topology, bool reorder, int32 phone, std::vector< std::pair< int32, int32 > > *path)
 This function generates a random path through the HMM for the given phone. More...
 
void GenerateRandomAlignment (const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, bool reorder, const std::vector< int32 > &phone_sequence, std::vector< int32 > *alignment)
 For use in test code, this function generates an alignment (a sequence of transition-ids) corresponding to a given phone sequence. More...
 
void TestHmmTopology ()
 
void TestConvertPhnxToProns ()
 
void TestAccumulateTreeStatsOptions ()
 
void TestSplitToPhones ()
 
void TestConvertAlignment ()
 
fst::VectorFst< fst::StdArc > * GetHmmAsFsa (std::vector< int32 > context_window, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const HTransducerConfig &config, HmmCacheType *cache=NULL)
 Called by GetHTransducer() and probably will not need to be called directly; it creates and returns the FST corresponding to the phone. More...
 
fst::VectorFst< fst::StdArc > * GetHmmAsFsaSimple (std::vector< int32 > context_window, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, BaseFloat prob_scale)
 Included mainly as a form of documentation, not used in any other code currently. More...
 
static fst::VectorFst< fst::StdArc > * MakeTrivialAcceptor (int32 label)
 This utility function, used in GetHTransducer(), creates an FSA (finite state acceptor, i.e. More...
 
fst::VectorFst< fst::StdArc > * GetHTransducer (const std::vector< std::vector< int32 > > &ilabel_info, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const HTransducerConfig &config, std::vector< int32 > *disambig_syms_left)
 Returns the H tranducer; result owned by caller. More...
 
void GetIlabelMapping (const std::vector< std::vector< int32 > > &ilabel_info_old, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, std::vector< int32 > *old2new_map)
 GetIlabelMapping produces a mapping that's similar to HTK's logical-to-physical model mapping (i.e. More...
 
fst::VectorFst< fst::StdArc > * GetPdfToTransitionIdTransducer (const TransitionModel &trans_model)
 Returns a transducer from pdfs plus one (input) to transition-ids (output). More...
 
static void AddSelfLoopsReorder (const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
 
static void AddSelfLoopsNoReorder (const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
 
void AddSelfLoops (const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool reorder, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
 For context, see AddSelfLoops(). More...
 
static bool IsReordered (const TransitionModel &trans_model, const std::vector< int32 > &alignment)
 
static bool SplitToPhonesInternal (const TransitionModel &trans_model, const std::vector< int32 > &alignment, bool reordered, std::vector< std::vector< int32 > > *split_output)
 
bool SplitToPhones (const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
 SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per instance of a phone). More...
 
static void ConvertAlignmentForPhone (const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_phone_alignment, const std::vector< int32 > &new_phone_window, bool old_is_reordered, bool new_is_reordered, std::vector< int32 > *new_phone_alignment)
 This function is used internally inside ConvertAlignment; it converts the alignment for a single phone. More...
 
static bool ComputeNewPhoneLengths (const HmmTopology &topology, const std::vector< int32 > &mapped_phones, const std::vector< int32 > &old_lengths, int32 conversion_shift, int32 subsample_factor, std::vector< int32 > *new_lengths)
 This function, called from ConvertAlignmentInternal(), works out suitable new lengths of phones in the case where subsample_factor != 1. More...
 
static bool ConvertAlignmentInternal (const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_alignment, int32 conversion_shift, int32 subsample_factor, bool new_is_reordered, const std::vector< int32 > *phone_map, std::vector< int32 > *new_alignment)
 This function is the same as 'ConvertAligment', but instead of the 'repeat_frames' option it supports the 'conversion_shift' option; see the documentation of ComputeNewPhoneLengths() for what 'conversion_shift' is for. More...
 
bool ConvertAlignment (const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_alignment, int32 subsample_factor, bool repeat_frames, bool reorder, const std::vector< int32 > *phone_map, std::vector< int32 > *new_alignment)
 ConvertAlignment converts an alignment that was created using one model, to another model. More...
 
static BaseFloat GetScaledTransitionLogProb (const TransitionModel &trans_model, int32 trans_id, BaseFloat transition_scale, BaseFloat self_loop_scale)
 
void AddTransitionProbs (const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat transition_scale, BaseFloat self_loop_scale, fst::VectorFst< fst::StdArc > *fst)
 Adds transition-probs, with the supplied scales (see Scaling of transition and acoustic probabilities), to the graph. More...
 
void AddTransitionProbs (const TransitionModel &trans_model, BaseFloat transition_scale, BaseFloat self_loop_scale, Lattice *lat)
 This is as AddSelfLoops(), but operates on a Lattice, where it affects the graph part of the weight (the first element of the pair). More...
 
bool ConvertPhnxToProns (const std::vector< int32 > &phnx, const std::vector< int32 > &words, int32 word_start_sym, int32 word_end_sym, std::vector< std::vector< int32 > > *prons)
 
void GetRandomAlignmentForPhone (const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const std::vector< int32 > &phone_window, std::vector< int32 > *alignment)
 
void ChangeReorderingOfAlignment (const TransitionModel &trans_model, std::vector< int32 > *alignment)
 
void GetPdfToPhonesMap (const TransitionModel &trans_model, std::vector< std::set< int32 > > *pdf2phones)
 
void ConvertTransitionIdsToPdfs (const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, fst::VectorFst< fst::StdArc > *fst)
 Converts all transition-ids in the FST to pdfs plus one. More...
 
void TestVectorToPosteriorEntry ()
 
void TestPosteriorIo ()
 
void WritePosterior (std::ostream &os, bool binary, const Posterior &post)
 stand-alone function for writing a Posterior. More...
 
void ReadPosterior (std::istream &os, bool binary, Posterior *post)
 stand-alone function for reading a Posterior. More...
 
void ScalePosterior (BaseFloat scale, Posterior *post)
 Scales the BaseFloat (weight) element in the posterior entries. More...
 
BaseFloat TotalPosterior (const Posterior &post)
 Returns the total of all the weights in "post". More...
 
bool PosteriorEntriesAreDisjoint (const std::vector< std::pair< int32, BaseFloat > > &post_elem1, const std::vector< std::pair< int32, BaseFloat > > &post_elem2)
 Returns true if the two lists of pairs have no common .first element. More...
 
int32 MergePosteriors (const Posterior &post1, const Posterior &post2, bool merge, bool drop_frames, Posterior *post)
 Merge two sets of posteriors, which must have the same length. More...
 
void AlignmentToPosterior (const std::vector< int32 > &ali, Posterior *post)
 Convert an alignment to a posterior (with a scale of 1.0 on each entry). More...
 
void SortPosteriorByPdfs (const TransitionModel &tmodel, Posterior *post)
 Sorts posterior entries so that transition-ids with same pdf-id are next to each other. More...
 
void ConvertPosteriorToPdfs (const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
 Converts a posterior over transition-ids to be a posterior over pdf-ids. More...
 
void ConvertPosteriorToPhones (const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
 Converts a posterior over transition-ids to be a posterior over phones. More...
 
void WeightSilencePost (const TransitionModel &trans_model, const ConstIntegerSet< int32 > &silence_set, BaseFloat silence_scale, Posterior *post)
 Weight any silence phones in the posterior (i.e. More...
 
void WeightSilencePostDistributed (const TransitionModel &trans_model, const ConstIntegerSet< int32 > &silence_set, BaseFloat silence_scale, Posterior *post)
 This is similar to WeightSilencePost, except that on each frame it works out the amount by which the overall posterior would be reduced, and scales down everything on that frame by the same amount. More...
 
static BaseFloat GetTotalPosterior (const std::vector< std::pair< int32, BaseFloat > > &post_entry)
 
BaseFloat VectorToPosteriorEntry (const VectorBase< BaseFloat > &log_likes, int32 num_gselect, BaseFloat min_post, std::vector< std::pair< int32, BaseFloat > > *post_entry)
 Given a vector of log-likelihoods (typically of Gaussians in a GMM but could be of pdf-ids), a number gselect >= 1 and a minimum posterior 0 <= min_post < 1, it gets the posterior for each element of log-likes by applying Softmax(), then prunes the posteriors using "gselect" and "min_post" (keeping at least one), and outputs the result into "post_entry", sorted from greatest to least posterior. More...
 
template<typename Real >
void PosteriorToMatrix (const Posterior &post, const int32 post_dim, Matrix< Real > *mat)
 This converts a Posterior to a Matrix. More...
 
template void PosteriorToMatrix< float > (const Posterior &post, const int32 post_dim, Matrix< float > *mat)
 
template void PosteriorToMatrix< double > (const Posterior &post, const int32 post_dim, Matrix< double > *mat)
 
template<typename Real >
void PosteriorToPdfMatrix (const Posterior &post, const TransitionModel &model, Matrix< Real > *mat)
 This converts a Posterior to a Matrix. More...
 
template void PosteriorToPdfMatrix< float > (const Posterior &post, const TransitionModel &model, Matrix< float > *mat)
 
template void PosteriorToPdfMatrix< double > (const Posterior &post, const TransitionModel &model, Matrix< double > *mat)
 
void TestTransitionModel ()
 
bool GetPdfsForPhones (const TransitionModel &trans_model, const std::vector< int32 > &phones, std::vector< int32 > *pdfs)
 Works out which pdfs might correspond to the given phones. More...
 
bool GetPhonesForPdfs (const TransitionModel &trans_model, const std::vector< int32 > &pdfs, std::vector< int32 > *phones)
 Works out which phones might correspond to the given pdfs. More...
 
static int32 MapPhone (const std::vector< int32 > &phone_map, int32 phone)
 
void TrimTrailingWhitespace (std::string *str)
 
static fst::StdVectorFstCreateGenFst (bool seps, const fst::SymbolTable *pst)
 
ArpaLmCompilerCompile (bool seps, const std::string &infile)
 
fst::StdArc::StateId AddToChainFsa (fst::StdMutableFst *fst, fst::StdArc::StateId last_state, int64 symbol)
 
void AddSelfLoops (fst::StdMutableFst *fst)
 
bool CoverageTest (bool seps, const std::string &infile)
 
bool ScoringTest (bool seps, const std::string &infile, const std::string &sentence, float expected)
 
bool ThrowsExceptionTest (bool seps, const std::string &infile)
 
bool BuildConstArpaLm (const ArpaParseOptions &options, const std::string &arpa_rxfilename, const std::string &const_arpa_wxfilename)
 
template<typename FST >
bool DecodeUtteranceLatticeIncremental (LatticeIncrementalDecoderTpl< FST > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignments_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 TODO. More...
 
template<typename FST >
bool DecodeUtteranceLatticeFaster (LatticeFasterDecoderTpl< FST > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignments_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 This function DecodeUtteranceLatticeFaster is used in several decoders, and we have moved it here. More...
 
template bool DecodeUtteranceLatticeIncremental (LatticeIncrementalDecoderTpl< fst::Fst< fst::StdArc > > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
template bool DecodeUtteranceLatticeIncremental (LatticeIncrementalDecoderTpl< fst::GrammarFst > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
template bool DecodeUtteranceLatticeFaster (LatticeFasterDecoderTpl< fst::Fst< fst::StdArc > > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
template bool DecodeUtteranceLatticeFaster (LatticeFasterDecoderTpl< fst::GrammarFst > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
bool DecodeUtteranceLatticeSimple (LatticeSimpleDecoder &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
void ModifyGraphForCarefulAlignment (fst::VectorFst< fst::StdArc > *fst)
 This function modifies the decoding graph for what we call "careful alignment". More...
 
void AlignUtteranceWrapper (const AlignConfig &config, const std::string &utt, BaseFloat acoustic_scale, fst::VectorFst< fst::StdArc > *fst, DecodableInterface *decodable, Int32VectorWriter *alignment_writer, BaseFloatWriter *scores_writer, int32 *num_done, int32 *num_error, int32 *num_retried, double *tot_like, int64 *frame_count, BaseFloatVectorWriter *per_frame_acwt_writer=NULL)
 AlignUtteranceWapper is a wrapper for alignment code used in training, that is called from many different binaries, e.g. More...
 
static void AddCompactLatticeArcToLattice (const CompactLatticeArc &clat_arc, LatticeArc::StateId src_state, Lattice *lat)
 
static int32 TotalNumArcs (const CompactLattice &clat)
 
void ComposeCompactLatticePruned (const ComposeLatticePrunedOptions &opts, const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat)
 Does pruned composition of a lattice 'clat' with a DeterministicOnDemandFst 'det_fst'; implements LM rescoring. More...
 
BaseFloat SentenceLevelConfidence (const CompactLattice &clat, int32 *num_paths, std::vector< int32 > *best_sentence, std::vector< int32 > *second_best_sentence)
 Caution: this function is not the only way to get confidences in Kaldi. More...
 
BaseFloat SentenceLevelConfidence (const Lattice &lat, int32 *num_paths, std::vector< int32 > *best_sentence, std::vector< int32 > *second_best_sentence)
 This version of SentenceLevelConfidence takes as input a state-level lattice. More...
 
CompactLatticeRandCompactLattice ()
 
LatticeRandLattice ()
 
void TestCompactLatticeTable (bool binary)
 
void TestCompactLatticeTableCross (bool binary)
 
void TestLatticeTable (bool binary)
 
void TestLatticeTableCross (bool binary)
 
template<class OrigWeightType >
CompactLatticeConvertToCompactLattice (fst::VectorFst< OrigWeightType > *ifst)
 Converts lattice types if necessary, deleting its input. More...
 
template<>
CompactLatticeConvertToCompactLattice (CompactLattice *ifst)
 
template<class OrigWeightType >
LatticeConvertToLattice (fst::VectorFst< OrigWeightType > *ifst)
 Converts lattice types if necessary, deleting its input. More...
 
template<>
LatticeConvertToLattice (Lattice *ifst)
 
bool WriteCompactLattice (std::ostream &os, bool binary, const CompactLattice &t)
 
CompactLatticeReadCompactLatticeText (std::istream &is)
 
LatticeReadLatticeText (std::istream &is)
 
bool ReadCompactLattice (std::istream &is, bool binary, CompactLattice **clat)
 
bool WriteLattice (std::ostream &os, bool binary, const Lattice &t)
 
bool ReadLattice (std::istream &is, bool binary, Lattice **lat)
 
void GetPerFrameAcousticCosts (const Lattice &nbest, Vector< BaseFloat > *per_frame_loglikes)
 This function extracts the per-frame log likelihoods from a linear lattice (which we refer to as an 'nbest' lattice elsewhere in Kaldi code). More...
 
int32 LatticeStateTimes (const Lattice &lat, vector< int32 > *times)
 This function iterates over the states of a topologically sorted lattice and counts the time instance corresponding to each state. More...
 
int32 CompactLatticeStateTimes (const CompactLattice &lat, vector< int32 > *times)
 As LatticeStateTimes, but in the CompactLattice format. More...
 
bool ComputeCompactLatticeAlphas (const CompactLattice &clat, vector< double > *alpha)
 
bool ComputeCompactLatticeBetas (const CompactLattice &clat, vector< double > *beta)
 
template<class LatType >
bool PruneLattice (BaseFloat beam, LatType *lat)
 
template bool PruneLattice (BaseFloat beam, Lattice *lat)
 
template bool PruneLattice (BaseFloat beam, CompactLattice *lat)
 
BaseFloat LatticeForwardBackward (const Lattice &lat, Posterior *arc_post, double *acoustic_like_sum=NULL)
 This function does the forward-backward over lattices and computes the posterior probabilities of the arcs. More...
 
void LatticeActivePhones (const Lattice &lat, const TransitionModel &trans, const vector< int32 > &silence_phones, vector< std::set< int32 > > *active_phones)
 Given a lattice, and a transition model to map pdf-ids to phones, outputs for each frame the set of phones active on that frame. More...
 
void ConvertLatticeToPhones (const TransitionModel &trans_model, Lattice *lat)
 Given a lattice, and a transition model to map pdf-ids to phones, replace the output symbols (presumably words), with phones; we use the TransitionModel to work out the phone sequence. More...
 
static double LogAddOrMax (bool viterbi, double a, double b)
 
template<typename LatticeType >
double ComputeLatticeAlphasAndBetas (const LatticeType &lat, bool viterbi, vector< double > *alpha, vector< double > *beta)
 
template double ComputeLatticeAlphasAndBetas (const Lattice &lat, bool viterbi, vector< double > *alpha, vector< double > *beta)
 
template double ComputeLatticeAlphasAndBetas (const CompactLattice &lat, bool viterbi, vector< double > *alpha, vector< double > *beta)
 
void CompactLatticeLimitDepth (int32 max_arcs_per_frame, CompactLattice *clat)
 This function limits the depth of the lattice, per frame: that means, it does not allow more than a specified number of arcs active on any given frame. More...
 
void TopSortCompactLatticeIfNeeded (CompactLattice *clat)
 Topologically sort the compact lattice if not already topologically sorted. More...
 
void TopSortLatticeIfNeeded (Lattice *clat)
 Topologically sort the lattice if not already topologically sorted. More...
 
BaseFloat CompactLatticeDepth (const CompactLattice &clat, int32 *num_frames)
 Returns the depth of the lattice, defined as the average number of arcs crossing any given frame. More...
 
void CompactLatticeDepthPerFrame (const CompactLattice &clat, std::vector< int32 > *depth_per_frame)
 This function returns, for each frame, the number of arcs crossing that frame. More...
 
void ConvertCompactLatticeToPhones (const TransitionModel &trans_model, CompactLattice *clat)
 Given a lattice, and a transition model to map pdf-ids to phones, replace the sequences of transition-ids with sequences of phones. More...
 
bool LatticeBoost (const TransitionModel &trans, const std::vector< int32 > &alignment, const std::vector< int32 > &silence_phones, BaseFloat b, BaseFloat max_silence_error, Lattice *lat)
 Boosts LM probabilities by b * [number of frame errors]; equivalently, adds -b*[number of frame errors] to the graph-component of the cost of each arc/path. More...
 
BaseFloat LatticeForwardBackwardMpeVariants (const TransitionModel &trans, const std::vector< int32 > &silence_phones, const Lattice &lat, const std::vector< int32 > &num_ali, std::string criterion, bool one_silence_class, Posterior *post)
 This function implements either the MPFE (minimum phone frame error) or SMBR (state-level minimum bayes risk) forward-backward, depending on whether "criterion" is "mpfe" or "smbr". More...
 
bool CompactLatticeToWordAlignment (const CompactLattice &clat, std::vector< int32 > *words, std::vector< int32 > *begin_times, std::vector< int32 > *lengths)
 This function takes a CompactLattice that should only contain a single linear sequence (e.g. More...
 
bool CompactLatticeToWordProns (const TransitionModel &tmodel, const CompactLattice &clat, std::vector< int32 > *words, std::vector< int32 > *begin_times, std::vector< int32 > *lengths, std::vector< std::vector< int32 > > *prons, std::vector< std::vector< int32 > > *phone_lengths)
 This function takes a CompactLattice that should only contain a single linear sequence (e.g. More...
 
void CompactLatticeShortestPath (const CompactLattice &clat, CompactLattice *shortest_path)
 A form of the shortest-path/best-path algorithm that's specially coded for CompactLattice. More...
 
void AddWordInsPenToCompactLattice (BaseFloat word_ins_penalty, CompactLattice *clat)
 This function add the word insertion penalty to graph score of each word in the compact lattice. More...
 
bool RescoreCompactLatticeInternal (const TransitionModel *tmodel, BaseFloat speedup_factor, DecodableInterface *decodable, CompactLattice *clat)
 RescoreCompactLatticeInternal is the internal code for both RescoreCompactLattice and RescoreCompatLatticeSpeedup. More...
 
bool RescoreCompactLatticeSpeedup (const TransitionModel &tmodel, BaseFloat speedup_factor, DecodableInterface *decodable, CompactLattice *clat)
 This function is like RescoreCompactLattice, but it is modified to avoid computing probabilities on most frames where all the pdf-ids are the same. More...
 
bool RescoreCompactLattice (DecodableInterface *decodable, CompactLattice *clat)
 This function *adds* the negated scores obtained from the Decodable object, to the acoustic scores on the arcs. More...
 
bool RescoreLattice (DecodableInterface *decodable, Lattice *lat)
 This function *adds* the negated scores obtained from the Decodable object, to the acoustic scores on the arcs. More...
 
BaseFloat LatticeForwardBackwardMmi (const TransitionModel &trans, const Lattice &lat, const std::vector< int32 > &num_ali, bool drop_frames, bool convert_to_pdf_ids, bool cancel, Posterior *arc_post)
 This function can be used to compute posteriors for MMI, with a positive contribution for the numerator and a negative one for the denominator. More...
 
int32 LongestSentenceLength (const Lattice &lat)
 This function returns the number of words in the longest sentence in a CompactLattice (i.e. More...
 
int32 LongestSentenceLength (const CompactLattice &lat)
 This function returns the number of words in the longest sentence in a CompactLattice, i.e. More...
 
void ComposeCompactLatticeDeterministic (const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat)
 This function Composes a CompactLattice format lattice with a DeterministicOnDemandFst<fst::StdFst> format fst, and outputs another CompactLattice format lattice. More...
 
void ComputeAcousticScoresMap (const Lattice &lat, unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > *acoustic_scores)
 This function computes the mapping from the pair (frame-index, transition-id) to the pair (sum-of-acoustic-scores, num-of-occurences) over all occurences of the transition-id in that frame. More...
 
void ReplaceAcousticScoresFromMap (const unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > &acoustic_scores, Lattice *lat)
 This function restores acoustic scores computed using the function ComputeAcousticScoresMap into the lattice. More...
 
int32 LatticeStateTimes (const Lattice &lat, std::vector< int32 > *times)
 This function iterates over the states of a topologically sorted lattice and counts the time instance corresponding to each state. More...
 
int32 CompactLatticeStateTimes (const CompactLattice &clat, std::vector< int32 > *times)
 As LatticeStateTimes, but in the CompactLattice format. More...
 
bool ComputeCompactLatticeAlphas (const CompactLattice &lat, std::vector< double > *alpha)
 
bool ComputeCompactLatticeBetas (const CompactLattice &lat, std::vector< double > *beta)
 
template<typename LatticeType >
double ComputeLatticeAlphasAndBetas (const LatticeType &lat, bool viterbi, std::vector< double > *alpha, std::vector< double > *beta)
 
void LatticeActivePhones (const Lattice &lat, const TransitionModel &trans, const std::vector< int32 > &sil_phones, std::vector< std::set< int32 > > *active_phones)
 Given a lattice, and a transition model to map pdf-ids to phones, outputs for each frame the set of phones active on that frame. More...
 
template<class LatticeType >
bool PruneLattice (BaseFloat beam, LatticeType *lat)
 Prunes a lattice or compact lattice. More...
 
CompactLatticeRandDeterministicCompactLattice ()
 
void TestMinimizeCompactLattice ()
 
bool PhoneAlignLattice (const CompactLattice &lat, const TransitionModel &tmodel, const PhoneAlignLatticeOptions &opts, CompactLattice *lat_out)
 Outputs a lattice in which the arcs correspond exactly to sequences of phones, so the boundaries between the arcs correspond to the boundaries between phones If remove-epsilon == false and replace-output-symbols == false, but an arc may have >1 phone on it, but the boundaries will still correspond with the boundaries between phones. More...
 
void TestPushCompactLatticeStrings ()
 
void TestPushCompactLatticeWeights ()
 
void GenerateLexicon (const std::vector< int32 > &phones, bool allow_zero_words, bool allow_empty_word, bool allow_multiple_prons, std::vector< std::vector< int32 > > *lexicon)
 
static void PrintLexicon (const std::vector< std::vector< int32 > > &lexicon)
 
static void PrintWordsAndPhones (const std::vector< int32 > &words, const std::vector< int32 > &phones)
 
void GenerateWordAndPhoneSequence (std::vector< std::vector< int32 > > &lexicon, std::vector< int32 > *phone_seq, std::vector< int32 > *word_seq)
 
void GenerateCompactLatticeRandomly (const std::vector< int32 > &alignment, const std::vector< int32 > &words, CompactLattice *clat)
 
void TestWordAlignLatticeLexicon ()
 
static bool IsPlausibleWord (const WordAlignLatticeLexiconInfo &lexicon_info, const TransitionModel &tmodel, int32 word_id, const std::vector< int32 > &transition_ids)
 
static void MapSymbols (const WordAlignLatticeLexiconInfo &lexicon_info, CompactLattice *lat)
 Testing code; map word symbols in the lattice "lat" using the equivalence-classes obtained from the lexicon, using the function EquivalenceClassOf in the lexicon_info object. More...
 
static bool TestWordAlignedLattice (const WordAlignLatticeLexiconInfo &lexicon_info, const TransitionModel &tmodel, CompactLattice clat, CompactLattice aligned_clat, bool allow_duplicate_paths)
 
bool WordAlignLatticeLexicon (const CompactLattice &lat, const TransitionModel &tmodel, const WordAlignLatticeLexiconInfo &lexicon_info, const WordAlignLatticeLexiconOpts &opts, CompactLattice *lat_out)
 Align lattice so that each arc has the transition-ids on it that correspond to the word that is on that arc. More...
 
bool ReadLexiconForWordAlign (std::istream &is, std::vector< std::vector< int32 > > *lexicon)
 Read the lexicon in the special format required for word alignment. More...
 
void TestWordAlignedLatticeLexicon (const CompactLattice &lat, const TransitionModel &tmodel, const std::vector< std::vector< int32 > > &lexicon, const CompactLattice &aligned_lat, bool allow_duplicate_paths)
 This function is designed to crash if something went wrong with the word-alignment of the lattice. More...
 
static bool IsPlausibleWord (const WordBoundaryInfo &info, const TransitionModel &tmodel, const std::vector< int32 > &transition_ids)
 
bool WordAlignLattice (const CompactLattice &lat, const TransitionModel &tmodel, const WordBoundaryInfo &info, int32 max_states, CompactLattice *lat_out)
 Align lattice so that each arc has the transition-ids on it that correspond to the word that is on that arc. More...
 
void TestWordAlignedLattice (const CompactLattice &lat, const TransitionModel &tmodel, const WordBoundaryInfo &info, const CompactLattice &aligned_lat)
 You should only test a lattice if WordAlignLattice returned true (i.e. More...
 
void RegisterCuAllocatorOptions (OptionsItf *po)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const CuArray< T > &vec)
 Print the vector to stream. More...
 
template<class T >
void AssertEqual (const std::vector< T > &vec1, const std::vector< T > &vec2)
 
template<class T >
static void UnitTestCuArray ()
 
template<typename Real >
static bool ApproxEqual (const CuBlockMatrix< Real > &A, const CuBlockMatrix< Real > &B, float tol=0.001)
 
template<class Real >
static void UnitTestCuBlockMatrixIO ()
 
template<class Real >
static void UnitTestCuBlockMatrixAddMatBlock ()
 
template<class Real >
static void UnitTestCuBlockMatrixAddMatMat ()
 
template<typename Real >
void CuBlockMatrixUnitTest ()
 
template<typename Real >
std::ostream & operator<< (std::ostream &out, const CuBlockMatrix< Real > &mat)
 Print the matrix to stream. More...
 
template std::ostream & operator<< (std::ostream &out, const CuBlockMatrix< float > &mat)
 
template std::ostream & operator<< (std::ostream &out, const CuBlockMatrix< double > &mat)
 
void CuCompressedMatrixTestSign ()
 
void CuCompressedMatrixTestNonnegative ()
 
void CuCompressedMatrixTestSymmetric ()
 
CuCompressedMatrixBaseNewCuCompressedMatrix (CuCompressedMatrixType t, BaseFloat range, bool truncate=true)
 This function allocates a new CuCompressedMatrix with type determined by t, and with the 'range' and 'truncate' parameters provided to the constructor of class CuCompressedMatrix. More...
 
template<typename Real >
void TestCuMatrixResize (int32 size_multiple)
 
template<typename Real >
void CudaMatrixResizeTest ()
 
void SynchronizeGpu ()
 The function SynchronizeGpu(), which for convenience is defined whether or not we have compiled for CUDA, is intended to be called in places where threads need to be synchronized. More...
 
template<typename Real >
static void UnitTestCuMathRandomize ()
 
template<typename Real >
static void UnitTestEnsureNonzero ()
 
template<typename Real >
static void UnitTestCuMathCopy ()
 
template<typename Real >
static void UnitTestCuMathSplice ()
 
template<typename Real >
static void UnitTestCuMathComputeLstmNonlinearity ()
 
void UnitTestLstmNonlinearity ()
 
template<typename Real >
static void UnitTestBackpropLstmNonlinearity ()
 
template<typename Real >
static void UnitTestCuMathNormalizePerRow ()
 
template<typename Real >
static void UnitTestCuMathNormalizePerRow_v2 ()
 
template<typename Real >
static void UnitTestCuDiffNormalizePerRow ()
 
template<typename Real >
void CudaMathUnitTest ()
 
template<typename Real >
void TestCuMatrixSum (int32 dim)
 
template<typename Real >
void TestCuMatrixMax (int32 dim)
 
template<typename Real >
void TestCuMatrixMin (int32 dim)
 
template<typename Real >
void TestCuMatrixDivRowsVec (int32 dim)
 
template<typename Real >
void TestCuMatrixTransposeNS (int32 dim)
 
template<typename Real >
void TestCuMatrixTransposeS (int32 dim)
 
template<typename Real >
void TestCuMatrixTransposeCross (int32 dim)
 
template<typename Real >
void TestCuMatrixAddMat (int32 dim, int32 num_row_blocks, int32 num_col_blocks)
 
template<typename Real >
void TestCuMatrixAddMatBlocks (int32 dim, int32 num_row_blocks, int32 num_col_blocks)
 
template<typename Real >
void TestCuMatrixMatMat (int32 dim)
 
template<typename Real >
void TestCuMatrixMatMatBatched (int32 dim, int32 batchCount)
 
template<typename Real >
void TestCuMatrixAddDiagVecMat (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestSymInvertPosDef (int32 dim)
 
template<typename Real >
static void TestCuMatrixCompObjfAndDeriv (int32 dim)
 
template<typename Real >
static void TestCuFindRowMaxId (int32 dim)
 
template<typename Real >
void TestCuMatrixSigmoid (int32 dim)
 
template<typename Real >
void TestCuMatrixHeaviside (int32 dim)
 
template<typename Real >
void TestCuMatrixMulRowsGroupMat (int32 dim)
 
template<typename Real >
void TestCuMatrixDiffSoftmax (int32 dim)
 
template<typename Real >
void TestCuMatrixDiffLogSoftmax (int32 dim)
 
template<typename Real >
void TestCuMatrixSoftmax (int32 dim)
 
template<typename Real >
void TestCuMatrixLogSoftmax (int32 dim)
 
template<typename Real >
void TestCuMatrixGroupPnorm (int32 dim)
 
template<typename Real >
void TestCuMatrixDiffGroupPnorm (int32 dim)
 
template<typename Real >
void TestCuMatrixGroupMax (int32 dim)
 
template<typename Real >
void TestCuMatrixGroupMaxAllGroupSizes (int32 dim)
 
template<typename Real >
void TestCuMatrixGroupMaxDeriv (int32 dim)
 
template<typename Real >
void TestCuMatrixTraceMatMat (int32 dim)
 
template<typename Real >
void TestCuMatrixCholesky (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyLowerToUpper (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyFromTp (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestCuMatrixCopyFromSp (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyUpperToLower (int32 dim)
 
template<typename Real >
void TestCuMatrixSetZeroAboveDiag (int32 dim)
 
template<typename Real >
void TestCuMatrixLookup (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyRows1 (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyRows2 (int32 dim)
 
template<typename Real >
void TestCuMatrixCopyToRows (int32 dim)
 
template<typename Real >
void TestCuMatrixAddRows1 (int32 dim)
 
template<typename Real >
void TestCuMatrixAddRows2 (int32 dim)
 
template<typename Real >
void TestCuMatrixAddToRows (int32 dim)
 
template<typename Real >
void TestCuMatrixAddRowRanges (int32 dim)
 
template<typename Real >
void TestCuSparseMatrixTraceMatSmat (int32 dim)
 
template<typename Real >
void CudaMatrixSpeedTest ()
 
template<typename Real >
static void InitRand (VectorBase< Real > *v)
 
template<typename Real >
static void InitRand (MatrixBase< Real > *M)
 
template<typename Real >
static void RandZeroToOneMatrix (MatrixBase< Real > *mat)
 
template<typename Real >
static void UnitTestCuMatrixTraceMatMat ()
 
template<typename Real >
static void UnitTestCuCholesky ()
 
template<typename Real >
static void UnitTestCuMatrixApplyLog ()
 
template<typename Real >
static void UnitTestCuMatrixApplyExpSpecial ()
 
template<typename Real >
static void UnitTestCuMatrixApplyExp ()
 
template<typename Real >
static void UnitTestCuMatrixApplyExpLimited ()
 
template<typename Real >
static void UnitTestCuMatrixSigmoid ()
 
template<typename Real >
static void UnitTestCuMatrixScale ()
 
template<typename Real >
static void UnitTestCuMatrixAdd ()
 
template<typename Real >
static void UnitTestCuMatrixSoftHinge ()
 
template<typename Real >
static void UnitTestCuMatrixGroupPnorm ()
 
template<typename Real >
static void UnitTestCuMatrixGroupMax ()
 
template<typename Real >
static void UnitTestCuMatrixSet ()
 
template<typename Real >
static void UnitTestCuMatrixApplyPow ()
 
template<typename Real >
static void UnitTestCuMatrixApplyPowAbs ()
 
template<typename Real >
static void UnitTestCuMatrixCopyRowsFromVec ()
 
template<typename Real >
static void UnitTestCuMatrixCopyColsFromVec ()
 
template<typename Real >
static void UnitTestCuMatrixCopyRows ()
 
template<typename Real >
static void UnitTestCuMatrixCopyToRows ()
 
template<typename Real >
static void UnitTestCuMatrixAddRows ()
 
template<typename Real >
static void UnitTestCuMatrixMulRows ()
 
template<typename Real >
static void UnitTestCuMatrixAddToRows ()
 
template<typename Real >
void UnitTestCuMatrixCopyCross ()
 
template<typename Real >
void UnitTestCuMatrixCopyCross2 ()
 
template<typename Real >
static void UnitTestCuMatrixSumColumnRanges ()
 
template<typename Real >
static void UnitTestCuMatrixAddRowRanges ()
 
template<typename Real >
static void UnitTestCuMatrixCopyCols ()
 
template<typename Real >
static void UnitTextCuMatrixAddSmat ()
 
template<typename Real >
static void UnitTextCuMatrixAddMatSmat ()
 
template<typename Real >
static void UnitTextCuMatrixAddSmatMat ()
 
template<typename Real >
static void UnitTestCuMatrixAddCols ()
 
template<typename Real >
static void UnitTestCuMatrixApplyFloor ()
 
template<typename Real >
static void UnitTestCuMatrixApplyCeiling ()
 
template<typename Real >
static void UnitTestCuMatrixApplyHeaviside ()
 
template<typename Real >
static void UnitTestCuMatrixHeaviside ()
 
template<typename Real >
static void UnitTestCuMatrixMulElements ()
 
template<typename Real >
static void UnitTestCuMatrixDivElements ()
 
template<typename Real >
static void UnitTestCuMatrixMax ()
 
template<typename Real >
static void UnitTestCuMatrixMin ()
 
template<typename Real >
static void UnitTestCuMatrixMulColsVec ()
 
template<typename Real >
static void UnitTestCuMatrixMulRowsVec ()
 
template<typename Real >
static void UnitTestCuMatrixMulRowsGroupMat ()
 
template<typename Real >
static void UnitTestCuMatrixDiffGroupPnorm ()
 
template<typename Real >
static void UnitTestCuMatrixGroupMaxDeriv ()
 
template<typename Real >
static void UnitTestCuMatrixAddDiagVecMat ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatDiagVec ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatMatElements ()
 
template<typename Real >
static void UnitTestCuMatrixSetMatMatDivMat ()
 
template<typename Real >
static void UnitTestCuMatrixDivRowsVec ()
 
template<typename Real >
static void UnitTestCuMatrixAddMat ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatBlocks1 ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatBlocks1Trans ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatBlocks2 ()
 
template<typename Real >
static void UnitTestCuMatrixReduceSum ()
 
template<typename Real >
static void UnitTestCuMatrixReduceMax ()
 
template<typename Real >
static void UnitTestCuMatrixReduceMin ()
 
template<typename Real >
static void UnitTestCuMatrixAddVecToCols ()
 
template<typename Real >
static void UnitTestCuMatrixAddVecToRows ()
 
template<typename Real >
static void UnitTestCuMatrixSymAddMat2 ()
 
template<typename Real >
static void UnitTestCuMatrixSymInvertPosDef ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatMat ()
 
template<typename Real >
static void UnitTestCuMatrixAddVecVec ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatMatBatched ()
 
template<typename Real >
static void UnitTestCuMatrixAddToDiag ()
 
template<typename Real >
static void UnitTestCuMatrixAdd2 ()
 
template<typename Real >
static void UnitTestCuMatrixCopyFromMat ()
 
template<typename Real >
static void UnitTestCuMatrixCopyFromTp ()
 
template<typename Real >
static void UnitTestCuMatrixAddMatTp ()
 
template<typename Real >
static void UnitTestCuMatrixTranspose ()
 
template<typename Real >
static void UnitTestCuMatrixAddTpMat ()
 
template<typename Real >
static void UnitTestCuVectorAddVec ()
 
template<typename Real >
static void UnitTestCuVectorAddRowSumMat ()
 
template<typename Real >
static void UnitTestCuVectorAddRowSumMatLarge ()
 
template<typename Real >
static void UnitTestCuVectorAddColSumMat ()
 
template<typename Real >
static void UnitTestCuSubMatrix ()
 
template<typename Real >
static void UnitTestCuVectorAddColSumMatLarge ()
 
template<typename Real >
static void UnitTestCuVectorInvertElements ()
 
template<typename Real >
static void UnitTestCuMatrixInvertElements ()
 
template<class Real >
static void UnitTestCuMatrixIO ()
 
template<typename Real >
static void UnitTestCuVectorAddTpVec ()
 
template<typename Real >
static void UnitTestCuApproxEqual ()
 
template<typename Real >
static void UnitTestCuVectorMulTp ()
 
template<typename Real , typename OtherReal >
static void UnitTestCuCopy ()
 
template<typename Real >
static void UnitTestCuSigmoid ()
 
template<typename Real >
static void UnitTestCuDiffSigmoid ()
 
template<typename Real >
static void UnitTestCuDiffSoftmax ()
 
template<typename Real >
static void UnitTestCuDiffLogSoftmax ()
 
template<typename Real >
static void UnitTestCuSoftmax ()
 
template<typename Real >
static void UnitTestCuLogSoftmax ()
 
template<typename Real >
static void UnitTestCuFindRowMaxId ()
 
template<typename Real >
static void UnitTestCuDiffXent ()
 
template<typename Real >
void UnitTestCheck ()
 
template<typename Real >
void UnitTestSwapCu2Cu ()
 
template<typename Real >
void UnitTestSwapCu2M ()
 
template<typename Real >
void UnitTestCuTanh ()
 
template<typename Real >
static void UnitTestCuDiffTanh ()
 
static int32 DoubleFactorial (int32 i)
 
template<typename Real >
static void UnitTestCuMatrixSetRandn ()
 
template<typename Real >
static void UnitTestCuMatrixSetRandUniform ()
 
template<typename Real >
static void UnitTestCuMatrixCopyLowerToUpper ()
 
template<typename Real >
static void UnitTestCuMatrixSetZeroAboveDiag ()
 
template<typename Real >
static void UnitTestCuMatrixCopyUpperToLower ()
 
template<typename Real >
static void UnitTestCuMatrixObjfDeriv ()
 
template<typename Real >
static void UnitTestCuMatrixAddElements ()
 
template<typename Real >
static void UnitTestCuMatrixAddToElements ()
 
template<typename Real >
static void UnitTestCuMatrixLookup ()
 
template<typename Real >
static void UnitTestCuMatrixEqualElementMask ()
 
template<typename Real >
void CudaMatrixUnitTest ()
 
template<typename Real >
Real TraceMatMat (const CuMatrixBase< Real > &A, const CuMatrixBase< Real > &B, MatrixTransposeType trans)
 
template float TraceMatMat (const CuMatrixBase< float > &A, const CuMatrixBase< float > &B, MatrixTransposeType trans)
 
template double TraceMatMat (const CuMatrixBase< double > &A, const CuMatrixBase< double > &B, MatrixTransposeType trans)
 
template<typename Real >
void AddMatMatBatched (const Real alpha, std::vector< CuSubMatrix< Real > *> &C, const std::vector< CuSubMatrix< Real > *> &A, MatrixTransposeType transA, const std::vector< CuSubMatrix< Real > *> &B, MatrixTransposeType transB, const Real beta)
 Does multiple matrix multiplications, executing them in parallel using cuBLAS's gemmBatched if we are using a GPU. More...
 
template void AddMatMatBatched (const float alpha, std::vector< CuSubMatrix< float > * > &C, const std::vector< CuSubMatrix< float > * > &A, MatrixTransposeType transA, const std::vector< CuSubMatrix< float > * > &B, MatrixTransposeType transB, const float beta)
 
template void AddMatMatBatched (const double alpha, std::vector< CuSubMatrix< double > * > &C, const std::vector< CuSubMatrix< double > * > &A, MatrixTransposeType transA, const std::vector< CuSubMatrix< double > * > &B, MatrixTransposeType transB, const double beta)
 
template<typename Real >
std::ostream & operator<< (std::ostream &out, const CuMatrixBase< Real > &mat)
 Print the matrix to stream. More...
 
template std::ostream & operator<< (std::ostream &out, const CuMatrixBase< float > &mat)
 
template std::ostream & operator<< (std::ostream &out, const CuMatrixBase< double > &mat)
 
template<typename Real >
bool ApproxEqual (const CuMatrixBase< Real > &A, const CuMatrixBase< Real > &B, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const CuMatrixBase< Real > &A, const CuMatrixBase< Real > &B, float tol=0.01)
 
template<typename Real >
bool SameDim (const CuMatrixBase< Real > &M, const CuMatrixBase< Real > &N)
 
template<typename Real >
bool SameDimAndStride (const CuMatrixBase< Real > &M, const CuMatrixBase< Real > &N)
 
template<typename Real >
static void AssertEqual (const CuPackedMatrix< Real > &A, const CuPackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static void AssertEqual (const PackedMatrix< Real > &A, const PackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static void AssertDiagEqual (const PackedMatrix< Real > &A, const CuPackedMatrix< Real > &B, float value, float tol=0.001)
 
template<typename Real >
static void AssertDiagEqual (const PackedMatrix< Real > &A, const PackedMatrix< Real > &B, float value, float tol=0.001)
 
template<typename Real >
static void AssertEqual (const PackedMatrix< Real > &A, const CuPackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static bool ApproxEqual (const PackedMatrix< Real > &A, const PackedMatrix< Real > &B, Real tol=0.001)
 
template<typename Real >
static void UnitTestCuPackedMatrixConstructor ()
 
template<typename Real >
static void UnitTestCuPackedMatrixCopy ()
 
template<typename Real >
static void UnitTestCuPackedMatrixTrace ()
 
template<typename Real >
static void UnitTestCuPackedMatrixScale ()
 
template<typename Real >
static void UnitTestCuPackedMatrixScaleDiag ()
 
template<typename Real >
static void UnitTestCuPackedMatrixAddToDiag ()
 
template<typename Real >
static void UnitTestCuPackedMatrixSetUnit ()
 
template<typename Real >
void CudaPackedMatrixUnitTest ()
 
template<typename Real >
std::ostream & operator<< (std::ostream &out, const CuPackedMatrix< Real > &mat)
 Print the matrix to stream. More...
 
template std::ostream & operator<< (std::ostream &out, const CuPackedMatrix< float > &mat)
 
template std::ostream & operator<< (std::ostream &out, const CuPackedMatrix< double > &mat)
 
template<typename T >
std::string ToString (const T &t)
 
template<typename Real >
std::string MeanVariance (const CuMatrixBase< Real > &m)
 
template<typename Real >
std::string MeanVariance (const CuVectorBase< Real > &v)
 
template<typename Real >
void CuRandUniformMatrixSpeedTest (const int32 iter)
 
template<typename Real >
void CuRandUniformMatrixBaseSpeedTest (const int32 iter)
 
template<typename Real >
void CuRandGaussianMatrixSpeedTest (const int32 iter)
 
template<typename Real >
void CuRandGaussianMatrixBaseSpeedTest (const int32 iter)
 
template<typename Real >
void CuRandUniformVectorSpeedTest (const int32 iter)
 
template<typename Real >
void CuRandGaussianVectorSpeedTest (const int32 iter)
 
template<typename Real >
static void UnitTestCuSpMatrixInvert (int32 dim)
 
template<typename Real >
static void UnitTestCuSpMatrixCopyFromMat (int32 dim, SpCopyType copy_type)
 
template<typename Real >
void CuSpMatrixSpeedTest ()
 
template<typename Real >
static void UnitTestCuSpMatrixConstructor ()
 
template<typename Real >
static void UnitTestCuSpMatrixApproxEqual ()
 
template<typename Real >
static void UnitTestCuSpMatrixOperator ()
 
template<typename Real >
static void UnitTestCuSpMatrixAddToDiag ()
 
template<typename Real >
static void UnitTestCuSpMatrixCopyFromMat ()
 
template<typename Real >
static void UnitTestCuSpMatrixInvert ()
 
template<typename Real >
static void UnitTestCuSpMatrixAddVec2 ()
 
template<typename Real >
static void UnitTestCuSpMatrixAddMat2 ()
 
template<typename Real >
static void UnitTestCuSpMatrixAddSp ()
 
template<typename Real , typename OtherReal >
static void UnitTestCuSpMatrixTraceSpSp ()
 
template<typename Real >
void UnitTestCuSpMatrixSetUnit ()
 
template<class Real >
static void UnitTestCuSpMatrixIO ()
 
template<typename Real , typename OtherReal >
static void UnitTestCuSpMatrixAddSp ()
 
template<typename Real >
void CudaSpMatrixUnitTest ()
 
template<typename Real , typename OtherReal >
void CudaSpMatrixUnitTest ()
 
template<typename Real , typename OtherReal >
Real TraceSpSp (const CuSpMatrix< Real > &A, const CuSpMatrix< OtherReal > &B)
 C++ templatd wrapper of ANSI-C CUBLAS function GEMM (matrix multiply) More...
 
template float TraceSpSp (const CuSpMatrix< float > &A, const CuSpMatrix< float > &B)
 
template float TraceSpSp (const CuSpMatrix< float > &A, const CuSpMatrix< double > &B)
 
template double TraceSpSp (const CuSpMatrix< double > &A, const CuSpMatrix< float > &B)
 
template double TraceSpSp (const CuSpMatrix< double > &A, const CuSpMatrix< double > &B)
 
template<typename Real >
bool ApproxEqual (const CuSpMatrix< Real > &A, const CuSpMatrix< Real > &B, Real tol=0.001)
 
template<typename Real >
void AssertEqual (const CuSpMatrix< Real > &A, const CuSpMatrix< Real > &B, Real tol=0.001)
 
template<typename Real >
static void UnitTestCuSparseMatrixConstructFromIndexes ()
 
template<typename Real >
static void UnitTestCuSparseMatrixSelectRowsAndTranspose ()
 
template<typename Real >
static void UnitTestCuSparseMatrixTraceMatSmat ()
 
template<typename Real >
static void UnitTestCuSparseMatrixSum ()
 
template<typename Real >
static void UnitTestCuSparseMatrixFrobeniusNorm ()
 
template<typename Real >
static void UnitTestCuSparseMatrixCopyToSmat ()
 
template<typename Real >
static void UnitTestCuSparseMatrixSwap ()
 
template<typename Real >
void CudaSparseMatrixUnitTest ()
 
template<typename Real >
Real TraceMatSmat (const CuMatrixBase< Real > &A, const CuSparseMatrix< Real > &B, MatrixTransposeType trans)
 
template float TraceMatSmat (const CuMatrixBase< float > &A, const CuSparseMatrix< float > &B, MatrixTransposeType trans)
 
template double TraceMatSmat (const CuMatrixBase< double > &A, const CuSparseMatrix< double > &B, MatrixTransposeType trans)
 
template<typename Real >
static void InitRand (SpMatrix< Real > *M)
 
template<typename Real >
static void InitRand (VectorBase< Real > *v)
 
template<typename Real >
static void UnitTestSetZeroAboveDiag ()
 
template<typename Real >
static void UnitTestCholesky ()
 
template<typename Real >
static void UnitTestTrace ()
 
template<typename Real >
static void UnitInvert ()
 
template<typename Real >
static void UnitTestInvert ()
 
template<typename Real >
static void UnitTestConstructor ()
 
template<typename Real >
static void UnitTestCopySp ()
 
template<typename Real >
static void UnitTestCopyFromMat ()
 
template<typename Real >
static void UnitTestMatrix ()
 
template<typename Real >
static void UnitTestMulTp ()
 
template<typename Real >
static void UnitTestVector ()
 
template<typename Real >
static void CuMatrixUnitTest ()
 
template<typename Real >
static void AssertEqual (const CuPackedMatrix< Real > &A, const CuPackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static void AssertEqual (const PackedMatrix< Real > &A, const PackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static void AssertEqual (const PackedMatrix< Real > &A, const CuPackedMatrix< Real > &B, float tol=0.001)
 
template<typename Real >
static void UnitTestCuTpMatrixInvert ()
 
template<typename Real >
static void UnitTestCuTpMatrixCopyFromTp ()
 
template<typename Real >
static void UnitTestCuTpMatrixCopyFromMat ()
 
template<typename Real >
static void UnitTestCuTpMatrixCholesky ()
 
template<class Real >
static void UnitTestCuTpMatrixIO ()
 
template<typename Real >
void CudaTpMatrixUnitTest ()
 
template<typename Real >
void TestCuVectorSoftmax (int32 dim)
 
template<typename Real >
void TestCuVectorSum (int32 dim)
 
template<typename Real , typename OtherReal >
void TestCuVectorCopyFromVec (int32 dim)
 
template<typename Real >
void TestCuVectorVecVecOne (int32 dim)
 
template<typename Real >
void TestCuVectorAddDiagMatMat (int32 dim, MatrixTransposeType transN, MatrixTransposeType transO)
 
template<typename Real >
void TestCuVectorAddDiagMat2OnVariousShapes (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestCuVectorAddDiagMat2 (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestCuVectorAddRowSumMat (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestCuVectorAddColSumMat (int32 dim, MatrixTransposeType trans)
 
template<typename Real >
void TestCuVectorApplyFloor (int32 dim)
 
template<typename Real >
void TestCuVectorApplyFloorNoCount (int32 dim)
 
template<typename Real >
void TestCuVectorApplyCeiling (int32 dim)
 
template<typename Real >
void TestCuVectorApplyCeilingNoCount (int32 dim)
 
template<typename Real >
void TestCuVectorAddDiagMatMatShape (int32 num_rows, int32 num_cols, MatrixTransposeType transM, MatrixTransposeType transN)
 
template<typename Real >
void CudaVectorSpeedTest ()
 
template<class Real >
static void UnitTestCuVectorIO ()
 
template<typename Real , typename OtherReal >
static void UnitTestCuVectorCopyFromVec ()
 
template<typename Real >
static void UnitTestCuSubVector ()
 
template<typename Real >
static void UnitTestCuVectorMulTp ()
 
template<typename Real >
static void UnitTestCuVectorAddTp ()
 
template<typename Real >
void CuVectorUnitTestVecVec ()
 
template<typename Real >
void CuVectorUnitTestAddVec ()
 
template<typename Real >
void CuVectorUnitTestAddVecCross ()
 
template<typename Real >
void CuVectorUnitTestAddVecExtra ()
 
template<typename Real >
void CuVectorUnitTestCopyElements ()
 
template<typename Real >
void UnitTestVecMatVec ()
 
template<typename Real >
void CuVectorUnitTestAddRowSumMat ()
 
template<typename Real >
void CuVectorUnitTestAddColSumMat ()
 
template<typename Real >
void CuVectorUnitTestApproxEqual ()
 
template<typename Real >
static void UnitTestCuVectorReplaceValue ()
 
template<typename Real >
static void UnitTestCuVectorSum ()
 
template<typename Real >
void CuVectorUnitTestInvertElements ()
 
template<typename Real >
void CuVectorUnitTestSum ()
 
template<typename Real >
void CuVectorUnitTestScale ()
 
template<typename Real >
void CuVectorUnitTestCopyFromMat ()
 
template<typename Real >
void CuVectorUnitTestCopyDiagFromPacked ()
 
template<typename Real >
void CuVectorUnitTestCopyCross ()
 
template<typename Real >
void CuVectorUnitTestCopyCross2 ()
 
template<typename Real >
void CuVectorUnitTestCopyDiagFromMat ()
 
template<typename Real >
void CuVectorUnitTestNorm ()
 
template<typename Real >
void CuVectorUnitTestMin ()
 
template<typename Real >
void CuVectorUnitTestMax ()
 
template<typename Real >
void CuVectorUnitTestApplySoftMax ()
 
template<typename Real >
void CuVectorUnitTestApplyExp ()
 
template<typename Real >
void CuVectorUnitTestApplyLog ()
 
template<typename Real >
void CuVectorUnitTestApplyFloor ()
 
template<typename Real >
void CuVectorUnitTestApplyFloorNoCount ()
 
template<typename Real >
void CuVectorUnitTestApplyCeiling ()
 
template<typename Real >
void CuVectorUnitTestApplyCeilingNoCount ()
 
template<typename Real >
void CuVectorUnitTestApplyPow ()
 
template<typename Real >
void CuVectorUnitTestAddVecVec ()
 
template<typename Real >
void CuVectorUnitTestAddDiagMat2 ()
 
template<typename Real >
static void CuVectorUnitTestAddDiagMatMat ()
 
template<typename Real >
void CuVectorUnitTestAddMatVec ()
 
template<typename Real >
void CuVectorUnitTestAddSpVec ()
 
template<typename Real >
void CuVectorUnitTest ()
 
template<typename Real >
Real VecVec (const CuVectorBase< Real > &a, const CuVectorBase< Real > &b)
 
template float VecVec (const CuVectorBase< float > &a, const CuVectorBase< float > &b)
 
template double VecVec (const CuVectorBase< double > &a, const CuVectorBase< double > &b)
 
template<typename Real , typename OtherReal >
Real VecVec (const CuVectorBase< Real > &A, const CuVectorBase< OtherReal > &B)
 
template float VecVec (const CuVectorBase< float > &A, const CuVectorBase< double > &B)
 
template double VecVec (const CuVectorBase< double > &A, const CuVectorBase< float > &B)
 
template<typename Real >
Real VecMatVec (const CuVectorBase< Real > &v1, const CuMatrixBase< Real > &M, const CuVectorBase< Real > &v2)
 Returns $ v_1^T M v_2 $ . More...
 
template float VecMatVec (const CuVectorBase< float > &v1, const CuMatrixBase< float > &M, const CuVectorBase< float > &v2)
 
template double VecMatVec (const CuVectorBase< double > &v1, const CuMatrixBase< double > &M, const CuVectorBase< double > &v2)
 
template<typename Real >
std::ostream & operator<< (std::ostream &out, const CuVectorBase< Real > &vec)
 Print the vector to stream. More...
 
template std::ostream & operator<< (std::ostream &out, const CuVectorBase< float > &vec)
 
template std::ostream & operator<< (std::ostream &out, const CuVectorBase< double > &vec)
 
template<typename Real >
bool ApproxEqual (const CuVectorBase< Real > &a, const CuVectorBase< Real > &b, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const CuVectorBase< Real > &a, const CuVectorBase< Real > &b, Real tol=0.01)
 
void GetSeenPhones (BuildTreeStatsType &stats, int P, std::vector< int32 > *phones_out)
 
void AddToCount (int32 location_to_add, double value_to_add, std::vector< double > *counts)
 
void AddToConfusionMatrix (int32 phone1, int32 phone2, Matrix< double > *counts)
 
void WriteAsKaldiVector (const std::vector< double > &counts, std::string &wxfilename, bool binary)
 
int32 ProcessTopo (const HmmTopology &topo, const std::vector< std::vector< int32 > > &questions)
 
void FrameLevelLpp (const SubVector< BaseFloat > &prob_row, const std::vector< std::set< int32 > > &pdf2phones, const std::vector< int32 > *phone_map, Vector< BaseFloat > *out_frame_level_lpp)
 FrameLevelLpp compute a log posterior for pure-phones by sum the posterior of the states belonging to those triphones whose current phone is the canonical phone: More...
 
void GetEditsSingleHyp (const std::string &hyp_rspecifier, const std::string &ref_rspecifier, const std::string &mode, std::vector< std::pair< int32, int32 > > &edit_word_per_hyp)
 
void GetEditsDualHyp (const std::string &hyp_rspecifier, const std::string &hyp_rspecifier2, const std::string &ref_rspecifier, const std::string &mode, std::vector< std::pair< int32, int32 > > &edit_word_per_hyp, std::vector< std::pair< int32, int32 > > &edit_word_per_hyp2)
 
void GetBootstrapWERInterval (const std::vector< std::pair< int32, int32 > > &edit_word_per_hyp, int32 replications, BaseFloat *mean, BaseFloat *interval)
 
void GetBootstrapWERTwoSystemComparison (const std::vector< std::pair< int32, int32 > > &edit_word_per_hyp, const std::vector< std::pair< int32, int32 > > &edit_word_per_hyp2, int32 replications, BaseFloat *p_improv)
 
void ApplySoftMaxPerRow (MatrixBase< BaseFloat > *mat)
 
int32 TypeOneUsage (const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
 
int32 TypeOneUsageAverage (const ParseOptions &po)
 
int32 TypeTwoUsage (const ParseOptions &po, bool binary)
 
int32 TypeThreeUsage (const ParseOptions &po, bool binary, bool average)
 
int32 TypeOneUsage (const ParseOptions &po)
 
int32 TypeTwoUsage (const ParseOptions &po, bool binary, bool average=false)
 
int32 TypeThreeUsage (const ParseOptions &po, bool binary)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const GaussPost &gpost, const TransitionModel &trans_model, const AmDiagGmm &am_gmm, FmllrDiagGmmAccs *spk_stats)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const Posterior &post, const TransitionModel &trans_model, const AmDiagGmm &am_gmm, FmllrDiagGmmAccs *spk_stats)
 
fst::Fst< fst::StdArc > * ReadNetwork (std::string filename)
 
void AccStatsForUtterance (const TransitionModel &trans_model, const AmDiagGmm &am_gmm, const GaussPost &gpost, const Matrix< BaseFloat > &feats, FmllrRawAccs *accs)
 
void AccStatsForUtterance (const TransitionModel &trans_model, const AmDiagGmm &am_gmm, const Posterior &post, const Matrix< BaseFloat > &feats, FmllrRawAccs *accs)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const GaussPost &gpost, const AmDiagGmm &am_gmm, FmllrDiagGmmAccs *spk_stats)
 
bool AccumulateForUtterance (const Matrix< BaseFloat > &feats, const DiagGmm &gmm, const std::string &key, RandomAccessBaseFloatVectorReader *weights_reader, RandomAccessInt32VectorVectorReader *gselect_reader, AccumFullGmm *fullcov_stats)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const Posterior &post, const DiagGmm &gmm, FmllrDiagGmmAccs *spk_stats)
 
void InitGmmFromRandomFrames (const Matrix< BaseFloat > &feats, DiagGmm *gmm)
 
void TrainOneIter (const Matrix< BaseFloat > &feats, const MleDiagGmmOptions &gmm_opts, int32 iter, int32 num_threads, DiagGmm *gmm)
 
void ReadSharedPhonesList (std::string rxfilename, std::vector< std::vector< int32 > > *list_out)
 
EventMapGetFullBiphoneStubMap (const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< int32 > &ci_phones_list, const std::vector< std::vector< int32 > > &bi_counts, int32 biphone_min_count, const std::vector< int32 > &mono_counts, int32 mono_min_count)
 
ContextDependencyBiphoneContextDependencyFull (std::vector< std::vector< int32 > > phone_sets, const std::vector< int32 > phone2num_pdf_classes, const std::vector< int32 > &ci_phones_list, const std::vector< std::vector< int32 > > &bi_counts, int32 biphone_min_count, const std::vector< int32 > &mono_counts, int32 mono_min_count)
 
void GetFeatureMeanAndVariance (const std::string &feat_rspecifier, Vector< BaseFloat > *inv_var_out, Vector< BaseFloat > *mean_out)
 
void InitAmGmm (const BuildTreeStatsType &stats, const EventMap &to_pdf_map, AmDiagGmm *am_gmm, const TransitionModel &trans_model, BaseFloat var_floor)
 InitAmGmm initializes the GMM with one Gaussian per state. More...
 
void GetOccs (const BuildTreeStatsType &stats, const EventMap &to_pdf_map, Vector< BaseFloat > *occs)
 Get state occupation counts. More...
 
void InitAmGmmFromOld (const BuildTreeStatsType &stats, const EventMap &to_pdf_map, int32 N, int32 P, const std::string &old_tree_rxfilename, const std::string &old_model_rxfilename, BaseFloat var_floor, AmDiagGmm *am_gmm)
 InitAmGmmFromOld initializes the GMM based on a previously trained model and tree, which must require no more phonetic context than the current tree. More...
 
bool DecodeUtterance (LatticeBiglmFasterDecoder &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
void MergeFullGmm (const FullGmm &src, FullGmm *dst)
 merges GMMs by appending Gaussians in "src" to "dst". More...
 
void AppendPostToFeats (const Matrix< BaseFloat > &in, const Posterior &post, const int32 post_dim, Matrix< BaseFloat > *out)
 
void AppendVectorToFeats (const Matrix< BaseFloat > &in, const Vector< BaseFloat > &vec, Matrix< BaseFloat > *out)
 
void GetUtterancePairs (const std::string &reco2file_and_channel_rxfilename, std::vector< std::vector< std::string > > *utt_pairs)
 
void AccCmvnStatsForPair (const std::string &utt1, const std::string &utt2, const MatrixBase< BaseFloat > &feats1, const MatrixBase< BaseFloat > &feats2, BaseFloat quieter_channel_weight, MatrixBase< double > *cmvn_stats1, MatrixBase< double > *cmvn_stats2)
 
bool AccCmvnStatsWrapper (const std::string &utt, const MatrixBase< BaseFloat > &feats, RandomAccessBaseFloatVectorReader *weights_reader, Matrix< double > *cmvn_stats)
 
void ConcatFeats (const std::vector< Matrix< BaseFloat > > &in, Matrix< BaseFloat > *out)
 
void IncreaseTransformDimension (int32 new_dimension, Matrix< BaseFloat > *mat)
 
void LinearlyInterpolatePitch (Matrix< BaseFloat > *mat)
 
bool AppendFeats (const std::vector< Matrix< BaseFloat > > &in, const std::string &utt, int32 tolerance, Matrix< BaseFloat > *out)
 
void ProcessPovFeatures (Matrix< BaseFloat > *mat)
 
void TakeLogOfPitch (Matrix< BaseFloat > *mat)
 
void SubtractMovingAverage (int32 normalization_window_size, Matrix< BaseFloat > *mat)
 
void SetToMovingAverage (int32 average_window_size, Matrix< BaseFloat > *mat)
 
void ShiftFeatureMatrix (const Matrix< BaseFloat > &src, int32 shift, Matrix< BaseFloat > *rearranged)
 
void AddVectorsOfUnequalLength (const VectorBase< BaseFloat > &signal1, Vector< BaseFloat > *signal2)
 
void AddVectorsWithOffset (const Vector< BaseFloat > &signal1, int32 offset, Vector< BaseFloat > *signal2)
 
BaseFloat MaxAbsolute (const Vector< BaseFloat > &vector)
 
BaseFloat ComputeEarlyReverbEnergy (const Vector< BaseFloat > &rir, const Vector< BaseFloat > &signal, BaseFloat samp_freq)
 
float DoReverberation (const Vector< BaseFloat > &rir, BaseFloat samp_freq, Vector< BaseFloat > *signal)
 
void AddNoise (Vector< BaseFloat > *noise, BaseFloat snr_db, BaseFloat time, BaseFloat samp_freq, BaseFloat signal_power, Vector< BaseFloat > *signal)
 
void ReadCommaSeparatedCommand (const std::string &s, std::vector< BaseFloat > *v)
 
bool ReadData (SequentialBaseFloatMatrixReader &feature_reader, RandomAccessPosteriorReader &target_reader, RandomAccessBaseFloatVectorReader &weights_reader, int32 length_tolerance, Matrix< BaseFloat > *feats, Posterior *targets, Vector< BaseFloat > *weights, int32 *num_no_tgt_mat, int32 *num_other_error)
 
bool CompactLatticeNormalize (CompactLattice *clat, BaseFloat weight)
 
void SplitStringToWeights (const string &full, const char *delim, vector< BaseFloat > *out)
 
int32 CopySubsetLattices (std::string filename, SequentialLatticeReader *lattice_reader, LatticeWriter *lattice_writer, bool include=true, bool ignore_missing=false, bool sorted=false)
 
int32 CopySubsetLattices (std::string filename, SequentialCompactLatticeReader *lattice_reader, CompactLatticeWriter *lattice_writer, bool include=true, bool ignore_missing=false, bool sorted=false)
 
bool DeterminizeLatticeWrapper (const Lattice &lat, const std::string &key, bool prune, BaseFloat beam, BaseFloat beam_ratio, int32 max_mem, int32 max_loop, BaseFloat delta, int32 num_loops, CompactLattice *clat)
 
void ReadSymbolList (const std::string &rxfilename, fst::SymbolTable *word_syms, LabelPairVector *lpairs)
 
void ConvertLatticeToUnweightedAcceptor (const kaldi::Lattice &ilat, const LabelPairVector &wildcards, fst::StdVectorFst *ofst)
 
void CreateEditDistance (const fst::StdVectorFst &fst1, const fst::StdVectorFst &fst2, fst::StdVectorFst *pfst)
 
void CountErrors (const fst::StdVectorFst &fst, int32 *correct, int32 *substitutions, int32 *insertions, int32 *deletions, int32 *num_words)
 
bool CheckFst (const fst::StdVectorFst &fst, string name, string key)
 
void LatticeAcousticRescore (const TransitionModel &trans_model, const Matrix< BaseFloat > &log_likes, const std::vector< int32 > &state_times, Lattice *lat)
 
void MakeLatticeFromLinear (const std::vector< int32 > &ali, const std::vector< int32 > &words, BaseFloat lm_cost, BaseFloat ac_cost, Lattice *lat_out)
 
static float _RandGauss ()
 
void ComputeFeatureNormalizingTransform (const FullGmm &gmm, Matrix< BaseFloat > *xform)
 Computes the inverse of an LDA transform (without dimensionality reduction) The computed transform is used in initializing the phonetic and speaker subspaces, as well as while increasing the dimensions of those spaces. More...
 
static void ApplyPreXformToGradient (const Sgmm2FmllrGlobalParams &globals, const Matrix< BaseFloat > &gradient_in, Matrix< BaseFloat > *gradient_out)
 
static void ApplyInvPreXformToChange (const Sgmm2FmllrGlobalParams &globals, const Matrix< BaseFloat > &delta_in, Matrix< BaseFloat > *delta_out)
 
static void ApplyHessianXformToGradient (const Sgmm2FmllrGlobalParams &globals, const Matrix< BaseFloat > &gradient_in, Matrix< BaseFloat > *gradient_out)
 
static void ApplyInvHessianXformToChange (const Sgmm2FmllrGlobalParams &globals, const Matrix< BaseFloat > &delta_in, Matrix< BaseFloat > *delta_out)
 
static BaseFloat CalcFmllrStepSize (const AffineXformStats &stats, const AmSgmm2 &sgmm, const MatrixBase< BaseFloat > &Delta, const MatrixBase< BaseFloat > &A, const Matrix< BaseFloat > &G, int32 max_iters)
 
void EstimateSgmm2FmllrSubspace (const SpMatrix< double > &fmllr_grad_scatter, int32 num_fmllr_bases, int32 feat_dim, Sgmm2FmllrGlobalParams *fmllr_globals, double min_eig=0.0)
 Computes the fMLLR basis matrices given the scatter of the vectorized gradients (eq: B.10). More...
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const Matrix< BaseFloat > &transformed_feats, const std::vector< std::vector< int32 > > &gselect, const Posterior &post, const TransitionModel &trans_model, const AmSgmm2 &am_sgmm, BaseFloat logdet, Sgmm2PerSpkDerivedVars *spk_vars, FmllrSgmm2Accs *spk_stats)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const Sgmm2GauPost &gpost, const TransitionModel &trans_model, const AmSgmm2 &am_sgmm, Sgmm2PerSpkDerivedVars *spk_vars, MleSgmm2SpeakerAccs *spk_stats)
 
void AccumulateForUtterance (const Matrix< BaseFloat > &feats, const Posterior &post, const TransitionModel &trans_model, const AmSgmm2 &am_sgmm, const vector< vector< int32 > > &gselect, Sgmm2PerSpkDerivedVars *spk_vars, MleSgmm2SpeakerAccs *spk_stats)
 
void ProcessUtterance (const AmSgmm2 &am_sgmm, const TransitionModel &trans_model, double log_prune, double acoustic_scale, const Matrix< BaseFloat > &features, RandomAccessInt32VectorVectorReader &gselect_reader, RandomAccessBaseFloatVectorReaderMapped &spkvecs_reader, const fst::SymbolTable *word_syms, const std::string &utt, bool determinize, bool allow_partial, Int32VectorWriter *alignments_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, LatticeFasterDecoder *decoder, double *like_sum, int64 *frame_sum, int32 *num_done, int32 *num_err, TaskSequencer< DecodeUtteranceLatticeFasterClass > *sequencer)
 
bool ProcessUtterance (LatticeFasterDecoder &decoder, const AmSgmm2 &am_sgmm, const TransitionModel &trans_model, double log_prune, double acoustic_scale, const Matrix< BaseFloat > &features, RandomAccessInt32VectorVectorReader &gselect_reader, RandomAccessBaseFloatVectorReaderMapped &spkvecs_reader, const fst::SymbolTable *word_syms, const std::string &utt, bool determinize, bool allow_partial, Int32VectorWriter *alignments_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
 
void GetWeights (const std::string &weights_str, int32 num_inputs, std::vector< BaseFloat > *weights)
 
std::vector< boolGetSkipLayers (const std::string &skip_layers_str, const int32 first_layer_idx, const int32 last_layer_idx)
 
bool SplitEgsKey (const std::string &key, std::string *utt_id, int32 *frame_id)
 
nnet2::ComponentConvertAffineTransformComponent (const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)
 
nnet2::ComponentConvertSoftmaxComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertSigmoidComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertSpliceComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertAddShiftComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertRescaleComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertComponent (const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)
 
nnet2::NnetConvertNnet1ToNnet2 (const nnet1::Nnet &nnet1, const bool use_preconditioned_affine_component)
 
void ReadModels (std::vector< std::pair< std::string, BaseFloat > > models_and_weights, nnet3::Nnet *output_nnet, int32 *success)
 
int32 GetCount (double expected_count)
 
void SplitArgOnEquals (const std::string &arg, std::string *name, std::string *rspecifier)
 
void HandleOutput (bool determinize, const fst::SymbolTable *word_syms, nnet3::NnetBatchDecoder *decoder, CompactLatticeWriter *clat_writer, LatticeWriter *lat_writer)
 
bool CompareInterval (const Interval &i1, const Interval &i2)
 
bool ClusterLattice (CompactLattice *clat, const std::vector< int32 > &state_times)
 
bool CreateFactorTransducer (const CompactLattice &clat, const std::vector< int32 > &state_times, int32 utterance_id, KwsProductFst *factor_transducer)
 
void RemoveLongSilences (int32 max_silence_frames, const std::vector< int32 > &state_times, KwsProductFst *factor_transducer)
 
template<class Arc >
static void DifferenceWrapper (const fst::VectorFst< Arc > &fst1, const fst::VectorFst< Arc > &fst2, fst::VectorFst< Arc > *difference)
 
void MaybeDoSanityCheck (const KwsLexicographicFst &index_transducer)
 
void MaybeDoSanityCheck (const KwsProductFst &product_transducer)
 
void DoFactorMerging (KwsProductFst *factor_transducer, KwsLexicographicFst *index_transducer)
 
void DoFactorDisambiguation (KwsLexicographicFst *index_transducer)
 
void OptimizeFactorTransducer (KwsLexicographicFst *index_transducer, int32 max_states, bool allow_partial)
 
template<class Arc >
static void ReplaceSymbolWithEpsilon (typename Arc::Label symbol, fst::VectorFst< Arc > *fst)
 
uint64 EncodeLabel (StateId ilabel, StateId olabel)
 
StateId DecodeLabelUid (uint64 osymbol)
 
bool GenerateActivePaths (const KwsLexicographicFst &proxy, std::vector< ActivePath > *paths, KwsLexicographicFst::StateId cur_state, std::vector< KwsLexicographicArc::Label > cur_path, KwsLexicographicArc::Weight cur_weight)
 
void SetLinearAcceptorWeight (double cost, fst::VectorFst< fst::StdArc > *fst)
 
void AgglomerativeCluster (const Matrix< BaseFloat > &costs, BaseFloat threshold, int32 min_clusters, int32 first_pass_max_points, BaseFloat max_cluster_fraction, std::vector< int32 > *assignments_out)
 This is the function that is called to perform the agglomerative clustering. More...
 
void TestIvectorExtractorIO (const IvectorExtractor &extractor)
 
void TestIvectorExtractorStatsIO (IvectorExtractorStats &stats)
 
void TestIvectorExtraction (const IvectorExtractor &extractor, const MatrixBase< BaseFloat > &feats, const FullGmm &fgmm)
 
void UnitTestIvectorExtractor ()
 
static double GetLogDetNoFailure (const SpMatrix< double > &var)
 
static void ConvertPostToGaussInfo (const std::vector< std::vector< std::pair< int32, BaseFloat > > > &gauss_post, std::unordered_map< int32, GaussInfo > *gauss_info)
 
double EstimateIvectorsOnline (const Matrix< BaseFloat > &feats, const Posterior &post, const IvectorExtractor &extractor, int32 ivector_period, int32 num_cg_iters, BaseFloat max_count, Matrix< BaseFloat > *ivectors)
 
void UnitTestPosteriors ()
 
void UnitTestTrain ()
 
void UnitTestPldaEstimation (int32 dim)
 
template<class Real >
static void ComputeNormalizingTransform (const SpMatrix< Real > &covar, MatrixBase< Real > *proj)
 This function computes a projection matrix that when applied makes the covariance unit (i.e. More...
 
void ComputeVadEnergy (const VadEnergyOptions &opts, const MatrixBase< BaseFloat > &input_features, Vector< BaseFloat > *output_voiced)
 Compute voice-activity vector for a file: 1 if we judge the frame as voiced, 0 otherwise. More...
 
BaseFloat ComputeEer (std::vector< BaseFloat > *target_scores, std::vector< BaseFloat > *nontarget_scores, BaseFloat *threshold)
 ComputeEer computes the Equal Error Rate (EER) for the given scores and returns it as a proportion beween 0 and 1. More...
 
void PrepareMap (const std::string &map_rxfilename, int32 num_classes, unordered_map< int32, int32 > *map)
 PrepareMap creates a map that specifies the mapping between the input and output class labels. More...
 
void PreparePriors (const std::string &priors_str, int32 num_classes, std::vector< BaseFloat > *priors)
 PreparePriors creates a table specifying the priors for each class. More...
 
template<class Real >
void ComputeNormalizingTransform (const SpMatrix< Real > &covar, Real floor, MatrixBase< Real > *proj)
 
void ComputeLdaTransform (const std::map< std::string, Vector< BaseFloat > *> &utt2ivector, const std::map< std::string, std::vector< std::string > > &spk2utt, BaseFloat total_covariance_factor, BaseFloat covariance_floor, MatrixBase< BaseFloat > *lda_out)
 
void ComputeAndSubtractMean (std::map< std::string, Vector< BaseFloat > *> utt2ivector, Vector< BaseFloat > *mean_out)
 
int32 RunPerSpeaker (const std::string &ivector_extractor_rxfilename, const IvectorEstimationOptions &opts, bool compute_objf_change, const std::string &spk2utt_rspecifier, const std::string &feature_rspecifier, const std::string &posterior_rspecifier, const std::string &ivector_wspecifier)
 
bool EstPca (const Matrix< BaseFloat > &ivector_mat, BaseFloat target_energy, const std::string &reco, Matrix< BaseFloat > *mat)
 
void TransformIvectors (const Matrix< BaseFloat > &ivectors_in, const PldaConfig &plda_config, const Plda &plda, Matrix< BaseFloat > *ivectors_out)
 
void ApplyPca (const Matrix< BaseFloat > &ivectors_in, const Matrix< BaseFloat > &pca_mat, Matrix< BaseFloat > *ivectors_out)
 
void PrepareMap (const std::string map_rxfilename, unordered_map< std::pair< int32, int32 >, int32, PairHasher< int32 > > *map)
 PrepareMap creates a mapping between the pairs of VAD decisions and the output label. More...
 
int PaCallback (const void *input, void *output, long unsigned frame_count, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data)
 
template<class Real >
static void AssertEqual (const Matrix< Real > &A, const Matrix< Real > &B, float tol=0.001)
 
void GetOutput (OnlineFeatInputItf *a, Matrix< BaseFloat > *output)
 
void TestOnlineMatrixInput ()
 
void TestOnlineFeatureMatrix ()
 
void TestOnlineLdaInput ()
 
void TestOnlineDeltaInput ()
 
void TestOnlineCmnInput ()
 
fst::Fst< fst::StdArc > * ReadDecodeGraph (const std::string &filename)
 
void PrintPartialResult (const std::vector< int32 > &words, const fst::SymbolTable *word_syms, bool line_break)
 
bool WriteFull (int32 desc, char *data, int32 size)
 
bool ReadLine (int32 desc, std::string *str)
 
std::string TimeToTimecode (float time)
 
bool WriteLine (int32 socket, std::string line)
 
void SendPartialResult (const std::vector< int32 > &words, const fst::SymbolTable *word_syms, const bool line_break, const int32 serv_sock, const sockaddr_in &client_addr)
 
static bool RuleActivated (const OnlineEndpointRule &rule, const std::string &rule_name, BaseFloat trailing_silence, BaseFloat relative_cost, BaseFloat utterance_length)
 
bool EndpointDetected (const OnlineEndpointConfig &config, int32 num_frames_decoded, int32 trailing_silence_frames, BaseFloat frame_shift_in_seconds, BaseFloat final_relative_cost)
 This function returns true if this set of endpointing rules thinks we should terminate decoding. More...
 
template<typename FST , typename DEC >
int32 TrailingSilenceLength (const TransitionModel &tmodel, const std::string &silence_phones, const DEC &decoder)
 returns the number of frames of trailing silence in the best-path traceback (not using final-probs). More...
 
template<typename FST >
bool EndpointDetected (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeFasterOnlineDecoderTpl< FST > &decoder)
 This is a higher-level convenience function that works out the arguments to the EndpointDetected function above, from the decoder. More...
 
template<typename FST >
bool EndpointDetected (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeIncrementalOnlineDecoderTpl< FST > &decoder)
 This is a higher-level convenience function that works out the arguments to the EndpointDetected function above, from the decoder. More...
 
template bool EndpointDetected< fst::Fst< fst::StdArc > > (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeFasterOnlineDecoderTpl< fst::Fst< fst::StdArc > > &decoder)
 
template bool EndpointDetected< fst::GrammarFst > (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeFasterOnlineDecoderTpl< fst::GrammarFst > &decoder)
 
template bool EndpointDetected< fst::Fst< fst::StdArc > > (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeIncrementalOnlineDecoderTpl< fst::Fst< fst::StdArc > > &decoder)
 
template bool EndpointDetected< fst::GrammarFst > (const OnlineEndpointConfig &config, const TransitionModel &tmodel, BaseFloat frame_shift_in_seconds, const LatticeIncrementalOnlineDecoderTpl< fst::GrammarFst > &decoder)
 
template void OnlineSilenceWeighting::ComputeCurrentTraceback< fst::Fst< fst::StdArc > > (const LatticeFasterOnlineDecoderTpl< fst::Fst< fst::StdArc > > &decoder)
 
template void OnlineSilenceWeighting::ComputeCurrentTraceback< fst::GrammarFst > (const LatticeFasterOnlineDecoderTpl< fst::GrammarFst > &decoder)
 
template void OnlineSilenceWeighting::ComputeCurrentTraceback< fst::Fst< fst::StdArc > > (const LatticeIncrementalOnlineDecoderTpl< fst::Fst< fst::StdArc > > &decoder)
 
template void OnlineSilenceWeighting::ComputeCurrentTraceback< fst::GrammarFst > (const LatticeIncrementalOnlineDecoderTpl< fst::GrammarFst > &decoder)
 
void FindQuietestSegment (const Vector< BaseFloat > &wav_in, BaseFloat samp_rate, Vector< BaseFloat > *wav_sil, BaseFloat search_dur=0.5, BaseFloat seg_dur=0.1, BaseFloat seg_shift_dur=0.05)
 
void ExtendWaveWithSilence (const Vector< BaseFloat > &wav_in, BaseFloat samp_rate, Vector< BaseFloat > *wav_out, BaseFloat sil_search_len, BaseFloat sil_extract_len, BaseFloat sil_extract_shift)
 
std::string LatticeToString (const Lattice &lat, const fst::SymbolTable &word_syms)
 
std::string GetTimeString (int32 t_beg, int32 t_end, BaseFloat time_unit)
 
int32 GetLatticeTimeSpan (const Lattice &lat)
 
std::string LatticeToString (const CompactLattice &clat, const fst::SymbolTable &word_syms)
 
void GetDiagnosticsAndPrintOutput (const std::string &utt, const fst::SymbolTable *word_syms, const CompactLattice &clat, int64 *tot_num_frames, double *tot_like)
 
template<typename Real >
Real TraceMatMat (const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans=kNoTrans)
 We need to declare this here as it will be a friend function. More...
 
void AccumulateTreeStats (const TransitionModel &trans_model, const AccumulateTreeStatsInfo &info, const std::vector< int32 > &alignment, const Matrix< BaseFloat > &features, std::map< EventType, GaussClusterable * > *stats)
 Accumulates the stats needed for training context-dependency trees (in the "normal" way). More...
 
void ReadPhoneMap (std::string phone_map_rxfilename, std::vector< int32 > *phone_map)
 

Variables

int32 g_kaldi_verbose_level = 0
 This is set by util/parse-options. More...
 
static std::string program_name
 
static LogHandler log_handler = NULL
 
static std::mutex _RandMutex
 
static const double kMinLogDiffDouble = Log(DBL_EPSILON)
 
static const float kMinLogDiffFloat = Log(FLT_EPSILON)
 
const float kLogZeroFloat = -std::numeric_limits<float>::infinity()
 
const double kLogZeroDouble = -std::numeric_limits<double>::infinity()
 
const BaseFloat kLogZeroBaseFloat = -std::numeric_limits<BaseFloat>::infinity()
 
ProfileStats g_profile_stats
 
int32 g_num_threads = 8
 
static ShellType kShellType = kBash
 
const char * ws_delim = " \t\n\r"
 
bool pitch_use_naive_search = false
 
const BaseFloat kWaveSampleMax = 32768.0
 For historical reasons, we scale waveforms to the range (2^15-1)*[-1, 1], not the usual default DSP range [-1, 1]. More...
 
static const EventKeyType kPdfClass = -1
 
const int32 kMaxVal = 20
 
static const int32 kNoPdf = -1
 A constant used in the HmmTopology class as the pdf-class kNoPdf, which is used when a HMM-state is nonemitting (has no associated PDF). More...
 
static const int kRandomSentences = 50
 
const int kTemporaryEpsilon = -2
 
const int kNumStatesOffset = 1000
 
CuAllocatorOptions g_allocator_options
 
int32 buffer_offset = 0
 
int32 buffer_fill = 0
 
char read_buffer [1025]
 
const float kFramesPerSecond = 100.0f
 

Detailed Description

This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:

Relabels neural network egs with the read pdf-id alignments.

"Improved mispronunciation detection with deep neural network trained acoustic models and transfer learning based logistic regression classifiers" by Hu et al., Speech Comunication, 2015.

GOP is widely used to detect mispronunciations. The DNN-based GOP was defined as the log phone posterior ratio between the canonical phone and the one with the highest score.

To compute GOP, we need to compute Log Phone Posterior (LPP): LPP(p) = p(p| o; t_s,t_e) where { o} is the input observations, p is the canonical phone, {t_s, t_e} are the start and end frame indexes.

LPP could be calculated as the average of the frame-level LPP, i.e. p(p|o_t): LPP(p) = {1}{t_e-t_s+1} {t=t_s}^{t_e} p(p|o_t) p(p|o_t) = {s p} p(s|o_t) where s is the senone label, {s|s p} is the states belonging to those triphones whose current phone is p.

GOP is extracted from LPP: GOP(p) = {LPP(p)}{{q Q} LPP(q)}

An array of a phone-level feature for each phone is extracted as well, which could be used to train a classifier to detect mispronunciations. Normally the classifier-based approach archives better performance than the GOP-based approach.

The phone-level feature is defined as: {[LPP(p_1),,LPP(p_M), LPR(p_1|p_i), , LPR(p_j|p_i),]}^T

where the Log Posterior Ratio (LPR) between phone p_j and p_i is defined as: LPR(p_j|p_i) = p(p_j| o; t_s, t_e) - p(p_i| o; t_s, t_e)

Typedef Documentation

◆ Arc

Definition at line 35 of file lattice-determinize-non-compact.cc.

◆ BaseFloat

typedef float BaseFloat

Definition at line 29 of file kaldi-types.h.

◆ CompactLattice

typedef fst::VectorFst<CompactLatticeArc> CompactLattice

Definition at line 46 of file kaldi-lattice.h.

◆ CompactLatticeArc

Definition at line 42 of file kaldi-lattice.h.

◆ CompactLatticeWeight

◆ CompactLatticeWeightCommonDivisor

◆ CompactLatticeWriter

◆ double64

typedef double double64

Definition at line 54 of file kaldi-types.h.

◆ EventAnswerType

As far as the event-map code itself is concerned, things of type EventAnswerType may take any value except kNoAnswer (== -1).

However, some specific uses of EventMap (e.g. in build-tree-utils.h) assume these quantities are nonnegative.

Definition at line 56 of file event-map.h.

◆ EventKeyType

Things of type EventKeyType can take any value.

The code does not assume they are contiguous. So values like -1, 1000000 and the like are acceptable.

Definition at line 45 of file event-map.h.

◆ EventType

typedef std::vector<std::pair<EventKeyType, EventValueType> > EventType

Definition at line 58 of file event-map.h.

◆ EventValueType

Given current code, things of type EventValueType should generally be nonnegative and in a reasonably small range (e.g.

not one million), as we sometimes construct vectors of the size: [largest value we saw for this key]. This deficiency may be fixed in future [would require modifying TableEventMap]

Definition at line 51 of file event-map.h.

◆ float32

typedef float float32

Definition at line 53 of file kaldi-types.h.

◆ GmmFlagsType

typedef uint16 GmmFlagsType

Bitwise OR of the above flags.

Definition at line 35 of file model-common.h.

◆ int32

Definition at line 27 of file online-tcp-source.cc.

◆ int_smaller

typedef int16 int_smaller

Definition at line 33 of file cluster-utils.cc.

◆ KwsLexicographicArc

Definition at line 45 of file kaldi-kws.h.

◆ KwsLexicographicFst

typedef fst::VectorFst<KwsLexicographicArc> KwsLexicographicFst

Definition at line 46 of file kaldi-kws.h.

◆ KwsLexicographicWeight

Definition at line 44 of file kaldi-kws.h.

◆ KwsProductArc

Definition at line 48 of file kaldi-kws.h.

◆ KwsProductFst

typedef fst::VectorFst<KwsProductArc> KwsProductFst

Definition at line 49 of file kaldi-kws.h.

◆ KwsProductWeight

Definition at line 47 of file kaldi-kws.h.

◆ Label

typedef fst::StdArc::Label Label

Definition at line 32 of file lattice-oracle.cc.

◆ LabelPairVector

typedef std::vector<std::pair<Label, Label> > LabelPairVector

Definition at line 33 of file lattice-oracle.cc.

◆ Lattice

typedef fst::VectorFst<LatticeArc> Lattice

Definition at line 44 of file kaldi-lattice.h.

◆ LatticeArc

typedef fst::ArcTpl<LatticeWeight> LatticeArc

Definition at line 40 of file kaldi-lattice.h.

◆ LatticeBiglmFasterDecoderConfig

◆ LatticeFasterDecoder

◆ LatticeFasterOnlineDecoder

◆ LatticeIncrementalDecoder

◆ LatticeIncrementalOnlineDecoder

◆ LatticeWeight

Definition at line 32 of file kaldi-lattice.h.

◆ LatticeWriter

Definition at line 145 of file kaldi-lattice.h.

◆ LogXStdXStdprimeArc

Definition at line 41 of file kaldi-kws.h.

◆ LogXStdXStdprimeWeight

typedef fst::ProductWeight<LogWeight, StdXStdprimeWeight> LogXStdXStdprimeWeight

Definition at line 40 of file kaldi-kws.h.

◆ MapAmDiagGmmSeqReader

◆ MapAmDiagGmmWriter

◆ MatrixIndexT

Definition at line 98 of file matrix-common.h.

◆ PipebufType

typedef basic_pipebuf<char> PipebufType

Definition at line 55 of file kaldi-io.cc.

◆ RandomAccessCompactLatticeReader

◆ RandomAccessLatticeReader

◆ RandomAccessMapAmDiagGmmReader

◆ RandomAccessMapAmDiagGmmReaderMapped

◆ RandomAccessRegtreeFmllrDiagGmmReader

◆ RandomAccessRegtreeFmllrDiagGmmReaderMapped

◆ RandomAccessRegtreeMllrDiagGmmReader

◆ RandomAccessRegtreeMllrDiagGmmReaderMapped

◆ RandomAccessSgmm2GauPostReader

◆ RegtreeFmllrDiagGmmSeqReader

◆ RegtreeFmllrDiagGmmWriter

◆ RegtreeMllrDiagGmmSeqReader

◆ RegtreeMllrDiagGmmWriter

◆ SequentialCompactLatticeReader

◆ SequentialLatticeReader

◆ SequentialSgmm2GauPostReader

◆ Sgmm2GauPostHolder

Definition at line 578 of file am-sgmm2.h.

◆ Sgmm2GauPostWriter

Definition at line 581 of file am-sgmm2.h.

◆ SgmmUpdateFlagsType

typedef uint16 SgmmUpdateFlagsType

Bitwise OR of the above flags.

Definition at line 59 of file model-common.h.

◆ SgmmWriteFlagsType

typedef uint16 SgmmWriteFlagsType

Bitwise OR of the above flags.

Definition at line 70 of file model-common.h.

◆ SignedMatrixIndexT

Definition at line 99 of file matrix-common.h.

◆ StateId

typedef Arc::StateId StateId

Definition at line 34 of file lattice-determinize-non-compact.cc.

◆ StdLStdLStdArc

typedef fst::ArcTpl<StdLStdLStdWeight> StdLStdLStdArc

Definition at line 36 of file kaldi-kws.h.

◆ StdLStdLStdWeight

typedef fst::LexicographicWeight<TropicalWeight, StdLStdWeight> StdLStdLStdWeight

Definition at line 35 of file kaldi-kws.h.

◆ StdLStdWeight

typedef fst::LexicographicWeight<TropicalWeight, TropicalWeight> StdLStdWeight

Definition at line 34 of file kaldi-kws.h.

◆ StdXStdprimeWeight

typedef fst::ProductWeight<TropicalWeight, ArcticWeight> StdXStdprimeWeight

Definition at line 39 of file kaldi-kws.h.

◆ uint_smaller

typedef uint16 uint_smaller

Definition at line 32 of file cluster-utils.cc.

◆ UnsignedMatrixIndexT

typedef uint32 UnsignedMatrixIndexT

Definition at line 100 of file matrix-common.h.

◆ Weight

typedef Arc::Weight Weight

Definition at line 31 of file kws-search.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kEps 
kDisambig 
kBos 
kEos 

Definition at line 33 of file arpa-lm-compiler-test.cc.

◆ cova_type

enum cova_type

Generate features for a certain covariance type covariance_type == 0: full covariance covariance_type == 1: diagonal covariance.

Enumerator
full 
diag 

Definition at line 58 of file regtree-fmllr-diag-gmm-test.cc.

◆ CuCompressedMatrixType

Enumerator
kCompressedMatrixInt8 
kCompressedMatrixUint8 
kCompressedMatrixInt16 
kCompressedMatrixUint16 

Definition at line 140 of file cu-compressed-matrix.h.

◆ DetectionDecision

Enumerator
kKwsFalseAlarm 
kKwsMiss 
kKwsCorr 
kKwsCorrUndetected 
kKwsUnseen 

Definition at line 81 of file kws-scoring.h.

81  {
82  kKwsFalseAlarm, // Marked incorrectly as a hit
83  kKwsMiss, // Not marked as hit while it should be
84  kKwsCorr, // Marked correctly as a hit
85  kKwsCorrUndetected, // Not marked as a hit, correctly
86  kKwsUnseen // Instance not seen in the hypotheses list
87 };

◆ GmmUpdateFlags

Enumerator
kGmmMeans 
kGmmVariances 
kGmmWeights 
kGmmTransitions 
kGmmAll 

Definition at line 28 of file model-common.h.

28  {
29  kGmmMeans = 0x001, // m
30  kGmmVariances = 0x002, // v
31  kGmmWeights = 0x004, // w
32  kGmmTransitions = 0x008, // t ... not really part of GMM.
33  kGmmAll = 0x00F // a
34 };

◆ MatrixResizeType

Enumerator
kSetZero 
kUndefined 
kCopyData 

Definition at line 37 of file matrix-common.h.

◆ MatrixStrideType

Enumerator
kDefaultStride 
kStrideEqualNumCols 

Definition at line 44 of file matrix-common.h.

◆ MatrixTransposeType

Enumerator
kTrans 
kNoTrans 

Definition at line 32 of file matrix-common.h.

32  {
33  kTrans = 112, // = CblasTrans
34  kNoTrans = 111 // = CblasNoTrans
MatrixTransposeType
Definition: matrix-common.h:32

◆ SgmmUpdateFlags

Enumerator
kSgmmPhoneVectors 

The letters correspond to the variable names.

kSgmmPhoneProjections 

v

kSgmmPhoneWeightProjections 

M.

kSgmmCovarianceMatrix 

w

kSgmmSubstateWeights 

S.

kSgmmSpeakerProjections 

c

kSgmmTransitions 

N.

kSgmmSpeakerWeightProjections 

t .. not really part of SGMM.

kSgmmAll 

u [ for SSGMM ]

Definition at line 47 of file model-common.h.

◆ SgmmWriteFlags

Enumerator
kSgmmGlobalParams 
kSgmmStateParams 

g

kSgmmNormalizers 

s

kSgmmBackgroundGmms 

n

kSgmmWriteAll 

u

Definition at line 62 of file model-common.h.

◆ ShellType

enum ShellType
Enumerator
kBash 

Definition at line 210 of file parse-options.cc.

210 { kBash = 0 };

◆ SpCopyType

enum SpCopyType
Enumerator
kTakeLower 
kTakeUpper 
kTakeMean 
kTakeMeanAndCheck 

Definition at line 49 of file matrix-common.h.

Function Documentation

◆ _RandGauss()

static float kaldi::_RandGauss ( )
inlinestatic

Definition at line 34 of file am-sgmm2.cc.

References RandGauss().

Referenced by AmSgmm2::SplitSubstatesInGroup().

35 {
36  return RandGauss();
37 }
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155

◆ AccCmvnStats() [1/2]

void AccCmvnStats ( const VectorBase< BaseFloat > &  feats,
BaseFloat  weight,
MatrixBase< double > *  stats 
)

Accumulation from a single frame (weighted).

Definition at line 30 of file cmvn.cc.

References VectorBase< Real >::Data(), VectorBase< Real >::Dim(), KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::RowData().

Referenced by AccCmvnStats(), AccCmvnStatsForPair(), AccCmvnStatsWrapper(), and main().

30  {
31  int32 dim = feats.Dim();
32  KALDI_ASSERT(stats != NULL);
33  KALDI_ASSERT(stats->NumRows() == 2 && stats->NumCols() == dim + 1);
34  // Remove these __restrict__ modifiers if they cause compilation problems.
35  // It's just an optimization.
36  double *__restrict__ mean_ptr = stats->RowData(0),
37  *__restrict__ var_ptr = stats->RowData(1),
38  *__restrict__ count_ptr = mean_ptr + dim;
39  const BaseFloat * __restrict__ feats_ptr = feats.Data();
40  *count_ptr += weight;
41  // Careful-- if we change the format of the matrix, the "mean_ptr < count_ptr"
42  // statement below might become wrong.
43  for (; mean_ptr < count_ptr; mean_ptr++, var_ptr++, feats_ptr++) {
44  *mean_ptr += *feats_ptr * weight;
45  *var_ptr += *feats_ptr * *feats_ptr * weight;
46  }
47 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AccCmvnStats() [2/2]

void AccCmvnStats ( const MatrixBase< BaseFloat > &  feats,
const VectorBase< BaseFloat > *  weights,
MatrixBase< double > *  stats 
)

Accumulation from a feature file (possibly weighted– useful in excluding silence).

Definition at line 49 of file cmvn.cc.

References AccCmvnStats(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

51  {
52  int32 num_frames = feats.NumRows();
53  if (weights != NULL) {
54  KALDI_ASSERT(weights->Dim() == num_frames);
55  }
56  for (int32 i = 0; i < num_frames; i++) {
57  SubVector<BaseFloat> this_frame = feats.Row(i);
58  BaseFloat weight = (weights == NULL ? 1.0 : (*weights)(i));
59  if (weight != 0.0)
60  AccCmvnStats(this_frame, weight, stats);
61  }
62 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
void AccCmvnStats(const MatrixBase< BaseFloat > &feats, const VectorBase< BaseFloat > *weights, MatrixBase< double > *stats)
Accumulation from a feature file (possibly weighted– useful in excluding silence).
Definition: cmvn.cc:49
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AccCmvnStatsForPair()

void kaldi::AccCmvnStatsForPair ( const std::string &  utt1,
const std::string &  utt2,
const MatrixBase< BaseFloat > &  feats1,
const MatrixBase< BaseFloat > &  feats2,
BaseFloat  quieter_channel_weight,
MatrixBase< double > *  cmvn_stats1,
MatrixBase< double > *  cmvn_stats2 
)

Definition at line 69 of file compute-cmvn-stats-two-channel.cc.

References AccCmvnStats(), rnnlm::i, KALDI_ASSERT, KALDI_WARN, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

Referenced by main().

74  {
75  KALDI_ASSERT(feats1.NumCols() == feats2.NumCols()); // same dim.
76  if (feats1.NumRows() != feats2.NumRows()) {
77  KALDI_WARN << "Number of frames differ between " << utt1 << " and " << utt2
78  << ": " << feats1.NumRows() << " vs. " << feats2.NumRows()
79  << ", treating them separately.";
80  AccCmvnStats(feats1, NULL, cmvn_stats1);
81  AccCmvnStats(feats2, NULL, cmvn_stats2);
82  return;
83  }
84 
85  for (int32 i = 0; i < feats1.NumRows(); i++) {
86  if (feats1(i, 0) > feats2(i, 0)) {
87  AccCmvnStats(feats1.Row(i), 1.0, cmvn_stats1);
88  AccCmvnStats(feats2.Row(i), quieter_channel_weight, cmvn_stats2);
89  }
90  else {
91  AccCmvnStats(feats2.Row(i), 1.0, cmvn_stats2);
92  AccCmvnStats(feats1.Row(i), quieter_channel_weight, cmvn_stats1);
93  }
94  }
95 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_WARN
Definition: kaldi-error.h:150
void AccCmvnStats(const VectorBase< BaseFloat > &feats, BaseFloat weight, MatrixBase< double > *stats)
Accumulation from a single frame (weighted).
Definition: cmvn.cc:30
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ AccCmvnStatsWrapper()

bool kaldi::AccCmvnStatsWrapper ( const std::string &  utt,
const MatrixBase< BaseFloat > &  feats,
RandomAccessBaseFloatVectorReader weights_reader,
Matrix< double > *  cmvn_stats 
)

Definition at line 28 of file compute-cmvn-stats.cc.

References AccCmvnStats(), VectorBase< Real >::Dim(), RandomAccessTableReader< Holder >::HasKey(), RandomAccessTableReader< Holder >::IsOpen(), KALDI_WARN, MatrixBase< Real >::NumRows(), and RandomAccessTableReader< Holder >::Value().

Referenced by main().

31  {
32  if (!weights_reader->IsOpen()) {
33  AccCmvnStats(feats, NULL, cmvn_stats);
34  return true;
35  } else {
36  if (!weights_reader->HasKey(utt)) {
37  KALDI_WARN << "No weights available for utterance " << utt;
38  return false;
39  }
40  const Vector<BaseFloat> &weights = weights_reader->Value(utt);
41  if (weights.Dim() != feats.NumRows()) {
42  KALDI_WARN << "Weights for utterance " << utt << " have wrong dimension "
43  << weights.Dim() << " vs. " << feats.NumRows();
44  return false;
45  }
46  AccCmvnStats(feats, &weights, cmvn_stats);
47  return true;
48  }
49 }
const T & Value(const std::string &key)
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
bool HasKey(const std::string &key)
void AccCmvnStats(const VectorBase< BaseFloat > &feats, BaseFloat weight, MatrixBase< double > *stats)
Accumulation from a single frame (weighted).
Definition: cmvn.cc:30
A class representing a vector.
Definition: kaldi-vector.h:406
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ AccStatsForUtterance() [1/2]

void kaldi::AccStatsForUtterance ( const TransitionModel trans_model,
const AmDiagGmm am_gmm,
const GaussPost gpost,
const Matrix< BaseFloat > &  feats,
FmllrRawAccs accs 
)

Definition at line 31 of file gmm-est-fmllr-raw-gpost.cc.

References FmllrRawAccs::AccumulateFromPosteriors(), AmDiagGmm::GetPdf(), rnnlm::i, and MatrixBase< Real >::Row().

Referenced by UtteranceSplitter::ExitStatus(), IvectorExtractorStats::IvectorExtractorStats(), and main().

35  {
36  for (size_t t = 0; t < gpost.size(); t++) {
37  for (size_t i = 0; i < gpost[t].size(); i++) {
38  int32 pdf = gpost[t][i].first;
39  const Vector<BaseFloat> &posterior(gpost[t][i].second);
40  accs->AccumulateFromPosteriors(am_gmm.GetPdf(pdf),
41  feats.Row(t), posterior);
42  }
43  }
44 }
kaldi::int32 int32
void AccumulateFromPosteriors(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.
Definition: fmllr-raw.cc:246
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
A class representing a vector.
Definition: kaldi-vector.h:406

◆ AccStatsForUtterance() [2/2]

void kaldi::AccStatsForUtterance ( const TransitionModel trans_model,
const AmDiagGmm am_gmm,
const Posterior post,
const Matrix< BaseFloat > &  feats,
FmllrRawAccs accs 
)

Definition at line 31 of file gmm-est-fmllr-raw.cc.

References FmllrRawAccs::AccumulateForGmm(), ConvertPosteriorToPdfs(), AmDiagGmm::GetPdf(), rnnlm::i, and MatrixBase< Real >::Row().

35  {
36  Posterior pdf_post;
37  ConvertPosteriorToPdfs(trans_model, post, &pdf_post);
38  for (size_t t = 0; t < post.size(); t++) {
39  for (size_t i = 0; i < pdf_post[t].size(); i++) {
40  int32 pdf = pdf_post[t][i].first;
41  BaseFloat weight = pdf_post[t][i].second;
42  accs->AccumulateForGmm(am_gmm.GetPdf(pdf),
43  feats.Row(t), weight);
44  }
45  }
46 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
BaseFloat AccumulateForGmm(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
Definition: fmllr-raw.cc:107
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322

◆ AccumulateForUtterance() [1/8]

bool kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const DiagGmm gmm,
const std::string &  key,
RandomAccessBaseFloatVectorReader weights_reader,
RandomAccessInt32VectorVectorReader gselect_reader,
AccumFullGmm fullcov_stats 
)

Definition at line 32 of file gmm-global-est-fmllr.cc.

References AccumFullGmm::AccumulateForComponent(), AccumFullGmm::AccumulateFromDiag(), VectorBase< Real >::Dim(), RandomAccessTableReader< Holder >::HasKey(), rnnlm::i, RandomAccessTableReader< Holder >::IsOpen(), KALDI_WARN, DiagGmm::LogLikelihoodsPreselect(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), and RandomAccessTableReader< Holder >::Value().

37  {
38  Vector<BaseFloat> weights;
39  if (weights_reader->IsOpen()) {
40  if (!weights_reader->HasKey(key)) {
41  KALDI_WARN << "No weights present for utterance " << key;
42  return false;
43  }
44  weights = weights_reader->Value(key);
45  }
46  int32 num_frames = feats.NumRows();
47  if (gselect_reader->IsOpen()) {
48  if (!gselect_reader->HasKey(key)) {
49  KALDI_WARN << "No gselect information present for utterance " << key;
50  return false;
51  }
52  const std::vector<std::vector<int32> > &gselect(gselect_reader->Value(key));
53  if (gselect.size() != num_frames) {
54  KALDI_WARN << "gselect information has wrong size for utterance " << key;
55  return false;
56  }
57  for (int32 t = 0; t < num_frames; t++) {
58  const std::vector<int32> &this_gselect(gselect[t]);
59  BaseFloat weight = (weights.Dim() != 0 ? weights(t) : 1.0);
60  if (weight != 0.0) {
61  Vector<BaseFloat> post(this_gselect.size());
62  gmm.LogLikelihoodsPreselect(feats.Row(t), this_gselect, &post);
63  post.ApplySoftMax(); // get posteriors.
64  post.Scale(weight); // scale by the weight for this frame.
65  for (size_t i = 0; i < this_gselect.size(); i++)
66  fullcov_stats->AccumulateForComponent(feats.Row(t),
67  this_gselect[i], post(i));
68  }
69  }
70  } else {
71  for (int32 t = 0; t < num_frames; t++) {
72  BaseFloat weight = (weights.Dim() != 0 ? weights(t) : 1.0);
73  if (weight != 0.0)
74  fullcov_stats->AccumulateFromDiag(gmm, feats.Row(t), weight);
75  }
76  }
77  return true;
78 }
void LogLikelihoodsPreselect(const VectorBase< BaseFloat > &data, const std::vector< int32 > &indices, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods of a subset of mixture components.
Definition: diag-gmm.cc:566
BaseFloat AccumulateFromDiag(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior)
Accumulate for all components given a diagonal-covariance GMM.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
const T & Value(const std::string &key)
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
bool HasKey(const std::string &key)
A class representing a vector.
Definition: kaldi-vector.h:406
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void AccumulateForComponent(const VectorBase< BaseFloat > &data, int32 comp_index, BaseFloat weight)
Accumulate for a single component, given the posterior.
Definition: mle-full-gmm.cc:96

◆ AccumulateForUtterance() [2/8]

void kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const Sgmm2GauPost gpost,
const TransitionModel trans_model,
const AmSgmm2 am_sgmm,
Sgmm2PerSpkDerivedVars spk_vars,
MleSgmm2SpeakerAccs spk_stats 
)

Definition at line 33 of file sgmm2-est-spkvecs-gpost.cc.

References MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), AmSgmm2::ComputePerFrameVars(), rnnlm::i, rnnlm::j, MatrixBase< Real >::Row(), and TransitionModel::TransitionIdToPdf().

38  {
39  kaldi::Sgmm2PerFrameDerivedVars per_frame_vars;
40 
41  for (size_t i = 0; i < gpost.size(); i++) {
42  am_sgmm.ComputePerFrameVars(feats.Row(i),
43  gpost[i].gselect, *spk_vars,
44  &per_frame_vars);
45 
46  for (size_t j = 0; j < gpost[i].tids.size(); j++) {
47  int32 pdf_id = trans_model.TransitionIdToPdf(gpost[i].tids[j]);
48  spk_stats->AccumulateFromPosteriors(am_sgmm, per_frame_vars,
49  gpost[i].posteriors[j], pdf_id,
50  spk_vars);
51  }
52  }
53 }
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
BaseFloat AccumulateFromPosteriors(const AmSgmm2 &model, const Sgmm2PerFrameDerivedVars &frame_vars, const Matrix< BaseFloat > &posteriors, int32 pdf_index, Sgmm2PerSpkDerivedVars *spk_vars)
Accumulate statistics, given posteriors.
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
void ComputePerFrameVars(const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: ...
Definition: am-sgmm2.cc:442
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
Definition: am-sgmm2.h:142

◆ AccumulateForUtterance() [3/8]

void kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const Posterior post,
const DiagGmm gmm,
FmllrDiagGmmAccs spk_stats 
)

Definition at line 34 of file gmm-global-est-lvtln-trans.cc.

References FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

37  {
38  KALDI_ASSERT(static_cast<int32>(post.size()) == feats.NumRows());
39  for (size_t i = 0; i < post.size(); i++) {
40  std::vector<int32> gselect(post[i].size());
41  Vector<BaseFloat> this_post(post[i].size());
42  for (size_t j = 0; j < post[i].size(); j++) {
43  int32 g = post[i][j].first;
44  BaseFloat weight = post[i][j].second;
45  gselect[j] = g;
46  this_post(j) = weight;
47  }
48  spk_stats->AccumulateFromPosteriorsPreselect(gmm, gselect,
49  feats.Row(i),
50  this_post);
51  }
52 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void AccumulateFromPosteriorsPreselect(const DiagGmm &gmm, const std::vector< int32 > &gselect, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.

◆ AccumulateForUtterance() [4/8]

void kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const GaussPost gpost,
const AmDiagGmm am_gmm,
FmllrDiagGmmAccs spk_stats 
)

Definition at line 34 of file gmm-est-lvtln-trans.cc.

References FmllrDiagGmmAccs::AccumulateFromPosteriors(), AmDiagGmm::GetPdf(), rnnlm::i, rnnlm::j, and MatrixBase< Real >::Row().

37  {
38  for (size_t i = 0; i < gpost.size(); i++) {
39  for (size_t j = 0; j < gpost[i].size(); j++) {
40  int32 pdf_id = gpost[i][j].first;
41  const Vector<BaseFloat> &posterior(gpost[i][j].second);
42  spk_stats->AccumulateFromPosteriors(am_gmm.GetPdf(pdf_id),
43  feats.Row(i), posterior);
44  }
45  }
46 }
void AccumulateFromPosteriors(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
A class representing a vector.
Definition: kaldi-vector.h:406

◆ AccumulateForUtterance() [5/8]

void AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const GaussPost gpost,
const TransitionModel trans_model,
const AmDiagGmm am_gmm,
FmllrDiagGmmAccs spk_stats 
)

Definition at line 35 of file gmm-basis-fmllr-accs-gpost.cc.

References FmllrDiagGmmAccs::AccumulateFromPosteriors(), AmDiagGmm::GetPdf(), rnnlm::i, rnnlm::j, and MatrixBase< Real >::Row().

Referenced by main().

39  {
40  for (size_t i = 0; i < gpost.size(); i++) {
41  for (size_t j = 0; j < gpost[i].size(); j++) {
42  int32 pdf_id = gpost[i][j].first;
43  const Vector<BaseFloat> & posterior(gpost[i][j].second);
44  spk_stats->AccumulateFromPosteriors(am_gmm.GetPdf(pdf_id),
45  feats.Row(i), posterior);
46  }
47  }
48 }
void AccumulateFromPosteriors(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
A class representing a vector.
Definition: kaldi-vector.h:406

◆ AccumulateForUtterance() [6/8]

void AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const Posterior post,
const TransitionModel trans_model,
const AmDiagGmm am_gmm,
FmllrDiagGmmAccs spk_stats 
)

Definition at line 35 of file gmm-basis-fmllr-accs.cc.

References FmllrDiagGmmAccs::AccumulateForGmm(), ConvertPosteriorToPdfs(), AmDiagGmm::GetPdf(), rnnlm::i, rnnlm::j, and MatrixBase< Real >::Row().

39  {
40  Posterior pdf_post;
41  ConvertPosteriorToPdfs(trans_model, post, &pdf_post);
42  for (size_t i = 0; i < post.size(); i++) {
43  for (size_t j = 0; j < pdf_post[i].size(); j++) {
44  int32 pdf_id = pdf_post[i][j].first;
45  spk_stats->AccumulateForGmm(am_gmm.GetPdf(pdf_id),
46  feats.Row(i),
47  pdf_post[i][j].second);
48  }
49  }
50 }
kaldi::int32 int32
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322
BaseFloat AccumulateForGmm(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.

◆ AccumulateForUtterance() [7/8]

void kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const Matrix< BaseFloat > &  transformed_feats,
const std::vector< std::vector< int32 > > &  gselect,
const Posterior post,
const TransitionModel trans_model,
const AmSgmm2 am_sgmm,
BaseFloat  logdet,
Sgmm2PerSpkDerivedVars spk_vars,
FmllrSgmm2Accs spk_stats 
)

Definition at line 35 of file sgmm2-est-fmllr.cc.

References FmllrSgmm2Accs::AccumulateFromPosteriors(), AmSgmm2::ComponentPosteriors(), AmSgmm2::ComputePerFrameVars(), ConvertPosteriorToPdfs(), rnnlm::j, MatrixBase< Real >::Row(), and MatrixBase< Real >::Scale().

43  {
44  kaldi::Sgmm2PerFrameDerivedVars per_frame_vars;
45 
46  Posterior pdf_post;
47  ConvertPosteriorToPdfs(trans_model, post, &pdf_post);
48  for (size_t t = 0; t < post.size(); t++) {
49  // per-frame vars only used for computing posteriors... use the
50  // transformed feats for this, if available.
51  am_sgmm.ComputePerFrameVars(transformed_feats.Row(t), gselect[t],
52  *spk_vars, &per_frame_vars);
53 
54 
55  for (size_t j = 0; j < pdf_post[t].size(); j++) {
56  int32 pdf_id = pdf_post[t][j].first;
57  Matrix<BaseFloat> posteriors;
58  am_sgmm.ComponentPosteriors(per_frame_vars, pdf_id,
59  spk_vars, &posteriors);
60  posteriors.Scale(pdf_post[t][j].second);
61  spk_stats->AccumulateFromPosteriors(am_sgmm, *spk_vars, feats.Row(t),
62  gselect[t], posteriors, pdf_id);
63  }
64  }
65 }
BaseFloat ComponentPosteriors(const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j2, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *post) const
Similar to LogLikelihood() function above, but also computes the posterior probabilities for the pre-...
Definition: am-sgmm2.cc:574
void AccumulateFromPosteriors(const AmSgmm2 &sgmm, const Sgmm2PerSpkDerivedVars &spk, const VectorBase< BaseFloat > &data, const std::vector< int32 > &gauss_select, const Matrix< BaseFloat > &posteriors, int32 state_index)
Definition: fmllr-sgmm2.cc:171
kaldi::int32 int32
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
void Scale(Real alpha)
Multiply each element with a scalar value.
void ComputePerFrameVars(const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: ...
Definition: am-sgmm2.cc:442
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
Definition: am-sgmm2.h:142

◆ AccumulateForUtterance() [8/8]

void kaldi::AccumulateForUtterance ( const Matrix< BaseFloat > &  feats,
const Posterior post,
const TransitionModel trans_model,
const AmSgmm2 am_sgmm,
const vector< vector< int32 > > &  gselect,
Sgmm2PerSpkDerivedVars spk_vars,
MleSgmm2SpeakerAccs spk_stats 
)

Definition at line 36 of file sgmm2-est-spkvecs.cc.

References MleSgmm2SpeakerAccs::Accumulate(), AmSgmm2::ComputePerFrameVars(), ConvertPosteriorToPdfs(), rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

42  {
43  kaldi::Sgmm2PerFrameDerivedVars per_frame_vars;
44 
45  KALDI_ASSERT(gselect.size() == feats.NumRows());
46  Posterior pdf_post;
47  ConvertPosteriorToPdfs(trans_model, post, &pdf_post);
48  for (size_t i = 0; i < post.size(); i++) {
49  am_sgmm.ComputePerFrameVars(feats.Row(i), gselect[i],
50  *spk_vars, &per_frame_vars);
51 
52  for (size_t j = 0; j < pdf_post[i].size(); j++) {
53  int32 pdf_id = pdf_post[i][j].first;
54  spk_stats->Accumulate(am_sgmm, per_frame_vars, pdf_id,
55  pdf_post[i][j].second, spk_vars);
56  }
57  }
58 }
BaseFloat Accumulate(const AmSgmm2 &model, const Sgmm2PerFrameDerivedVars &frame_vars, int32 pdf_index, BaseFloat weight, Sgmm2PerSpkDerivedVars *spk_vars)
Accumulate statistics. Returns per-frame log-likelihood.
kaldi::int32 int32
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
void ComputePerFrameVars(const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: ...
Definition: am-sgmm2.cc:442
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
Definition: am-sgmm2.h:142

◆ AccumulateTreeStats()

void AccumulateTreeStats ( const TransitionModel trans_model,
const AccumulateTreeStatsInfo info,
const std::vector< int32 > &  alignment,
const Matrix< BaseFloat > &  features,
std::map< EventType, GaussClusterable * > *  stats 
)

Accumulates the stats needed for training context-dependency trees (in the "normal" way).

It adds to 'stats' the stats obtained from this file. Any new GaussClusterable* pointers in "stats" will be allocated with "new".

Definition at line 36 of file tree-accu.cc.

References AccumulateTreeStatsInfo::central_position, AccumulateTreeStatsInfo::ci_phones, AccumulateTreeStatsInfo::context_width, rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_WARN, kPdfClass, MapPhone(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), AccumulateTreeStatsInfo::phone_map, MatrixBase< Real >::Row(), SplitToPhones(), TransitionModel::TransitionIdToPdfClass(), TransitionModel::TransitionIdToPhone(), and AccumulateTreeStatsInfo::var_floor.

Referenced by main().

40  {
41  std::vector<std::vector<int32> > split_alignment;
42  bool ans = SplitToPhones(trans_model, alignment, &split_alignment);
43  if (!ans) {
44  KALDI_WARN << "AccumulateTreeStats: alignment appears to be bad, not using it";
45  return;
46  }
47  int32 cur_pos = 0;
48  int32 dim = features.NumCols();
49  KALDI_ASSERT(features.NumRows() == static_cast<int32>(alignment.size()));
50  for (int32 i = -info.context_width; i < static_cast<int32>(split_alignment.size()); i++) {
51  // consider window starting at i, only if i+info.central_position is within
52  // list of phones.
53  if (i + info.central_position >= 0 &&
54  i + info.central_position < static_cast<int32>(split_alignment.size())) {
55  int32 central_phone =
56  MapPhone(info.phone_map,
57  trans_model.TransitionIdToPhone(
58  split_alignment[i+info.central_position][0]));
59  bool is_ctx_dep = !std::binary_search(info.ci_phones.begin(),
60  info.ci_phones.end(),
61  central_phone);
62  EventType evec;
63  for (int32 j = 0; j < info.context_width; j++) {
64  int32 phone;
65  if (i + j >= 0 && i + j < static_cast<int32>(split_alignment.size()))
66  phone =
67  MapPhone(info.phone_map,
68  trans_model.TransitionIdToPhone(split_alignment[i+j][0]));
69  else
70  phone = 0; // ContextDependency class uses 0 to mean "out of window";
71  // we also set the phone arbitrarily to 0
72 
73  // Don't add stuff to the event that we don't "allow" to be asked, due
74  // to the central phone being context-independent: check "is_ctx_dep".
75  // Why not just set the value to zero in this
76  // case? It's for safety. By omitting the key from the event, we
77  // ensure that there is no way a question can ever be asked that might
78  // give an inconsistent answer in tree-training versus graph-building.
79  // [setting it to zero would have the same effect given the "normal"
80  // recipe but might be less robust to changes in tree-building recipe].
81  if (is_ctx_dep || j == info.central_position)
82  evec.push_back(std::make_pair(static_cast<EventKeyType>(j), static_cast<EventValueType>(phone)));
83  }
84  for (int32 j = 0; j < static_cast<int32>(split_alignment[i+info.central_position].size());j++) {
85  // for central phone of this window...
86  EventType evec_more(evec);
87  int32 pdf_class = trans_model.TransitionIdToPdfClass(
88  split_alignment[i+info.central_position][j]);
89  // pdf_class will normally by 0, 1 or 2 for 3-state HMM.
90  std::pair<EventKeyType, EventValueType> pr(kPdfClass, pdf_class);
91  evec_more.push_back(pr);
92  std::sort(evec_more.begin(), evec_more.end()); // these must be sorted!
93  if (stats->count(evec_more) == 0)
94  (*stats)[evec_more] = new GaussClusterable(dim, info.var_floor);
95 
96  BaseFloat weight = 1.0;
97  (*stats)[evec_more]->AddStats(features.Row(cur_pos), weight);
98  cur_pos++;
99  }
100  }
101  }
102  KALDI_ASSERT(cur_pos == static_cast<int32>(alignment.size()));
103 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
static int32 MapPhone(const std::vector< int32 > &phone_map, int32 phone)
Definition: tree-accu.cc:26
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
Definition: hmm-utils.cc:723
static const EventKeyType kPdfClass
Definition: context-dep.h:39
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ AddCompactLatticeArcToLattice()

static void kaldi::AddCompactLatticeArcToLattice ( const CompactLatticeArc clat_arc,
LatticeArc::StateId  src_state,
Lattice lat 
)
static

Definition at line 1106 of file lattice-incremental-decoder.cc.

References rnnlm::i.

Referenced by LatticeIncrementalDeterminizer::InitializeRawLatticeChunk().

1109  {
1110  const std::vector<int32> &string = clat_arc.weight.String();
1111  size_t N = string.size();
1112  if (N == 0) {
1113  LatticeArc arc;
1114  arc.ilabel = 0;
1115  arc.olabel = clat_arc.ilabel;
1116  arc.nextstate = clat_arc.nextstate;
1117  arc.weight = clat_arc.weight.Weight();
1118  lat->AddArc(src_state, arc);
1119  } else {
1120  LatticeArc::StateId cur_state = src_state;
1121  for (size_t i = 0; i < N; i++) {
1122  LatticeArc arc;
1123  arc.ilabel = string[i];
1124  arc.olabel = (i == 0 ? clat_arc.ilabel : 0);
1125  arc.nextstate = (i + 1 == N ? clat_arc.nextstate : lat->AddState());
1126  arc.weight = (i == 0 ? clat_arc.weight.Weight() : LatticeWeight::One());
1127  lat->AddArc(cur_state, arc);
1128  cur_state = arc.nextstate;
1129  }
1130  }
1131 }
fst::StdArc::StateId StateId
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40

◆ AddMatMatBatched() [1/3]

void AddMatMatBatched ( const Real  alpha,
std::vector< CuSubMatrix< Real > *> &  C,
const std::vector< CuSubMatrix< Real > *> &  A,
MatrixTransposeType  transA,
const std::vector< CuSubMatrix< Real > *> &  B,
MatrixTransposeType  transB,
const Real  beta 
)

Does multiple matrix multiplications, executing them in parallel using cuBLAS's gemmBatched if we are using a GPU.

Vectors A, B and C must have the same length; for each i, this function executes the matrix operation C[i] = alpha * A[i](^T)*B[i](^T) + beta * C[i].

Definition at line 2207 of file cu-matrix.cc.

References AddMatMatBatched(), CuMatrixBase< Real >::data_, rnnlm::i, KALDI_ASSERT, kTrans, rnnlm::n, CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().

Referenced by TestCuMatrixMatMatBatched(), and UnitTestCuMatrixAddMatMatBatched().

2211  {
2212  KALDI_ASSERT(A.size() == B.size() && B.size() == C.size());
2213  int32 size = A.size();
2214 
2215  if (size == 0) return;
2216 
2217  // all elements must have the same num-rows, num-cols and stride
2218  for (int32 i = 0; i + 1 < size; i++) {
2219  KALDI_ASSERT(A[i]->NumRows() == A[i+1]->NumRows());
2220  KALDI_ASSERT(A[i]->NumCols() == A[i+1]->NumCols());
2221  KALDI_ASSERT(A[i]->Stride() == A[i+1]->Stride());
2222  KALDI_ASSERT(B[i]->NumRows() == B[i+1]->NumRows());
2223  KALDI_ASSERT(B[i]->NumCols() == B[i+1]->NumCols());
2224  KALDI_ASSERT(B[i]->Stride() == B[i+1]->Stride());
2225  KALDI_ASSERT(C[i]->NumRows() == C[i+1]->NumRows());
2226  KALDI_ASSERT(C[i]->NumCols() == C[i+1]->NumCols());
2227  KALDI_ASSERT(C[i]->Stride() == C[i+1]->Stride());
2228  }
2229  // CUBLAS is col-major, cudamatrix is row-major, how to do the mapping?
2230  // keep trans..., just swap A&B matrices: A->B B->A
2231  MatrixIndexT m = ((transB==kTrans)? B[0]->NumRows() : B[0]->NumCols());
2232  MatrixIndexT n = ((transA==kTrans)? A[0]->NumCols() : A[0]->NumRows());
2233  MatrixIndexT k = ((transB==kTrans)? B[0]->NumCols() : B[0]->NumRows());
2234  MatrixIndexT k1 = ((transA==kTrans)? A[0]->NumRows() : A[0]->NumCols());
2235 
2236  KALDI_ASSERT(m == C[0]->NumCols());
2237  KALDI_ASSERT(n == C[0]->NumRows());
2238  KALDI_ASSERT(k == k1);
2239 
2240  if (m == 0) return;
2241 
2242 #if HAVE_CUDA == 1
2243  if (CuDevice::Instantiate().Enabled()) {
2244  CuTimer tim;
2245  Real **device_abc_array =
2246  static_cast<Real**>(CuDevice::Instantiate().Malloc(3 * size * sizeof(Real*)));
2247  const Real **device_a_array = const_cast<const Real**>(device_abc_array);
2248  const Real **device_b_array = const_cast<const Real**>(device_abc_array) + size;
2249  Real **device_c_array = device_abc_array + 2 * size;
2250  const Real **host_abc_array = new const Real*[3*size];
2251  const Real **host_a_array = host_abc_array;
2252  const Real **host_b_array = host_abc_array + size;
2253  const Real **host_c_array = host_abc_array + 2 * size;
2254 
2255  for (int32 i = 0; i < size; i++) {
2256  host_a_array[i] = A[i]->data_;
2257  host_b_array[i] = B[i]->data_;
2258  host_c_array[i] = C[i]->data_;
2259  }
2260 
2261  CU_SAFE_CALL(cudaMemcpyAsync(device_abc_array, host_abc_array,
2262  3*size*sizeof(Real*), cudaMemcpyHostToDevice,
2263  cudaStreamPerThread));
2264 
2265  CUBLAS_SAFE_CALL(cublas_gemmBatched(GetCublasHandle(),
2266  (transB==kTrans? CUBLAS_OP_T:CUBLAS_OP_N),
2267  (transA==kTrans? CUBLAS_OP_T:CUBLAS_OP_N),
2268  m, n, k, alpha, device_b_array,
2269  B[0]->Stride(), device_a_array,
2270  A[0]->Stride(), beta, device_c_array,
2271  C[0]->Stride(), size));
2272 
2273  CuDevice::Instantiate().Free(device_abc_array);
2274  delete[] host_abc_array;
2275 
2276  CuDevice::Instantiate().AccuProfile(__func__, tim);
2277  } else
2278 #endif
2279  {
2280  for (int32 i = 0; i < size; i++) {
2281  C[i]->Mat().AddMatMat(alpha, A[i]->Mat(), transA, B[i]->Mat(), transB, beta);
2282  }
2283  }
2284 }
kaldi::int32 int32
int32 MatrixIndexT
Definition: matrix-common.h:98
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AddMatMatBatched() [2/3]

template void kaldi::AddMatMatBatched ( const float  alpha,
std::vector< CuSubMatrix< float > * > &  C,
const std::vector< CuSubMatrix< float > * > &  A,
MatrixTransposeType  transA,
const std::vector< CuSubMatrix< float > * > &  B,
MatrixTransposeType  transB,
const float  beta 
)

◆ AddMatMatBatched() [3/3]

template void kaldi::AddMatMatBatched ( const double  alpha,
std::vector< CuSubMatrix< double > * > &  C,
const std::vector< CuSubMatrix< double > * > &  A,
MatrixTransposeType  transA,
const std::vector< CuSubMatrix< double > * > &  B,
MatrixTransposeType  transB,
const double  beta 
)

Referenced by AddMatMatBatched().

◆ AddNoise()

void kaldi::AddNoise ( Vector< BaseFloat > *  noise,
BaseFloat  snr_db,
BaseFloat  time,
BaseFloat  samp_freq,
BaseFloat  signal_power,
Vector< BaseFloat > *  signal 
)

Definition at line 104 of file wav-reverberate.cc.

References AddVectorsWithOffset(), VectorBase< Real >::Dim(), KALDI_VLOG, VectorBase< Real >::Scale(), and VecVec().

Referenced by main().

106  {
107  float noise_power = VecVec(*noise, *noise) / noise->Dim();
108  float scale_factor = sqrt(pow(10, -snr_db / 10) * signal_power / noise_power);
109  noise->Scale(scale_factor);
110  KALDI_VLOG(1) << "Noise signal is being scaled with " << scale_factor
111  << " to generate output with SNR " << snr_db << "db\n";
112  int32 offset = time * samp_freq;
113  AddVectorsWithOffset(*noise, offset, signal);
114 }
kaldi::int32 int32
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
void Scale(Real alpha)
Multiplies all elements by this constant.
void AddVectorsWithOffset(const Vector< BaseFloat > &signal1, int32 offset, Vector< BaseFloat > *signal2)
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ AddOuterProductPlusMinus< double >()

template void kaldi::AddOuterProductPlusMinus< double > ( double  alpha,
const VectorBase< double > &  a,
const VectorBase< double > &  b,
MatrixBase< double > *  plus,
MatrixBase< double > *  minus 
)

◆ AddOuterProductPlusMinus< float >()

template void kaldi::AddOuterProductPlusMinus< float > ( float  alpha,
const VectorBase< float > &  a,
const VectorBase< float > &  b,
MatrixBase< float > *  plus,
MatrixBase< float > *  minus 
)

◆ AddSelfLoops()

void kaldi::AddSelfLoops ( fst::StdMutableFst *  fst)

Definition at line 109 of file arpa-lm-compiler-test.cc.

References kDisambig, and kEps.

109  {
110  for (fst::StateIterator<fst::StdMutableFst> siter(*fst);
111  !siter.Done(); siter.Next()) {
112  fst->AddArc(siter.Value(),
113  fst::StdArc(kEps, kDisambig, 0, siter.Value()));
114  }
115 }
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc

◆ AddSelfLoopsNoReorder()

static void kaldi::AddSelfLoopsNoReorder ( const TransitionModel trans_model,
const std::vector< int32 > &  disambig_syms,
BaseFloat  self_loop_scale,
bool  check_no_self_loops,
fst::VectorFst< fst::StdArc > *  fst 
)
static

Definition at line 555 of file hmm-utils.cc.

References TransitionModel::GetNonSelfLoopLogProb(), TransitionModel::GetTransitionLogProb(), KALDI_ASSERT, fst::MakeFollowingInputSymbolsSameClass(), TransitionModel::SelfLoopOf(), and fst::Times().

Referenced by AddSelfLoops().

560  {
561  using namespace fst;
562  typedef StdArc Arc;
563  typedef Arc::Label Label;
564  typedef Arc::StateId StateId;
565  typedef Arc::Weight Weight;
566 
567  // Duplicate states as necessary so that each state has at most one self-loop
568  // on it.
569  TidToTstateMapper f(trans_model, disambig_syms, check_no_self_loops);
571 
572  StateId num_states = fst->NumStates();
573  for (StateId s = 0; s < num_states; s++) {
574  int32 my_trans_state = f(kNoLabel);
575  KALDI_ASSERT(my_trans_state == -1);
576  for (MutableArcIterator<VectorFst<Arc> > aiter(fst, s);
577  !aiter.Done();
578  aiter.Next()) {
579  Arc arc = aiter.Value();
580  if (my_trans_state == -1) my_trans_state = f(arc.ilabel);
581  else KALDI_ASSERT(my_trans_state == f(arc.ilabel)); // or MakeFollowingInputSymbolsSameClass failed.
582  if (my_trans_state > 0) { // transition-id; multiply weight...
583  BaseFloat log_prob = trans_model.GetNonSelfLoopLogProb(my_trans_state);
584  arc.weight = Times(arc.weight, Weight(-log_prob*self_loop_scale));
585  aiter.SetValue(arc);
586  }
587  }
588  if (fst->Final(s) != Weight::Zero()) {
589  KALDI_ASSERT(my_trans_state == kNoLabel || my_trans_state == 0); // or MakeFollowingInputSymbolsSameClass failed.
590  }
591  if (my_trans_state != kNoLabel && my_trans_state != 0) {
592  // a transition-state; add self-loop, if it has one.
593  int32 trans_id = trans_model.SelfLoopOf(my_trans_state);
594  if (trans_id != 0) { // has self-loop.
595  BaseFloat log_prob = trans_model.GetTransitionLogProb(trans_id);
596  fst->AddArc(s, Arc(trans_id, 0, Weight(-log_prob*self_loop_scale), s));
597  }
598  }
599  }
600 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc
kaldi::int32 int32
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
fst::StdArc::Label Label
float BaseFloat
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void MakeFollowingInputSymbolsSameClass(bool end_is_epsilon, MutableFst< Arc > *fst, const F &f)
As MakeFollowingInputSymbolsSame, but takes a functor object that maps labels to classes.

◆ AddSelfLoopsReorder()

static void kaldi::AddSelfLoopsReorder ( const TransitionModel trans_model,
const std::vector< int32 > &  disambig_syms,
BaseFloat  self_loop_scale,
bool  check_no_self_loops,
fst::VectorFst< fst::StdArc > *  fst 
)
static

Definition at line 472 of file hmm-utils.cc.

References TransitionModel::GetNonSelfLoopLogProb(), TransitionModel::GetTransitionLogProb(), KALDI_ASSERT, fst::MakePrecedingInputSymbolsSameClass(), TransitionModel::SelfLoopOf(), and fst::Times().

Referenced by AddSelfLoops().

476  {
477  using namespace fst;
478  typedef StdArc Arc;
479  typedef Arc::Label Label;
480  typedef Arc::StateId StateId;
481  typedef Arc::Weight Weight;
482 
483  TidToTstateMapper f(trans_model, disambig_syms, check_no_self_loops);
484  // Duplicate states as necessary so that each state will require at most one
485  // self-loop to be added to it. Approximately this means that if a
486  // state has multiple different symbols on arcs entering it, it will be
487  // duplicated, with one copy per incoming symbol.
489 
490  int32 kNoTransState = f(kNoLabel);
491  KALDI_ASSERT(kNoTransState == -1);
492 
493  // use the following to keep track of the transition-state for each state.
494  std::vector<int32> state_in(fst->NumStates(), kNoTransState);
495 
496  // This first loop just works out the label into each state,
497  // and converts the transitions in the graph from transition-states
498  // to transition-ids.
499 
500  for (StateIterator<VectorFst<Arc> > siter(*fst);
501  !siter.Done();
502  siter.Next()) {
503  StateId s = siter.Value();
504  for (MutableArcIterator<VectorFst<Arc> > aiter(fst, s);
505  !aiter.Done();
506  aiter.Next()) {
507  Arc arc = aiter.Value();
508  int32 trans_state = f(arc.ilabel);
509  if (state_in[arc.nextstate] == kNoTransState)
510  state_in[arc.nextstate] = trans_state;
511  else {
512  KALDI_ASSERT(state_in[arc.nextstate] == trans_state);
513  // or probably an error in MakePrecedingInputSymbolsSame.
514  }
515  }
516  }
517 
518  KALDI_ASSERT(state_in[fst->Start()] == kNoStateId || state_in[fst->Start()] == 0);
519  // or MakePrecedingInputSymbolsSame failed.
520 
521  // The next loop looks at each graph state, adds the self-loop [if needed] and
522  // multiples all the out-transitions' probs (and final-prob) by the
523  // forward-prob for that state (which is one minus self-loop-prob). We do it
524  // like this to maintain stochasticity (i.e. rather than multiplying the arcs
525  // with the corresponding labels on them by this probability).
526 
527  for (StateId s = 0; s < static_cast<StateId>(state_in.size()); s++) {
528  if (state_in[s] > 0) { // defined, and not eps or a disambiguation symbol or a
529  // nonterminal-related sybol for grammar decoding...
530  int32 trans_state = static_cast<int32>(state_in[s]);
531  // First multiply all probabilities by "forward" probability.
532  BaseFloat log_prob = trans_model.GetNonSelfLoopLogProb(trans_state);
533  fst->SetFinal(s, Times(fst->Final(s), Weight(-log_prob*self_loop_scale)));
534  for (MutableArcIterator<MutableFst<Arc> > aiter(fst, s);
535  !aiter.Done();
536  aiter.Next()) {
537  Arc arc = aiter.Value();
538  arc.weight = Times(arc.weight, Weight(-log_prob*self_loop_scale));
539  aiter.SetValue(arc);
540  }
541  // Now add self-loop, if needed.
542  int32 trans_id = trans_model.SelfLoopOf(trans_state);
543  if (trans_id != 0) { // has self-loop.
544  BaseFloat log_prob = trans_model.GetTransitionLogProb(trans_id);
545  fst->AddArc(s, Arc(trans_id, 0, Weight(-log_prob*self_loop_scale), s));
546  }
547  }
548  }
549 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc
kaldi::int32 int32
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
fst::StdArc::Label Label
float BaseFloat
void MakePrecedingInputSymbolsSameClass(bool start_is_epsilon, MutableFst< Arc > *fst, const F &f)
As MakePrecedingInputSymbolsSame, but takes a functor object that maps labels to classes.
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AddToChainFsa()

fst::StdArc::StateId kaldi::AddToChainFsa ( fst::StdMutableFst *  fst,
fst::StdArc::StateId  last_state,
int64  symbol 
)

Definition at line 100 of file arpa-lm-compiler-test.cc.

Referenced by ScoringTest().

102  {
103  fst::StdArc::StateId next_state = fst->AddState();
104  fst->AddArc(last_state, fst::StdArc(symbol, symbol, 0, next_state));
105  return next_state;
106 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc

◆ AddToConfusionMatrix()

void kaldi::AddToConfusionMatrix ( int32  phone1,
int32  phone2,
Matrix< double > *  counts 
)

Definition at line 40 of file compare-int-vector.cc.

References KALDI_ERR, kCopyData, MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by main().

41  {
42  if (phone1 < 0 || phone2 < 0)
43  KALDI_ERR << "Contents of vectors cannot be "
44  "negative if --write-confusion-matrix option is "
45  "provided.";
46  int32 max_size = std::max<int32>(phone1, phone2) + 1;
47  if (counts->NumRows() < max_size)
48  counts->Resize(max_size, max_size, kCopyData);
49  (*counts)(phone1, phone2) += 1.0;
50 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ AddToCount()

void kaldi::AddToCount ( int32  location_to_add,
double  value_to_add,
std::vector< double > *  counts 
)

Definition at line 28 of file compare-int-vector.cc.

References KALDI_ERR.

Referenced by main().

30  {
31  if (location_to_add < 0)
32  KALDI_ERR << "Contents of vectors cannot be "
33  "negative if --write-tot-counts or --write-diff-counts "
34  "options are provided.";
35  if (counts->size() <= static_cast<size_t>(location_to_add))
36  counts->resize(location_to_add + 1, 0.0);
37  (*counts)[location_to_add] += value_to_add;
38 }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ AddVectorsOfUnequalLength()

void kaldi::AddVectorsOfUnequalLength ( const VectorBase< BaseFloat > &  signal1,
Vector< BaseFloat > *  signal2 
)

Definition at line 31 of file wav-reverberate.cc.

References VectorBase< Real >::Dim(), and VectorBase< Real >::Range().

Referenced by main().

32  {
33  for (int32 po = 0; po < signal2->Dim(); po += signal1.Dim()) {
34  int32 block_length = signal1.Dim();
35  if (signal2->Dim() - po < block_length) block_length = signal2->Dim() - po;
36  signal2->Range(po, block_length).AddVec(1.0, signal1.Range(0, block_length));
37  }
38 }
kaldi::int32 int32
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
Definition: kaldi-vector.h:94

◆ AddVectorsWithOffset()

void kaldi::AddVectorsWithOffset ( const Vector< BaseFloat > &  signal1,
int32  offset,
Vector< BaseFloat > *  signal2 
)

Definition at line 44 of file wav-reverberate.cc.

References VectorBase< Real >::Dim(), and VectorBase< Real >::Range().

Referenced by AddNoise().

45  {
46  int32 add_length = std::min(signal2->Dim() - offset, signal1.Dim());
47  if (add_length > 0)
48  signal2->Range(offset, add_length).AddVec(1.0, signal1.Range(0, add_length));
49 }
kaldi::int32 int32
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
Definition: kaldi-vector.h:94

◆ AddWordInsPenToCompactLattice()

void AddWordInsPenToCompactLattice ( BaseFloat  word_ins_penalty,
CompactLattice clat 
)

This function add the word insertion penalty to graph score of each word in the compact lattice.

Definition at line 1181 of file lattice-functions.cc.

References LatticeWeightTpl< FloatType >::SetValue1(), and LatticeWeightTpl< FloatType >::Value1().

Referenced by main().

1182  {
1183  typedef CompactLatticeArc Arc;
1184  int32 num_states = clat->NumStates();
1185 
1186  //scan the lattice
1187  for (int32 state = 0; state < num_states; state++) {
1188  for (fst::MutableArcIterator<CompactLattice> aiter(clat, state);
1189  !aiter.Done(); aiter.Next()) {
1190 
1191  Arc arc(aiter.Value());
1192 
1193  if (arc.ilabel != 0) { // if there is a word on this arc
1194  LatticeWeight weight = arc.weight.Weight();
1195  // add word insertion penalty to lattice
1196  weight.SetValue1( weight.Value1() + word_ins_penalty);
1197  arc.weight.SetWeight(weight);
1198  aiter.SetValue(arc);
1199  }
1200  } // end looping over arcs
1201  } // end looping over states
1202 }
kaldi::int32 int32
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ AgglomerativeCluster()

void AgglomerativeCluster ( const Matrix< BaseFloat > &  costs,
BaseFloat  threshold,
int32  min_clusters,
int32  first_pass_max_points,
BaseFloat  max_cluster_fraction,
std::vector< int32 > *  assignments_out 
)

This is the function that is called to perform the agglomerative clustering.

It takes the following arguments:

  • A matrix of all pairwise costs, with each row/column corresponding to an utterance ID, and the elements of the matrix containing the cost for pairing the utterances for its row and column
  • A threshold which is used as the stopping criterion for the clusters
  • A minimum number of clusters that will not be merged past
  • A maximum fraction of points that can be in a cluster
  • A vector which will be filled with integer IDs corresponding to each of the rows/columns of the score matrix.

The basic algorithm is as follows:

while (num-clusters > min-clusters && smallest-merge-cost <= threshold)
if (size-of-new-cluster <= max-cluster-size)
merge the two clusters with lowest cost

The cost between two clusters is the average cost of all pairwise costs between points across the two clusters.

The algorithm takes advantage of the fact that the sum of the pairwise costs between the points of clusters I and J is equiavlent to the sum of the pairwise costs between cluster I and the parents of cluster J. In other words, the total cost between I and J is the sum of the costs between clusters I and M and clusters I and N, where cluster J was formed by merging clusters M and N.

If the number of points to cluster is larger than first-pass-max-points, then clustering is done in two passes. In the first pass, input points are divided into contiguous subsets of size at most first-pass-max-points and each subset is clustered separately. In the second pass, the first pass clusters are merged into the final set of clusters.

Definition at line 223 of file agglomerative-clustering.cc.

References AgglomerativeClusterer::Cluster(), and KALDI_ASSERT.

Referenced by main().

229  {
230  KALDI_ASSERT(min_clusters >= 0);
231  KALDI_ASSERT(max_cluster_fraction >= 1.0 / min_clusters);
232  AgglomerativeClusterer ac(costs, threshold, min_clusters,
233  first_pass_max_points, max_cluster_fraction,
234  assignments_out);
235  ac.Cluster();
236 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AlignUtteranceWrapper()

void AlignUtteranceWrapper ( const AlignConfig config,
const std::string &  utt,
BaseFloat  acoustic_scale,
fst::VectorFst< fst::StdArc > *  fst,
DecodableInterface decodable,
Int32VectorWriter alignment_writer,
BaseFloatWriter scores_writer,
int32 num_done,
int32 num_error,
int32 num_retried,
double *  tot_like,
int64 *  frame_count,
BaseFloatVectorWriter per_frame_acwt_writer = NULL 
)

AlignUtteranceWapper is a wrapper for alignment code used in training, that is called from many different binaries, e.g.

gmm-align, gmm-align-compiled, sgmm-align, etc. The writers for alignments and words will only be written to if they are open. The num_done, num_error, num_retried, tot_like and frame_count pointers will (if non-NULL) be incremented or added to, not set, by this function.

Definition at line 576 of file decoder-wrappers.cc.

References FasterDecoderOptions::beam, AlignConfig::beam, AlignConfig::careful, FasterDecoder::Decode(), FasterDecoder::GetBestPath(), fst::GetLinearSymbolSequence(), GetPerFrameAcousticCosts(), TableWriter< Holder >::IsOpen(), KALDI_ERR, KALDI_WARN, ModifyGraphForCarefulAlignment(), DecodableInterface::NumFramesReady(), FasterDecoder::ReachedFinal(), AlignConfig::retry_beam, VectorBase< Real >::Scale(), FasterDecoder::SetOptions(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), words, and TableWriter< Holder >::Write().

Referenced by main(), and AlignConfig::Register().

591  {
592 
593  if ((config.retry_beam != 0 && config.retry_beam <= config.beam) ||
594  config.beam <= 0.0) {
595  KALDI_ERR << "Beams do not make sense: beam " << config.beam
596  << ", retry-beam " << config.retry_beam;
597  }
598 
599  if (fst->Start() == fst::kNoStateId) {
600  KALDI_WARN << "Empty decoding graph for " << utt;
601  if (num_error != NULL) (*num_error)++;
602  return;
603  }
604 
605  if (config.careful)
607 
608  FasterDecoderOptions decode_opts;
609  decode_opts.beam = config.beam;
610 
611  FasterDecoder decoder(*fst, decode_opts);
612  decoder.Decode(decodable);
613 
614  bool ans = decoder.ReachedFinal(); // consider only final states.
615 
616  if (!ans && config.retry_beam != 0.0) {
617  if (num_retried != NULL) (*num_retried)++;
618  KALDI_WARN << "Retrying utterance " << utt << " with beam "
619  << config.retry_beam;
620  decode_opts.beam = config.retry_beam;
621  decoder.SetOptions(decode_opts);
622  decoder.Decode(decodable);
623  ans = decoder.ReachedFinal();
624  }
625 
626  if (!ans) { // Still did not reach final state.
627  KALDI_WARN << "Did not successfully decode file " << utt << ", len = "
628  << decodable->NumFramesReady();
629  if (num_error != NULL) (*num_error)++;
630  return;
631  }
632 
633  fst::VectorFst<LatticeArc> decoded; // linear FST.
634  decoder.GetBestPath(&decoded);
635  if (decoded.NumStates() == 0) {
636  KALDI_WARN << "Error getting best path from decoder (likely a bug)";
637  if (num_error != NULL) (*num_error)++;
638  return;
639  }
640 
641  std::vector<int32> alignment;
642  std::vector<int32> words;
643  LatticeWeight weight;
644 
645  GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
646  BaseFloat like = -(weight.Value1()+weight.Value2()) / acoustic_scale;
647 
648  if (num_done != NULL) (*num_done)++;
649  if (tot_like != NULL) (*tot_like) += like;
650  if (frame_count != NULL) (*frame_count) += decodable->NumFramesReady();
651 
652  if (alignment_writer != NULL && alignment_writer->IsOpen())
653  alignment_writer->Write(utt, alignment);
654 
655  if (scores_writer != NULL && scores_writer->IsOpen())
656  scores_writer->Write(utt, -(weight.Value1()+weight.Value2()));
657 
658  Vector<BaseFloat> per_frame_loglikes;
659  if (per_frame_acwt_writer != NULL && per_frame_acwt_writer->IsOpen()) {
660  GetPerFrameAcousticCosts(decoded, &per_frame_loglikes);
661  per_frame_loglikes.Scale(-1 / acoustic_scale);
662  per_frame_acwt_writer->Write(utt, per_frame_loglikes);
663  }
664 }
int32 words[kMaxOrder]
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void GetPerFrameAcousticCosts(const Lattice &nbest, Vector< BaseFloat > *per_frame_loglikes)
This function extracts the per-frame log likelihoods from a linear lattice (which we refer to as an &#39;...
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
void ModifyGraphForCarefulAlignment(fst::VectorFst< fst::StdArc > *fst)
This function modifies the decoding graph for what we call "careful alignment".
LatticeWeightTpl< BaseFloat > LatticeWeight

◆ AppendFeats()

bool kaldi::AppendFeats ( const std::vector< Matrix< BaseFloat > > &  in,
const std::string &  utt,
int32  tolerance,
Matrix< BaseFloat > *  out 
)

Definition at line 30 of file paste-feats.cc.

References rnnlm::i, KALDI_VLOG, KALDI_WARN, MatrixBase< Real >::Range(), and Matrix< Real >::Resize().

Referenced by main().

33  {
34  // Check the lengths
35  int32 min_len = in[0].NumRows(),
36  max_len = in[0].NumRows(),
37  tot_dim = in[0].NumCols();
38  for (int32 i = 1; i < in.size(); i++) {
39  int32 len = in[i].NumRows(), dim = in[i].NumCols();
40  tot_dim += dim;
41  if(len < min_len) min_len = len;
42  if(len > max_len) max_len = len;
43  }
44  if (max_len - min_len > tolerance || min_len == 0) {
45  KALDI_WARN << "Length mismatch " << max_len << " vs. " << min_len
46  << (utt.empty() ? "" : " for utt ") << utt
47  << " exceeds tolerance " << tolerance;
48  out->Resize(0, 0);
49  return false;
50  }
51  if (max_len - min_len > 0) {
52  KALDI_VLOG(2) << "Length mismatch " << max_len << " vs. " << min_len
53  << (utt.empty() ? "" : " for utt ") << utt
54  << " within tolerance " << tolerance;
55  }
56  out->Resize(min_len, tot_dim);
57  int32 dim_offset = 0;
58  for (int32 i = 0; i < in.size(); i++) {
59  int32 this_dim = in[i].NumCols();
60  out->Range(0, min_len, dim_offset, this_dim).CopyFromMat(
61  in[i].Range(0, min_len, 0, this_dim));
62  dim_offset += this_dim;
63  }
64  return true;
65 }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ AppendPostToFeats()

void kaldi::AppendPostToFeats ( const Matrix< BaseFloat > &  in,
const Posterior post,
const int32  post_dim,
Matrix< BaseFloat > *  out 
)

Definition at line 28 of file append-post-to-feats.cc.

References MatrixBase< Real >::ColRange(), KALDI_ASSERT, KALDI_WARN, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), PosteriorToMatrix(), and Matrix< Real >::Resize().

Referenced by main().

31  {
32  // Check inputs,
33  if (in.NumRows() != post.size()) {
34  KALDI_WARN << "Mismatch of length!"
35  << " features: " << in.NumRows()
36  << " posteriors: " << post.size();
37  }
38  KALDI_ASSERT(in.NumRows() == post.size());
39  // Convert post to Matrix,
40  Matrix<BaseFloat> post_mat;
41  PosteriorToMatrix(post, post_dim, &post_mat);
42  // Build the output matrix,
43  out->Resize(in.NumRows(), in.NumCols() + post_dim);
44  out->ColRange(0, in.NumCols()).CopyFromMat(in);
45  out->ColRange(in.NumCols(), post_mat.NumCols()).CopyFromMat(post_mat);
46 }
void PosteriorToMatrix(const Posterior &post, const int32 post_dim, Matrix< Real > *mat)
This converts a Posterior to a Matrix.
Definition: posterior.cc:512
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
SubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Definition: kaldi-matrix.h:213
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ AppendVector()

void kaldi::AppendVector ( const VectorBase< Real > &  src,
Vector< Real > *  dst 
)
inline

Definition at line 1377 of file pitch-functions.cc.

References VectorBase< Real >::Dim(), kCopyData, VectorBase< Real >::Range(), and Vector< Real >::Resize().

1377  {
1378  if (src.Dim() == 0) return;
1379  dst->Resize(dst->Dim() + src.Dim(), kCopyData);
1380  dst->Range(dst->Dim() - src.Dim(), src.Dim()).CopyFromVec(src);
1381 }

◆ AppendVectorToFeats()

void kaldi::AppendVectorToFeats ( const Matrix< BaseFloat > &  in,
const Vector< BaseFloat > &  vec,
Matrix< BaseFloat > *  out 
)

Definition at line 29 of file append-vector-to-feats.cc.

References MatrixBase< Real >::ColRange(), VectorBase< Real >::Dim(), KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by main().

31  {
32  // Check inputs,
33  KALDI_ASSERT(in.NumRows() != 0);
34  // Build the output matrix,
35  out->Resize(in.NumRows(), in.NumCols() + vec.Dim());
36  out->ColRange(0, in.NumCols()).CopyFromMat(in);
37  out->ColRange(in.NumCols(), vec.Dim()).CopyRowsFromVec(vec);
38 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
SubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Definition: kaldi-matrix.h:213
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ApplyAffineTransform()

void ApplyAffineTransform ( const MatrixBase< BaseFloat > &  xform,
VectorBase< BaseFloat > *  vec 
)

Applies the affine transform 'xform' to the vector 'vec' and overwrites the contents of 'vec'.

Definition at line 168 of file transform-common.cc.

References VectorBase< Real >::AddMatVec(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), KALDI_ASSERT, kNoTrans, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by AffineXformStats::AffineXformStats(), main(), TestOnlineTransform(), UnitTestFmllrDiagGmm(), UnitTestFmllrDiagGmmDiagonal(), UnitTestFmllrDiagGmmOffset(), and UnitTestFmllrRaw().

169  {
170  int32 dim = xform.NumRows();
171  KALDI_ASSERT(dim > 0 && xform.NumCols() == dim+1 && vec->Dim() == dim);
172  Vector<BaseFloat> tmp(dim+1);
173  SubVector<BaseFloat> tmp_part(tmp, 0, dim);
174  tmp_part.CopyFromVec(*vec);
175  tmp(dim) = 1.0;
176  // next line is: vec = 1.0 * xform * tmp + 0.0 * vec
177  vec->AddMatVec(1.0, xform, kNoTrans, tmp, 0.0);
178 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApplyCmvn()

void ApplyCmvn ( const MatrixBase< double > &  stats,
bool  norm_vars,
MatrixBase< BaseFloat > *  feats 
)

Apply cepstral mean and variance normalization to a matrix of features.

If norm_vars == true, expects stats to be of dimension 2 by (dim+1), but if norm_vars == false, will accept stats of dimension 1 by (dim+1); these are produced by the balanced-cmvn code when it computes an offset and represents it as "fake stats".

Definition at line 64 of file cmvn.cc.

References VectorBase< Real >::AddVec(), MatrixBase< Real >::AddVecToRows(), count, rnnlm::d, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, MatrixBase< Real >::MulColsVec(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), and MatrixBase< Real >::RowData().

Referenced by OnlineCmvn::GetFrame(), and main().

66  {
67  KALDI_ASSERT(feats != NULL);
68  int32 dim = stats.NumCols() - 1;
69  if (stats.NumRows() > 2 || stats.NumRows() < 1 || feats->NumCols() != dim) {
70  KALDI_ERR << "Dim mismatch: cmvn "
71  << stats.NumRows() << 'x' << stats.NumCols()
72  << ", feats " << feats->NumRows() << 'x' << feats->NumCols();
73  }
74  if (stats.NumRows() == 1 && var_norm)
75  KALDI_ERR << "You requested variance normalization but no variance stats "
76  << "are supplied.";
77 
78  double count = stats(0, dim);
79  // Do not change the threshold of 1.0 here: in the balanced-cmvn code, when
80  // computing an offset and representing it as stats, we use a count of one.
81  if (count < 1.0)
82  KALDI_ERR << "Insufficient stats for cepstral mean and variance normalization: "
83  << "count = " << count;
84 
85  if (!var_norm) {
86  Vector<BaseFloat> offset(dim);
87  SubVector<double> mean_stats(stats.RowData(0), dim);
88  offset.AddVec(-1.0 / count, mean_stats);
89  feats->AddVecToRows(1.0, offset);
90  return;
91  }
92  // norm(0, d) = mean offset;
93  // norm(1, d) = scale, e.g. x(d) <-- x(d)*norm(1, d) + norm(0, d).
94  Matrix<BaseFloat> norm(2, dim);
95  for (int32 d = 0; d < dim; d++) {
96  double mean, offset, scale;
97  mean = stats(0, d)/count;
98  double var = (stats(1, d)/count) - mean*mean,
99  floor = 1.0e-20;
100  if (var < floor) {
101  KALDI_WARN << "Flooring cepstral variance from " << var << " to "
102  << floor;
103  var = floor;
104  }
105  scale = 1.0 / sqrt(var);
106  if (scale != scale || 1/scale == 0.0)
107  KALDI_ERR << "NaN or infinity in cepstral mean/variance computation";
108  offset = -(mean*scale);
109  norm(0, d) = offset;
110  norm(1, d) = scale;
111  }
112  // Apply the normalization.
113  feats->MulColsVec(norm.Row(1));
114  feats->AddVecToRows(1.0, norm.Row(0));
115 }
kaldi::int32 int32
const size_t count
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApplyCmvnReverse()

void ApplyCmvnReverse ( const MatrixBase< double > &  stats,
bool  norm_vars,
MatrixBase< BaseFloat > *  feats 
)

This is as ApplyCmvn, but does so in the reverse sense, i.e.

applies a transform that would take zero-mean, unit-variance input and turn it into output with the stats of "stats". This can be useful if you trained without CMVN but later want to correct a mismatch, so you would first apply CMVN and then do the "reverse" CMVN with the summed stats of your training data.

Definition at line 117 of file cmvn.cc.

References MatrixBase< Real >::AddVecToRows(), count, rnnlm::d, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, MatrixBase< Real >::MulColsVec(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

Referenced by main().

119  {
120  KALDI_ASSERT(feats != NULL);
121  int32 dim = stats.NumCols() - 1;
122  if (stats.NumRows() > 2 || stats.NumRows() < 1 || feats->NumCols() != dim) {
123  KALDI_ERR << "Dim mismatch: cmvn "
124  << stats.NumRows() << 'x' << stats.NumCols()
125  << ", feats " << feats->NumRows() << 'x' << feats->NumCols();
126  }
127  if (stats.NumRows() == 1 && var_norm)
128  KALDI_ERR << "You requested variance normalization but no variance stats "
129  << "are supplied.";
130 
131  double count = stats(0, dim);
132  // Do not change the threshold of 1.0 here: in the balanced-cmvn code, when
133  // computing an offset and representing it as stats, we use a count of one.
134  if (count < 1.0)
135  KALDI_ERR << "Insufficient stats for cepstral mean and variance normalization: "
136  << "count = " << count;
137 
138  Matrix<BaseFloat> norm(2, dim); // norm(0, d) = mean offset
139  // norm(1, d) = scale, e.g. x(d) <-- x(d)*norm(1, d) + norm(0, d).
140  for (int32 d = 0; d < dim; d++) {
141  double mean, offset, scale;
142  mean = stats(0, d) / count;
143  if (!var_norm) {
144  scale = 1.0;
145  offset = mean;
146  } else {
147  double var = (stats(1, d)/count) - mean*mean,
148  floor = 1.0e-20;
149  if (var < floor) {
150  KALDI_WARN << "Flooring cepstral variance from " << var << " to "
151  << floor;
152  var = floor;
153  }
154  // we aim to transform zero-mean, unit-variance input into data
155  // with the given mean and variance.
156  scale = sqrt(var);
157  offset = mean;
158  }
159  norm(0, d) = offset;
160  norm(1, d) = scale;
161  }
162  if (var_norm)
163  feats->MulColsVec(norm.Row(1));
164  feats->AddVecToRows(1.0, norm.Row(0));
165 }
kaldi::int32 int32
const size_t count
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApplyFeatureTransformToStats()

void ApplyFeatureTransformToStats ( const MatrixBase< BaseFloat > &  xform,
AffineXformStats stats 
)

This function applies a feature-level transform to stats (useful for certain techniques based on fMLLR).

Assumes the stats are of the standard diagonal sort. The transform "xform" may be either dim x dim (linear), dim x dim+1 (affine), or dim+1 x dim+1 (affine with the last row equal to 0 0 0 .. 0 1).

Definition at line 381 of file fmllr-diag-gmm.cc.

References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), MatrixBase< Real >::CopyFromMat(), AffineXformStats::Dim(), AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_ASSERT, kNoTrans, kTrans, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by ComputeFmllrLogDet(), LinearVtln::ComputeTransform(), and UnitTestFmllrDiagGmm().

382  {
383  KALDI_ASSERT(stats != NULL && stats->Dim() != 0);
384  int32 dim = stats->Dim();
385  // make sure the stats are of the standard diagonal kind.
386  KALDI_ASSERT(stats->G_.size() == static_cast<size_t>(dim));
387  KALDI_ASSERT( (xform.NumRows() == dim && xform.NumCols() == dim) // linear
388  || (xform.NumRows() == dim && xform.NumCols() == dim+1) // affine
389  || (xform.NumRows() == dim+1 && xform.NumCols() == dim+1)); // affine w/ extra row.
390  if (xform.NumRows() == dim+1) { // check last row of input
391  // has correct value. 0 0 0 .. 0 1.
392  for (int32 i = 0; i < dim; i++)
393  KALDI_ASSERT(xform(dim, i) == 0.0);
394  KALDI_ASSERT(xform(dim, dim) == 1.0);
395  }
396 
397  // Get the transform into the (dim+1 x dim+1) format, with
398  // 0 0 0 .. 0 1 as the last row.
399  SubMatrix<BaseFloat> xform_square(xform, 0, dim, 0, dim);
400  Matrix<double> xform_full(dim+1, dim+1);
401  SubMatrix<double> xform_full_square(xform_full, 0, dim, 0, dim);
402  xform_full_square.CopyFromMat(xform_square);
403  if (xform.NumCols() == dim+1) // copy offset.
404  for (int32 i = 0; i < dim; i++)
405  xform_full(i, dim) = xform(i, dim);
406 
407  xform_full(dim, dim) = 1.0;
408 
409  SpMatrix<double> Gtmp(dim+1);
410  for (int32 i = 0; i < dim; i++) {
411  // Gtmp <-- xform_full * stats->G_[i] * xform_full^T
412  Gtmp.AddMat2Sp(1.0, xform_full, kNoTrans, stats->G_[i], 0.0);
413  stats->G_[i].CopyFromSp(Gtmp);
414  }
415  Matrix<double> Ktmp(dim, dim+1);
416  // Ktmp <-- stats->K_ * xform_full^T
417  Ktmp.AddMatMat(1.0, stats->K_, kNoTrans, xform_full, kTrans, 0.0);
418  stats->K_.CopyFromMat(Ktmp);
419 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApplyHessianXformToGradient()

static void kaldi::ApplyHessianXformToGradient ( const Sgmm2FmllrGlobalParams globals,
const Matrix< BaseFloat > &  gradient_in,
Matrix< BaseFloat > *  gradient_out 
)
static

Definition at line 59 of file fmllr-sgmm2.cc.

References KALDI_ERR, Sgmm2FmllrGlobalParams::mean_scatter_, VectorBase< Real >::Min(), and MatrixBase< Real >::NumRows().

Referenced by FmllrSgmm2Accs::AccumulateForFmllrSubspace(), and FmllrSgmm2Accs::Update().

61  {
62  int32 dim = gradient_in.NumRows();
63  const Vector<BaseFloat> &D = globals.mean_scatter_;
64  if (D.Min() <= 0.0)
65  KALDI_ERR << "Cannot estimate FMLLR: mean scatter has 0 eigenvalues.";
66  for (int32 r = 0; r < dim; r++) {
67  for (int32 c = 0; c < r; c++) {
68  // Eq. (B.15)
69  (*gradient_out)(r, c) = gradient_in(r, c) / std::sqrt(1 + D(c));
70  // Eq. (B.16)
71  (*gradient_out)(c, r) = gradient_in(c, r) / std::sqrt(1 + D(r) -
72  1 / (1 + D(c))) - gradient_in(r, c) / ((1 + D(c)) *
73  std::sqrt(1 + D(r) - 1 / (1 + D(c))));
74  }
75  // Eq. (B.17) & (B.18)
76  (*gradient_out)(r, r) = gradient_in(r, r) / std::sqrt(2 + D(r));
77  (*gradient_out)(r, dim) = gradient_in(r, dim);
78  }
79 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ApplyInvHessianXformToChange()

static void kaldi::ApplyInvHessianXformToChange ( const Sgmm2FmllrGlobalParams globals,
const Matrix< BaseFloat > &  delta_in,
Matrix< BaseFloat > *  delta_out 
)
static

Definition at line 81 of file fmllr-sgmm2.cc.

References KALDI_ERR, Sgmm2FmllrGlobalParams::mean_scatter_, VectorBase< Real >::Min(), and MatrixBase< Real >::NumRows().

Referenced by FmllrSgmm2Accs::Update().

83  {
84  int32 dim = delta_in.NumRows();
85  const Vector<BaseFloat> &D = globals.mean_scatter_;
86  if (D.Min() <= 0.0)
87  KALDI_ERR << "Cannot estimate FMLLR: mean scatter has 0 eigenvalues.";
88  for (int32 r = 0; r < dim; r++) {
89  for (int32 c = 0; c < r; c++) {
90  // Eq. (B.21)
91  (*delta_out)(r, c) = delta_in(r, c) / std::sqrt(1 + D(c)) -
92  delta_in(c, r) / ((1 + D(c)) * std::sqrt(1 + D(r) - 1 / (1 + D(c))));
93  // Eq. (B.22)
94  (*delta_out)(c, r) = delta_in(c, r) / std::sqrt(1 + D(r) - 1/ (1 + D(c)));
95  }
96  // Eq. (B.23) & (B.24)
97  (*delta_out)(r, r) = delta_in(r, r) / std::sqrt(2 + D(r));
98  (*delta_out)(r, dim) = delta_in(r, dim);
99  }
100 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ApplyInvPreXformToChange()

static void kaldi::ApplyInvPreXformToChange ( const Sgmm2FmllrGlobalParams globals,
const Matrix< BaseFloat > &  delta_in,
Matrix< BaseFloat > *  delta_out 
)
static

Definition at line 45 of file fmllr-sgmm2.cc.

References MatrixBase< Real >::AddMatMat(), Sgmm2FmllrGlobalParams::inv_xform_, kNoTrans, kSetZero, kUndefined, MatrixBase< Real >::NumRows(), Sgmm2FmllrGlobalParams::pre_xform_, and MatrixBase< Real >::Range().

Referenced by FmllrSgmm2Accs::Update().

47  {
48  // Eq. (B.25): \Delta = A_{inv} \Delta' W_{pre}^+
49  int32 dim = delta_in.NumRows();
50  Matrix<BaseFloat> Wpre_plus(dim + 1, dim + 1, kSetZero);
51  Wpre_plus.Range(0, dim, 0, dim + 1).CopyFromMat(globals.pre_xform_);
52  Wpre_plus(dim, dim) = 1;
53  SubMatrix<BaseFloat> Ainv(globals.inv_xform_, 0, dim, 0, dim);
54  Matrix<BaseFloat> AinvD(dim, dim + 1, kUndefined);
55  AinvD.AddMatMat(1.0, Ainv, kNoTrans, delta_in, kNoTrans, 0.0);
56  delta_out->AddMatMat(1.0, AinvD, kNoTrans, Wpre_plus, kNoTrans, 0.0);
57 }
kaldi::int32 int32
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ApplyModelTransformToStats()

void ApplyModelTransformToStats ( const MatrixBase< BaseFloat > &  xform,
AffineXformStats stats 
)

ApplyModelTransformToStats takes a transform "xform", which must be diagonal (i.e.

of the form T = [ D; b ] where D is diagonal), and applies it to the stats as if we had made it a model-space transform (note that the transform applied to the model means is the inverse transform of T). Thus, if we are estimating a transform T U, and we get stats valid for estimating T U and we estimate T, we can then call this function (treating T as a model-space transform) and will get stats valid for estimating U. This only works if T is diagonal, because otherwise the standard stats format is not valid. xform must be of dimension d x d+1

Definition at line 421 of file fmllr-diag-gmm.cc.

References AffineXformStats::Dim(), AffineXformStats::G_, rnnlm::i, MatrixBase< Real >::IsDiagonal(), rnnlm::j, AffineXformStats::K_, KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by ComputeFmllrLogDet(), UnitTestFmllrDiagGmmDiagonal(), and UnitTestFmllrDiagGmmOffset().

422  {
423  KALDI_ASSERT(stats != NULL && stats->Dim() != 0.0);
424  int32 dim = stats->Dim();
425  KALDI_ASSERT(xform.NumRows() == dim && xform.NumCols() == dim+1);
426  {
427  SubMatrix<BaseFloat> xform_square(xform, 0, dim, 0, dim);
428  // Only works with diagonal transforms.
429  KALDI_ASSERT(xform_square.IsDiagonal());
430  }
431 
432  // Working out rules for transforming fMLLR statistics under diagonal
433  // model-space transformations.
434  //
435  // We work out what the stats would be if we had accumulated
436  // with offset/scaled means and vars. Let T be the transform
437  // T = [ D; b ],
438  // where D is diagonal, d_i is the i'th diagonal of D, and b_i
439  // is the i'th offset element. This is equivalent to the transform
440  // x_i -> y_i = d_i x_i + b_i,
441  // so d_i is the diagonal and b_i is the offset term. We work out the
442  // reverse feature transform (from general to speaker-specific space),
443  // which is
444  // y_i -> x_i = (y_i - b_i) / d_i
445  // the corresponding mean transform to speaker-space is the same:
446  // mu_i -> (mu_i - b_i) / d_i
447  // and the transfrom on the variances is:
448  // sigma_i^2 -> sigma_i^2 / d_i^2,
449  // so on inverse variance this becomes:
450  // (1/sigma_i^2) -> (1/sigma_i^2) * d_i^2.
451  //
452  // Now, we work out the change in K and G_i from these effects on the
453  // means and variances.
454  //
455  // Now, k_{ij} is \sum_{m, t} \gamma_m (1/\sigma^2_{m, i}) \mu_{m, i} x^+_j .
456  //
457  // If we are transforming to K', we want:
458  //
459  // k'_{ij} = \sum_{m, t} \gamma_m (d_i^2/\sigma^2_{m, i}) ((\mu_{m, i} - b_i)/d_i) x^+_j .
460  // = d_i k_{i, j} - \sum_{m, t} \gamma_m (1/\sigma^2_{m, i}) d_i b_i x^+_j .
461  // = d_i k_{i, j} - d_i b_i g_{i, d, j},
462  // where g_{i, d, j} is the {d, j}'th element of G_i. (in zero-based indexing).
463  //
464  //
465  // G_i only depends on the variances and features, so the only change
466  // in G_i is G_i -> d_i^2 G_i (this comes from the change in 1/sigma_i^2).
467  // This is done after the change in K.
468 
469  for (int32 i = 0; i < dim; i++) {
470  BaseFloat d_i = xform(i, i), b_i = xform(i, dim);
471  for (int32 j = 0; j <= dim; j++) {
472  stats->K_(i, j) = d_i * stats->K_(i, j) - d_i * b_i * stats->G_[i](dim, j);
473  }
474  }
475  for (int32 i = 0; i < dim; i++) {
476  BaseFloat d_i = xform(i, i);
477  stats->G_[i].Scale(d_i * d_i);
478  }
479 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApplyPca()

void kaldi::ApplyPca ( const Matrix< BaseFloat > &  ivectors_in,
const Matrix< BaseFloat > &  pca_mat,
Matrix< BaseFloat > *  ivectors_out 
)

Definition at line 101 of file ivector-plda-scoring-dense.cc.

References MatrixBase< Real >::AddMatMat(), KALDI_ASSERT, kNoTrans, kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by main().

102  {
103  int32 transform_cols = pca_mat.NumCols(),
104  transform_rows = pca_mat.NumRows(),
105  feat_dim = ivectors_in.NumCols();
106  ivectors_out->Resize(ivectors_in.NumRows(), transform_rows);
107  KALDI_ASSERT(transform_cols == feat_dim);
108  ivectors_out->AddMatMat(1.0, ivectors_in, kNoTrans,
109  pca_mat, kTrans, 0.0);
110 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ApplyPreXformToGradient()

static void kaldi::ApplyPreXformToGradient ( const Sgmm2FmllrGlobalParams globals,
const Matrix< BaseFloat > &  gradient_in,
Matrix< BaseFloat > *  gradient_out 
)
static

Definition at line 31 of file fmllr-sgmm2.cc.

References MatrixBase< Real >::AddMatMat(), Sgmm2FmllrGlobalParams::inv_xform_, kNoTrans, kSetZero, kTrans, kUndefined, MatrixBase< Real >::NumRows(), Sgmm2FmllrGlobalParams::pre_xform_, and MatrixBase< Real >::Range().

Referenced by FmllrSgmm2Accs::AccumulateForFmllrSubspace(), and FmllrSgmm2Accs::Update().

33  {
34  // Eq. (B.14): P' = A_{inv}^T P {W_{pre}^+}^T
35  int32 dim = gradient_in.NumRows();
36  Matrix<BaseFloat> Wpre_plus(dim + 1, dim + 1, kSetZero);
37  Wpre_plus.Range(0, dim, 0, dim + 1).CopyFromMat(globals.pre_xform_);
38  Wpre_plus(dim, dim) = 1;
39  SubMatrix<BaseFloat> Ainv(globals.inv_xform_, 0, dim, 0, dim);
40  Matrix<BaseFloat> AinvP(dim, dim + 1, kUndefined);
41  AinvP.AddMatMat(1.0, Ainv, kTrans, gradient_in, kNoTrans, 0.0);
42  gradient_out->AddMatMat(1.0, AinvP, kNoTrans, Wpre_plus, kTrans, 0.0);
43 }
kaldi::int32 int32
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ApplySoftMaxPerRow()

void kaldi::ApplySoftMaxPerRow ( MatrixBase< BaseFloat > *  mat)

Definition at line 27 of file copy-matrix.cc.

References rnnlm::i, MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

Referenced by main().

27  {
28  for (int32 i = 0; i < mat->NumRows(); i++) {
29  mat->Row(i).ApplySoftMax();
30  }
31 }
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ approx_equal()

static bool kaldi::approx_equal ( Real  a,
Real  b 
)
static

Definition at line 3323 of file matrix-lib-test.cc.

Referenced by UnitTestTrace().

3323  {
3324  return ( std::abs(a-b) <= 1.0e-03 * (std::abs(a)+std::abs(b)));
3325 }

◆ ApproxEqual() [1/6]

static bool kaldi::ApproxEqual ( const CuBlockMatrix< Real > &  A,
const CuBlockMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 35 of file cu-block-matrix-test.cc.

37  {
38  CuMatrix<Real> Acopy(A), Bcopy(B);
39  return Acopy.ApproxEqual(Bcopy, tol);
40 }
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71

◆ ApproxEqual() [2/6]

static bool kaldi::ApproxEqual ( const PackedMatrix< Real > &  A,
const PackedMatrix< Real > &  B,
Real  tol = 0.001 
)
static

Definition at line 100 of file cu-packed-matrix-test.cc.

References rnnlm::d, KALDI_ASSERT, PackedMatrix< Real >::Max(), PackedMatrix< Real >::Min(), and PackedMatrix< Real >::NumRows().

101  {
102  KALDI_ASSERT(A.NumRows() == B.NumRows());
103  PackedMatrix<Real> diff(A);
104  diff.AddPacked(1.0, B);
105  Real a = std::max(A.Max(), -A.Min()), b = std::max(B.Max(), -B.Min()),
106  d = std::max(diff.Max(), -diff.Min());
107  return (d <= tol * std::max(a, b));
108 }
MatrixIndexT NumRows() const
Packed matrix: base class for triangular and symmetric matrices.
Definition: matrix-common.h:64
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ApproxEqual() [3/6]

bool kaldi::ApproxEqual ( const CuSpMatrix< Real > &  A,
const CuSpMatrix< Real > &  B,
Real  tol = 0.001 
)
inline

Definition at line 141 of file cu-sp-matrix.h.

142  {
143  return A.ApproxEqual(B, tol);
144 }

◆ ApproxEqual() [4/6]

static bool kaldi::ApproxEqual ( float  a,
float  b,
float  relative_tolerance = 0.001 
)
inlinestatic

return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).

Definition at line 265 of file kaldi-math.h.

Referenced by AssertEqual(), MleAmSgmm2Accs::Check(), ComputeFmllrMatrixDiagGmmFull(), ComputeLatticeAlphasAndBetas(), CreateEigenvalueMatrix(), CuVectorUnitTestNorm(), CuVectorUnitTestScale(), DecisionTreeSplitter::DoSplitInternal(), EstPca(), kaldi::nnet3::ExampleApproxEqual(), FindBestSplitForKey(), LatticeForwardBackward(), LatticeForwardBackwardMpeVariants(), AmSgmm2::LogLikelihood(), main(), FullGmm::Merge(), DiagGmm::Merge(), FullGmm::MergePreselect(), NnetIo::operator==(), OnlinePreconditioner::PreconditionDirectionsInternal(), KlHmm::PropagateFnc(), MultiBasisComponent::PropagateFnc(), LatticeSimpleDecoder::PruneForwardLinksFinal(), LatticeFasterDecoderTpl< fst::StdFst, decoder::BackpointerToken >::PruneForwardLinksFinal(), LatticeBiglmFasterDecoder::PruneForwardLinksFinal(), LatticeIncrementalDecoderTpl< FST, decoder::BackpointerToken >::PruneForwardLinksFinal(), OnlinePitchFeatureImpl::RecomputeBacktraces(), ScoringTest(), TestCuMatrixCompObjfAndDeriv(), kaldi::nnet3::time_height_convolution::TestDataBackprop(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::time_height_convolution::TestParamsBackprop(), TestPushCompactLatticeWeights(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), UnitTestApproxEqual(), UnitTestComplexFft2(), UnitTestCompressedMatrix2(), UnitTestCuBlockMatrixAddMatMat(), UnitTestCuDiffLogSoftmax(), UnitTestCuDiffSigmoid(), UnitTestCuDiffSoftmax(), UnitTestCuDiffTanh(), UnitTestCuDiffXent(), UnitTestCuLogSoftmax(), UnitTestCuMatrixAdd(), UnitTestCuMatrixAdd2(), UnitTestCuMatrixAddCols(), UnitTestCuMatrixAddDiagVecMat(), UnitTestCuMatrixAddElements(), UnitTestCuMatrixAddMat(), UnitTestCuMatrixAddMatBlocks1(), UnitTestCuMatrixAddMatBlocks1Trans(), UnitTestCuMatrixAddMatBlocks2(), UnitTestCuMatrixAddMatDiagVec(), UnitTestCuMatrixAddMatMat(), UnitTestCuMatrixAddMatMatBatched(), UnitTestCuMatrixAddMatMatElements(), UnitTestCuMatrixAddRowRanges(), UnitTestCuMatrixAddRows(), UnitTestCuMatrixAddToDiag(), UnitTestCuMatrixAddToElements(), UnitTestCuMatrixAddToRows(), UnitTestCuMatrixAddVecToCols(), UnitTestCuMatrixAddVecToRows(), UnitTestCuMatrixAddVecVec(), UnitTestCuMatrixApplyCeiling(), UnitTestCuMatrixApplyExp(), UnitTestCuMatrixApplyExpLimited(), UnitTestCuMatrixApplyExpSpecial(), UnitTestCuMatrixApplyFloor(), UnitTestCuMatrixApplyHeaviside(), UnitTestCuMatrixApplyLog(), UnitTestCuMatrixApplyPow(), UnitTestCuMatrixApplyPowAbs(), UnitTestCuMatrixCopyCols(), UnitTestCuMatrixCopyColsFromVec(), UnitTestCuMatrixCopyCross(), UnitTestCuMatrixCopyCross2(), UnitTestCuMatrixCopyRows(), UnitTestCuMatrixCopyRowsFromVec(), UnitTestCuMatrixCopyToRows(), UnitTestCuMatrixDiffGroupPnorm(), UnitTestCuMatrixDivElements(), UnitTestCuMatrixDivRowsVec(), UnitTestCuMatrixGroupMax(), UnitTestCuMatrixGroupMaxDeriv(), UnitTestCuMatrixGroupPnorm(), UnitTestCuMatrixHeaviside(), UnitTestCuMatrixInvertElements(), UnitTestCuMatrixIO(), UnitTestCuMatrixMax(), UnitTestCuMatrixMin(), UnitTestCuMatrixMulColsVec(), UnitTestCuMatrixMulElements(), UnitTestCuMatrixMulRows(), UnitTestCuMatrixMulRowsGroupMat(), UnitTestCuMatrixMulRowsVec(), UnitTestCuMatrixObjfDeriv(), UnitTestCuMatrixReduceMax(), UnitTestCuMatrixReduceMin(), UnitTestCuMatrixReduceSum(), UnitTestCuMatrixScale(), UnitTestCuMatrixSet(), UnitTestCuMatrixSetMatMatDivMat(), UnitTestCuMatrixSetRandn(), UnitTestCuMatrixSigmoid(), UnitTestCuMatrixSoftHinge(), UnitTestCuMatrixSumColumnRanges(), UnitTestCuMatrixSymAddMat2(), UnitTestCuMatrixSymInvertPosDef(), UnitTestCuMatrixTraceMatMat(), UnitTestCuMatrixTranspose(), UnitTestCuSigmoid(), UnitTestCuSoftmax(), UnitTestCuSpMatrixCopyFromMat(), UnitTestCuSpMatrixTraceSpSp(), UnitTestCuTanh(), UnitTestCuVectorAddColSumMat(), UnitTestCuVectorAddColSumMatLarge(), UnitTestCuVectorAddRowSumMat(), UnitTestCuVectorAddRowSumMatLarge(), UnitTestCuVectorAddTpVec(), UnitTestCuVectorAddVec(), UnitTestCuVectorInvertElements(), UnitTestCuVectorMulTp(), UnitTestCuVectorSum(), UnitTestDelay(), UnitTestEstimateDiagGmm(), UnitTestEstimateFullGmm(), UnitTestFmllrDiagGmm(), UnitTestFmllrDiagGmmDiagonal(), UnitTestFmllrDiagGmmOffset(), UnitTestLinearResample(), UnitTestLstmNonlinearity(), kaldi::nnet3::UnitTestNnetCompute(), kaldi::nnet2::UnitTestNnetDecodable(), kaldi::nnet3::UnitTestNnetInputDerivatives(), kaldi::nnet3::UnitTestNnetModelDerivatives(), kaldi::nnet3::UnitTestNnetOptimizeWithOptions(), UnitTestNorm(), UnitTestPieces(), UnitTestPosteriors(), UnitTestRange(), UnitTestReadConfig(), UnitTestSnipEdges(), UnitTestSplitRadixComplexFft2(), UnitTestSwapCu2Cu(), UnitTestSwapCu2M(), UnitTestTableRandomBothDouble(), UnitTestTableSequentialBaseFloatVectorBoth(), UnitTestTableSequentialDouble(), UnitTestTableSequentialDoubleBoth(), UnitTestTableSequentialDoubleMatrixBoth(), UnitTextCuMatrixAddMatSmat(), UnitTextCuMatrixAddSmat(), UnitTextCuMatrixAddSmatMat(), IvectorExtractorStats::UpdatePrior(), and MleSgmm2SpeakerAccs::UpdateWithU().

266  {
267  // a==b handles infinities.
268  if (a == b) return true;
269  float diff = std::abs(a-b);
270  if (diff == std::numeric_limits<float>::infinity()
271  || diff != diff) return false; // diff is +inf or nan.
272  return (diff <= relative_tolerance*(std::abs(a)+std::abs(b)));
273 }

◆ ApproxEqual() [5/6]

bool kaldi::ApproxEqual ( const CuVectorBase< Real > &  a,
const CuVectorBase< Real > &  b,
Real  tol = 0.01 
)

Definition at line 364 of file cu-vector.h.

365  {
366  return a.ApproxEqual(b, tol);
367 }

◆ ApproxEqual() [6/6]

bool kaldi::ApproxEqual ( const CuMatrixBase< Real > &  A,
const CuMatrixBase< Real > &  B,
Real  tol = 0.01 
)

Definition at line 937 of file cu-matrix.h.

938  {
939  return A.ApproxEqual(B, tol);
940 }

◆ AssertDiagEqual() [1/2]

static void kaldi::AssertDiagEqual ( const PackedMatrix< Real > &  A,
const CuPackedMatrix< Real > &  B,
float  value,
float  tol = 0.001 
)
static

Definition at line 68 of file cu-packed-matrix-test.cc.

References rnnlm::i, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

Referenced by UnitTestCuPackedMatrixAddToDiag().

71  {
72  for (MatrixIndexT i = 0; i < A.NumRows(); i++) {
73  KALDI_ASSERT(std::abs((A(i, i)+value) - B(i, i))
74  < tol * std::max(1.0, (double) (std::abs(A(i, i)) + std::abs(B(i, i) + value))));
75  }
76 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertDiagEqual() [2/2]

static void kaldi::AssertDiagEqual ( const PackedMatrix< Real > &  A,
const PackedMatrix< Real > &  B,
float  value,
float  tol = 0.001 
)
static

Definition at line 78 of file cu-packed-matrix-test.cc.

References rnnlm::i, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

81  {
82  for (MatrixIndexT i = 0; i < A.NumRows(); i++) {
83  KALDI_ASSERT(std::abs((A(i, i)+value) - B(i, i))
84  < tol * std::max(1.0, (double) (std::abs(A(i, i)) + std::abs(B(i, i) + value))));
85  }
86 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [1/12]

void kaldi::AssertEqual ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)

Definition at line 36 of file cu-array-test.cc.

References rnnlm::i, and KALDI_ASSERT.

37  {
38  // use this instead of "vec1 == vec2" because
39  // for doubles and floats, this can fail if we
40  // have NaNs, even if identical.
41  KALDI_ASSERT(vec1.size() == vec2.size());
42  if (vec1.size() > 0) {
43  const char *p1 = reinterpret_cast<const char*>(&(vec1[0]));
44  const char *p2 = reinterpret_cast<const char*>(&(vec2[0]));
45  size_t size = sizeof(T) * vec1.size();
46  for (size_t i = 0; i < size; i++)
47  KALDI_ASSERT(p1[i] == p2[i]);
48  }
49 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [2/12]

static void kaldi::AssertEqual ( const CuPackedMatrix< Real > &  A,
const CuPackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 41 of file cu-tp-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, and CuPackedMatrix< Real >::NumRows().

43  {
44  KALDI_ASSERT(A.NumRows() == B.NumRows());
45  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
46  for (MatrixIndexT j = 0; j <= i; j++)
47  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
48  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
49 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [3/12]

static void kaldi::AssertEqual ( const CuPackedMatrix< Real > &  A,
const CuPackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 46 of file cu-packed-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, and CuPackedMatrix< Real >::NumRows().

48  {
49  KALDI_ASSERT(A.NumRows() == B.NumRows());
50  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
51  for (MatrixIndexT j = 0; j <= i; j++)
52  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
53  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
54 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [4/12]

static void kaldi::AssertEqual ( const PackedMatrix< Real > &  A,
const PackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 52 of file cu-tp-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

54  {
55  KALDI_ASSERT(A.NumRows() == B.NumRows());
56  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
57  for (MatrixIndexT j = 0; j <= i; j++)
58  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
59  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
60 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [5/12]

static void kaldi::AssertEqual ( const PackedMatrix< Real > &  A,
const PackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 57 of file cu-packed-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

59  {
60  KALDI_ASSERT(A.NumRows() == B.NumRows());
61  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
62  for (MatrixIndexT j = 0; j <= i; j++)
63  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
64  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
65 }
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [6/12]

static void kaldi::AssertEqual ( const PackedMatrix< Real > &  A,
const CuPackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 63 of file cu-tp-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, PackedMatrix< Real >::NumRows(), and CuPackedMatrix< Real >::NumRows().

65  {
66  KALDI_ASSERT(A.NumRows() == B.NumRows());
67  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
68  for (MatrixIndexT j = 0; j <= i; j++)
69  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
70  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
71 }
MatrixIndexT NumRows() const
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [7/12]

static void kaldi::AssertEqual ( const Matrix< Real > &  A,
const Matrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 69 of file online-feat-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

71  {
72  KALDI_ASSERT(A.NumRows() == B.NumRows()&&A.NumCols() == B.NumCols());
73  for (MatrixIndexT i = 0;i < A.NumRows();i++)
74  for (MatrixIndexT j = 0;j < A.NumCols();j++) {
75  KALDI_ASSERT(std::abs(A(i, j)-B(i, j)) < tol*std::max(1.0, (double) (std::abs(A(i, j))+std::abs(B(i, j)))));
76  }
77 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ AssertEqual() [8/12]

static void kaldi::AssertEqual ( const PackedMatrix< Real > &  A,
const CuPackedMatrix< Real > &  B,
float  tol = 0.001 
)
static

Definition at line 89 of file cu-packed-matrix-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, PackedMatrix< Real >::NumRows(), and CuPackedMatrix< Real >::NumRows().

91  {
92  KALDI_ASSERT(A.NumRows() == B.NumRows());
93  for (MatrixIndexT i = 0; i < A.NumRows(); i++)
94  for (MatrixIndexT j = 0; j <= i; j++)
95  KALDI_ASSERT(std::abs(A(i, j) - B(i, j))
96  < tol * std::max(1.0, (double) (std::abs(A(i, j)) + std::abs(B(i, j)))));
97 }
MatrixIndexT NumRows() const
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [9/12]

void kaldi::AssertEqual ( const CuSpMatrix< Real > &  A,
const CuSpMatrix< Real > &  B,
Real  tol = 0.001 
)
inline

Definition at line 147 of file cu-sp-matrix.h.

References CuSpMatrix< Real >::ApproxEqual(), and KALDI_ASSERT.

148  {
149  KALDI_ASSERT(ApproxEqual(A, B, tol));
150 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool ApproxEqual(const CuSpMatrix< Real > &A, const CuSpMatrix< Real > &B, Real tol=0.001)
Definition: cu-sp-matrix.h:141

◆ AssertEqual() [10/12]

static void kaldi::AssertEqual ( float  a,
float  b,
float  relative_tolerance = 0.001 
)
inlinestatic

assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))

Definition at line 276 of file kaldi-math.h.

References ApproxEqual(), KALDI_ASSERT, rnnlm::n, and RoundUpToNearestPowerOfTwo().

Referenced by AddToClustersOptimized(), CholeskyUnitTestTr(), CuCompressedMatrixTestSign(), CuVectorUnitTestAddColSumMat(), CuVectorUnitTestAddDiagMat2(), CuVectorUnitTestAddDiagMatMat(), CuVectorUnitTestAddMatVec(), CuVectorUnitTestAddRowSumMat(), CuVectorUnitTestAddSpVec(), CuVectorUnitTestAddVec(), CuVectorUnitTestAddVecCross(), CuVectorUnitTestAddVecExtra(), CuVectorUnitTestAddVecVec(), CuVectorUnitTestApplyCeiling(), CuVectorUnitTestApplyCeilingNoCount(), CuVectorUnitTestApplyFloor(), CuVectorUnitTestApplyFloorNoCount(), CuVectorUnitTestApplyPow(), CuVectorUnitTestApplySoftMax(), CuVectorUnitTestCopyCross(), CuVectorUnitTestCopyCross2(), CuVectorUnitTestCopyDiagFromMat(), CuVectorUnitTestCopyElements(), CuVectorUnitTestInvertElements(), CuVectorUnitTestVecVec(), RegressionTree::GatherStats(), PldaEstimator::GetOutput(), fst::LatticeWeightTest(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), test_flags_driven_update(), test_io(), TestAddToClusters(), TestAddToClustersOptimized(), TestAmDiagGmmAccsIO(), TestAmDiagGmmIO(), TestComponentAcc(), fst::TestContextFst(), TestCuMatrixCopyFromSp(), TestCuMatrixCopyFromTp(), TestCuMatrixCopyLowerToUpper(), TestCuMatrixCopyUpperToLower(), TestCuMatrixTransposeCross(), TestDistance(), TestMllrAccsIO(), TestObjfMinus(), TestObjfPlus(), TestOnlineMatrixCacheFeature(), TestOnlineMatrixInput(), TestOnlineMfcc(), TestOnlinePlp(), TestOnlineTransform(), TestRefineClusters(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), TestSgmm2Substates(), kaldi::nnet3::TestSimpleComponentPropagateProperties(), TestSplitStates(), TestSum(), TestSumObjfAndSumNormalizer(), TestXformMean(), UnitTestAddDiagMat2(), UnitTestAddDiagMatMat(), UnitTestAddDiagVecMat(), UnitTestAddMat2(), UnitTestAddMat2Sp(), UnitTestAddMatDiagVec(), UnitTestAddMatMatElements(), UnitTestAddMatSelf(), UnitTestAddMatSmat(), UnitTestAddOuterProductPlusMinus(), UnitTestAddRows(), UnitTestAddSp(), UnitTestAddToDiag(), UnitTestAddToDiagMatrix(), UnitTestAddToRows(), UnitTestAddVec2Sp(), UnitTestAddVecCross(), UnitTestAddVecToCols(), UnitTestAddVecToRows(), UnitTestAddVecVec(), UnitTestApplyExpSpecial(), UnitTestAssertFunc(), kaldi::nnet3::attention::UnitTestAttentionDotProductAndAddScales(), UnitTestAxpy(), UnitTestBackpropLstmNonlinearity(), UnitTestCholesky(), UnitTestComplexFft(), UnitTestComplexFt(), UnitTestComplexPower(), UnitTestCompressedMatrix(), kaldi::nnet1::UnitTestConvolutionalComponent3x3(), kaldi::nnet1::UnitTestConvolutionalComponentUnity(), UnitTestCopyCols(), UnitTestCopyRows(), UnitTestCopySp(), UnitTestCopyToRows(), UnitTestCuArray(), UnitTestCuBlockMatrixAddMatBlock(), UnitTestCuBlockMatrixIO(), UnitTestCuDiffNormalizePerRow(), UnitTestCuMathComputeLstmNonlinearity(), UnitTestCuMathCopy(), UnitTestCuMathNormalizePerRow(), UnitTestCuMathNormalizePerRow_v2(), UnitTestCuMathRandomize(), UnitTestCuMathSplice(), UnitTestCuPackedMatrixConstructor(), UnitTestCuPackedMatrixCopy(), UnitTestCuPackedMatrixScale(), UnitTestCuPackedMatrixScaleDiag(), UnitTestCuPackedMatrixTrace(), UnitTestCuSparseMatrixConstructFromIndexes(), UnitTestCuSparseMatrixCopyToSmat(), UnitTestCuSparseMatrixFrobeniusNorm(), UnitTestCuSparseMatrixSelectRowsAndTranspose(), UnitTestCuSparseMatrixSwap(), UnitTestCuSparseMatrixTraceMatSmat(), UnitTestCuSpMatrixAddMat2(), UnitTestCuSpMatrixAddSp(), UnitTestCuSpMatrixAddToDiag(), UnitTestCuSpMatrixAddVec2(), UnitTestCuSpMatrixConstructor(), UnitTestCuSpMatrixInvert(), UnitTestCuSpMatrixIO(), UnitTestCuSpMatrixSetUnit(), UnitTestCuTpMatrixCopyFromMat(), UnitTestCuTpMatrixIO(), UnitTestCuVectorAddTp(), UnitTestCuVectorCopyFromVec(), UnitTestCuVectorIO(), UnitTestCuVectorMulTp(), UnitTestCuVectorReplaceValue(), UnitTestDeterminantSign(), UnitTestDiagGmm(), UnitTestDiagGmmGenerate(), kaldi::nnet1::UnitTestDropoutComponent(), UnitTestEig(), UnitTestEigSymmetric(), UnitTestEndless1(), UnitTestEndless2(), UnitTestEstimateDiagGmm(), UnitTestEstimateFullGmm(), UnitTestFFTbasedBlockConvolution(), UnitTestFFTbasedConvolution(), UnitTestFloorCeiling(), UnitTestFullGmm(), UnitTestGeneralMatrix(), UnitTestHtkIo(), UnitTestInnerProd(), UnitTestInvert(), UnitTestIo(), UnitTestIoCross(), UnitTestIoNew(), UnitTestIoPipe(), kaldi::nnet1::UnitTestLengthNorm(), UnitTestLinearResample2(), UnitTestMat2Vec(), UnitTestMatrixAddMatSmat(), UnitTestMatrixAddSmatMat(), UnitTestMatrixRandomizer(), UnitTestMax2(), UnitTestMaxAbsEig(), UnitTestMaxMin(), kaldi::nnet1::UnitTestMaxPoolingComponent(), UnitTestMmulSym(), UnitTestMono22K(), UnitTestMul(), UnitTestMulTp(), kaldi::nnet2::UnitTestNnetCompute(), kaldi::nnet2::UnitTestNnetComputeChunked(), UnitTestNonsymmetricPower(), UnitTestPca(), UnitTestPca2(), UnitTestPieces(), UnitTestPower(), UnitTestPowerAbs(), kaldi::nnet3::UnitTestPreconditionDirectionsOnline(), kaldi::nnet2::UnitTestPreconditionDirectionsOnline(), UnitTestRankNUpdate(), UnitTestRealFft(), UnitTestReplaceValue(), UnitTestResize(), UnitTestResizeCopyDataDifferentStrideType(), UnitTestRow(), UnitTestScaleDiag(), UnitTestSearch(), UnitTestSetDiag(), UnitTestSigmoid(), UnitTestSimple(), UnitTestSimpleForMat(), UnitTestSimpleForVec(), kaldi::nnet1::UnitTestSimpleSentenceAveragingComponent(), UnitTestSnipEdges(), UnitTestSoftHinge(), UnitTestSolve(), UnitTestSpAddDiagVec(), UnitTestSpAddVecVec(), UnitTestSparseMatrixAddToMat(), UnitTestSparseMatrixConstructor(), UnitTestSparseMatrixFrobeniusNorm(), UnitTestSparseMatrixSum(), UnitTestSparseMatrixTraceMatSmat(), UnitTestSparseVectorAddToVec(), UnitTestSparseVectorMax(), UnitTestSparseVectorSum(), UnitTestSpliceRows(), UnitTestSplitRadixComplexFft(), UnitTestSplitRadixRealFft(), UnitTestSpVec(), UnitTestStdVectorRandomizer(), UnitTestStereo8K(), UnitTestSubvector(), UnitTestSvd(), UnitTestSvdJustvec(), UnitTestSymAddMat2(), UnitTestTanh(), UnitTestTopEigs(), UnitTestTp2(), UnitTestTp2Sp(), UnitTestTrace(), UnitTestTraceSpSpLower(), UnitTestTranspose(), UnitTestTridiagonalize(), UnitTestTridiagonalizeAndQr(), UnitTestTriVecSolver(), UnitTestVecMatVec(), UnitTestVecmul(), UnitTestVector(), UnitTestVectorRandomizer(), UnitTestVtln(), FmllrSgmm2Accs::Update(), and AccumDiagGmm::variance_accumulator().

277  {
278  // a==b handles infinities.
279  KALDI_ASSERT(ApproxEqual(a, b, relative_tolerance));
280 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ AssertEqual() [11/12]

void kaldi::AssertEqual ( const CuVectorBase< Real > &  a,
const CuVectorBase< Real > &  b,
Real  tol = 0.01 
)
inline

Definition at line 370 of file cu-vector.h.

References KALDI_ASSERT.

371  {
372  KALDI_ASSERT(a.ApproxEqual(b, tol));
373 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AssertEqual() [12/12]

void kaldi::AssertEqual ( const CuMatrixBase< Real > &  A,
const CuMatrixBase< Real > &  B,
float  tol = 0.01 
)
inline

Definition at line 943 of file cu-matrix.h.

References KALDI_ASSERT.

944  {
945  KALDI_ASSERT(A.ApproxEqual(B, tol));
946 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ AttemptComplexPower() [1/2]

template bool kaldi::AttemptComplexPower ( float x_re,
float x_im,
float  power 
)

◆ AttemptComplexPower() [2/2]

template bool kaldi::AttemptComplexPower ( double *  x_re,
double *  x_im,
double  power 
)

◆ AugmentGmmFlags()

GmmFlagsType AugmentGmmFlags ( GmmFlagsType  f)

Returns "augmented" version of flags: e.g.

if just updating means, need weights too.

Definition at line 52 of file model-common.cc.

References KALDI_ASSERT, KALDI_WARN, kGmmAll, kGmmMeans, kGmmVariances, and kGmmWeights.

Referenced by DiagGmmToStats(), AccumFullGmm::Resize(), and AccumDiagGmm::Resize().

52  {
53 KALDI_ASSERT((flags & ~kGmmAll) == 0); // make sure only valid flags are present.
54  if (flags & kGmmVariances) flags |= kGmmMeans;
55  if (flags & kGmmMeans) flags |= kGmmWeights;
56  if (!(flags & kGmmWeights)) {
57  KALDI_WARN << "Adding in kGmmWeights (\"w\") to empty flags.";
58  flags |= kGmmWeights; // Just add this in regardless:
59  // if user wants no stats, this will stop programs from crashing due to dim mismatches.
60  }
61  return flags;
62 }
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ BiphoneContextDependencyFull()

ContextDependency* kaldi::BiphoneContextDependencyFull ( std::vector< std::vector< int32 > >  phone_sets,
const std::vector< int32 phone2num_pdf_classes,
const std::vector< int32 > &  ci_phones_list,
const std::vector< std::vector< int32 > > &  bi_counts,
int32  biphone_min_count,
const std::vector< int32 > &  mono_counts,
int32  mono_min_count 
)

Definition at line 180 of file gmm-init-biphone.cc.

References GetFullBiphoneStubMap(), rnnlm::i, and rnnlm::j.

Referenced by main().

186  {
187  // Remove all the CI phones from the phone sets
188  std::set<int32> ci_phones;
189  for (size_t i = 0; i < ci_phones_list.size(); i++)
190  ci_phones.insert(ci_phones_list[i]);
191  for (int32 i = phone_sets.size() - 1; i >= 0; i--) {
192  for (int32 j = phone_sets[i].size() - 1; j >= 0; j--) {
193  if (ci_phones.find(phone_sets[i][j]) != ci_phones.end()) { // Delete it
194  phone_sets[i].erase(phone_sets[i].begin() + j);
195  if (phone_sets[i].empty()) // If empty, delete the whole entry
196  phone_sets.erase(phone_sets.begin() + i);
197  }
198  }
199  }
200 
201  std::vector<bool> share_roots(phone_sets.size(), false); // Don't share roots
202  // N is context size, P = position of central phone (must be 0).
203  int32 P = 1, N = 2;
204  EventMap *pdf_map = GetFullBiphoneStubMap(phone_sets,
205  phone2num_pdf_classes,
206  ci_phones_list, bi_counts,
207  biphone_min_count, mono_counts,
208  mono_min_count);
209  return new ContextDependency(N, P, pdf_map);
210 }
kaldi::int32 int32
A class that is capable of representing a generic mapping from EventType (which is a vector of (key...
Definition: event-map.h:86
EventMap * GetFullBiphoneStubMap(const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< int32 > &ci_phones_list, const std::vector< std::vector< int32 > > &bi_counts, int32 biphone_min_count, const std::vector< int32 > &mono_counts, int32 mono_min_count)

◆ BuildConstArpaLm()

bool BuildConstArpaLm ( const ArpaParseOptions options,
const std::string &  arpa_rxfilename,
const std::string &  const_arpa_wxfilename 
)

Definition at line 1074 of file const-arpa-lm.cc.

References KALDI_LOG, ArpaFileParser::Read(), Input::Stream(), and WriteKaldiObject().

1076  {
1077  ConstArpaLmBuilder lm_builder(options);
1078  KALDI_LOG << "Reading " << arpa_rxfilename;
1079  Input ki(arpa_rxfilename);
1080  lm_builder.Read(ki.Stream());
1081  WriteKaldiObject(lm_builder, const_arpa_wxfilename, true);
1082  return true;
1083 }
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ CalBasisFmllrStepSize()

BaseFloat CalBasisFmllrStepSize ( const AffineXformStats spk_stats,
const Matrix< BaseFloat > &  spk_stats_tmp_K,
const std::vector< SpMatrix< BaseFloat > > &  spk_stats_tmp_G,
const Matrix< BaseFloat > &  delta,
const Matrix< BaseFloat > &  A,
const Matrix< BaseFloat > &  S,
int32  max_iters 
)
static

This function takes the step direction (delta) of fMLLR matrix as argument, and optimize step size using Newton's method.

This is an iterative method, where each iteration should not decrease the auxiliary function. Note that the resulting step size should be close to 1. If <<1 or >>1, there maybe problems with preconditioning or the speaker stats.

Definition at line 374 of file basis-fmllr-diag-gmm.cc.

References MatrixBase< Real >::AddMat(), MatrixBase< Real >::AddMatMat(), VectorBase< Real >::AddSpVec(), AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), rnnlm::d, AffineXformStats::dim_, MatrixBase< Real >::InvertDouble(), KALDI_ASSERT, KALDI_WARN, kNoTrans, kTrans, MatrixBase< Real >::LogDet(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), TraceMat(), TraceMatMat(), and VecVec().

Referenced by BasisFmllrEstimate::ComputeTransform().

380  {
381 
382  int32 dim = spk_stats.dim_;
383  KALDI_ASSERT(dim == delta.NumRows() && dim == S.NumRows());
384  // The first D columns of delta_W
385  SubMatrix<BaseFloat> delta_Dim(delta, 0, dim, 0, dim);
386  // Eq. (46): b = tr(delta K^T) - tr(delta S^T)
387  BaseFloat b = TraceMatMat(delta, spk_stats_tmp_K, kTrans)
388  - TraceMatMat(delta, S, kTrans);
389  // Eq. (47): c = sum_d tr(delta_{d} G_{d} delta_{d})
390  BaseFloat c = 0;
391  Vector<BaseFloat> G_row_delta(dim + 1);
392  for (int32 d = 0; d < dim; ++d) {
393  G_row_delta.AddSpVec(1.0, spk_stats_tmp_G[d], delta.Row(d), 0.0);
394  c += VecVec(G_row_delta, delta.Row(d));
395  }
396 
397  // Sometimes, the change of step size, d1/d2, may get tiny
398  // Due to numerical precision, we compute everything in double
399  BaseFloat step_size = 0.0;
400  BaseFloat obj_old, obj_new = 0.0;
401  Matrix<BaseFloat> N(dim, dim);
402  for (int32 iter_step = 1; iter_step <= max_iters; ++iter_step) {
403  if (iter_step == 1) {
404  // k = 0, auxf = beta logdet(A)
405  obj_old = spk_stats.beta_ * A.LogDet();
406  } else {
407  obj_old = obj_new;
408  }
409 
410  // Eq. (49): N = (A + k * delta_Dim)^{-1} delta_Dim
411  // In case of bad condition, careful preconditioning should be done. Maybe safer
412  // to use SolveQuadraticMatrixProblem. Future work for Yajie.
413  Matrix<BaseFloat> tmp_A(A);
414  tmp_A.AddMat(step_size, delta_Dim, kNoTrans);
415  tmp_A.InvertDouble();
416  N.AddMatMat(1.0, tmp_A, kNoTrans, delta_Dim, kNoTrans, 0.0);
417  // first-order derivative w.r.t. k
418  // Eq. (50): d1 = beta * trace(N) + b - k * c
419  BaseFloat d1 = spk_stats.beta_ * TraceMat(N) + b - step_size * c;
420  // second-order derivative w.r.t. k
421  // Eq. (51): d2 = -beta * tr(N N) - c
422  BaseFloat d2 = -c - spk_stats.beta_ * TraceMatMat(N, N, kNoTrans);
423  d2 = std::min((double)d2, -c / 10.0);
424  // convergence judgment from fmllr-sgmm.cc
425  // it seems to work well, though not sure whether 1e-06 is appropriate
426  // note from Dan: commenting this out after someone complained it was
427  // causing a test to behave weirdly. This doesn't dominate computation
428  // anyway, I don't think.
429  // if (std::fabs(d1 / d2) < 0.000001) { break; }
430 
431  // Eq. (52): update step_size
432  BaseFloat step_size_change = -(d1 / d2);
433  step_size += step_size_change;
434 
435  // Repeatedly check auxiliary function; halve step size change if auxf decreases.
436  // According to the paper, we should limit the number of repetitions. The
437  // following implementation seems to work well. But the termination condition/judgment
438  // should be optimized later.
439  do {
440  // Eq. (48): auxf = beta * logdet(A + k * delta_Dim) + kb - 0.5 * k * k * c
441  tmp_A.CopyFromMat(A);
442  tmp_A.AddMat(step_size, delta_Dim, kNoTrans);
443  obj_new = spk_stats.beta_ * tmp_A.LogDet() + step_size * b -
444  0.5 * step_size * step_size * c;
445 
446  if (obj_new - obj_old < -1.0e-04 * spk_stats.beta_) { // deal with numerical issues
447  KALDI_WARN << "Objective function decreased (" << obj_old << "->"
448  << obj_new << "). Halving step size change ( step size "
449  << step_size << " -> " << (step_size - (step_size_change/2))
450  << ")";
451  step_size_change /= 2;
452  step_size -= step_size_change;
453  }
454  } while (obj_new - obj_old < -1.0e-04 * spk_stats.beta_ && step_size_change > 1e-05);
455  }
456  return step_size;
457 }
double TraceMat(const MatrixBase< Real > &A)
Returns trace of matrix.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_WARN
Definition: kaldi-error.h:150
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
Real LogDet(Real *det_sign=NULL) const
Returns logdet of matrix.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ CalcFmllrStepSize()

static BaseFloat kaldi::CalcFmllrStepSize ( const AffineXformStats stats,
const AmSgmm2 sgmm,
const MatrixBase< BaseFloat > &  Delta,
const MatrixBase< BaseFloat > &  A,
const Matrix< BaseFloat > &  G,
int32  max_iters 
)
static

Definition at line 286 of file fmllr-sgmm2.cc.

References MatrixBase< Real >::AddMat(), MatrixBase< Real >::AddMatMat(), AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), rnnlm::d, AmSgmm2::FeatureDim(), AffineXformStats::G_, AmSgmm2::GetInvCovars(), rnnlm::i, MatrixBase< Real >::InvertDouble(), AffineXformStats::K_, KALDI_WARN, kNoTrans, kTrans, MatrixBase< Real >::LogDet(), rnnlm::n, AmSgmm2::NumGauss(), TraceMat(), TraceMatMat(), and TraceMatSpMatSp().

Referenced by FmllrSgmm2Accs::Update().

291  {
292  int32 dim = sgmm.FeatureDim();
293  Matrix<double> Delta_d(Delta);
294  Matrix<double> G_d(G);
295  SubMatrix<double> Delta_C(Delta_d, 0, dim, 0, dim);
296 
297  // Eq. (B.28): m = tr(\Delta K^T) - tr(\Delta S^T)
298  BaseFloat m = TraceMatMat(Delta_d, stats.K_, kTrans)
299  - TraceMatMat(Delta_d, G_d, kTrans);
300  // Eq. (B.29): n = \sum_i tr(\Delta \Sigma_{i}^{-1} \Delta S_{i})
301  BaseFloat n = 0;
302  SpMatrix<double> inv_covar;
303  for (int32 i = 0, num_gauss = sgmm.NumGauss(); i < num_gauss; i++) {
304  sgmm.GetInvCovars(i, &inv_covar);
305  n += TraceMatSpMatSp(Delta_d, kTrans, inv_covar, Delta_d, kNoTrans,
306  stats.G_[i]);
307  }
308 
309  BaseFloat step_size = 0.0;
310  // initialize just to get rid of compile errors.
311  BaseFloat obj_step_old, obj_step_new = 0.0;
312  Matrix<double> new_A(dim, dim);
313  Matrix<double> B(dim, dim);
314  for (int32 iter_step = 0; iter_step < max_iters; iter_step++) {
315  if (iter_step == 0) {
316  obj_step_old = stats.beta_ * A.LogDet(); // Q_0 = \beta * log det(A)
317  } else {
318  obj_step_old = obj_step_new;
319  }
320 
321  // Eq. (B.30); B = (A + k\Delta^{-C})^{-1} \Delta^{-C}
322  new_A.CopyFromMat(A);
323  new_A.AddMat(step_size, Delta_C, kNoTrans);
324  new_A.InvertDouble();
325  B.AddMatMat(1.0, new_A, kNoTrans, Delta_C, kNoTrans, 0.0);
326 
327  BaseFloat d = m - step_size * n + stats.beta_ * TraceMat(B);
328  BaseFloat d2 = -n - stats.beta_ * TraceMatMat(B, B, kNoTrans);
329  if (std::fabs(d / d2) < 0.000001) { break; } // converged
330 
331  BaseFloat step_size_change = -(d / d2);
332  step_size += step_size_change; // Eq. (B.33)
333 
334  // Halve step size when the auxiliary function decreases.
335  do {
336  new_A.CopyFromMat(A);
337  new_A.AddMat(step_size, Delta_C, kNoTrans);
338  BaseFloat logdet = new_A.LogDet();
339  obj_step_new = stats.beta_ * logdet + step_size * m -
340  0.5 * step_size * step_size * n;
341 
342  if (obj_step_new - obj_step_old < -0.001) {
343  KALDI_WARN << "Objective function decreased (" << obj_step_old << "->"
344  << obj_step_new << "). Halving step size change ("
345  << step_size << " -> " << (step_size - (step_size_change/2))
346  << ")";
347  step_size_change /= 2;
348  step_size -= step_size_change; // take away half of our step
349  } // Facing numeric precision issues. Compute in double?
350  } while (obj_step_new - obj_step_old < -0.001 && step_size_change > 1e-05);
351  }
352  return step_size;
353 }
double TraceMat(const MatrixBase< Real > &A)
Returns trace of matrix.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
struct rnnlm::@11::@12 n
#define KALDI_WARN
Definition: kaldi-error.h:150
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
Real TraceMatSpMatSp(const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const MatrixBase< Real > &C, MatrixTransposeType transC, const SpMatrix< Real > &D)
Returns tr (A B C D) (A and C may be transposed as specified by transA and transB).
Definition: sp-matrix.cc:438

◆ cblas_Xasum() [1/2]

float kaldi::cblas_Xasum ( const int  N,
const float X,
const int  incX 
)
inline

Definition at line 48 of file cblas-wrappers.h.

48  {
49  return cblas_sasum(N, X, incX);
50 }

◆ cblas_Xasum() [2/2]

double kaldi::cblas_Xasum ( const int  N,
const double *  X,
const int  incX 
)
inline

Definition at line 52 of file cblas-wrappers.h.

52  {
53  return cblas_dasum(N, X, incX);
54 }

◆ cblas_Xaxpy() [1/2]

void kaldi::cblas_Xaxpy ( const int  N,
const float  alpha,
const float X,
const int  incX,
float Y,
const int  incY 
)
inline

◆ cblas_Xaxpy() [2/2]

void kaldi::cblas_Xaxpy ( const int  N,
const double  alpha,
const double *  X,
const int  incX,
double *  Y,
const int  incY 
)
inline

Definition at line 78 of file cblas-wrappers.h.

79  {
80  cblas_daxpy(N, alpha, X, incX, Y, incY);
81 }

◆ cblas_Xcopy() [1/2]

void kaldi::cblas_Xcopy ( const int  N,
const float X,
const int  incX,
float Y,
const int  incY 
)
inline

Definition at line 37 of file cblas-wrappers.h.

Referenced by VectorBase< float >::CopyDiagFromMat(), MatrixBase< float >::CopyRows(), and MatrixBase< float >::CopyToRows().

38  {
39  cblas_scopy(N, X, incX, Y, incY);
40 }

◆ cblas_Xcopy() [2/2]

void kaldi::cblas_Xcopy ( const int  N,
const double *  X,
const int  incX,
double *  Y,
const int  incY 
)
inline

Definition at line 42 of file cblas-wrappers.h.

43  {
44  cblas_dcopy(N, X, incX, Y, incY);
45 }

◆ cblas_Xdot() [1/2]

float kaldi::cblas_Xdot ( const int  N,
const float *const  X,
const int  incX,
const float *const  Y,
const int  incY 
)
inline

◆ cblas_Xdot() [2/2]

double kaldi::cblas_Xdot ( const int  N,
const double *const  X,
const int  incX,
const double *const  Y,
const int  incY 
)
inline

Definition at line 69 of file cblas-wrappers.h.

71  {
72  return cblas_ddot(N, X, incX, Y, incY);
73 }

◆ cblas_Xgbmv() [1/2]

void kaldi::cblas_Xgbmv ( MatrixTransposeType  trans,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
MatrixIndexT  num_below,
MatrixIndexT  num_above,
float  alpha,
const float Mdata,
MatrixIndexT  stride,
const float xdata,
MatrixIndexT  incX,
float  beta,
float ydata,
MatrixIndexT  incY 
)
inline

Definition at line 178 of file cblas-wrappers.h.

Referenced by VectorBase< float >::AddVecVec().

182  {
183  cblas_sgbmv(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(trans), num_rows,
184  num_cols, num_below, num_above, alpha, Mdata, stride, xdata,
185  incX, beta, ydata, incY);
186 }

◆ cblas_Xgbmv() [2/2]

void kaldi::cblas_Xgbmv ( MatrixTransposeType  trans,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
MatrixIndexT  num_below,
MatrixIndexT  num_above,
double  alpha,
const double *  Mdata,
MatrixIndexT  stride,
const double *  xdata,
MatrixIndexT  incX,
double  beta,
double *  ydata,
MatrixIndexT  incY 
)
inline

Definition at line 187 of file cblas-wrappers.h.

191  {
192  cblas_dgbmv(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(trans), num_rows,
193  num_cols, num_below, num_above, alpha, Mdata, stride, xdata,
194  incX, beta, ydata, incY);
195 }

◆ cblas_Xgemm() [1/2]

void kaldi::cblas_Xgemm ( const float  alpha,
MatrixTransposeType  transA,
const float Adata,
MatrixIndexT  a_num_rows,
MatrixIndexT  a_num_cols,
MatrixIndexT  a_stride,
MatrixTransposeType  transB,
const float Bdata,
MatrixIndexT  b_stride,
const float  beta,
float Mdata,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
MatrixIndexT  stride 
)
inline

Definition at line 224 of file cblas-wrappers.h.

References kNoTrans.

Referenced by MatrixBase< float >::AddMatMat().

232  {
233  cblas_sgemm(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(transA),
234  static_cast<CBLAS_TRANSPOSE>(transB),
235  num_rows, num_cols, transA == kNoTrans ? a_num_cols : a_num_rows,
236  alpha, Adata, a_stride, Bdata, b_stride,
237  beta, Mdata, stride);
238 }

◆ cblas_Xgemm() [2/2]

void kaldi::cblas_Xgemm ( const double  alpha,
MatrixTransposeType  transA,
const double *  Adata,
MatrixIndexT  a_num_rows,
MatrixIndexT  a_num_cols,
MatrixIndexT  a_stride,
MatrixTransposeType  transB,
const double *  Bdata,
MatrixIndexT  b_stride,
const double  beta,
double *  Mdata,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
MatrixIndexT  stride 
)
inline

Definition at line 239 of file cblas-wrappers.h.

References kNoTrans.

247  {
248  cblas_dgemm(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(transA),
249  static_cast<CBLAS_TRANSPOSE>(transB),
250  num_rows, num_cols, transA == kNoTrans ? a_num_cols : a_num_rows,
251  alpha, Adata, a_stride, Bdata, b_stride,
252  beta, Mdata, stride);
253 }

◆ cblas_Xgemv() [1/2]

void kaldi::cblas_Xgemv ( MatrixTransposeType  trans,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
float  alpha,
const float Mdata,
MatrixIndexT  stride,
const float xdata,
MatrixIndexT  incX,
float  beta,
float ydata,
MatrixIndexT  incY 
)
inline

Definition at line 162 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::AddMat2Sp(), VectorBase< float >::AddMatVec(), and SpMatrix< float >::Tridiagonalize().

165  {
166  cblas_sgemv(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(trans), num_rows,
167  num_cols, alpha, Mdata, stride, xdata, incX, beta, ydata, incY);
168 }

◆ cblas_Xgemv() [2/2]

void kaldi::cblas_Xgemv ( MatrixTransposeType  trans,
MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
double  alpha,
const double *  Mdata,
MatrixIndexT  stride,
const double *  xdata,
MatrixIndexT  incX,
double  beta,
double *  ydata,
MatrixIndexT  incY 
)
inline

Definition at line 169 of file cblas-wrappers.h.

172  {
173  cblas_dgemv(CblasRowMajor, static_cast<CBLAS_TRANSPOSE>(trans), num_rows,
174  num_cols, alpha, Mdata, stride, xdata, incX, beta, ydata, incY);
175 }

◆ cblas_Xger() [1/2]

void kaldi::cblas_Xger ( MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
float  alpha,
const float xdata,
MatrixIndexT  incX,
const float ydata,
MatrixIndexT  incY,
float Mdata,
MatrixIndexT  stride 
)
inline

Definition at line 275 of file cblas-wrappers.h.

Referenced by MatrixBase< float >::AddVecVec(), and SpMatrix< float >::Tridiagonalize().

277  {
278  cblas_sger(CblasRowMajor, num_rows, num_cols, alpha, xdata, 1, ydata, 1,
279  Mdata, stride);
280 }

◆ cblas_Xger() [2/2]

void kaldi::cblas_Xger ( MatrixIndexT  num_rows,
MatrixIndexT  num_cols,
double  alpha,
const double *  xdata,
MatrixIndexT  incX,
const double *  ydata,
MatrixIndexT  incY,
double *  Mdata,
MatrixIndexT  stride 
)
inline

Definition at line 281 of file cblas-wrappers.h.

283  {
284  cblas_dger(CblasRowMajor, num_rows, num_cols, alpha, xdata, 1, ydata, 1,
285  Mdata, stride);
286 }

◆ cblas_Xrot() [1/2]

void kaldi::cblas_Xrot ( const int  N,
float X,
const int  incX,
float Y,
const int  incY,
const float  c,
const float  s 
)
inline

Definition at line 56 of file cblas-wrappers.h.

Referenced by QrStep().

57  {
58  cblas_srot(N, X, incX, Y, incY, c, s);
59 }

◆ cblas_Xrot() [2/2]

void kaldi::cblas_Xrot ( const int  N,
double *  X,
const int  incX,
double *  Y,
const int  incY,
const double  c,
const double  s 
)
inline

Definition at line 60 of file cblas-wrappers.h.

61  {
62  cblas_drot(N, X, incX, Y, incY, c, s);
63 }

◆ cblas_Xsbmv1() [1/2]

void kaldi::cblas_Xsbmv1 ( const MatrixIndexT  dim,
const double *  A,
const double  alpha,
const double *  x,
const double  beta,
double *  y 
)
inline

matrix-vector multiply using a banded matrix; we always call this with b = 1 meaning we're multiplying by a diagonal matrix.

This is used for elementwise multiplication. We miss some of the arguments out of this wrapper.

Definition at line 317 of file cblas-wrappers.h.

323  {
324  cblas_dsbmv(CblasRowMajor, CblasLower, dim, 0, alpha, A,
325  1, x, 1, beta, y, 1);
326 }

◆ cblas_Xsbmv1() [2/2]

void kaldi::cblas_Xsbmv1 ( const MatrixIndexT  dim,
const float A,
const float  alpha,
const float x,
const float  beta,
float y 
)
inline

Definition at line 328 of file cblas-wrappers.h.

334  {
335  cblas_ssbmv(CblasRowMajor, CblasLower, dim, 0, alpha, A,
336  1, x, 1, beta, y, 1);
337 }

◆ cblas_Xscal() [1/2]

void kaldi::cblas_Xscal ( const int  N,
const float  alpha,
float data,
const int  inc 
)
inline

◆ cblas_Xscal() [2/2]

void kaldi::cblas_Xscal ( const int  N,
const double  alpha,
double *  data,
const int  inc 
)
inline

Definition at line 86 of file cblas-wrappers.h.

87  {
88  cblas_dscal(N, alpha, data, inc);
89 }

◆ cblas_Xspmv() [1/4]

void kaldi::cblas_Xspmv ( const float  alpha,
const int  num_rows,
const float Mdata,
const float v,
const int  v_inc,
const float  beta,
float y,
const int  y_inc 
)
inline

Definition at line 90 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::AddMat2Sp(), VectorBase< float >::AddSpVec(), SpMatrix< float >::Tridiagonalize(), UnitTestTridiagonalize(), UnitTestTridiagonalizeAndQr(), and VecSpVec().

92  {
93  cblas_sspmv(CblasRowMajor, CblasLower, num_rows, alpha, Mdata, v, v_inc, beta, y, y_inc);
94 }

◆ cblas_Xspmv() [2/4]

void kaldi::cblas_Xspmv ( const double  alpha,
const int  num_rows,
const double *  Mdata,
const double *  v,
const int  v_inc,
const double  beta,
double *  y,
const int  y_inc 
)
inline

Definition at line 95 of file cblas-wrappers.h.

97  {
98  cblas_dspmv(CblasRowMajor, CblasLower, num_rows, alpha, Mdata, v, v_inc, beta, y, y_inc);
99 }

◆ cblas_Xspmv() [3/4]

void kaldi::cblas_Xspmv ( MatrixIndexT  dim,
float  alpha,
const float Mdata,
const float ydata,
MatrixIndexT  ystride,
float  beta,
float xdata,
MatrixIndexT  xstride 
)
inline

Definition at line 124 of file cblas-wrappers.h.

126  {
127  cblas_sspmv(CblasRowMajor, CblasLower, dim, alpha, Mdata,
128  ydata, ystride, beta, xdata, xstride);
129 }

◆ cblas_Xspmv() [4/4]

void kaldi::cblas_Xspmv ( MatrixIndexT  dim,
double  alpha,
const double *  Mdata,
const double *  ydata,
MatrixIndexT  ystride,
double  beta,
double *  xdata,
MatrixIndexT  xstride 
)
inline

Definition at line 130 of file cblas-wrappers.h.

132  {
133  cblas_dspmv(CblasRowMajor, CblasLower, dim, alpha, Mdata,
134  ydata, ystride, beta, xdata, xstride);
135 }

◆ cblas_Xspr() [1/2]

void kaldi::cblas_Xspr ( MatrixIndexT  dim,
float  alpha,
const float Xdata,
MatrixIndexT  incX,
float Adata 
)
inline

Definition at line 152 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::AddMat2Vec(), and SpMatrix< float >::AddVec2().

153  {
154  cblas_sspr(CblasRowMajor, CblasLower, dim, alpha, Xdata, incX, Adata);
155 }

◆ cblas_Xspr() [2/2]

void kaldi::cblas_Xspr ( MatrixIndexT  dim,
double  alpha,
const double *  Xdata,
MatrixIndexT  incX,
double *  Adata 
)
inline

Definition at line 156 of file cblas-wrappers.h.

157  {
158  cblas_dspr(CblasRowMajor, CblasLower, dim, alpha, Xdata, incX, Adata);
159 }

◆ cblas_Xspr2() [1/2]

void kaldi::cblas_Xspr2 ( MatrixIndexT  dim,
float  alpha,
const float Xdata,
MatrixIndexT  incX,
const float Ydata,
MatrixIndexT  incY,
float Adata 
)
inline

Definition at line 138 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::AddVecVec(), and SpMatrix< float >::Tridiagonalize().

140  {
141  cblas_sspr2(CblasRowMajor, CblasLower, dim, alpha, Xdata,
142  incX, Ydata, incY, Adata);
143 }

◆ cblas_Xspr2() [2/2]

void kaldi::cblas_Xspr2 ( MatrixIndexT  dim,
double  alpha,
const double *  Xdata,
MatrixIndexT  incX,
const double *  Ydata,
MatrixIndexT  incY,
double *  Adata 
)
inline

Definition at line 144 of file cblas-wrappers.h.

146  {
147  cblas_dspr2(CblasRowMajor, CblasLower, dim, alpha, Xdata,
148  incX, Ydata, incY, Adata);
149 }

◆ cblas_Xsymm() [1/2]

void kaldi::cblas_Xsymm ( const float  alpha,
MatrixIndexT  sz,
const float Adata,
MatrixIndexT  a_stride,
const float Bdata,
MatrixIndexT  b_stride,
const float  beta,
float Mdata,
MatrixIndexT  stride 
)
inline

Definition at line 256 of file cblas-wrappers.h.

Referenced by MatrixBase< float >::AddSpSp().

261  {
262  cblas_ssymm(CblasRowMajor, CblasLeft, CblasLower, sz, sz, alpha, Adata,
263  a_stride, Bdata, b_stride, beta, Mdata, stride);
264 }

◆ cblas_Xsymm() [2/2]

void kaldi::cblas_Xsymm ( const double  alpha,
MatrixIndexT  sz,
const double *  Adata,
MatrixIndexT  a_stride,
const double *  Bdata,
MatrixIndexT  b_stride,
const double  beta,
double *  Mdata,
MatrixIndexT  stride 
)
inline

Definition at line 265 of file cblas-wrappers.h.

270  {
271  cblas_dsymm(CblasRowMajor, CblasLeft, CblasLower, sz, sz, alpha, Adata,
272  a_stride, Bdata, b_stride, beta, Mdata, stride);
273 }

◆ cblas_Xsyrk() [1/2]

void kaldi::cblas_Xsyrk ( const MatrixTransposeType  trans,
const MatrixIndexT  dim_c,
const MatrixIndexT  other_dim_a,
const float  alpha,
const float A,
const MatrixIndexT  a_stride,
const float  beta,
float C,
const MatrixIndexT  c_stride 
)
inline

Definition at line 295 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::AddMat2(), and MatrixBase< float >::SymAddMat2().

299  {
300  cblas_ssyrk(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
301  dim_c, other_dim_a, alpha, A, a_stride, beta, C, c_stride);
302 }

◆ cblas_Xsyrk() [2/2]

void kaldi::cblas_Xsyrk ( const MatrixTransposeType  trans,
const MatrixIndexT  dim_c,
const MatrixIndexT  other_dim_a,
const double  alpha,
const double *  A,
const MatrixIndexT  a_stride,
const double  beta,
double *  C,
const MatrixIndexT  c_stride 
)
inline

Definition at line 304 of file cblas-wrappers.h.

308  {
309  cblas_dsyrk(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
310  dim_c, other_dim_a, alpha, A, a_stride, beta, C, c_stride);
311 }

◆ cblas_Xtpmv() [1/2]

void kaldi::cblas_Xtpmv ( MatrixTransposeType  trans,
const float Mdata,
const int  num_rows,
float y,
const int  y_inc 
)
inline

Definition at line 100 of file cblas-wrappers.h.

Referenced by VectorBase< float >::MulTp().

101  {
102  cblas_stpmv(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
103  CblasNonUnit, num_rows, Mdata, y, y_inc);
104 }

◆ cblas_Xtpmv() [2/2]

void kaldi::cblas_Xtpmv ( MatrixTransposeType  trans,
const double *  Mdata,
const int  num_rows,
double *  y,
const int  y_inc 
)
inline

Definition at line 105 of file cblas-wrappers.h.

106  {
107  cblas_dtpmv(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
108  CblasNonUnit, num_rows, Mdata, y, y_inc);
109 }

◆ cblas_Xtpsv() [1/2]

void kaldi::cblas_Xtpsv ( MatrixTransposeType  trans,
const float Mdata,
const int  num_rows,
float y,
const int  y_inc 
)
inline

Definition at line 112 of file cblas-wrappers.h.

Referenced by VectorBase< float >::Solve().

113  {
114  cblas_stpsv(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
115  CblasNonUnit, num_rows, Mdata, y, y_inc);
116 }

◆ cblas_Xtpsv() [2/2]

void kaldi::cblas_Xtpsv ( MatrixTransposeType  trans,
const double *  Mdata,
const int  num_rows,
double *  y,
const int  y_inc 
)
inline

Definition at line 117 of file cblas-wrappers.h.

118  {
119  cblas_dtpsv(CblasRowMajor, CblasLower, static_cast<CBLAS_TRANSPOSE>(trans),
120  CblasNonUnit, num_rows, Mdata, y, y_inc);
121 }

◆ CharToString()

◆ CheckFst()

bool kaldi::CheckFst ( const fst::StdVectorFst fst,
string  name,
string  key 
)

Definition at line 151 of file lattice-oracle.cc.

Referenced by main().

151  {
152 #ifdef DEBUG
153  fst::StdArc::StateId numstates = fst.NumStates();
154  std::cerr << " " << name << " has " << numstates << " states" << std::endl;
155  std::stringstream ss;
156  ss << name << key << ".fst";
157  fst.Write(ss.str());
158  return(fst.Start() == fst::kNoStateId);
159 #else
160  return true;
161 #endif
162 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21

◆ CheckToken()

void kaldi::CheckToken ( const char *  token)

Definition at line 122 of file io-funcs.cc.

References KALDI_ERR.

Referenced by ExpectToken(), and WriteToken().

122  {
123  if (*token == '\0')
124  KALDI_ERR << "Token is empty (not a valid token)";
125  const char *orig_token = token;
126  while (*token != '\0') {
127  if (::isspace(*token))
128  KALDI_ERR << "Token is not a valid token (contains space): '"
129  << orig_token << "'";
130  token++;
131  }
132 }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ CholeskyUnitTestTr()

static void kaldi::CholeskyUnitTestTr ( )
static

Definition at line 140 of file matrix-lib-test.cc.

References SpMatrix< Real >::AddMat2(), MatrixBase< Real >::AddMatMat(), AssertEqual(), TpMatrix< Real >::Cholesky(), rnnlm::i, InitRandNonsingular(), TpMatrix< Real >::Invert(), MatrixBase< Real >::Invert(), MatrixBase< Real >::IsUnit(), KALDI_ASSERT, kNoTrans, and Rand().

140  {
141  for (MatrixIndexT i = 0; i < 5; i++) {
142  MatrixIndexT dimM = 2 + Rand() % 10;
143  Matrix<Real> M(dimM, dimM);
145  SpMatrix<Real> S(dimM);
146  S.AddMat2(1.0, M, kNoTrans, 0.0);
147  TpMatrix<Real> C(dimM);
148  C.Cholesky(S);
149  Matrix<Real> CM(C);
150  TpMatrix<Real> Cinv(C);
151  Cinv.Invert();
152  {
153  Matrix<Real> A(C), B(Cinv), AB(dimM, dimM);
154  AB.AddMatMat(1.0, A, kNoTrans, B, kNoTrans, 0.0);
155  KALDI_ASSERT(AB.IsUnit());
156  }
157  SpMatrix<Real> S2(dimM);
158  S2.AddMat2(1.0, CM, kNoTrans, 0.0);
159  AssertEqual(S, S2);
160  C.Invert();
161  Matrix<Real> CM2(C);
162  CM2.Invert();
163  SpMatrix<Real> S3(dimM);
164  S3.AddMat2(1.0, CM2, kNoTrans, 0.0);
165  AssertEqual(S, S3);
166  }
167 }
Packed symetric matrix class.
Definition: matrix-common.h:62
A class for storing matrices.
Definition: kaldi-matrix.h:823
int32 MatrixIndexT
Definition: matrix-common.h:98
Packed symetric matrix class.
Definition: matrix-common.h:63
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
static void InitRandNonsingular(SpMatrix< Real > *M)

◆ clapack_Xgesvd() [1/2]

void kaldi::clapack_Xgesvd ( char *  v,
char *  u,
KaldiBlasInt *  num_cols,
KaldiBlasInt *  num_rows,
float Mdata,
KaldiBlasInt *  stride,
float sv,
float Vdata,
KaldiBlasInt *  vstride,
float Udata,
KaldiBlasInt *  ustride,
float p_work,
KaldiBlasInt *  l_work,
KaldiBlasInt *  result 
)
inline

Definition at line 415 of file cblas-wrappers.h.

Referenced by MatrixBase< float >::LapackGesvd().

419  {
420  sgesvd_(v, u,
421  num_cols, num_rows, Mdata, stride,
422  sv, Vdata, vstride, Udata, ustride,
423  p_work, l_work, result);
424 }

◆ clapack_Xgesvd() [2/2]

void kaldi::clapack_Xgesvd ( char *  v,
char *  u,
KaldiBlasInt *  num_cols,
KaldiBlasInt *  num_rows,
double *  Mdata,
KaldiBlasInt *  stride,
double *  sv,
double *  Vdata,
KaldiBlasInt *  vstride,
double *  Udata,
KaldiBlasInt *  ustride,
double *  p_work,
KaldiBlasInt *  l_work,
KaldiBlasInt *  result 
)
inline

Definition at line 425 of file cblas-wrappers.h.

429  {
430  dgesvd_(v, u,
431  num_cols, num_rows, Mdata, stride,
432  sv, Vdata, vstride, Udata, ustride,
433  p_work, l_work, result);
434 }

◆ clapack_Xgetrf2() [1/2]

void kaldi::clapack_Xgetrf2 ( KaldiBlasInt *  num_rows,
KaldiBlasInt *  num_cols,
float Mdata,
KaldiBlasInt *  stride,
KaldiBlasInt *  pivot,
KaldiBlasInt *  result 
)
inline

Definition at line 392 of file cblas-wrappers.h.

Referenced by MatrixBase< float >::Invert().

394  {
395  sgetrf_(num_rows, num_cols, Mdata, stride, pivot, result);
396 }

◆ clapack_Xgetrf2() [2/2]

void kaldi::clapack_Xgetrf2 ( KaldiBlasInt *  num_rows,
KaldiBlasInt *  num_cols,
double *  Mdata,
KaldiBlasInt *  stride,
KaldiBlasInt *  pivot,
KaldiBlasInt *  result 
)
inline

Definition at line 397 of file cblas-wrappers.h.

399  {
400  dgetrf_(num_rows, num_cols, Mdata, stride, pivot, result);
401 }

◆ clapack_Xgetri2() [1/2]

void kaldi::clapack_Xgetri2 ( KaldiBlasInt *  num_rows,
float Mdata,
KaldiBlasInt *  stride,
KaldiBlasInt *  pivot,
float p_work,
KaldiBlasInt *  l_work,
KaldiBlasInt *  result 
)
inline

Definition at line 404 of file cblas-wrappers.h.

Referenced by MatrixBase< float >::Invert().

406  {
407  sgetri_(num_rows, Mdata, stride, pivot, p_work, l_work, result);
408 }

◆ clapack_Xgetri2() [2/2]

void kaldi::clapack_Xgetri2 ( KaldiBlasInt *  num_rows,
double *  Mdata,
KaldiBlasInt *  stride,
KaldiBlasInt *  pivot,
double *  p_work,
KaldiBlasInt *  l_work,
KaldiBlasInt *  result 
)
inline

Definition at line 409 of file cblas-wrappers.h.

411  {
412  dgetri_(num_rows, Mdata, stride, pivot, p_work, l_work, result);
413 }

◆ clapack_Xsptrf() [1/2]

void kaldi::clapack_Xsptrf ( KaldiBlasInt *  num_rows,
float Mdata,
KaldiBlasInt *  ipiv,
KaldiBlasInt *  result 
)
inline

Definition at line 445 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::Invert().

446  {
447  ssptrf_(const_cast<char *>("U"), num_rows, Mdata, ipiv, result);
448 }

◆ clapack_Xsptrf() [2/2]

void kaldi::clapack_Xsptrf ( KaldiBlasInt *  num_rows,
double *  Mdata,
KaldiBlasInt *  ipiv,
KaldiBlasInt *  result 
)
inline

Definition at line 449 of file cblas-wrappers.h.

450  {
451  dsptrf_(const_cast<char *>("U"), num_rows, Mdata, ipiv, result);
452 }

◆ clapack_Xsptri() [1/2]

void kaldi::clapack_Xsptri ( KaldiBlasInt *  num_rows,
float Mdata,
KaldiBlasInt *  ipiv,
float work,
KaldiBlasInt *  result 
)
inline

Definition at line 436 of file cblas-wrappers.h.

Referenced by SpMatrix< float >::Invert().

437  {
438  ssptri_(const_cast<char *>("U"), num_rows, Mdata, ipiv, work, result);
439 }

◆ clapack_Xsptri() [2/2]

void kaldi::clapack_Xsptri ( KaldiBlasInt *  num_rows,
double *  Mdata,
KaldiBlasInt *  ipiv,
double *  work,
KaldiBlasInt *  result 
)
inline

Definition at line 440 of file cblas-wrappers.h.

441  {
442  dsptri_(const_cast<char *>("U"), num_rows, Mdata, ipiv, work, result);
443 }

◆ clapack_Xtptri() [1/2]

void kaldi::clapack_Xtptri ( KaldiBlasInt *  num_rows,
float Mdata,
KaldiBlasInt *  result 
)
inline

Definition at line 385 of file cblas-wrappers.h.

Referenced by TpMatrix< float >::Invert().

385  {
386  stptri_(const_cast<char *>("U"), const_cast<char *>("N"), num_rows, Mdata, result);
387 }

◆ clapack_Xtptri() [2/2]

void kaldi::clapack_Xtptri ( KaldiBlasInt *  num_rows,
double *  Mdata,
KaldiBlasInt *  result 
)
inline

Definition at line 388 of file cblas-wrappers.h.

388  {
389  dtptri_(const_cast<char *>("U"), const_cast<char *>("N"), num_rows, Mdata, result);
390 }

◆ ClusterEventMapRestrictedHelper()

static int32 kaldi::ClusterEventMapRestrictedHelper ( const EventMap e_in,
const BuildTreeStatsType stats,
BaseFloat  thresh,
std::vector< EventKeyType keys,
std::vector< EventMap *> *  leaf_mapping 
)
static

Definition at line 803 of file build-tree-utils.cc.

References ClusterEventMapGetMapping(), rnnlm::i, and SplitStatsByKey().

Referenced by ClusterEventMapRestrictedByKeys().

807  {
808  if (keys.size() == 0) {
809  return ClusterEventMapGetMapping(e_in, stats, thresh, leaf_mapping);
810  } else { // split on the key.
811  int32 ans = 0;
812  std::vector<BuildTreeStatsType> split_stats;
813  SplitStatsByKey(stats, keys.back(), &split_stats);
814  keys.pop_back();
815  for (size_t i = 0; i< split_stats.size(); i++)
816  if (split_stats[i].size() != 0)
817  ans += ClusterEventMapRestrictedHelper(e_in, split_stats[i], thresh, keys, leaf_mapping);
818  return ans;
819  }
820 }
static int32 ClusterEventMapRestrictedHelper(const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, std::vector< EventKeyType > keys, std::vector< EventMap *> *leaf_mapping)
kaldi::int32 int32
void SplitStatsByKey(const BuildTreeStatsType &stats_in, EventKeyType key, std::vector< BuildTreeStatsType > *stats_out)
SplitStatsByKey splits stats up according to the value of a particular key, which must be always defi...
int ClusterEventMapGetMapping(const EventMap &e_in, const BuildTreeStatsType &stats, BaseFloat thresh, std::vector< EventMap *> *mapping)
"ClusterEventMapGetMapping" clusters the leaves of the EventMap, with "thresh" a delta-likelihood thr...

◆ ClusterKMeansOnce()

BaseFloat kaldi::ClusterKMeansOnce ( const std::vector< Clusterable *> &  points,
int32  num_clust,
std::vector< Clusterable *> *  clusters_out,
std::vector< int32 > *  assignments_out,
ClusterKMeansOptions cfg 
)

ClusterKMeansOnce is called internally by ClusterKMeans; it is equivalent to calling ClusterKMeans with cfg.num_tries == 1.

It returns the objective function improvement versus everything being in one cluster.

Definition at line 918 of file cluster-utils.cc.

References count, Gcd(), rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_LOG, KALDI_WARN, ClusterKMeansOptions::num_iters, Clusterable::Objf(), Rand(), ClusterKMeansOptions::refine_cfg, RefineClusters(), SumClusterable(), SumClusterableNormalizer(), SumClusterableObjf(), and ClusterKMeansOptions::verbose.

Referenced by ClusterKMeans().

922  {
923  std::vector<int32> my_assignments;
924  int32 num_points = points.size();
925  KALDI_ASSERT(clusters_out != NULL);
926  KALDI_ASSERT(num_points != 0);
927  KALDI_ASSERT(num_clust <= num_points);
928 
929  KALDI_ASSERT(clusters_out->empty()); // or we wouldn't know what to do with pointers in there.
930  clusters_out->resize(num_clust, (Clusterable*)NULL);
931  assignments_out->resize(num_points);
932 
933  { // This block assigns points to clusters.
934  // This is done pseudo-randomly using Rand() so that
935  // if we call ClusterKMeans multiple times we get different answers (so we can choose
936  // the best if we want).
937  int32 skip; // randomly choose a "skip" that's coprime to num_points.
938  if (num_points == 1) {
939  skip = 1;
940  } else {
941  skip = 1 + (Rand() % (num_points-1)); // a number between 1 and num_points-1.
942  while (Gcd(skip, num_points) != 1) { // while skip is not coprime to num_points...
943  if (skip == num_points-1) skip = 0;
944  skip++; // skip is now still betweeen 1 and num_points-1. will cycle through
945  // all of 1...num_points-1.
946  }
947  }
948  int32 i, j, count = 0;
949  for (i = 0, j = 0; count != num_points;i = (i+skip)%num_points, j = (j+1)%num_clust, count++) {
950  // i cycles pseudo-randomly through all points; j skips ahead by 1 each time
951  // modulo num_points.
952  // assign point i to cluster j.
953  if ((*clusters_out)[j] == NULL) (*clusters_out)[j] = points[i]->Copy();
954  else (*clusters_out)[j]->Add(*(points[i]));
955  (*assignments_out)[i] = j;
956  }
957  }
958 
959 
960  BaseFloat normalizer = SumClusterableNormalizer(*clusters_out);
961  BaseFloat ans;
962  { // work out initial value of "ans" (objective function improvement).
963  Clusterable *all_stats = SumClusterable(*clusters_out);
964  ans = SumClusterableObjf(*clusters_out) - all_stats->Objf(); // improvement just from the random
965  // initialization.
966  if (ans < -0.01 && ans < -0.01 * fabs(all_stats->Objf())) { // something bad happend.
967  KALDI_WARN << "ClusterKMeans: objective function after random assignment to clusters is worse than in single cluster: "<< (all_stats->Objf()) << " changed by " << ans << ". Perhaps your stats class has the wrong properties?";
968  }
969  delete all_stats;
970  }
971  for (int32 iter = 0;iter < cfg.num_iters;iter++) {
972  // Keep refining clusters by reassigning points.
973  BaseFloat objf_before;
974  if (cfg.verbose) objf_before =SumClusterableObjf(*clusters_out);
975  BaseFloat impr = RefineClusters(points, clusters_out, assignments_out, cfg.refine_cfg);
976  BaseFloat objf_after;
977  if (cfg.verbose) objf_after = SumClusterableObjf(*clusters_out);
978  ans += impr;
979  if (cfg.verbose)
980  KALDI_LOG << "ClusterKMeans: on iteration "<<(iter)<<", objf before = "<<(objf_before)<<", impr = "<<(impr)<<", objf after = "<<(objf_after)<<", normalized by "<<(normalizer)<<" = "<<(objf_after/normalizer);
981  if (impr == 0) break;
982  }
983  return ans;
984 }
BaseFloat RefineClusters(const std::vector< Clusterable *> &points, std::vector< Clusterable *> *clusters, std::vector< int32 > *assignments, RefineClustersOptions cfg)
RefineClusters is mainly used internally by other clustering algorithms.
BaseFloat SumClusterableNormalizer(const std::vector< Clusterable *> &vec)
Returns the total normalizer (usually count) of the cluster (pointers may be NULL).
I Gcd(I m, I n)
Definition: kaldi-math.h:297
kaldi::int32 int32
const size_t count
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
BaseFloat SumClusterableObjf(const std::vector< Clusterable *> &vec)
Returns the total objective function after adding up all the statistics in the vector (pointers may b...
#define KALDI_LOG
Definition: kaldi-error.h:153
Clusterable * SumClusterable(const std::vector< Clusterable *> &vec)
Sums stats (ptrs may be NULL). Returns NULL if no non-NULL stats present.

◆ ClusterLattice()

bool ClusterLattice ( CompactLattice clat,
const std::vector< int32 > &  state_times 
)

Definition at line 40 of file kws-functions.cc.

References CompareInterval(), rnnlm::i, and Interval::Overlap().

Referenced by main().

41  {
42  using namespace fst;
44 
45  // Hashmap to store the cluster heads.
46  unordered_map<StateId, std::vector<Interval> > head;
47 
48  // Step 1: Iterate over the lattice to get the arcs
49  StateId max_id = 0;
50  for (StateIterator<CompactLattice> siter(*clat); !siter.Done();
51  siter.Next()) {
52  StateId state_id = siter.Value();
53  for (ArcIterator<CompactLattice> aiter(*clat, state_id); !aiter.Done();
54  aiter.Next()) {
55  CompactLatticeArc arc = aiter.Value();
56  if (state_id >= state_times.size() || arc.nextstate >= state_times.size())
57  return false;
58  if (state_id > max_id)
59  max_id = state_id;
60  if (arc.nextstate > max_id)
61  max_id = arc.nextstate;
62  head[arc.ilabel].push_back(Interval(state_times[state_id],
63  state_times[arc.nextstate]));
64  }
65  }
66  // Check if alignments and the states match
67  if (state_times.size() != max_id+1)
68  return false;
69 
70  // Step 2: Iterates over the hashmap to get the cluster heads.
71  // We sort all the words on their start-time, and the process for getting
72  // the cluster heads is to take the first one as a cluster head; then go
73  // till we find the next one that doesn't overlap in time with the current
74  // cluster head, and so on.
75  unordered_map<StateId, std::vector<Interval> >::iterator iter;
76  for (iter = head.begin(); iter != head.end(); ++iter) {
77  // For this ilabel, sort all the arcs on time, from first to last.
78  sort(iter->second.begin(), iter->second.end(), CompareInterval);
79  std::vector<Interval> tmp;
80  tmp.push_back(iter->second[0]);
81  for (int32 i = 1; i < iter->second.size(); i++) {
82  if (tmp.back().End() <= iter->second[i].Start())
83  tmp.push_back(iter->second[i]);
84  }
85  iter->second = tmp;
86  }
87 
88  // Step 3: Cluster arcs according to the maximum overlap: attach
89  // each arc to the cluster-head (as identified in Step 2) which
90  // has the most temporal overlap with the current arc.
91  for (StateIterator<CompactLattice> siter(*clat); !siter.Done();
92  siter.Next()) {
93  CompactLatticeArc::StateId state_id = siter.Value();
94  for (MutableArcIterator<CompactLattice> aiter(clat, state_id);
95  !aiter.Done(); aiter.Next()) {
96  CompactLatticeArc arc = aiter.Value();
97  // We don't cluster the epsilon arcs
98  if (arc.ilabel == 0)
99  continue;
100  // We cluster the non-epsilon arcs
101  Interval interval(state_times[state_id], state_times[arc.nextstate]);
102  int32 max_overlap = 0;
103  size_t olabel = 1;
104  for (int32 i = 0; i < head[arc.ilabel].size(); i++) {
105  int32 overlap = interval.Overlap(head[arc.ilabel][i]);
106  if (overlap > max_overlap) {
107  max_overlap = overlap;
108  olabel = i + 1; // need non-epsilon label.
109  }
110  }
111  arc.olabel = olabel;
112  aiter.SetValue(arc);
113  }
114  }
115 
116  return true;
117 }
fst::StdArc::StateId StateId
bool CompareInterval(const Interval &i1, const Interval &i2)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeDepth()

BaseFloat CompactLatticeDepth ( const CompactLattice clat,
int32 num_frames 
)

Returns the depth of the lattice, defined as the average number of arcs crossing any given frame.

Returns the depth of the lattice, defined as the average number of arcs (or final-prob strings) crossing any given frame.

Returns 1 for empty lattices. Requires that input is topologically sorted.

Returns 1 for empty lattices. Requires that clat is topologically sorted!

Definition at line 628 of file lattice-functions.cc.

References CompactLatticeStateTimes(), and KALDI_ERR.

Referenced by main().

629  {
631  if (clat.Properties(fst::kTopSorted, true) == 0) {
632  KALDI_ERR << "Lattice input to CompactLatticeDepth was not topologically "
633  << "sorted.";
634  }
635  if (clat.Start() == fst::kNoStateId) {
636  *num_frames = 0;
637  return 1.0;
638  }
639  size_t num_arc_frames = 0;
640  int32 t;
641  {
642  vector<int32> state_times;
643  t = CompactLatticeStateTimes(clat, &state_times);
644  }
645  if (num_frames != NULL)
646  *num_frames = t;
647  for (StateId s = 0; s < clat.NumStates(); s++) {
648  for (fst::ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done();
649  aiter.Next()) {
650  const CompactLatticeArc &arc = aiter.Value();
651  num_arc_frames += arc.weight.String().size();
652  }
653  num_arc_frames += clat.Final(s).String().size();
654  }
655  return num_arc_frames / static_cast<BaseFloat>(t);
656 }
fst::StdArc::StateId StateId
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeDepthPerFrame()

void CompactLatticeDepthPerFrame ( const CompactLattice clat,
std::vector< int32 > *  depth_per_frame 
)

This function returns, for each frame, the number of arcs crossing that frame.

Definition at line 659 of file lattice-functions.cc.

References CompactLatticeStateTimes(), KALDI_ASSERT, and KALDI_ERR.

Referenced by main().

660  {
662  if (clat.Properties(fst::kTopSorted, true) == 0) {
663  KALDI_ERR << "Lattice input to CompactLatticeDepthPerFrame was not "
664  << "topologically sorted.";
665  }
666  if (clat.Start() == fst::kNoStateId) {
667  depth_per_frame->clear();
668  return;
669  }
670  vector<int32> state_times;
671  int32 T = CompactLatticeStateTimes(clat, &state_times);
672 
673  depth_per_frame->clear();
674  if (T <= 0) {
675  return;
676  } else {
677  depth_per_frame->resize(T, 0);
678  for (StateId s = 0; s < clat.NumStates(); s++) {
679  int32 start_time = state_times[s];
680  for (fst::ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done();
681  aiter.Next()) {
682  const CompactLatticeArc &arc = aiter.Value();
683  int32 len = arc.weight.String().size();
684  for (int32 t = start_time; t < start_time + len; t++) {
685  KALDI_ASSERT(t < T);
686  (*depth_per_frame)[t]++;
687  }
688  }
689  int32 final_len = clat.Final(s).String().size();
690  for (int32 t = start_time; t < start_time + final_len; t++) {
691  KALDI_ASSERT(t < T);
692  (*depth_per_frame)[t]++;
693  }
694  }
695  }
696 }
fst::StdArc::StateId StateId
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeLimitDepth()

void CompactLatticeLimitDepth ( int32  max_arcs_per_frame,
CompactLattice clat 
)

This function limits the depth of the lattice, per frame: that means, it does not allow more than a specified number of arcs active on any given frame.

This can be used to reduce the size of the "very deep" portions of the lattice.

Definition at line 532 of file lattice-functions.cc.

References LatticeArcRecord::arc, CompactLatticeStateTimes(), ComputeLatticeAlphasAndBetas(), fst::ConvertToCost(), KALDI_ASSERT, KALDI_ERR, KALDI_WARN, LatticeArcRecord::logprob, LatticeArcRecord::state, and TopSortCompactLatticeIfNeeded().

Referenced by main().

533  {
534  typedef CompactLatticeArc Arc;
535  typedef Arc::Weight Weight;
536  typedef Arc::StateId StateId;
537 
538  if (clat->Start() == fst::kNoStateId) {
539  KALDI_WARN << "Limiting depth of empty lattice.";
540  return;
541  }
542  if (clat->Properties(fst::kTopSorted, true) == 0) {
543  if (!TopSort(clat))
544  KALDI_ERR << "Topological sorting of lattice failed.";
545  }
546 
547  vector<int32> state_times;
548  int32 T = CompactLatticeStateTimes(*clat, &state_times);
549 
550  // The alpha and beta quantities here are "viterbi" alphas and beta.
551  std::vector<double> alpha;
552  std::vector<double> beta;
553  bool viterbi = true;
554  double best_prob = ComputeLatticeAlphasAndBetas(*clat, viterbi,
555  &alpha, &beta);
556 
557  std::vector<std::vector<LatticeArcRecord> > arc_records(T);
558 
559  StateId num_states = clat->NumStates();
560  for (StateId s = 0; s < num_states; s++) {
561  for (fst::ArcIterator<CompactLattice> aiter(*clat, s); !aiter.Done();
562  aiter.Next()) {
563  const Arc &arc = aiter.Value();
564  LatticeArcRecord arc_record;
565  arc_record.state = s;
566  arc_record.arc = aiter.Position();
567  arc_record.logprob =
568  (alpha[s] + beta[arc.nextstate] - ConvertToCost(arc.weight))
569  - best_prob;
570  KALDI_ASSERT(arc_record.logprob < 0.1); // Should be zero or negative.
571  int32 num_frames = arc.weight.String().size(), start_t = state_times[s];
572  for (int32 t = start_t; t < start_t + num_frames; t++) {
573  KALDI_ASSERT(t < T);
574  arc_records[t].push_back(arc_record);
575  }
576  }
577  }
578  StateId dead_state = clat->AddState(); // A non-coaccesible state which we use
579  // to remove arcs (make them end
580  // there).
581  size_t max_depth = max_depth_per_frame;
582  for (int32 t = 0; t < T; t++) {
583  size_t size = arc_records[t].size();
584  if (size > max_depth) {
585  // we sort from worst to best, so we keep the later-numbered ones,
586  // and delete the lower-numbered ones.
587  size_t cutoff = size - max_depth;
588  std::nth_element(arc_records[t].begin(),
589  arc_records[t].begin() + cutoff,
590  arc_records[t].end());
591  for (size_t index = 0; index < cutoff; index++) {
592  LatticeArcRecord record(arc_records[t][index]);
593  fst::MutableArcIterator<CompactLattice> aiter(clat, record.state);
594  aiter.Seek(record.arc);
595  Arc arc = aiter.Value();
596  if (arc.nextstate != dead_state) { // not already killed.
597  arc.nextstate = dead_state;
598  aiter.SetValue(arc);
599  }
600  }
601  }
602  }
603  Connect(clat);
605 }
fst::StdArc::StateId StateId
kaldi::int32 int32
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
template double ComputeLatticeAlphasAndBetas(const CompactLattice &lat, bool viterbi, vector< double > *alpha, vector< double > *beta)

◆ CompactLatticeNormalize()

bool kaldi::CompactLatticeNormalize ( CompactLattice clat,
BaseFloat  weight 
)

Definition at line 54 of file lattice-combine.cc.

References ComputeCompactLatticeBetas(), KALDI_WARN, Log(), LatticeWeightTpl< FloatType >::SetValue1(), CompactLatticeWeightTpl< WeightType, IntType >::SetWeight(), LatticeWeightTpl< FloatType >::Value1(), and CompactLatticeWeightTpl< WeightType, IntType >::Weight().

Referenced by main().

54  {
55  if (weight <= 0.0) {
56  KALDI_WARN << "Weights must be positive; found: " << weight;
57  return false;
58  }
59 
60  if (clat->Properties(fst::kTopSorted, false) == 0) {
61  if (fst::TopSort(clat) == false) {
62  KALDI_WARN << "Cycles detected in lattice: cannot normalize.";
63  return false;
64  }
65  }
66 
67  vector<double> beta;
68  if (!ComputeCompactLatticeBetas(*clat, &beta)) {
69  KALDI_WARN << "Failed to compute backward probabilities on lattice.";
70  return false;
71  }
72 
74  StateId start = clat->Start(); // Should be 0
75  BaseFloat total_backward_cost = beta[start];
76 
77  total_backward_cost -= Log(weight);
78 
79  for (fst::StateIterator<CompactLattice> sit(*clat); !sit.Done(); sit.Next()) {
80  CompactLatticeWeight f = clat->Final(sit.Value());
81  LatticeWeight w = f.Weight();
82  w.SetValue1(w.Value1() + total_backward_cost);
83  f.SetWeight(w);
84  clat->SetFinal(sit.Value(), f);
85  }
86  return true;
87 }
fst::StdArc::StateId StateId
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
bool ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ CompactLatticeShortestPath()

void CompactLatticeShortestPath ( const CompactLattice clat,
CompactLattice shortest_path 
)

A form of the shortest-path/best-path algorithm that's specially coded for CompactLattice.

Requires that clat be acyclic.

Definition at line 1097 of file lattice-functions.cc.

References fst::ConvertToCost(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, and KALDI_WARN.

Referenced by DecodeUtteranceLatticeIncremental(), GetDiagnosticsAndPrintOutput(), LatticeToString(), and main().

1098  {
1099  using namespace fst;
1100  if (clat.Properties(fst::kTopSorted, true) == 0) {
1101  CompactLattice clat_copy(clat);
1102  if (!TopSort(&clat_copy))
1103  KALDI_ERR << "Was not able to topologically sort lattice (cycles found?)";
1104  CompactLatticeShortestPath(clat_copy, shortest_path);
1105  return;
1106  }
1107  // Now we can assume it's topologically sorted.
1108  shortest_path->DeleteStates();
1109  if (clat.Start() == kNoStateId) return;
1110  typedef CompactLatticeArc Arc;
1111  typedef Arc::StateId StateId;
1112  typedef CompactLatticeWeight Weight;
1113  vector<std::pair<double, StateId> > best_cost_and_pred(clat.NumStates() + 1);
1114  StateId superfinal = clat.NumStates();
1115  for (StateId s = 0; s <= clat.NumStates(); s++) {
1116  best_cost_and_pred[s].first = std::numeric_limits<double>::infinity();
1117  best_cost_and_pred[s].second = fst::kNoStateId;
1118  }
1119  best_cost_and_pred[clat.Start()].first = 0;
1120  for (StateId s = 0; s < clat.NumStates(); s++) {
1121  double my_cost = best_cost_and_pred[s].first;
1122  for (ArcIterator<CompactLattice> aiter(clat, s);
1123  !aiter.Done();
1124  aiter.Next()) {
1125  const Arc &arc = aiter.Value();
1126  double arc_cost = ConvertToCost(arc.weight),
1127  next_cost = my_cost + arc_cost;
1128  if (next_cost < best_cost_and_pred[arc.nextstate].first) {
1129  best_cost_and_pred[arc.nextstate].first = next_cost;
1130  best_cost_and_pred[arc.nextstate].second = s;
1131  }
1132  }
1133  double final_cost = ConvertToCost(clat.Final(s)),
1134  tot_final = my_cost + final_cost;
1135  if (tot_final < best_cost_and_pred[superfinal].first) {
1136  best_cost_and_pred[superfinal].first = tot_final;
1137  best_cost_and_pred[superfinal].second = s;
1138  }
1139  }
1140  std::vector<StateId> states; // states on best path.
1141  StateId cur_state = superfinal, start_state = clat.Start();
1142  while (cur_state != start_state) {
1143  StateId prev_state = best_cost_and_pred[cur_state].second;
1144  if (prev_state == kNoStateId) {
1145  KALDI_WARN << "Failure in best-path algorithm for lattice (infinite costs?)";
1146  return; // return empty best-path.
1147  }
1148  states.push_back(prev_state);
1149  KALDI_ASSERT(cur_state != prev_state && "Lattice with cycles");
1150  cur_state = prev_state;
1151  }
1152  std::reverse(states.begin(), states.end());
1153  for (size_t i = 0; i < states.size(); i++)
1154  shortest_path->AddState();
1155  for (StateId s = 0; static_cast<size_t>(s) < states.size(); s++) {
1156  if (s == 0) shortest_path->SetStart(s);
1157  if (static_cast<size_t>(s + 1) < states.size()) { // transition to next state.
1158  bool have_arc = false;
1159  Arc cur_arc;
1160  for (ArcIterator<CompactLattice> aiter(clat, states[s]);
1161  !aiter.Done();
1162  aiter.Next()) {
1163  const Arc &arc = aiter.Value();
1164  if (arc.nextstate == states[s+1]) {
1165  if (!have_arc ||
1166  ConvertToCost(arc.weight) < ConvertToCost(cur_arc.weight)) {
1167  cur_arc = arc;
1168  have_arc = true;
1169  }
1170  }
1171  }
1172  KALDI_ASSERT(have_arc && "Code error.");
1173  shortest_path->AddArc(s, Arc(cur_arc.ilabel, cur_arc.olabel,
1174  cur_arc.weight, s+1));
1175  } else { // final-prob.
1176  shortest_path->SetFinal(s, clat.Final(states[s]));
1177  }
1178  }
1179 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void CompactLatticeShortestPath(const CompactLattice &clat, CompactLattice *shortest_path)
A form of the shortest-path/best-path algorithm that&#39;s specially coded for CompactLattice.
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeStateTimes() [1/2]

int32 kaldi::CompactLatticeStateTimes ( const CompactLattice clat,
std::vector< int32 > *  times 
)

As LatticeStateTimes, but in the CompactLattice format.

Note: must be topologically sorted. Returns length of the utterance in frames, which might not be the same as the maximum time in the lattice, due to frames in the final-prob.

Definition at line 111 of file lattice-functions.cc.

References KALDI_ASSERT, KALDI_ERR, KALDI_WARN, and CompactLatticeWeightTpl< WeightType, IntType >::Zero().

Referenced by DiscriminativeNnetExample::Check(), CompactLatticeDepth(), CompactLatticeDepthPerFrame(), CompactLatticeLimitDepth(), kaldi::nnet2::LatticeToDiscriminativeExample(), main(), ArcPosteriorComputer::OutputPosteriors(), MinimumBayesRisk::PrepareLatticeAndInitStats(), and RescoreCompactLatticeInternal().

111  {
112  if (!lat.Properties(fst::kTopSorted, true))
113  KALDI_ERR << "Input lattice must be topologically sorted.";
114  KALDI_ASSERT(lat.Start() == 0);
115  int32 num_states = lat.NumStates();
116  times->clear();
117  times->resize(num_states, -1);
118  (*times)[0] = 0;
119  int32 utt_len = -1;
120  for (int32 state = 0; state < num_states; state++) {
121  int32 cur_time = (*times)[state];
122  for (fst::ArcIterator<CompactLattice> aiter(lat, state); !aiter.Done();
123  aiter.Next()) {
124  const CompactLatticeArc &arc = aiter.Value();
125  int32 arc_len = static_cast<int32>(arc.weight.String().size());
126  if ((*times)[arc.nextstate] == -1)
127  (*times)[arc.nextstate] = cur_time + arc_len;
128  else
129  KALDI_ASSERT((*times)[arc.nextstate] == cur_time + arc_len);
130  }
131  if (lat.Final(state) != CompactLatticeWeight::Zero()) {
132  int32 this_utt_len = (*times)[state] + lat.Final(state).String().size();
133  if (utt_len == -1) utt_len = this_utt_len;
134  else {
135  if (this_utt_len != utt_len) {
136  KALDI_WARN << "Utterance does not "
137  "seem to have a consistent length.";
138  utt_len = std::max(utt_len, this_utt_len);
139  }
140  }
141  }
142  }
143  if (utt_len == -1) {
144  KALDI_WARN << "Utterance does not have a final-state.";
145  return 0;
146  }
147  return utt_len;
148 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeStateTimes() [2/2]

int32 kaldi::CompactLatticeStateTimes ( const CompactLattice clat,
std::vector< int32 > *  times 
)

As LatticeStateTimes, but in the CompactLattice format.

Note: must be topologically sorted. Returns length of the utterance in frames, which might not be the same as the maximum time in the lattice, due to frames in the final-prob.

Definition at line 111 of file lattice-functions.cc.

References KALDI_ASSERT, KALDI_ERR, KALDI_WARN, and CompactLatticeWeightTpl< WeightType, IntType >::Zero().

Referenced by DiscriminativeNnetExample::Check(), CompactLatticeDepth(), CompactLatticeDepthPerFrame(), CompactLatticeLimitDepth(), kaldi::nnet2::LatticeToDiscriminativeExample(), main(), ArcPosteriorComputer::OutputPosteriors(), MinimumBayesRisk::PrepareLatticeAndInitStats(), and RescoreCompactLatticeInternal().

111  {
112  if (!lat.Properties(fst::kTopSorted, true))
113  KALDI_ERR << "Input lattice must be topologically sorted.";
114  KALDI_ASSERT(lat.Start() == 0);
115  int32 num_states = lat.NumStates();
116  times->clear();
117  times->resize(num_states, -1);
118  (*times)[0] = 0;
119  int32 utt_len = -1;
120  for (int32 state = 0; state < num_states; state++) {
121  int32 cur_time = (*times)[state];
122  for (fst::ArcIterator<CompactLattice> aiter(lat, state); !aiter.Done();
123  aiter.Next()) {
124  const CompactLatticeArc &arc = aiter.Value();
125  int32 arc_len = static_cast<int32>(arc.weight.String().size());
126  if ((*times)[arc.nextstate] == -1)
127  (*times)[arc.nextstate] = cur_time + arc_len;
128  else
129  KALDI_ASSERT((*times)[arc.nextstate] == cur_time + arc_len);
130  }
131  if (lat.Final(state) != CompactLatticeWeight::Zero()) {
132  int32 this_utt_len = (*times)[state] + lat.Final(state).String().size();
133  if (utt_len == -1) utt_len = this_utt_len;
134  else {
135  if (this_utt_len != utt_len) {
136  KALDI_WARN << "Utterance does not "
137  "seem to have a consistent length.";
138  utt_len = std::max(utt_len, this_utt_len);
139  }
140  }
141  }
142  }
143  if (utt_len == -1) {
144  KALDI_WARN << "Utterance does not have a final-state.";
145  return 0;
146  }
147  return utt_len;
148 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ CompactLatticeToWordAlignment()

bool CompactLatticeToWordAlignment ( const CompactLattice clat,
std::vector< int32 > *  words,
std::vector< int32 > *  begin_times,
std::vector< int32 > *  lengths 
)

This function takes a CompactLattice that should only contain a single linear sequence (e.g.

derived from lattice-1best), and that should have been processed so that the arcs in the CompactLattice align correctly with the word boundaries (e.g. by lattice-align-words). It outputs 3 vectors of the same size, which give, for each word in the lattice (in sequence), the word label and the begin time and length in frames. This is done even for zero (epsilon) words, generally corresponding to optional silence– if you don't want them, just ignore them in the output. This function will print a warning and return false, if the lattice did not have the correct format (e.g. if it is empty or it is not linear).

Definition at line 975 of file lattice-functions.cc.

References KALDI_WARN.

Referenced by main().

978  {
979  words->clear();
980  begin_times->clear();
981  lengths->clear();
982  typedef CompactLattice::Arc Arc;
983  typedef Arc::Label Label;
986  using namespace fst;
987  StateId state = clat.Start();
988  int32 cur_time = 0;
989  if (state == kNoStateId) {
990  KALDI_WARN << "Empty lattice.";
991  return false;
992  }
993  while (1) {
994  Weight final = clat.Final(state);
995  size_t num_arcs = clat.NumArcs(state);
996  if (final != Weight::Zero()) {
997  if (num_arcs != 0) {
998  KALDI_WARN << "Lattice is not linear.";
999  return false;
1000  }
1001  if (! final.String().empty()) {
1002  KALDI_WARN << "Lattice has alignments on final-weight: probably "
1003  "was not word-aligned (alignments will be approximate)";
1004  }
1005  return true;
1006  } else {
1007  if (num_arcs != 1) {
1008  KALDI_WARN << "Lattice is not linear: num-arcs = " << num_arcs;
1009  return false;
1010  }
1011  fst::ArcIterator<CompactLattice> aiter(clat, state);
1012  const Arc &arc = aiter.Value();
1013  Label word_id = arc.ilabel; // Note: ilabel==olabel, since acceptor.
1014  // Also note: word_id may be zero; we output it anyway.
1015  int32 length = arc.weight.String().size();
1016  words->push_back(word_id);
1017  begin_times->push_back(cur_time);
1018  lengths->push_back(length);
1019  cur_time += length;
1020  state = arc.nextstate;
1021  }
1022  }
1023 }
int32 words[kMaxOrder]
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Label Label
fst::StdArc::Weight Weight

◆ CompactLatticeToWordProns()

bool CompactLatticeToWordProns ( const TransitionModel tmodel,
const CompactLattice clat,
std::vector< int32 > *  words,
std::vector< int32 > *  begin_times,
std::vector< int32 > *  lengths,
std::vector< std::vector< int32 > > *  prons,
std::vector< std::vector< int32 > > *  phone_lengths 
)

This function takes a CompactLattice that should only contain a single linear sequence (e.g.

derived from lattice-1best), and that should have been processed so that the arcs in the CompactLattice align correctly with the word boundaries (e.g. by lattice-align-words). It outputs 4 vectors of the same size, which give, for each word in the lattice (in sequence), the word label, the begin time and length in frames, and the pronunciation (sequence of phones). This is done even for zero words, corresponding to optional silences – if you don't want them, just ignore them in the output. This function will print a warning and return false, if the lattice did not have the correct format (e.g. if it is empty or it is not linear).

Definition at line 1026 of file lattice-functions.cc.

References rnnlm::i, KALDI_ASSERT, KALDI_WARN, SplitToPhones(), and TransitionModel::TransitionIdToPhone().

Referenced by main().

1033  {
1034  words->clear();
1035  begin_times->clear();
1036  lengths->clear();
1037  prons->clear();
1038  phone_lengths->clear();
1039  typedef CompactLattice::Arc Arc;
1040  typedef Arc::Label Label;
1043  using namespace fst;
1044  StateId state = clat.Start();
1045  int32 cur_time = 0;
1046  if (state == kNoStateId) {
1047  KALDI_WARN << "Empty lattice.";
1048  return false;
1049  }
1050  while (1) {
1051  Weight final = clat.Final(state);
1052  size_t num_arcs = clat.NumArcs(state);
1053  if (final != Weight::Zero()) {
1054  if (num_arcs != 0) {
1055  KALDI_WARN << "Lattice is not linear.";
1056  return false;
1057  }
1058  if (! final.String().empty()) {
1059  KALDI_WARN << "Lattice has alignments on final-weight: probably "
1060  "was not word-aligned (alignments will be approximate)";
1061  }
1062  return true;
1063  } else {
1064  if (num_arcs != 1) {
1065  KALDI_WARN << "Lattice is not linear: num-arcs = " << num_arcs;
1066  return false;
1067  }
1068  fst::ArcIterator<CompactLattice> aiter(clat, state);
1069  const Arc &arc = aiter.Value();
1070  Label word_id = arc.ilabel; // Note: ilabel==olabel, since acceptor.
1071  // Also note: word_id may be zero; we output it anyway.
1072  int32 length = arc.weight.String().size();
1073  words->push_back(word_id);
1074  begin_times->push_back(cur_time);
1075  lengths->push_back(length);
1076  const std::vector<int32> &arc_alignment = arc.weight.String();
1077  std::vector<std::vector<int32> > split_alignment;
1078  SplitToPhones(tmodel, arc_alignment, &split_alignment);
1079  std::vector<int32> phones(split_alignment.size());
1080  std::vector<int32> plengths(split_alignment.size());
1081  for (size_t i = 0; i < split_alignment.size(); i++) {
1082  KALDI_ASSERT(!split_alignment[i].empty());
1083  phones[i] = tmodel.TransitionIdToPhone(split_alignment[i][0]);
1084  plengths[i] = split_alignment[i].size();
1085  }
1086  prons->push_back(phones);
1087  phone_lengths->push_back(plengths);
1088 
1089  cur_time += length;
1090  state = arc.nextstate;
1091  }
1092  }
1093 }
int32 words[kMaxOrder]
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
Definition: hmm-utils.cc:723
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Label Label
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CompareInterval()

bool CompareInterval ( const Interval i1,
const Interval i2 
)

Definition at line 33 of file kws-functions.cc.

References Interval::End(), and Interval::Start().

Referenced by ClusterLattice().

34  {
35  return (i1.Start() < i2.Start() ? true :
36  i1.Start() > i2.Start() ? false:
37  i1.End() < i2.End() ? true: false);
38 }

◆ Compile()

ArpaLmCompiler* kaldi::Compile ( bool  seps,
const std::string &  infile 
)

Definition at line 75 of file arpa-lm-compiler-test.cc.

References ArpaParseOptions::bos_symbol, ArpaParseOptions::eos_symbol, ArpaParseOptions::kAddToSymbols, kBos, kDisambig, kEos, kEps, ArpaParseOptions::oov_handling, ArpaFileParser::Read(), and Input::Stream().

Referenced by CoverageTest(), ScoringTest(), and ThrowsExceptionTest().

75  {
76  ArpaParseOptions options;
77  fst::SymbolTable symbols;
78  // Use spaces on special symbols, so we rather fail than read them by mistake.
79  symbols.AddSymbol(" <eps>", kEps);
80  symbols.AddSymbol(" #0", kDisambig);
81  options.bos_symbol = symbols.AddSymbol("<s>", kBos);
82  options.eos_symbol = symbols.AddSymbol("</s>", kEos);
83  options.oov_handling = ArpaParseOptions::kAddToSymbols;
84 
85  // Tests in this form cannot be run with epsilon substitution, unless every
86  // random path is also fitted with a #0-transducing self-loop.
87  ArpaLmCompiler* lm_compiler =
88  new ArpaLmCompiler(options,
89  seps ? kDisambig : 0,
90  &symbols);
91  {
92  Input ki(infile);
93  lm_compiler->Read(ki.Stream());
94  }
95  return lm_compiler;
96 }

◆ ComplexFft() [1/2]

template void kaldi::ComplexFft ( VectorBase< float > *  v,
bool  forward,
Vector< float > *  tmp_in 
)

◆ ComplexFft() [2/2]

template void kaldi::ComplexFft ( VectorBase< double > *  v,
bool  forward,
Vector< double > *  tmp_in 
)

◆ ComplexFftRecursive()

void kaldi::ComplexFftRecursive ( Real *  data,
int  nffts,
int  N,
const int *  factor_begin,
const int *  factor_end,
bool  forward,
Vector< Real > *  tmp_vec 
)

ComplexFftRecursive is a recursive function that computes the complex FFT of size N.

The "nffts" arguments specifies how many separate FFTs to compute in parallel (we assume the data for each one is consecutive in memory). The "forward argument" specifies whether to do the FFT (true) or IFFT (false), although note that we do not include the factor of 1/N (the user should do this if required. The iterators factor_begin and factor_end point to the beginning and end (i.e. one past the last element) of an array of small factors of N (typically prime factors). See the comments below this code for the detailed equations of the recursion.

Definition at line 97 of file matrix-functions.cc.

References ComplexAddProduct(), ComplexImExp(), ComplexMul(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), KALDI_ASSERT, KALDI_COMPLEXFFT_BLOCKSIZE, M_2PI, rnnlm::n, and Vector< Real >::Resize().

Referenced by ComplexFft().

100  {
101  if (factor_begin == factor_end) {
102  KALDI_ASSERT(N == 1);
103  return;
104  }
105 
106  { // an optimization: compute in smaller blocks.
107  // this block of code could be removed and it would still work.
108  MatrixIndexT size_perblock = N * 2 * sizeof(Real);
109  if (nffts > 1 && size_perblock*nffts > KALDI_COMPLEXFFT_BLOCKSIZE) { // can break it up...
110  // Break up into multiple blocks. This is an optimization. We make
111  // no progress on the FFT when we do this.
112  int block_skip = KALDI_COMPLEXFFT_BLOCKSIZE / size_perblock; // n blocks per call
113  if (block_skip == 0) block_skip = 1;
114  if (block_skip < nffts) {
115  int blocks_left = nffts;
116  while (blocks_left > 0) {
117  int skip_now = std::min(blocks_left, block_skip);
118  ComplexFftRecursive(data, skip_now, N, factor_begin, factor_end, forward, tmp_vec);
119  blocks_left -= skip_now;
120  data += skip_now * N*2;
121  }
122  return;
123  } // else do the actual algorithm.
124  } // else do the actual algorithm.
125  }
126 
127  int P = *factor_begin;
128  KALDI_ASSERT(P > 1);
129  int Q = N / P;
130 
131 
132  if (P > 1 && Q > 1) { // Do the rearrangement. C.f. eq. (8) below. Transform
133  // (a) to (b).
134  Real *data_thisblock = data;
135  if (tmp_vec->Dim() < (MatrixIndexT)N) tmp_vec->Resize(N);
136  Real *data_tmp = tmp_vec->Data();
137  for (int thisfft = 0; thisfft < nffts; thisfft++, data_thisblock+=N*2) {
138  for (int offset = 0; offset < 2; offset++) { // 0 == real, 1 == im.
139  for (int p = 0; p < P; p++) {
140  for (int q = 0; q < Q; q++) {
141  int aidx = q*P + p, bidx = p*Q + q;
142  data_tmp[bidx] = data_thisblock[2*aidx+offset];
143  }
144  }
145  for (int n = 0;n < P*Q;n++) data_thisblock[2*n+offset] = data_tmp[n];
146  }
147  }
148  }
149 
150  { // Recurse.
151  ComplexFftRecursive(data, nffts*P, Q, factor_begin+1, factor_end, forward, tmp_vec);
152  }
153 
154  int exp_sign = (forward ? -1 : 1);
155  Real rootN_re, rootN_im; // Nth root of unity.
156  ComplexImExp(static_cast<Real>(exp_sign * M_2PI / N), &rootN_re, &rootN_im);
157 
158  Real rootP_re, rootP_im; // Pth root of unity.
159  ComplexImExp(static_cast<Real>(exp_sign * M_2PI / P), &rootP_re, &rootP_im);
160 
161  { // Do the multiplication
162  // could avoid a bunch of complex multiplies by moving the loop over data_thisblock
163  // inside.
164  if (tmp_vec->Dim() < (MatrixIndexT)(P*2)) tmp_vec->Resize(P*2);
165  Real *temp_a = tmp_vec->Data();
166 
167  Real *data_thisblock = data, *data_end = data+(N*2*nffts);
168  for (; data_thisblock != data_end; data_thisblock += N*2) { // for each separate fft.
169  Real qd_re = 1.0, qd_im = 0.0; // 1^(q'/N)
170  for (int qd = 0; qd < Q; qd++) {
171  Real pdQ_qd_re = qd_re, pdQ_qd_im = qd_im; // 1^((p'Q+q') / N) == 1^((p'/P) + (q'/N))
172  // Initialize to q'/N, corresponding to p' == 0.
173  for (int pd = 0; pd < P; pd++) { // pd == p'
174  { // This is the p = 0 case of the loop below [an optimization].
175  temp_a[pd*2] = data_thisblock[qd*2];
176  temp_a[pd*2 + 1] = data_thisblock[qd*2 + 1];
177  }
178  { // This is the p = 1 case of the loop below [an optimization]
179  // **** MOST OF THE TIME (>60% I think) gets spent here. ***
180  ComplexAddProduct(pdQ_qd_re, pdQ_qd_im,
181  data_thisblock[(qd+Q)*2], data_thisblock[(qd+Q)*2 + 1],
182  &(temp_a[pd*2]), &(temp_a[pd*2 + 1]));
183  }
184  if (P > 2) {
185  Real p_pdQ_qd_re = pdQ_qd_re, p_pdQ_qd_im = pdQ_qd_im; // 1^(p(p'Q+q')/N)
186  for (int p = 2; p < P; p++) {
187  ComplexMul(pdQ_qd_re, pdQ_qd_im, &p_pdQ_qd_re, &p_pdQ_qd_im); // p_pdQ_qd *= pdQ_qd.
188  int data_idx = p*Q + qd;
189  ComplexAddProduct(p_pdQ_qd_re, p_pdQ_qd_im,
190  data_thisblock[data_idx*2], data_thisblock[data_idx*2 + 1],
191  &(temp_a[pd*2]), &(temp_a[pd*2 + 1]));
192  }
193  }
194  if (pd != P-1)
195  ComplexMul(rootP_re, rootP_im, &pdQ_qd_re, &pdQ_qd_im); // pdQ_qd *= (rootP == 1^{1/P})
196  // (using 1/P == Q/N)
197  }
198  for (int pd = 0; pd < P; pd++) {
199  data_thisblock[(pd*Q + qd)*2] = temp_a[pd*2];
200  data_thisblock[(pd*Q + qd)*2 + 1] = temp_a[pd*2 + 1];
201  }
202  ComplexMul(rootN_re, rootN_im, &qd_re, &qd_im); // qd *= rootN.
203  }
204  }
205  }
206 }
void ComplexFftRecursive(Real *data, int nffts, int N, const int *factor_begin, const int *factor_end, bool forward, Vector< Real > *tmp_vec)
ComplexFftRecursive is a recursive function that computes the complex FFT of size N...
int32 MatrixIndexT
Definition: matrix-common.h:98
void ComplexAddProduct(const Real &a_re, const Real &a_im, const Real &b_re, const Real &b_im, Real *c_re, Real *c_im)
ComplexMul implements, inline, the complex operation c += (a * b).
struct rnnlm::@11::@12 n
void ComplexMul(const Real &a_re, const Real &a_im, Real *b_re, Real *b_im)
ComplexMul implements, inline, the complex multiplication b *= a.
#define KALDI_COMPLEXFFT_BLOCKSIZE
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define M_2PI
Definition: kaldi-math.h:52
void ComplexImExp(Real x, Real *a_re, Real *a_im)
ComplexImExp implements a <– exp(i x), inline.

◆ ComplexFt() [1/2]

template void kaldi::ComplexFt ( const VectorBase< float > &  in,
VectorBase< float > *  out,
bool  forward 
)

◆ ComplexFt() [2/2]

template void kaldi::ComplexFt ( const VectorBase< double > &  in,
VectorBase< double > *  out,
bool  forward 
)

◆ ComposeCompactLatticeDeterministic()

void ComposeCompactLatticeDeterministic ( const CompactLattice clat,
fst::DeterministicOnDemandFst< fst::StdArc > *  det_fst,
CompactLattice composed_clat 
)

This function Composes a CompactLattice format lattice with a DeterministicOnDemandFst<fst::StdFst> format fst, and outputs another CompactLattice format lattice.

The first element (the one that corresponds to LM weight) in CompactLatticeWeight is used for composition.

Note that the DeterministicOnDemandFst interface is not "const", therefore we cannot use "const" for <det_fst>.

Definition at line 1528 of file lattice-functions.cc.

References DeterministicOnDemandFst< Arc >::Final(), DeterministicOnDemandFst< Arc >::GetArc(), KALDI_ASSERT, and DeterministicOnDemandFst< Arc >::Start().

Referenced by main().

1531  {
1532  // StdFst::Arc and CompactLatticeArc has the same StateId type.
1533  typedef fst::StdArc::StateId StateId;
1534  typedef fst::StdArc::Weight Weight1;
1535  typedef CompactLatticeArc::Weight Weight2;
1536  typedef std::pair<StateId, StateId> StatePair;
1537  typedef unordered_map<StatePair, StateId, PairHasher<StateId> > MapType;
1538  typedef MapType::iterator IterType;
1539 
1540  // Empties the output FST.
1541  KALDI_ASSERT(composed_clat != NULL);
1542  composed_clat->DeleteStates();
1543 
1544  MapType state_map;
1545  std::queue<StatePair> state_queue;
1546 
1547  // Sets start state in <composed_clat>.
1548  StateId start_state = composed_clat->AddState();
1549  StatePair start_pair(clat.Start(), det_fst->Start());
1550  composed_clat->SetStart(start_state);
1551  state_queue.push(start_pair);
1552  std::pair<IterType, bool> result =
1553  state_map.insert(std::make_pair(start_pair, start_state));
1554  KALDI_ASSERT(result.second == true);
1555 
1556  // Starts composition here.
1557  while (!state_queue.empty()) {
1558  // Gets the first state in the queue.
1559  StatePair s = state_queue.front();
1560  StateId s1 = s.first;
1561  StateId s2 = s.second;
1562  state_queue.pop();
1563 
1564 
1565  Weight2 clat_final = clat.Final(s1);
1566  if (clat_final.Weight().Value1() !=
1567  std::numeric_limits<BaseFloat>::infinity()) {
1568  // Test for whether the final-prob of state s1 was zero.
1569  Weight1 det_fst_final = det_fst->Final(s2);
1570  if (det_fst_final.Value() !=
1571  std::numeric_limits<BaseFloat>::infinity()) {
1572  // Test for whether the final-prob of state s2 was zero. If neither
1573  // source-state final prob was zero, then we should create final state
1574  // in fst_composed. We compute the product manually since this is more
1575  // efficient.
1576  Weight2 final_weight(LatticeWeight(clat_final.Weight().Value1() +
1577  det_fst_final.Value(),
1578  clat_final.Weight().Value2()),
1579  clat_final.String());
1580  // we can assume final_weight is not Zero(), since neither of
1581  // the sources was zero.
1582  KALDI_ASSERT(state_map.find(s) != state_map.end());
1583  composed_clat->SetFinal(state_map[s], final_weight);
1584  }
1585  }
1586 
1587  // Loops over pair of edges at s1 and s2.
1588  for (fst::ArcIterator<CompactLattice> aiter(clat, s1);
1589  !aiter.Done(); aiter.Next()) {
1590  const CompactLatticeArc& arc1 = aiter.Value();
1591  fst::StdArc arc2;
1592  StateId next_state1 = arc1.nextstate, next_state2;
1593  bool matched = false;
1594 
1595  if (arc1.olabel == 0) {
1596  // If the symbol on <arc1> is <epsilon>, we transit to the next state
1597  // for <clat>, but keep <det_fst> at the current state.
1598  matched = true;
1599  next_state2 = s2;
1600  } else {
1601  // Otherwise try to find the matched arc in <det_fst>.
1602  matched = det_fst->GetArc(s2, arc1.olabel, &arc2);
1603  if (matched) {
1604  next_state2 = arc2.nextstate;
1605  }
1606  }
1607 
1608  // If matched arc is found in <det_fst>, then we have to add new arcs to
1609  // <composed_clat>.
1610  if (matched) {
1611  StatePair next_state_pair(next_state1, next_state2);
1612  IterType siter = state_map.find(next_state_pair);
1613  StateId next_state;
1614 
1615  // Adds composed state to <state_map>.
1616  if (siter == state_map.end()) {
1617  // If the composed state has not been created yet, create it.
1618  next_state = composed_clat->AddState();
1619  std::pair<const StatePair, StateId> next_state_map(next_state_pair,
1620  next_state);
1621  std::pair<IterType, bool> result = state_map.insert(next_state_map);
1622  KALDI_ASSERT(result.second);
1623  state_queue.push(next_state_pair);
1624  } else {
1625  // If the composed state is already in <state_map>, we can directly
1626  // use that.
1627  next_state = siter->second;
1628  }
1629 
1630  // Adds arc to <composed_clat>.
1631  if (arc1.olabel == 0) {
1632  composed_clat->AddArc(state_map[s],
1633  CompactLatticeArc(arc1.ilabel, 0,
1634  arc1.weight, next_state));
1635  } else {
1636  Weight2 composed_weight(
1637  LatticeWeight(arc1.weight.Weight().Value1() +
1638  arc2.weight.Value(),
1639  arc1.weight.Weight().Value2()),
1640  arc1.weight.String());
1641  composed_clat->AddArc(state_map[s],
1642  CompactLatticeArc(arc1.ilabel, arc2.olabel,
1643  composed_weight, next_state));
1644  }
1645  }
1646  }
1647  }
1648  fst::Connect(composed_clat);
1649 }
fst::StdArc::StateId StateId
virtual bool GetArc(StateId s, Label ilabel, Arc *oarc)=0
Note: ilabel must not be epsilon.
virtual Weight Final(StateId s)=0
fst::StdArc StdArc
virtual StateId Start()=0
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
LatticeWeightTpl< BaseFloat > LatticeWeight
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ ComposeCompactLatticePruned()

void ComposeCompactLatticePruned ( const ComposeLatticePrunedOptions opts,
const CompactLattice clat,
fst::DeterministicOnDemandFst< fst::StdArc > *  det_fst,
CompactLattice composed_clat 
)

Does pruned composition of a lattice 'clat' with a DeterministicOnDemandFst 'det_fst'; implements LM rescoring.

Parameters
[in]optsClass containing options
[in]clatThe input lattice, which is expected to already have a reasonable acoustic scale applied (e.g. 0.1 if it's a normal cross-entropy system, but 1.0 for a chain system); this scale affects the pruning.
[in]det_fstThe on-demand FST that we are composing with; its ilabels will correspond to words and it should be an acceptor in practice (ilabel == olabel). Will often contain a weighted difference of language model scores, with scores of the form alpha * new - alpha * old, where alpha is the interpolation weight for the 'new' language model (e.g. 0.5 or 0.8). It's non-const because 'det_fst' is on-demand.
[out]composed_clatThe output, which is a result of composing 'clat' with '*det_fst'. Notionally, '*det_fst' is on the right, although both are acceptors so it doesn't really matter in practice. Although the two FSTs are of different types, the code manually does the conversion. The weights in '*det_fst' will be interpreted as graph weights (Value1()) in the lattice semiring.

Definition at line 946 of file compose-lattice-pruned.cc.

References PrunedCompactLatticeComposer::Compose().

Referenced by main(), and ComposeLatticePrunedOptions::Register().

950  {
951  PrunedCompactLatticeComposer composer(opts, clat, det_fst, composed_clat);
952  composer.Compose();
953 }

◆ ComposeTransforms()

bool ComposeTransforms ( const Matrix< BaseFloat > &  a,
const Matrix< BaseFloat > &  b,
bool  b_is_affine,
Matrix< BaseFloat > *  c 
)

Definition at line 132 of file transform-common.cc.

References MatrixBase< Real >::AddMatMat(), MatrixBase< Real >::CopyFromMat(), KALDI_ERR, KALDI_WARN, kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by AffineXformStats::AffineXformStats(), LinearVtln::ComputeTransform(), and main().

134  {
135  if (b.NumRows() == 0 || a.NumCols() == 0) {
136  KALDI_WARN << "Empty matrix in ComposeTransforms";
137  return false;
138  }
139  if (a.NumCols() == b.NumRows()) {
140  c->Resize(a.NumRows(), b.NumCols());
141  c->AddMatMat(1.0, a, kNoTrans, b, kNoTrans, 0.0); // c = a * b.
142  return true;
143  } else if (a.NumCols() == b.NumRows()+1) { // a is affine.
144  if (b_is_affine) { // append 0 0 0 0 ... 1 to b and multiply.
145  Matrix<BaseFloat> b_ext(b.NumRows()+1, b.NumCols());
146  SubMatrix<BaseFloat> b_part(b_ext, 0, b.NumRows(), 0, b.NumCols());
147  b_part.CopyFromMat(b);
148  b_ext(b.NumRows(), b.NumCols()-1) = 1.0; // so the last row is 0 0 0 0 ... 0 1
149  c->Resize(a.NumRows(), b.NumCols());
150  c->AddMatMat(1.0, a, kNoTrans, b_ext, kNoTrans, 0.0); // c = a * b_ext.
151  } else { // extend b by 1 row and column with all zeros except a 1 on diagonal.
152  Matrix<BaseFloat> b_ext(b.NumRows()+1, b.NumCols()+1);
153  SubMatrix<BaseFloat> b_part(b_ext, 0, b.NumRows(), 0, b.NumCols());
154  b_part.CopyFromMat(b);
155  b_ext(b.NumRows(), b.NumCols()) = 1.0; // so the last row is 0 0 0 0 ... 0 1;
156  // rest of last column is zero (this is the offset term)
157  c->Resize(a.NumRows(), b.NumCols()+1);
158  c->AddMatMat(1.0, a, kNoTrans, b_ext, kNoTrans, 0.0); // c = a * b_ext.
159  }
160  return true;
161  } else {
162  KALDI_ERR << "ComposeTransforms: mismatched dimensions, a has " << a.NumCols()
163  << " columns and b has " << b.NumRows() << " rows."; // this is fatal.
164  return false;
165  }
166 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ComputeAcousticScoresMap()

void ComputeAcousticScoresMap ( const Lattice lat,
unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > *  acoustic_scores 
)

This function computes the mapping from the pair (frame-index, transition-id) to the pair (sum-of-acoustic-scores, num-of-occurences) over all occurences of the transition-id in that frame.

frame-index in the lattice. This function is useful for retaining the acoustic scores in a non-compact lattice after a process like determinization where the frame-level acoustic scores are typically lost. The function ReplaceAcousticScoresFromMap is used to restore the acoustic scores computed by this function.

Parameters
[in]latInput lattice. Expected to be top-sorted. Otherwise the function will crash.
[out]acoustic_scoresPointer to a map from the pair (frame-index, transition-id) to a pair (sum-of-acoustic-scores, num-of-occurences). Usually the acoustic scores for a pdf-id (and hence transition-id) on a frame will be the same for all the occurences of the pdf-id in that frame. But if not, we will take the average of the acoustic scores. Hence, we store both the sum-of-acoustic-scores and the num-of-occurences of the transition-id in that frame.

Definition at line 1652 of file lattice-functions.cc.

References KALDI_ASSERT, KALDI_VLOG, LatticeStateTimes(), LatticeWeightTpl< FloatType >::Value2(), and LatticeWeightTpl< BaseFloat >::Zero().

Referenced by main().

1655  {
1656  // typedef the arc, weight types
1657  typedef Lattice::Arc Arc;
1658  typedef Arc::Weight LatticeWeight;
1659  typedef Arc::StateId StateId;
1660 
1661  acoustic_scores->clear();
1662 
1663  std::vector<int32> state_times;
1664  LatticeStateTimes(lat, &state_times); // Assumes the input is top sorted
1665 
1666  KALDI_ASSERT(lat.Start() == 0);
1667 
1668  for (StateId s = 0; s < lat.NumStates(); s++) {
1669  int32 t = state_times[s];
1670  for (fst::ArcIterator<Lattice> aiter(lat, s); !aiter.Done();
1671  aiter.Next()) {
1672  const Arc &arc = aiter.Value();
1673  const LatticeWeight &weight = arc.weight;
1674 
1675  int32 tid = arc.ilabel;
1676 
1677  if (tid != 0) {
1678  unordered_map<std::pair<int32, int32>, std::pair<BaseFloat, int32>,
1679  PairHasher<int32> >::iterator it = acoustic_scores->find(std::make_pair(t, tid));
1680  if (it == acoustic_scores->end()) {
1681  acoustic_scores->insert(std::make_pair(std::make_pair(t, tid),
1682  std::make_pair(weight.Value2(), 1)));
1683  } else {
1684  if (it->second.second == 2
1685  && it->second.first / it->second.second != weight.Value2()) {
1686  KALDI_VLOG(2) << "Transitions on the same frame have different "
1687  << "acoustic costs for tid " << tid << "; "
1688  << it->second.first / it->second.second
1689  << " vs " << weight.Value2();
1690  }
1691  it->second.first += weight.Value2();
1692  it->second.second++;
1693  }
1694  } else {
1695  // Arcs with epsilon input label (tid) must have 0 acoustic cost
1696  KALDI_ASSERT(weight.Value2() == 0);
1697  }
1698  }
1699 
1700  LatticeWeight f = lat.Final(s);
1701  if (f != LatticeWeight::Zero()) {
1702  // Final acoustic cost must be 0 as we are reading from
1703  // non-determinized, non-compact lattice
1704  KALDI_ASSERT(f.Value2() == 0.0);
1705  }
1706  }
1707 }
fst::StdArc::StateId StateId
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
kaldi::int32 int32
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
LatticeWeightTpl< BaseFloat > LatticeWeight

◆ ComputeAmGmmFeatureDeriv()

BaseFloat ComputeAmGmmFeatureDeriv ( const AmDiagGmm am_gmm,
const TransitionModel trans_model,
const Posterior posterior,
const MatrixBase< BaseFloat > &  features,
Matrix< BaseFloat > *  direct_deriv,
const AccumAmDiagGmm model_diff = NULL,
Matrix< BaseFloat > *  indirect_deriv = NULL 
)

Computes derivatives of the likelihood of these states (weighted), w.r.t.

the feature values. Used in fMPE training. Note, the weights "posterior" may be positive or negative– for MMI, MPE, etc., they will typically be of both signs. Will resize "deriv". Returns the sum of (GMM likelihood * weight), which may be used as an approximation to the objective function. Last two parameters are optional. See GetStatsDerivative() for or fMPE paper (ICASSP, 2005) more info on indirect derivative. Caution: if you supply the last two parameters, this function only works in the MMI case as it assumes the stats with positive weight are numerator == ml stats– this is only the same thing in the MMI case, not fMPE.

Definition at line 522 of file fmpe.cc.

References VectorBase< Real >::AddMatVec(), VectorBase< Real >::AddVec(), VectorBase< Real >::AddVecVec(), DiagGmm::ComponentPosteriors(), AccumAmDiagGmm::GetAcc(), AmDiagGmm::GetPdf(), rnnlm::i, DiagGmm::inv_vars(), rnnlm::j, KALDI_ASSERT, kTrans, AccumDiagGmm::mean_accumulator(), DiagGmm::means_invvars(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), Matrix< Real >::Resize(), VectorBase< Real >::Scale(), TransitionModel::TransitionIdToPdf(), and AccumDiagGmm::variance_accumulator().

Referenced by main().

528  {
529  KALDI_ASSERT((model_diff != NULL) == (indirect_deriv != NULL));
530  BaseFloat ans = 0.0;
531  KALDI_ASSERT(posterior.size() == static_cast<size_t>(features.NumRows()));
532  direct_deriv->Resize(features.NumRows(), features.NumCols());
533  if (indirect_deriv != NULL)
534  indirect_deriv->Resize(features.NumRows(), features.NumCols());
535  Vector<BaseFloat> temp_vec(features.NumCols());
536  Vector<double> temp_vec_dbl(features.NumCols());
537  for (size_t i = 0; i < posterior.size(); i++) {
538  for (size_t j = 0; j < posterior[i].size(); j++) {
539  int32 tid = posterior[i][j].first, // transition identifier.
540  pdf_id = trans_model.TransitionIdToPdf(tid);
541  BaseFloat weight = posterior[i][j].second;
542  const DiagGmm &gmm = am_gmm.GetPdf(pdf_id);
543  Vector<BaseFloat> gauss_posteriors;
544  SubVector<BaseFloat> this_feat(features, i);
545  SubVector<BaseFloat> this_direct_deriv(*direct_deriv, i);
546  ans += weight *
547  gmm.ComponentPosteriors(this_feat, &gauss_posteriors);
548 
549  gauss_posteriors.Scale(weight);
550  // The next line does: to i'th row of deriv, add
551  // means_invvars^T * gauss_posteriors,
552  // where each row of means_invvars is the mean times
553  // diagonal inverse covariance... after transposing,
554  // this becomes a weighted of these rows, weighted by
555  // the posteriors. This comes from the term
556  // feat^T * inv_var * mean
557  // in the objective function.
558  this_direct_deriv.AddMatVec(1.0, gmm.means_invvars(), kTrans,
559  gauss_posteriors, 1.0);
560 
561  // next line does temp_vec == inv_vars^T * gauss_posteriors,
562  // which sets temp_vec to a weighted sum of the inv_vars,
563  // weighed by Gaussian posterior.
564  temp_vec.AddMatVec(1.0, gmm.inv_vars(), kTrans,
565  gauss_posteriors, 0.0);
566  // Add to the derivative, -(this_feat .* temp_vec),
567  // which is the term that comes from the -0.5 * inv_var^T feat_sq,
568  // in the objective function (where inv_var is a vector, and feat_sq
569  // is a vector of squares of the feature values).
570  // Note: we have to do some messing about with double-precision here
571  // because the stats only come in double precision.
572  this_direct_deriv.AddVecVec(-1.0, this_feat, temp_vec, 1.0);
573  if (model_diff != NULL && weight > 0.0) { // We need to get the indirect diff.
574  // This "weight > 0.0" checks that this is the numerator stats, as the
575  // fMPE indirect diff applies only to the ML stats-- CAUTION, this
576  // code will only work as-is for fMMI (and the stats should not be
577  // canceled), due to the assumption that ML stats == num stats.
578  Vector<double> gauss_posteriors_dbl(gauss_posteriors);
579  const AccumDiagGmm &deriv_acc = model_diff->GetAcc(pdf_id);
580  // part of the derivative. Note: we could just store the direct and
581  // indirect derivatives together in one matrix, but it makes it easier
582  // to accumulate certain diagnostics if we store them separately.
583  SubVector<BaseFloat> this_indirect_deriv(*indirect_deriv, i);
584  // note: deriv_acc.mean_accumulator() contains the derivative of
585  // the objective function w.r.t. the "x stats" accumulated for
586  // this GMM. variance_accumulator() is the same for the "x^2 stats".
587  temp_vec_dbl.AddMatVec(1.0, deriv_acc.mean_accumulator(), kTrans,
588  gauss_posteriors_dbl, 0.0);
589  this_indirect_deriv.AddVec(1.0, temp_vec_dbl);
590  temp_vec_dbl.AddMatVec(1.0, deriv_acc.variance_accumulator(), kTrans,
591  gauss_posteriors_dbl, 0.0);
592  temp_vec.CopyFromVec(temp_vec_dbl); // convert to float.
593  // next line because d(x^2 stats for Gaussian)/d(feature) =
594  // 2 * (gaussian posterior) * feature.
595  this_indirect_deriv.AddVecVec(2.0, this_feat, temp_vec, 1.0);
596  }
597  }
598  }
599  return ans;
600 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ComputeAndSubtractMean()

void kaldi::ComputeAndSubtractMean ( std::map< std::string, Vector< BaseFloat > *>  utt2ivector,
Vector< BaseFloat > *  mean_out 
)

Definition at line 186 of file ivector-compute-lda.cc.

References VectorBase< Real >::AddVec(), VectorBase< Real >::CopyFromVec(), and Vector< Real >::Resize().

Referenced by main().

188  {
189  int32 dim = utt2ivector.begin()->second->Dim();
190  size_t num_ivectors = utt2ivector.size();
191  Vector<double> mean(dim);
192  std::map<std::string, Vector<BaseFloat> *>::iterator iter;
193  for (iter = utt2ivector.begin(); iter != utt2ivector.end(); ++iter)
194  mean.AddVec(1.0 / num_ivectors, *(iter->second));
195  mean_out->Resize(dim);
196  mean_out->CopyFromVec(mean);
197  for (iter = utt2ivector.begin(); iter != utt2ivector.end(); ++iter)
198  iter->second->AddVec(-1.0, *mean_out);
199 }
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).

◆ ComputeCompactLatticeAlphas() [1/2]

bool kaldi::ComputeCompactLatticeAlphas ( const CompactLattice lat,
std::vector< double > *  alpha 
)

Definition at line 150 of file lattice-functions.cc.

References KALDI_WARN, kLogZeroDouble, and LogAdd().

Referenced by CreateFactorTransducer(), and ArcPosteriorComputer::OutputPosteriors().

151  {
152  using namespace fst;
153 
154  // typedef the arc, weight types
155  typedef CompactLattice::Arc Arc;
156  typedef Arc::Weight Weight;
157  typedef Arc::StateId StateId;
158 
159  //Make sure the lattice is topologically sorted.
160  if (clat.Properties(fst::kTopSorted, true) == 0) {
161  KALDI_WARN << "Input lattice must be topologically sorted.";
162  return false;
163  }
164  if (clat.Start() != 0) {
165  KALDI_WARN << "Input lattice must start from state 0.";
166  return false;
167  }
168 
169  int32 num_states = clat.NumStates();
170  (*alpha).resize(0);
171  (*alpha).resize(num_states, kLogZeroDouble);
172 
173  // Now propagate alphas forward. Note that we don't acount the weight of the
174  // final state to alpha[final_state] -- we acount it to beta[final_state];
175  (*alpha)[0] = 0.0;
176  for (StateId s = 0; s < num_states; s++) {
177  double this_alpha = (*alpha)[s];
178  for (ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done(); aiter.Next()) {
179  const Arc &arc = aiter.Value();
180  double arc_like = -(arc.weight.Weight().Value1() + arc.weight.Weight().Value2());
181  (*alpha)[arc.nextstate] = LogAdd((*alpha)[arc.nextstate], this_alpha + arc_like);
182  }
183  }
184 
185  return true;
186 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ ComputeCompactLatticeAlphas() [2/2]

bool kaldi::ComputeCompactLatticeAlphas ( const CompactLattice clat,
vector< double > *  alpha 
)

Definition at line 150 of file lattice-functions.cc.

References KALDI_WARN, kLogZeroDouble, and LogAdd().

Referenced by CreateFactorTransducer(), and ArcPosteriorComputer::OutputPosteriors().

151  {
152  using namespace fst;
153 
154  // typedef the arc, weight types
155  typedef CompactLattice::Arc Arc;
156  typedef Arc::Weight Weight;
157  typedef Arc::StateId StateId;
158 
159  //Make sure the lattice is topologically sorted.
160  if (clat.Properties(fst::kTopSorted, true) == 0) {
161  KALDI_WARN << "Input lattice must be topologically sorted.";
162  return false;
163  }
164  if (clat.Start() != 0) {
165  KALDI_WARN << "Input lattice must start from state 0.";
166  return false;
167  }
168 
169  int32 num_states = clat.NumStates();
170  (*alpha).resize(0);
171  (*alpha).resize(num_states, kLogZeroDouble);
172 
173  // Now propagate alphas forward. Note that we don't acount the weight of the
174  // final state to alpha[final_state] -- we acount it to beta[final_state];
175  (*alpha)[0] = 0.0;
176  for (StateId s = 0; s < num_states; s++) {
177  double this_alpha = (*alpha)[s];
178  for (ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done(); aiter.Next()) {
179  const Arc &arc = aiter.Value();
180  double arc_like = -(arc.weight.Weight().Value1() + arc.weight.Weight().Value2());
181  (*alpha)[arc.nextstate] = LogAdd((*alpha)[arc.nextstate], this_alpha + arc_like);
182  }
183  }
184 
185  return true;
186 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ ComputeCompactLatticeBetas() [1/2]

bool kaldi::ComputeCompactLatticeBetas ( const CompactLattice lat,
std::vector< double > *  beta 
)

Definition at line 188 of file lattice-functions.cc.

References KALDI_WARN, kLogZeroDouble, and LogAdd().

Referenced by CompactLatticeNormalize(), CreateFactorTransducer(), and ArcPosteriorComputer::OutputPosteriors().

189  {
190  using namespace fst;
191 
192  // typedef the arc, weight types
193  typedef CompactLattice::Arc Arc;
194  typedef Arc::Weight Weight;
195  typedef Arc::StateId StateId;
196 
197  // Make sure the lattice is topologically sorted.
198  if (clat.Properties(fst::kTopSorted, true) == 0) {
199  KALDI_WARN << "Input lattice must be topologically sorted.";
200  return false;
201  }
202  if (clat.Start() != 0) {
203  KALDI_WARN << "Input lattice must start from state 0.";
204  return false;
205  }
206 
207  int32 num_states = clat.NumStates();
208  (*beta).resize(0);
209  (*beta).resize(num_states, kLogZeroDouble);
210 
211  // Now propagate betas backward. Note that beta[final_state] contains the
212  // weight of the final state in the lattice -- compare that with alpha.
213  for (StateId s = num_states-1; s >= 0; s--) {
214  Weight f = clat.Final(s);
215  double this_beta = -(f.Weight().Value1()+f.Weight().Value2());
216  for (ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done(); aiter.Next()) {
217  const Arc &arc = aiter.Value();
218  double arc_like = -(arc.weight.Weight().Value1()+arc.weight.Weight().Value2());
219  double arc_beta = (*beta)[arc.nextstate] + arc_like;
220  this_beta = LogAdd(this_beta, arc_beta);
221  }
222  (*beta)[s] = this_beta;
223  }
224 
225  return true;
226 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ ComputeCompactLatticeBetas() [2/2]

bool kaldi::ComputeCompactLatticeBetas ( const CompactLattice clat,
vector< double > *  beta 
)

Definition at line 188 of file lattice-functions.cc.

References KALDI_WARN, kLogZeroDouble, and LogAdd().

Referenced by CompactLatticeNormalize(), CreateFactorTransducer(), and ArcPosteriorComputer::OutputPosteriors().

189  {
190  using namespace fst;
191 
192  // typedef the arc, weight types
193  typedef CompactLattice::Arc Arc;
194  typedef Arc::Weight Weight;
195  typedef Arc::StateId StateId;
196 
197  // Make sure the lattice is topologically sorted.
198  if (clat.Properties(fst::kTopSorted, true) == 0) {
199  KALDI_WARN << "Input lattice must be topologically sorted.";
200  return false;
201  }
202  if (clat.Start() != 0) {
203  KALDI_WARN << "Input lattice must start from state 0.";
204  return false;
205  }
206 
207  int32 num_states = clat.NumStates();
208  (*beta).resize(0);
209  (*beta).resize(num_states, kLogZeroDouble);
210 
211  // Now propagate betas backward. Note that beta[final_state] contains the
212  // weight of the final state in the lattice -- compare that with alpha.
213  for (StateId s = num_states-1; s >= 0; s--) {
214  Weight f = clat.Final(s);
215  double this_beta = -(f.Weight().Value1()+f.Weight().Value2());
216  for (ArcIterator<CompactLattice> aiter(clat, s); !aiter.Done(); aiter.Next()) {
217  const Arc &arc = aiter.Value();
218  double arc_like = -(arc.weight.Weight().Value1()+arc.weight.Weight().Value2());
219  double arc_beta = (*beta)[arc.nextstate] + arc_like;
220  this_beta = LogAdd(this_beta, arc_beta);
221  }
222  (*beta)[s] = this_beta;
223  }
224 
225  return true;
226 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ ComputeCorrelation()

void kaldi::ComputeCorrelation ( const VectorBase< BaseFloat > &  wave,
int32  first_lag,
int32  last_lag,
int32  nccf_window_size,
VectorBase< BaseFloat > *  inner_prod,
VectorBase< BaseFloat > *  norm_prod 
)

This function computes some dot products that are required while computing the NCCF.

For each integer lag from start to end-1, this function outputs to (*inner_prod)(lag - start), the dot-product of a window starting at 0 with a window starting at lag. All windows are of length nccf_window_size. It outputs to (*norm_prod)(lag - start), e1 * e2, where e1 is the dot-product of the un-shifted window with itself, and d2 is the dot-product of the window shifted by "lag" with itself.

Definition at line 102 of file pitch-functions.cc.

References VectorBase< Real >::Add(), VectorBase< Real >::Sum(), and VecVec().

Referenced by OnlinePitchFeatureImpl::AcceptWaveform().

106  {
107  Vector<BaseFloat> zero_mean_wave(wave);
108  // TODO: possibly fix this, the mean normalization is done in a strange way.
109  SubVector<BaseFloat> wave_part(wave, 0, nccf_window_size);
110  // subtract mean-frame from wave
111  zero_mean_wave.Add(-wave_part.Sum() / nccf_window_size);
112  BaseFloat e1, e2, sum;
113  SubVector<BaseFloat> sub_vec1(zero_mean_wave, 0, nccf_window_size);
114  e1 = VecVec(sub_vec1, sub_vec1);
115  for (int32 lag = first_lag; lag <= last_lag; lag++) {
116  SubVector<BaseFloat> sub_vec2(zero_mean_wave, lag, nccf_window_size);
117  e2 = VecVec(sub_vec2, sub_vec2);
118  sum = VecVec(sub_vec1, sub_vec2);
119  (*inner_prod)(lag - first_lag) = sum;
120  (*norm_prod)(lag - first_lag) = e1 * e2;
121  }
122 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ ComputeDctMatrix() [1/2]

template void kaldi::ComputeDctMatrix ( Matrix< float > *  M)

◆ ComputeDctMatrix() [2/2]

template void kaldi::ComputeDctMatrix ( Matrix< double > *  M)

◆ ComputeEarlyReverbEnergy()

BaseFloat kaldi::ComputeEarlyReverbEnergy ( const Vector< BaseFloat > &  rir,
const Vector< BaseFloat > &  signal,
BaseFloat  samp_freq 
)

Definition at line 64 of file wav-reverberate.cc.

References VectorBase< Real >::Dim(), FFTbasedBlockConvolveSignals(), KALDI_VLOG, VectorBase< Real >::Max(), VectorBase< Real >::Range(), and VecVec().

Referenced by DoReverberation().

65  {
66  int32 peak_index = 0;
67  rir.Max(&peak_index);
68  KALDI_VLOG(1) << "peak index is " << peak_index;
69 
70  const float sec_before_peak = 0.001;
71  const float sec_after_peak = 0.05;
72  int32 early_rir_start_index = peak_index - sec_before_peak * samp_freq;
73  int32 early_rir_end_index = peak_index + sec_after_peak * samp_freq;
74  if (early_rir_start_index < 0) early_rir_start_index = 0;
75  if (early_rir_end_index > rir.Dim()) early_rir_end_index = rir.Dim();
76 
77  int32 duration = early_rir_end_index - early_rir_start_index;
78  Vector<BaseFloat> early_rir(rir.Range(early_rir_start_index, duration));
79  Vector<BaseFloat> early_reverb(signal);
80  FFTbasedBlockConvolveSignals(early_rir, &early_reverb);
81 
82  // compute the energy
83  return VecVec(early_reverb, early_reverb) / early_reverb.Dim();
84 }
kaldi::int32 int32
void FFTbasedBlockConvolveSignals(const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
Definition: signal.cc:77
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
Definition: kaldi-vector.h:94

◆ ComputeEer()

BaseFloat kaldi::ComputeEer ( std::vector< BaseFloat > *  target_scores,
std::vector< BaseFloat > *  nontarget_scores,
BaseFloat threshold 
)

ComputeEer computes the Equal Error Rate (EER) for the given scores and returns it as a proportion beween 0 and 1.

If we set the threshold at x, then the target error-rate is the proportion of target_scores below x; and the non-target error-rate is the proportion of non-target scores above x. We seek a threshold x for which these error rates are the same; this error rate is the EER.

We compute this by iterating over the positions in target_scores: 0, 1, 2, and so on, and for each position consider whether the cutoff could be here. For each of these position we compute the corresponding position in nontarget_scores where the cutoff would be if the EER were the same. For instance, if the vectors had the same length, this would be position length() - 1, length() - 2, and so on. As soon as the value at that position in nontarget_scores at that position is less than the value from target_scores, we have our EER.

In coding this we weren't particularly careful about edge cases or making sure whether it's actually n + 1 instead of n.

Definition at line 48 of file compute-eer.cc.

References KALDI_ASSERT.

Referenced by main().

50  {
51  KALDI_ASSERT(!target_scores->empty() && !nontarget_scores->empty());
52  std::sort(target_scores->begin(), target_scores->end());
53  std::sort(nontarget_scores->begin(), nontarget_scores->end());
54 
55  size_t target_position = 0,
56  target_size = target_scores->size();
57  for (; target_position + 1 < target_size; target_position++) {
58  ssize_t nontarget_size = nontarget_scores->size(),
59  nontarget_n = nontarget_size * target_position * 1.0 / target_size,
60  nontarget_position = nontarget_size - 1 - nontarget_n;
61  if (nontarget_position < 0)
62  nontarget_position = 0;
63  if ((*nontarget_scores)[nontarget_position] <
64  (*target_scores)[target_position])
65  break;
66  }
67  *threshold = (*target_scores)[target_position];
68  BaseFloat eer = target_position * 1.0 / target_size;
69  return eer;
70 }
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeFeatureNormalizingTransform()

void ComputeFeatureNormalizingTransform ( const FullGmm gmm,
Matrix< BaseFloat > *  xform 
)

Computes the inverse of an LDA transform (without dimensionality reduction) The computed transform is used in initializing the phonetic and speaker subspaces, as well as while increasing the dimensions of those spaces.

Definition at line 1297 of file am-sgmm2.cc.

References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), SpMatrix< Real >::AddSp(), VectorBase< Real >::AddVec(), SpMatrix< Real >::AddVec2(), TpMatrix< Real >::Cholesky(), MatrixBase< Real >::CopyFromTp(), VectorBase< Real >::CopyFromVec(), FullGmm::Dim(), SpMatrix< Real >::Eig(), FullGmm::GetCovarsAndMeans(), rnnlm::i, TpMatrix< Real >::InvertDouble(), MatrixBase< Real >::InvertDouble(), KALDI_ASSERT, KALDI_WARN, kNoTrans, kTrans, FullGmm::NumGauss(), Matrix< Real >::Resize(), MatrixBase< Real >::Row(), PackedMatrix< Real >::Scale(), VectorBase< Real >::Scale(), SortSvd(), and FullGmm::weights().

Referenced by AmSgmm2::GetVarScaledSubstateSpeakerMean(), AmSgmm2::InitializeFromFullGmm(), main(), and TestSgmm2IncreaseDim().

1297  {
1298  int32 dim = gmm.Dim();
1299  int32 num_gauss = gmm.NumGauss();
1300  SpMatrix<BaseFloat> within_class_covar(dim);
1301  SpMatrix<BaseFloat> between_class_covar(dim);
1302  Vector<BaseFloat> global_mean(dim);
1303 
1304  // Accumulate LDA statistics from the GMM parameters.
1305  {
1306  BaseFloat total_weight = 0.0;
1307  Vector<BaseFloat> tmp_weight(num_gauss);
1308  Matrix<BaseFloat> tmp_means;
1309  std::vector< SpMatrix<BaseFloat> > tmp_covars;
1310  tmp_weight.CopyFromVec(gmm.weights());
1311  gmm.GetCovarsAndMeans(&tmp_covars, &tmp_means);
1312  for (int32 i = 0; i < num_gauss; i++) {
1313  BaseFloat w_i = tmp_weight(i);
1314  total_weight += w_i;
1315  within_class_covar.AddSp(w_i, tmp_covars[i]);
1316  between_class_covar.AddVec2(w_i, tmp_means.Row(i));
1317  global_mean.AddVec(w_i, tmp_means.Row(i));
1318  }
1319  KALDI_ASSERT(total_weight > 0);
1320  if (fabs(total_weight - 1.0) > 0.001) {
1321  KALDI_WARN << "Total weight across the GMMs is " << (total_weight)
1322  << ", renormalizing.";
1323  global_mean.Scale(1.0 / total_weight);
1324  within_class_covar.Scale(1.0 / total_weight);
1325  between_class_covar.Scale(1.0 / total_weight);
1326  }
1327  between_class_covar.AddVec2(-1.0, global_mean);
1328  }
1329 
1330  TpMatrix<BaseFloat> chol(dim);
1331  chol.Cholesky(within_class_covar); // Sigma_W = L L^T
1332  TpMatrix<BaseFloat> chol_inv(chol);
1333  chol_inv.InvertDouble();
1334  Matrix<BaseFloat> chol_full(dim, dim);
1335  chol_full.CopyFromTp(chol_inv);
1336  SpMatrix<BaseFloat> LBL(dim);
1337  // LBL = L^{-1} \Sigma_B L^{-T}
1338  LBL.AddMat2Sp(1.0, chol_full, kNoTrans, between_class_covar, 0.0);
1339  Vector<BaseFloat> Dvec(dim);
1340  Matrix<BaseFloat> U(dim, dim);
1341  LBL.Eig(&Dvec, &U);
1342  SortSvd(&Dvec, &U);
1343 
1344  xform->Resize(dim, dim);
1345  chol_full.CopyFromTp(chol);
1346  // T := L U, eq (23)
1347  xform->AddMatMat(1.0, chol_full, kNoTrans, U, kNoTrans, 0.0);
1348 
1349 #ifdef KALDI_PARANOID
1350  Matrix<BaseFloat> inv_xform(*xform);
1351  inv_xform.InvertDouble();
1352  { // Check that T*within_class_covar*T' = I.
1353  Matrix<BaseFloat> wc_covar_full(dim, dim), tmp(dim, dim);
1354  wc_covar_full.CopyFromSp(within_class_covar);
1355  tmp.AddMatMat(1.0, inv_xform, kNoTrans, wc_covar_full, kNoTrans, 0.0);
1356  wc_covar_full.AddMatMat(1.0, tmp, kNoTrans, inv_xform, kTrans, 0.0);
1357  KALDI_ASSERT(wc_covar_full.IsUnit(0.01));
1358  }
1359  { // Check that T*between_class_covar*T' = diagonal.
1360  Matrix<BaseFloat> bc_covar_full(dim, dim), tmp(dim, dim);
1361  bc_covar_full.CopyFromSp(between_class_covar);
1362  tmp.AddMatMat(1.0, inv_xform, kNoTrans, bc_covar_full, kNoTrans, 0.0);
1363  bc_covar_full.AddMatMat(1.0, tmp, kNoTrans, inv_xform, kTrans, 0.0);
1364  KALDI_ASSERT(bc_covar_full.IsDiagonal(0.01));
1365  }
1366 #endif
1367 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.

◆ ComputeFmllrDiagGmm()

BaseFloat kaldi::ComputeFmllrDiagGmm ( const FmllrDiagGmmAccs accs,
const FmllrOptions opts,
Matrix< BaseFloat > *  out_fmllr,
BaseFloat logdet 
)

Referenced by InitFmllr().

◆ ComputeFmllrLogDet()

BaseFloat kaldi::ComputeFmllrLogDet ( const Matrix< BaseFloat > &  fmllr_mat)
inline

Definition at line 176 of file fmllr-diag-gmm.h.

References ApplyFeatureTransformToStats(), ApplyModelTransformToStats(), ComputeFmllrMatrixDiagGmm(), ComputeFmllrMatrixDiagGmmDiagonal(), ComputeFmllrMatrixDiagGmmDiagonal2(), ComputeFmllrMatrixDiagGmmFull(), ComputeFmllrMatrixDiagGmmOffset(), FmllrAuxfGradient(), FmllrAuxFuncDiagGmm(), FmllrInnerUpdate(), KALDI_ASSERT, MatrixBase< Real >::LogDet(), FmllrOptions::num_iters, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

176  {
177  KALDI_ASSERT(fmllr_mat.NumRows() != 0 && fmllr_mat.NumCols() == fmllr_mat.NumRows()+1);
178  SubMatrix<BaseFloat> tmp(fmllr_mat,
179  0, fmllr_mat.NumRows(),
180  0, fmllr_mat.NumRows());
181  return tmp.LogDet();
182 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ComputeFmllrMatrixDiagGmm()

BaseFloat ComputeFmllrMatrixDiagGmm ( const MatrixBase< BaseFloat > &  in_xform,
const AffineXformStats stats,
std::string  fmllr_type,
int32  num_iters,
MatrixBase< BaseFloat > *  out_xform 
)

This function internally calls ComputeFmllrMatrixDiagGmm{Full, Diagonal, Offset}, depending on "fmllr_type".

Definition at line 169 of file fmllr-diag-gmm.cc.

References ComputeFmllrMatrixDiagGmmDiagonal(), ComputeFmllrMatrixDiagGmmFull(), ComputeFmllrMatrixDiagGmmOffset(), MatrixBase< Real >::IsUnit(), KALDI_ERR, KALDI_WARN, and MatrixBase< Real >::SetUnit().

Referenced by ComputeFmllrLogDet(), and LinearVtln::ComputeTransform().

173  {
174  if (fmllr_type == "full") {
175  return ComputeFmllrMatrixDiagGmmFull(in_xform, stats, num_iters, out_xform);
176  } else if (fmllr_type == "diag") {
177  return ComputeFmllrMatrixDiagGmmDiagonal(in_xform, stats, out_xform);
178  } else if (fmllr_type == "offset") {
179  return ComputeFmllrMatrixDiagGmmOffset(in_xform, stats, out_xform);
180  } else if (fmllr_type == "none") {
181  if (!in_xform.IsUnit())
182  KALDI_WARN << "You set fMLLR type to \"none\" but your starting transform "
183  "is not unit [this is strange, and diagnostics will be wrong].";
184  out_xform->SetUnit();
185  return 0.0;
186  } else
187  KALDI_ERR << "Unknown fMLLR update type " << fmllr_type
188  << ", must be one of \"full\"|\"diag\"|\"offset\"|\"none\"";
189  return 0.0;
190 }
BaseFloat ComputeFmllrMatrixDiagGmmFull(const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, int32 num_iters, MatrixBase< BaseFloat > *out_xform)
Updates the FMLLR matrix using Mark Gales&#39; row-by-row update.
BaseFloat ComputeFmllrMatrixDiagGmmOffset(const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *out_xform)
This does offset-only fMLLR, i.e. it only estimates an offset.
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
BaseFloat ComputeFmllrMatrixDiagGmmDiagonal(const MatrixBase< BaseFloat > &in_xform, const AffineXformStats &stats, MatrixBase< BaseFloat > *out_xform)
This does diagonal fMLLR (i.e.

◆ ComputeFmllrMatrixDiagGmmDiagonal()

BaseFloat ComputeFmllrMatrixDiagGmmDiagonal ( const MatrixBase< BaseFloat > &  in_xform,
const AffineXformStats stats,
MatrixBase< BaseFloat > *  out_xform 
)

This does diagonal fMLLR (i.e.

only estimate an offset and scale per dimension). The format of the output is the same as for the full case. Of course, these statistics are unnecessarily large for this case. Returns the objective function improvement, not normalized by number of frames.

Definition at line 275 of file fmllr-diag-gmm.cc.

References AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), FmllrAuxFuncDiagGmm(), AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_ASSERT, KALDI_VLOG, KALDI_WARN, and MatrixBase< Real >::Range().

Referenced by ComputeFmllrLogDet(), ComputeFmllrMatrixDiagGmm(), FmllrDiagGmmAccs::Update(), and RegtreeFmllrDiagGmmAccs::Update().

277  {
278  // The "Diagonal" here means a diagonal fMLLR matrix, i.e. like W = [ A; b] where
279  // A is diagonal.
280  // We re-derived the math (see exponential transform paper) to get a simpler
281  // update rule.
282 
283  /*
284  Write out_xform as D, which is a d x d+1 matrix (where d is the feature dimension).
285  We are solving for s == d_{i,i}, and o == d_{i,d} [assuming zero-based indexing];
286  s is a scale, o is an offset.
287  The stats are K (dimension d x d+1) and G_i for i=0..d-1 (dimension: d+1 x d+1),
288  and the count beta.
289 
290  The auxf for the i'th row of the transform is (assuming zero-based indexing):
291 
292  s k_{i,i} + o k_{i,d}
293  - \frac{1}{2} s^2 g_{i,i,i} - \frac{1}{2} o^2 g_{i,d,d} - s o g_{i,d,i}
294  + \beta \log |s|
295 
296  Suppose we know s, we can solve for o:
297  o = (k_{i,d} - s g_{i,d,i}) / g_{i,d,d}
298  Substituting this expression for o into the auxf (and ignoring
299  terms that don't vary with s), we have the auxf:
300 
301  \frac{1}{2} s^2 ( g_{i,d,i}^2 / g_{i,d,d} - g_{i,i,i} )
302  + s ( k_{i,i} - g_{i,d,i} k_{i,d} / g_{i,d,d} )
303  + \beta \log |s|
304 
305  Differentiating w.r.t. s and assuming s is positive, we have
306  a s + b + c/s = 0
307  where
308  a = ( g_{i,d,i}^2 / g_{i,d,d} - g_{i,i,i} ),
309  b = ( k_{i,i} - g_{i,d,i} k_{i,d} / g_{i,d,d} )
310  c = beta
311  Multiplying by s, we have the equation
312  a s^2 + b s + c = 0, where we assume s > 0.
313  We solve it with:
314  s = (-b - \sqrt{b^2 - 4ac}) / 2a
315  [take the negative root because we know a is negative, and this gives
316  the more positive solution for s; the other one would be negative].
317  We then solve for o with the equation above, i.e.:
318  o = (k_{i,d} - s g_{i,d,i}) / g_{i,d,d})
319  */
320 
321  int32 dim = stats.G_.size();
322  double beta = stats.beta_;
323  out_xform->CopyFromMat(in_xform);
324  if (beta == 0.0) {
325  KALDI_WARN << "Computing diagonal fMLLR matrix: no stats [using original transform]";
326  return 0.0;
327  }
328  BaseFloat old_obj = FmllrAuxFuncDiagGmm(*out_xform, stats);
329  KALDI_ASSERT(out_xform->Range(0, dim, 0, dim).IsDiagonal()); // orig transform
330  // must be diagonal.
331  for(int32 i = 0; i < dim; i++) {
332  double k_ii = stats.K_(i, i), k_id = stats.K_(i, dim),
333  g_iii = stats.G_[i](i, i), g_idd = stats.G_[i](dim, dim),
334  g_idi = stats.G_[i](dim, i);
335  double a = g_idi*g_idi/g_idd - g_iii,
336  b = k_ii - g_idi*k_id/g_idd,
337  c = beta;
338  double s = (-b - std::sqrt(b*b - 4*a*c)) / (2*a);
339  KALDI_ASSERT(s > 0.0);
340  double o = (k_id - s*g_idi) / g_idd;
341  (*out_xform)(i, i) = s;
342  (*out_xform)(i, dim) = o;
343  }
344  BaseFloat new_obj = FmllrAuxFuncDiagGmm(*out_xform, stats);
345  KALDI_VLOG(2) << "fMLLR objective function improvement = "
346  << (new_obj - old_obj);
347  return new_obj - old_obj;
348 }
kaldi::int32 int32
double FmllrAuxFuncDiagGmm(const MatrixBase< double > &xform, const AffineXformStats &stats)
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ ComputeFmllrMatrixDiagGmmDiagonal2()

BaseFloat kaldi::ComputeFmllrMatrixDiagGmmDiagonal2 ( const MatrixBase< BaseFloat > &  in_xform,
const AffineXformStats stats,
MatrixBase< BaseFloat > *  out_xform 
)

Referenced by ComputeFmllrLogDet().

◆ ComputeFmllrMatrixDiagGmmFull()

BaseFloat ComputeFmllrMatrixDiagGmmFull ( const MatrixBase< BaseFloat > &  in_xform,
const AffineXformStats stats,
int32  num_iters,
MatrixBase< BaseFloat > *  out_xform 
)

Updates the FMLLR matrix using Mark Gales' row-by-row update.

Uses full fMLLR matrix (no structure). Returns the objective function improvement, not normalized by number of frames.

Definition at line 236 of file fmllr-diag-gmm.cc.

References ApproxEqual(), AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), rnnlm::d, FmllrAuxFuncDiagGmm(), FmllrInnerUpdate(), AffineXformStats::G_, AffineXformStats::K_, KALDI_LOG, KALDI_WARN, and kNoTrans.

Referenced by ComputeFmllrLogDet(), ComputeFmllrMatrixDiagGmm(), FmllrDiagGmmAccs::Update(), and RegtreeFmllrDiagGmmAccs::Update().

239  {
240  int32 dim = static_cast<int32>(stats.G_.size());
241 
242  // Compute the inverse matrices of second-order statistics
243  vector< SpMatrix<double> > inv_g(dim);
244  for (int32 d = 0; d < dim; d++) {
245  inv_g[d].Resize(dim + 1);
246  inv_g[d].CopyFromSp(stats.G_[d]);
247  inv_g[d].Invert();
248  }
249 
250  Matrix<double> old_xform(in_xform), new_xform(in_xform);
251  BaseFloat old_objf = FmllrAuxFuncDiagGmm(old_xform, stats);
252 
253  for (int32 iter = 0; iter < num_iters; ++iter) {
254  for (int32 d = 0; d < dim; d++) {
255  SubVector<double> k_d(stats.K_, d);
256  FmllrInnerUpdate(inv_g[d], k_d, stats.beta_, d, &new_xform);
257  } // end of looping over rows
258  } // end of iterations
259 
260  BaseFloat new_objf = FmllrAuxFuncDiagGmm(new_xform, stats),
261  objf_improvement = new_objf - old_objf;
262  KALDI_LOG << "fMLLR objf improvement is "
263  << (objf_improvement / (stats.beta_ + 1.0e-10))
264  << " per frame over " << stats.beta_ << " frames.";
265  if (objf_improvement < 0.0 && !ApproxEqual(new_objf, old_objf)) {
266  KALDI_WARN << "No applying fMLLR transform change because objective "
267  << "function did not increase.";
268  return 0.0;
269  } else {
270  out_xform->CopyFromMat(new_xform, kNoTrans);
271  return objf_improvement;
272  }
273 }
kaldi::int32 int32
double FmllrAuxFuncDiagGmm(const MatrixBase< double > &xform, const AffineXformStats &stats)
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
void FmllrInnerUpdate(SpMatrix< double > &inv_G, VectorBase< double > &k, double beta, int32 row, MatrixBase< double > *transform)
This function does one row of the inner-loop fMLLR transform update.
#define KALDI_LOG
Definition: kaldi-error.h:153
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ ComputeFmllrMatrixDiagGmmOffset()

BaseFloat ComputeFmllrMatrixDiagGmmOffset ( const MatrixBase< BaseFloat > &  in_xform,
const AffineXformStats stats,
MatrixBase< BaseFloat > *  out_xform 
)

This does offset-only fMLLR, i.e. it only estimates an offset.

Definition at line 350 of file fmllr-diag-gmm.cc.

References MatrixBase< Real >::CopyFromMat(), AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_ASSERT, KALDI_WARN, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by ComputeFmllrLogDet(), ComputeFmllrMatrixDiagGmm(), FmllrDiagGmmAccs::Update(), and RegtreeFmllrDiagGmmAccs::Update().

352  {
353  int32 dim = stats.G_.size();
354  KALDI_ASSERT(in_xform.NumRows() == dim && in_xform.NumCols() == dim+1);
355  SubMatrix<BaseFloat> square_part(in_xform, 0, dim, 0, dim);
356  KALDI_ASSERT(square_part.IsUnit());
357  BaseFloat objf_impr = 0.0;
358  out_xform->CopyFromMat(in_xform);
359  for (int32 i = 0; i < dim; i++) {
360  // auxf in this offset b_i is:
361  // -0.5 b_i^2 G_i(dim, dim) - b_i G_i(i, dim)*1.0 + b_i K(i, dim) (1)
362  // answer is:
363  // b_i = [K(i, dim) - G_i(i, dim)] / G_i(dim, dim)
364  // objf change is given by (1)
365  BaseFloat b_i = (*out_xform)(i, dim);
366  BaseFloat objf_before = -0.5 * b_i * b_i * stats.G_[i](dim, dim)
367  - b_i * stats.G_[i](i, dim) + b_i * stats.K_(i, dim);
368  b_i = (stats.K_(i, dim) - stats.G_[i](i, dim)) / stats.G_[i](dim, dim);
369  (*out_xform)(i, dim) = b_i;
370  BaseFloat objf_after = -0.5 * b_i * b_i * stats.G_[i](dim, dim)
371  - b_i * stats.G_[i](i, dim) + b_i * stats.K_(i, dim);
372  if (objf_after < objf_before)
373  KALDI_WARN << "Objf decrease in offset estimation:"
374  << objf_after << " < " << objf_before;
375  objf_impr += objf_after - objf_before;
376  }
377  return objf_impr;
378 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeGconsts()

static void kaldi::ComputeGconsts ( const VectorBase< BaseFloat > &  weights,
const MatrixBase< BaseFloat > &  means,
const MatrixBase< BaseFloat > &  inv_vars,
VectorBase< BaseFloat > *  gconsts_out 
)
static

Definition at line 112 of file decodable-am-diag-gmm-regtree.cc.

References rnnlm::d, VectorBase< Real >::Dim(), KALDI_ASSERT, KALDI_ERR, KALDI_ISINF, KALDI_ISNAN, KALDI_WARN, Log(), M_LOG_2PI, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by DecodableAmDiagGmmRegtreeMllr::GetXformedMeanInvVars().

115  {
116  int32 num_gauss = weights.Dim();
117  int32 dim = means.NumCols();
118  KALDI_ASSERT(means.NumRows() == num_gauss
119  && inv_vars.NumRows() == num_gauss && inv_vars.NumCols() == dim);
120  KALDI_ASSERT(gconsts_out->Dim() == num_gauss);
121 
122  BaseFloat offset = -0.5 * M_LOG_2PI * dim; // constant term in gconst.
123  int32 num_bad = 0;
124 
125  for (int32 gauss = 0; gauss < num_gauss; gauss++) {
126  KALDI_ASSERT(weights(gauss) >= 0); // Cannot have negative weights.
127  BaseFloat gc = Log(weights(gauss)) + offset; // May be -inf if weights == 0
128  for (int32 d = 0; d < dim; d++) {
129  gc += 0.5 * Log(inv_vars(gauss, d)) - 0.5 * means(gauss, d)
130  * means(gauss, d) * inv_vars(gauss, d); // diff from DiagGmm version.
131  }
132 
133  if (KALDI_ISNAN(gc)) { // negative infinity is OK but NaN is not acceptable
134  KALDI_ERR << "At component " << gauss
135  << ", not a number in gconst computation";
136  }
137  if (KALDI_ISINF(gc)) {
138  num_bad++;
139  // If positive infinity, make it negative infinity.
140  // Want to make sure the answer becomes -inf in the end, not NaN.
141  if (gc > 0) gc = -gc;
142  }
143  (*gconsts_out)(gauss) = gc;
144  }
145  if (num_bad > 0)
146  KALDI_WARN << num_bad << " unusable components found while computing "
147  << "gconsts.";
148 }
#define M_LOG_2PI
Definition: kaldi-math.h:60
#define KALDI_ISINF
Definition: kaldi-math.h:73
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ISNAN
Definition: kaldi-math.h:72
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeInitialSplit()

BaseFloat kaldi::ComputeInitialSplit ( const std::vector< Clusterable *> &  summed_stats,
const Questions q_opts,
EventKeyType  key,
std::vector< EventValueType > *  yes_set 
)

Definition at line 297 of file build-tree-utils.cc.

References AddToClustersOptimized(), DeletePointers(), Questions::GetQuestionsOf(), rnnlm::i, QuestionsForKey::initial_questions, KALDI_ASSERT, KALDI_WARN, Clusterable::Objf(), SumClusterable(), and SumClusterableObjf().

Referenced by FindBestSplitForKey().

299  {
300  KALDI_ASSERT(yes_set != NULL);
301  yes_set->clear();
302  const QuestionsForKey &key_opts = q_opts.GetQuestionsOf(key);
303 
304  // "total" needed for optimization in AddToClustersOptimized,
305  // and also used to work otu total objf.
306  Clusterable *total = SumClusterable(summed_stats);
307  if (total == NULL) return 0.0; // because there were no stats or non-NULL stats.
308  BaseFloat unsplit_objf = total->Objf();
309 
310  const std::vector<std::vector<EventValueType> > &questions_of_this_key = key_opts.initial_questions;
311 
312  int32 best_idx = -1;
313  BaseFloat best_objf_change = 0;
314 
315  for (size_t i = 0; i < questions_of_this_key.size(); i++) {
316  const std::vector<EventValueType> &yes_set = questions_of_this_key[i];
317  std::vector<int32> assignments(summed_stats.size(), 0); // 0 is index of "no".
318  std::vector<Clusterable*> clusters(2); // no and yes clusters.
319  for (std::vector<EventValueType>::const_iterator iter = yes_set.begin(); iter != yes_set.end(); ++iter) {
320  KALDI_ASSERT(*iter>=0);
321  if (*iter < (EventValueType)assignments.size()) assignments[*iter] = 1;
322  }
323  kaldi::AddToClustersOptimized(summed_stats, assignments, *total, &clusters);
324  BaseFloat this_objf = SumClusterableObjf(clusters);
325 
326  if (this_objf < unsplit_objf- 0.001*std::abs(unsplit_objf)) { // got worse; should never happen.
327  // of course small differences can be caused by roundoff.
328  KALDI_WARN << "Objective function got worse when building tree: "<< this_objf << " < " << unsplit_objf;
329  KALDI_ASSERT(!(this_objf < unsplit_objf - 0.01*(200 + std::abs(unsplit_objf)))); // do assert on more stringent check.
330  }
331 
332  BaseFloat this_objf_change = this_objf - unsplit_objf;
333  if (this_objf_change > best_objf_change) {
334  best_objf_change = this_objf_change;
335  best_idx = i;
336  }
337  DeletePointers(&clusters);
338  }
339  delete total;
340  if (best_idx != -1)
341  *yes_set = questions_of_this_key[best_idx];
342  return best_objf_change;
343 }
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:184
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
void AddToClustersOptimized(const std::vector< Clusterable *> &stats, const std::vector< int32 > &assignments, const Clusterable &total, std::vector< Clusterable *> *clusters)
AddToClustersOptimized does the same as AddToClusters (it sums up the stats within each cluster...
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
BaseFloat SumClusterableObjf(const std::vector< Clusterable *> &vec)
Returns the total objective function after adding up all the statistics in the vector (pointers may b...
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
Definition: event-map.h:51
Clusterable * SumClusterable(const std::vector< Clusterable *> &vec)
Sums stats (ptrs may be NULL). Returns NULL if no non-NULL stats present.

◆ ComputeKaldiPitchFirstPass()

void kaldi::ComputeKaldiPitchFirstPass ( const PitchExtractionOptions opts,
const VectorBase< BaseFloat > &  wave,
Matrix< BaseFloat > *  output 
)

This function is called from ComputeKaldiPitch when the user specifies opts.simulate_first_pass_online == true.

It gives the "first-pass" version of the features, which you would get on the first decoding pass in an online setting. These may differ slightly from the final features due to both the way the Viterbi traceback works (this is affected by opts.max_frames_latency), and the online way we compute the average signal energy.

Definition at line 1248 of file pitch-functions.cc.

References OnlinePitchFeature::AcceptWaveform(), VectorBase< Real >::Dim(), PitchExtractionOptions::frame_shift_ms, PitchExtractionOptions::frames_per_chunk, OnlinePitchFeature::GetFrame(), OnlinePitchFeature::InputFinished(), KALDI_ASSERT, KALDI_WARN, kCopyData, OnlinePitchFeature::NumFramesReady(), Matrix< Real >::Resize(), MatrixBase< Real >::RowRange(), and PitchExtractionOptions::samp_freq.

Referenced by ComputeKaldiPitch().

1251  {
1252 
1253  int32 cur_rows = 100;
1254  Matrix<BaseFloat> feats(cur_rows, 2);
1255 
1256  OnlinePitchFeature pitch_extractor(opts);
1257  KALDI_ASSERT(opts.frames_per_chunk > 0 &&
1258  "--simulate-first-pass-online option does not make sense "
1259  "unless you specify --frames-per-chunk");
1260 
1261  int32 cur_offset = 0, cur_frame = 0, samp_per_chunk =
1262  opts.frames_per_chunk * opts.samp_freq * opts.frame_shift_ms / 1000.0f;
1263 
1264  while (cur_offset < wave.Dim()) {
1265  int32 num_samp = std::min(samp_per_chunk, wave.Dim() - cur_offset);
1266  SubVector<BaseFloat> wave_chunk(wave, cur_offset, num_samp);
1267  pitch_extractor.AcceptWaveform(opts.samp_freq, wave_chunk);
1268  cur_offset += num_samp;
1269  if (cur_offset == wave.Dim())
1270  pitch_extractor.InputFinished();
1271  // Get each frame as soon as it is ready.
1272  for (; cur_frame < pitch_extractor.NumFramesReady(); cur_frame++) {
1273  if (cur_frame >= cur_rows) {
1274  cur_rows *= 2;
1275  feats.Resize(cur_rows, 2, kCopyData);
1276  }
1277  SubVector<BaseFloat> row(feats, cur_frame);
1278  pitch_extractor.GetFrame(cur_frame, &row);
1279  }
1280  }
1281  if (cur_frame == 0) {
1282  KALDI_WARN << "No features output since wave file too short";
1283  output->Resize(0, 0);
1284  } else {
1285  *output = feats.RowRange(0, cur_frame);
1286  }
1287 }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
SubMatrix< Real > RowRange(const MatrixIndexT row_offset, const MatrixIndexT num_rows) const
Definition: kaldi-matrix.h:209
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ComputeLatticeAlphasAndBetas() [1/4]

double kaldi::ComputeLatticeAlphasAndBetas ( const LatticeType &  lat,
bool  viterbi,
std::vector< double > *  alpha,
std::vector< double > *  beta 
)

Definition at line 452 of file lattice-functions.cc.

References ApproxEqual(), ComputeLatticeAlphasAndBetas(), fst::ConvertToCost(), KALDI_ASSERT, KALDI_WARN, kLogZeroDouble, and LogAddOrMax().

Referenced by CompactLatticeLimitDepth(), ComputeLatticeAlphasAndBetas(), and DiscriminativeSupervisionSplitter::ComputeLatticeScores().

455  {
456  typedef typename LatticeType::Arc Arc;
457  typedef typename Arc::Weight Weight;
458  typedef typename Arc::StateId StateId;
459 
460  StateId num_states = lat.NumStates();
461  KALDI_ASSERT(lat.Properties(fst::kTopSorted, true) == fst::kTopSorted);
462  KALDI_ASSERT(lat.Start() == 0);
463  alpha->clear();
464  beta->clear();
465  alpha->resize(num_states, kLogZeroDouble);
466  beta->resize(num_states, kLogZeroDouble);
467 
468  double tot_forward_prob = kLogZeroDouble;
469  (*alpha)[0] = 0.0;
470  // Propagate alphas forward.
471  for (StateId s = 0; s < num_states; s++) {
472  double this_alpha = (*alpha)[s];
473  for (fst::ArcIterator<LatticeType> aiter(lat, s); !aiter.Done();
474  aiter.Next()) {
475  const Arc &arc = aiter.Value();
476  double arc_like = -ConvertToCost(arc.weight);
477  (*alpha)[arc.nextstate] = LogAddOrMax(viterbi, (*alpha)[arc.nextstate],
478  this_alpha + arc_like);
479  }
480  Weight f = lat.Final(s);
481  if (f != Weight::Zero()) {
482  double final_like = this_alpha - ConvertToCost(f);
483  tot_forward_prob = LogAddOrMax(viterbi, tot_forward_prob, final_like);
484  }
485  }
486  for (StateId s = num_states-1; s >= 0; s--) { // it's guaranteed signed.
487  double this_beta = -ConvertToCost(lat.Final(s));
488  for (fst::ArcIterator<LatticeType> aiter(lat, s); !aiter.Done();
489  aiter.Next()) {
490  const Arc &arc = aiter.Value();
491  double arc_like = -ConvertToCost(arc.weight),
492  arc_beta = (*beta)[arc.nextstate] + arc_like;
493  this_beta = LogAddOrMax(viterbi, this_beta, arc_beta);
494  }
495  (*beta)[s] = this_beta;
496  }
497  double tot_backward_prob = (*beta)[lat.Start()];
498  if (!ApproxEqual(tot_forward_prob, tot_backward_prob, 1e-8)) {
499  KALDI_WARN << "Total forward probability over lattice = " << tot_forward_prob
500  << ", while total backward probability = " << tot_backward_prob;
501  }
502  // Split the difference when returning... they should be the same.
503  return 0.5 * (tot_backward_prob + tot_forward_prob);
504 }
fst::StdArc::StateId StateId
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
const double kLogZeroDouble
Definition: kaldi-math.h:129
static double LogAddOrMax(bool viterbi, double a, double b)
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ ComputeLatticeAlphasAndBetas() [2/4]

double kaldi::ComputeLatticeAlphasAndBetas ( const LatticeType &  lat,
bool  viterbi,
vector< double > *  alpha,
vector< double > *  beta 
)

Definition at line 452 of file lattice-functions.cc.

References ApproxEqual(), ComputeLatticeAlphasAndBetas(), fst::ConvertToCost(), KALDI_ASSERT, KALDI_WARN, kLogZeroDouble, and LogAddOrMax().

Referenced by CompactLatticeLimitDepth(), ComputeLatticeAlphasAndBetas(), and DiscriminativeSupervisionSplitter::ComputeLatticeScores().

455  {
456  typedef typename LatticeType::Arc Arc;
457  typedef typename Arc::Weight Weight;
458  typedef typename Arc::StateId StateId;
459 
460  StateId num_states = lat.NumStates();
461  KALDI_ASSERT(lat.Properties(fst::kTopSorted, true) == fst::kTopSorted);
462  KALDI_ASSERT(lat.Start() == 0);
463  alpha->clear();
464  beta->clear();
465  alpha->resize(num_states, kLogZeroDouble);
466  beta->resize(num_states, kLogZeroDouble);
467 
468  double tot_forward_prob = kLogZeroDouble;
469  (*alpha)[0] = 0.0;
470  // Propagate alphas forward.
471  for (StateId s = 0; s < num_states; s++) {
472  double this_alpha = (*alpha)[s];
473  for (fst::ArcIterator<LatticeType> aiter(lat, s); !aiter.Done();
474  aiter.Next()) {
475  const Arc &arc = aiter.Value();
476  double arc_like = -ConvertToCost(arc.weight);
477  (*alpha)[arc.nextstate] = LogAddOrMax(viterbi, (*alpha)[arc.nextstate],
478  this_alpha + arc_like);
479  }
480  Weight f = lat.Final(s);
481  if (f != Weight::Zero()) {
482  double final_like = this_alpha - ConvertToCost(f);
483  tot_forward_prob = LogAddOrMax(viterbi, tot_forward_prob, final_like);
484  }
485  }
486  for (StateId s = num_states-1; s >= 0; s--) { // it's guaranteed signed.
487  double this_beta = -ConvertToCost(lat.Final(s));
488  for (fst::ArcIterator<LatticeType> aiter(lat, s); !aiter.Done();
489  aiter.Next()) {
490  const Arc &arc = aiter.Value();
491  double arc_like = -ConvertToCost(arc.weight),
492  arc_beta = (*beta)[arc.nextstate] + arc_like;
493  this_beta = LogAddOrMax(viterbi, this_beta, arc_beta);
494  }
495  (*beta)[s] = this_beta;
496  }
497  double tot_backward_prob = (*beta)[lat.Start()];
498  if (!ApproxEqual(tot_forward_prob, tot_backward_prob, 1e-8)) {
499  KALDI_WARN << "Total forward probability over lattice = " << tot_forward_prob
500  << ", while total backward probability = " << tot_backward_prob;
501  }
502  // Split the difference when returning... they should be the same.
503  return 0.5 * (tot_backward_prob + tot_forward_prob);
504 }
fst::StdArc::StateId StateId
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
const double kLogZeroDouble
Definition: kaldi-math.h:129
static double LogAddOrMax(bool viterbi, double a, double b)
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ ComputeLatticeAlphasAndBetas() [3/4]

template double kaldi::ComputeLatticeAlphasAndBetas ( const Lattice lat,
bool  viterbi,
vector< double > *  alpha,
vector< double > *  beta 
)

◆ ComputeLatticeAlphasAndBetas() [4/4]

template double kaldi::ComputeLatticeAlphasAndBetas ( const CompactLattice lat,
bool  viterbi,
vector< double > *  alpha,
vector< double > *  beta 
)

◆ ComputeLdaTransform()

void kaldi::ComputeLdaTransform ( const std::map< std::string, Vector< BaseFloat > *> &  utt2ivector,
const std::map< std::string, std::vector< std::string > > &  spk2utt,
BaseFloat  total_covariance_factor,
BaseFloat  covariance_floor,
MatrixBase< BaseFloat > *  lda_out 
)

Definition at line 107 of file ivector-compute-lda.cc.

References CovarianceStats::AccStats(), SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), SpMatrix< Real >::AddSp(), ComputeNormalizingTransform(), MatrixBase< Real >::CopyFromMat(), SpMatrix< Real >::Eig(), CovarianceStats::Empty(), CovarianceStats::GetTotalCovar(), CovarianceStats::GetWithinCovar(), CovarianceStats::Info(), KALDI_ASSERT, KALDI_LOG, kNoTrans, kTrans, rnnlm::n, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), CovarianceStats::SingularTotCovar(), and SortSvd().

Referenced by main().

112  {
113  KALDI_ASSERT(!utt2ivector.empty());
114  int32 lda_dim = lda_out->NumRows(), dim = lda_out->NumCols();
115  KALDI_ASSERT(dim == utt2ivector.begin()->second->Dim());
116  KALDI_ASSERT(lda_dim > 0 && lda_dim <= dim);
117 
118  CovarianceStats stats(dim);
119 
120  std::map<std::string, std::vector<std::string> >::const_iterator iter;
121  for (iter = spk2utt.begin(); iter != spk2utt.end(); ++iter) {
122  const std::vector<std::string> &uttlist = iter->second;
123  KALDI_ASSERT(!uttlist.empty());
124 
125  int32 N = uttlist.size(); // number of utterances.
126  Matrix<double> utts_of_this_spk(N, dim);
127  for (int32 n = 0; n < N; n++) {
128  std::string utt = uttlist[n];
129  KALDI_ASSERT(utt2ivector.count(utt) != 0);
130  utts_of_this_spk.Row(n).CopyFromVec(
131  *(utt2ivector.find(utt)->second));
132  }
133  stats.AccStats(utts_of_this_spk);
134  }
135 
136  KALDI_LOG << "Stats have " << stats.Info();
137  KALDI_ASSERT(!stats.Empty());
138  KALDI_ASSERT(!stats.SingularTotCovar() &&
139  "Too little data for iVector dimension.");
140 
141 
142  SpMatrix<double> total_covar;
143  stats.GetTotalCovar(&total_covar);
144  SpMatrix<double> within_covar;
145  stats.GetWithinCovar(&within_covar);
146 
147 
148  SpMatrix<double> mat_to_normalize(dim);
149  mat_to_normalize.AddSp(total_covariance_factor, total_covar);
150  mat_to_normalize.AddSp(1.0 - total_covariance_factor, within_covar);
151 
152  Matrix<double> T(dim, dim);
153  ComputeNormalizingTransform(mat_to_normalize,
154  static_cast<double>(covariance_floor), &T);
155 
156  SpMatrix<double> between_covar(total_covar);
157  between_covar.AddSp(-1.0, within_covar);
158 
159  SpMatrix<double> between_covar_proj(dim);
160  between_covar_proj.AddMat2Sp(1.0, T, kNoTrans, between_covar, 0.0);
161 
162  Matrix<double> U(dim, dim);
163  Vector<double> s(dim);
164  between_covar_proj.Eig(&s, &U);
165  bool sort_on_absolute_value = false; // any negative ones will go last (they
166  // shouldn't exist anyway so doesn't
167  // really matter)
168  SortSvd(&s, &U, static_cast<Matrix<double>*>(NULL),
169  sort_on_absolute_value);
170 
171  KALDI_LOG << "Singular values of between-class covariance after projecting "
172  << "with interpolated [total/within] covariance with a weight of "
173  << total_covariance_factor << " on the total covariance, are: " << s;
174 
175  // U^T is the transform that will diagonalize the between-class covariance.
176  // U_part is just the part of U that corresponds to the kept dimensions.
177  SubMatrix<double> U_part(U, 0, dim, 0, lda_dim);
178 
179  // We first transform by T and then by U_part^T. This means T
180  // goes on the right.
181  Matrix<double> temp(lda_dim, dim);
182  temp.AddMatMat(1.0, U_part, kTrans, T, kNoTrans, 0.0);
183  lda_out->CopyFromMat(temp);
184 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void ComputeNormalizingTransform(const SpMatrix< Real > &covar, Real floor, MatrixBase< Real > *proj)
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_LOG
Definition: kaldi-error.h:153
Sub-matrix representation.
Definition: kaldi-matrix.h:988
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.

◆ ComputeLocalCost()

void kaldi::ComputeLocalCost ( const VectorBase< BaseFloat > &  nccf_pitch,
const VectorBase< BaseFloat > &  lags,
const PitchExtractionOptions opts,
VectorBase< BaseFloat > *  local_cost 
)

This function computes the local-cost for the Viterbi computation, see eq.

(5) in the paper.

Parameters
optsThe options as provided by the user
nccf_pitchThe nccf as computed for the pitch computation (with ballast).
lagsThe log-spaced lags at which nccf_pitch is sampled.
local_costWe output the local-cost to here.

Definition at line 178 of file pitch-functions.cc.

References VectorBase< Real >::AddVec(), VectorBase< Real >::AddVecVec(), VectorBase< Real >::Dim(), KALDI_ASSERT, VectorBase< Real >::Set(), and PitchExtractionOptions::soft_min_f0.

Referenced by PitchFrameInfo::ComputeBacktraces().

181  {
182  // from the paper, eq. 5, local_cost = 1 - Phi(t,i)(1 - soft_min_f0 L_i)
183  // nccf is the nccf on this frame measured at the lags in "lags".
184  KALDI_ASSERT(nccf_pitch.Dim() == local_cost->Dim() &&
185  nccf_pitch.Dim() == lags.Dim());
186  local_cost->Set(1.0);
187  // add the term -Phi(t,i):
188  local_cost->AddVec(-1.0, nccf_pitch);
189  // add the term soft_min_f0 Phi(t,i) L_i
190  local_cost->AddVecVec(opts.soft_min_f0, lags, nccf_pitch, 1.0);
191 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeMllrMatrix()

static void kaldi::ComputeMllrMatrix ( const Matrix< double > &  K,
const vector< SpMatrix< double > > &  G,
Matrix< BaseFloat > *  out 
)
static

Definition at line 283 of file regtree-mllr-diag-gmm.cc.

References MatrixBase< Real >::CopyFromMat(), rnnlm::d, SpMatrix< Real >::Invert(), KALDI_WARN, kNoTrans, MatrixBase< Real >::Row(), and MatrixBase< Real >::SetUnit().

Referenced by RegtreeMllrDiagGmmAccs::Update().

285  {
286  int32 dim = G.size();
287  Matrix<double> tmp_out(dim, dim+1);
288  for (int32 d = 0; d < dim; d++) {
289  if (G[d].Cond() > 1.0e+9) {
290  KALDI_WARN << "Dim " << d << ": Badly conditioned stats. Setting MLLR "
291  << "transform to unit.";
292  tmp_out.SetUnit();
293  break;
294  }
295  SpMatrix<double> inv_g(G[d]);
296 // KALDI_LOG << "Dim " << d << ": G: max = " << inv_g.Max() << ", min = "
297 // << inv_g.Min() << ", log det = " << inv_g.LogDet(NULL)
298 // << ", cond = " << inv_g.Cond();
299  inv_g.Invert();
300 // KALDI_LOG << "Inv G: max = " << inv_g.Max() << ", min = " << inv_g.Min()
301 // << ", log det = " << inv_g.LogDet(NULL) << ", cond = "
302 // << inv_g.Cond();
303  tmp_out.Row(d).AddSpVec(1.0, inv_g, K.Row(d), 0.0);
304  }
305  out->CopyFromMat(tmp_out, kNoTrans);
306 }
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ ComputeNccf()

void kaldi::ComputeNccf ( const VectorBase< BaseFloat > &  inner_prod,
const VectorBase< BaseFloat > &  norm_prod,
BaseFloat  nccf_ballast,
VectorBase< BaseFloat > *  nccf_vec 
)

Computes the NCCF as a fraction of the numerator term (a dot product between two vectors) and a denominator term which equals sqrt(e1*e2 + nccf_ballast) where e1 and e2 are both dot-products of bits of the wave with themselves, and e1*e2 is supplied as "norm_prod".

These quantities are computed by "ComputeCorrelation".

Definition at line 131 of file pitch-functions.cc.

References VectorBase< Real >::Dim(), and KALDI_ASSERT.

Referenced by OnlinePitchFeatureImpl::AcceptWaveform().

134  {
135  KALDI_ASSERT(inner_prod.Dim() == norm_prod.Dim() &&
136  inner_prod.Dim() == nccf_vec->Dim());
137  for (int32 lag = 0; lag < inner_prod.Dim(); lag++) {
138  BaseFloat numerator = inner_prod(lag),
139  denominator = pow(norm_prod(lag) + nccf_ballast, 0.5),
140  nccf;
141  if (denominator != 0.0) {
142  nccf = numerator / denominator;
143  } else {
144  KALDI_ASSERT(numerator == 0.0);
145  nccf = 0.0;
146  }
147  KALDI_ASSERT(nccf < 1.01 && nccf > -1.01);
148  (*nccf_vec)(lag) = nccf;
149  }
150 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeNewPhoneLengths()

static bool kaldi::ComputeNewPhoneLengths ( const HmmTopology topology,
const std::vector< int32 > &  mapped_phones,
const std::vector< int32 > &  old_lengths,
int32  conversion_shift,
int32  subsample_factor,
std::vector< int32 > *  new_lengths 
)
static

This function, called from ConvertAlignmentInternal(), works out suitable new lengths of phones in the case where subsample_factor != 1.

The input vectors 'mapped_phones' and 'old_lengths' must be the same size– the length of the phone sequence. The 'topology' object and 'mapped_phones' are needed to work out the minimum length of each phone in the sequence. Returns false only if it could not assign lengths (because the topology was too long relative to the number of frames).

Parameters
topology[in] The new phone lengths are computed with regard to this topology
mapped_phones[in] The phones for which this function computes new lengths
old_lengths[in] The old lengths
conversion_shift[in] This will normally equal subsample_factor - 1 but may be less than that if the 'repeat_frames' option is true; it's used for generating 'frame-shifted' versions of alignments that we will later interpolate. This helps us keep the phone boundaries of the subsampled and interpolated alignments the same as the original alignment.
subsample_factor[in] The frame subsampling factor... normally 1, but might be > 1 if we're converting to a reduced-frame-rate system.
new_lengths[out] The vector for storing new lengths.

Definition at line 849 of file hmm-utils.cc.

References rnnlm::i, rnnlm::j, and HmmTopology::MinLength().

Referenced by ConvertAlignmentInternal().

854  {
855  int32 phone_sequence_length = old_lengths.size();
856  std::vector<int32> min_lengths(phone_sequence_length);
857  new_lengths->resize(phone_sequence_length);
858  for (int32 i = 0; i < phone_sequence_length; i++)
859  min_lengths[i] = topology.MinLength(mapped_phones[i]);
860  int32 cur_time_elapsed = 0;
861  for (int32 i = 0; i < phone_sequence_length; i++) {
862  // Note: the '+ subsample_factor - 1' here is needed so that
863  // the subsampled alignments have the same length as features
864  // subsampled with 'subsample-feats'.
865  int32 subsampled_time =
866  (cur_time_elapsed + conversion_shift) / subsample_factor;
867  cur_time_elapsed += old_lengths[i];
868  int32 next_subsampled_time =
869  (cur_time_elapsed + conversion_shift) / subsample_factor;
870  (*new_lengths)[i] = next_subsampled_time - subsampled_time;
871  }
872  bool changed = true;
873  while (changed) {
874  changed = false;
875  for (int32 i = 0; i < phone_sequence_length; i++) {
876  if ((*new_lengths)[i] < min_lengths[i]) {
877  changed = true;
878  // we need at least one extra frame.. just try to get one frame for now.
879  // Get it from the left or the right, depending which one has the closest
880  // availability of a 'spare' frame.
881  int32 min_distance = std::numeric_limits<int32>::max(),
882  best_other_phone_index = -1,
883  cur_distance = 0;
884  // first try to the left.
885  for (int32 j = i - 1; j >= 0; j--) {
886  if ((*new_lengths)[j] > min_lengths[j]) {
887  min_distance = cur_distance;
888  best_other_phone_index = j;
889  break;
890  } else {
891  cur_distance += (*new_lengths)[j];
892  }
893  }
894  // .. now to the right.
895  cur_distance = 0;
896  for (int32 j = i + 1; j < phone_sequence_length; j++) {
897  if ((*new_lengths)[j] > min_lengths[j]) {
898  if (cur_distance < min_distance) {
899  min_distance = cur_distance;
900  best_other_phone_index = j;
901  }
902  break;
903  } else {
904  cur_distance += (*new_lengths)[j];
905  }
906  }
907  if (best_other_phone_index == -1)
908  return false;
909  // assign an extra frame to this phone...
910  (*new_lengths)[i]++;
911  // and borrow it from the place that we found.
912  (*new_lengths)[best_other_phone_index]--;
913  }
914  }
915  }
916  return true;
917 }
kaldi::int32 int32

◆ ComputeNormalizingTransform() [1/2]

static void kaldi::ComputeNormalizingTransform ( const SpMatrix< Real > &  covar,
MatrixBase< Real > *  proj 
)
static

This function computes a projection matrix that when applied makes the covariance unit (i.e.

all 1).

Definition at line 46 of file plda.cc.

References TpMatrix< Real >::Cholesky(), MatrixBase< Real >::CopyFromTp(), TpMatrix< Real >::Invert(), kNoTrans, and PackedMatrix< Real >::NumRows().

Referenced by Plda::ApplyTransform(), ComputeLdaTransform(), and PldaEstimator::GetOutput().

47  {
48  int32 dim = covar.NumRows();
49  TpMatrix<Real> C(dim); // Cholesky of covar, covar = C C^T
50  C.Cholesky(covar);
51  C.Invert(); // The matrix that makes covar unit is C^{-1}, because
52  // C^{-1} covar C^{-T} = C^{-1} C C^T C^{-T} = I.
53  proj->CopyFromTp(C, kNoTrans); // set "proj" to C^{-1}.
54 }
kaldi::int32 int32

◆ ComputeNormalizingTransform() [2/2]

void kaldi::ComputeNormalizingTransform ( const SpMatrix< Real > &  covar,
Real  floor,
MatrixBase< Real > *  proj 
)

Definition at line 84 of file ivector-compute-lda.cc.

References MatrixBase< Real >::AddDiagVecMat(), VectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplyPow(), SpMatrix< Real >::Eig(), KALDI_WARN, kTrans, PackedMatrix< Real >::NumRows(), and SortSvd().

86  {
87  int32 dim = covar.NumRows();
88  Matrix<Real> U(dim, dim);
89  Vector<Real> s(dim);
90  covar.Eig(&s, &U);
91  // Sort eigvenvalues from largest to smallest.
92  SortSvd(&s, &U);
93  // Floor eigenvalues to a small positive value.
94  int32 num_floored;
95  floor *= s(0); // Floor relative to the largest eigenvalue
96  s.ApplyFloor(floor, &num_floored);
97  if (num_floored > 0) {
98  KALDI_WARN << "Floored " << num_floored << " eigenvalues of covariance "
99  << "to " << floor;
100  }
101  // Next two lines computes projection proj, such that
102  // proj * covar * proj^T = I.
103  s.ApplyPow(-0.5);
104  proj->AddDiagVecMat(1.0, s, U, kTrans, 0.0);
105 }
kaldi::int32 int32
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
Definition: qr.cc:433
A class for storing matrices.
Definition: kaldi-matrix.h:823
MatrixIndexT NumRows() const
#define KALDI_WARN
Definition: kaldi-error.h:150
A class representing a vector.
Definition: kaldi-vector.h:406
void AddDiagVecMat(const Real alpha, const VectorBase< Real > &v, const MatrixBase< Real > &M, MatrixTransposeType transM, Real beta=1.0)
*this = beta * *this + alpha * diag(v) * M [or M^T].
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.

◆ ComputePca() [1/2]

template void kaldi::ComputePca ( const MatrixBase< float > &  X,
MatrixBase< float > *  U,
MatrixBase< float > *  A,
bool  print_eigs,
bool  exact 
)

◆ ComputePca() [2/2]

template void kaldi::ComputePca ( const MatrixBase< double > &  X,
MatrixBase< double > *  U,
MatrixBase< double > *  A,
bool  print_eigs,
bool  exact 
)

◆ ComputeTreeMapping()

static void kaldi::ComputeTreeMapping ( const EventMap small_tree,
const EventMap big_tree,
const BuildTreeStatsType stats,
std::vector< int32 > *  leaf_map 
)
static

Definition at line 320 of file build-tree.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, EventMap::Map(), EventMap::MaxResult(), and SplitStatsByMap().

Referenced by BuildTreeTwoLevel().

323  {
324  std::vector<BuildTreeStatsType> split_stats_small; // stats split by small tree
325  int32 num_leaves_big = big_tree.MaxResult() + 1,
326  num_leaves_small = small_tree.MaxResult() + 1;
327  SplitStatsByMap(stats, small_tree, &split_stats_small);
328  KALDI_ASSERT(static_cast<int32>(split_stats_small.size()) <=
329  num_leaves_small);
330  leaf_map->clear();
331  leaf_map->resize(num_leaves_big, -1); // fill with -1.
332 
333  std::vector<int32> small_leaves_unseen; // a list of small leaves that had no stats..
334  // this is used as a workaround for when there are no stats at leaves...
335  // it's really an error condition and it will cause errors later (e.g. when
336  // you initialize your model), but at this point we will try to handle it
337  // gracefully.
338 
339  for (int32 i = 0; i < num_leaves_small; i++) {
340  if (static_cast<size_t>(i) >= split_stats_small.size() ||
341  split_stats_small[i].empty()) {
342  KALDI_WARN << "No stats mapping to " << i << " in small tree. "
343  << "Continuing but this is a serious error.";
344  small_leaves_unseen.push_back(i);
345  } else {
346  for (size_t j = 0; j < split_stats_small[i].size(); j++) {
347  int32 leaf = 0; // = 0 to keep compiler happy. Leaf in big tree.
348  bool ok = big_tree.Map(split_stats_small[i][j].first, &leaf);
349  if (!ok)
350  KALDI_ERR << "Could not map stats with big tree: probable code error.";
351  if (leaf < 0 || leaf >= num_leaves_big)
352  KALDI_ERR << "Leaf out of range: " << leaf << " vs. " << num_leaves_big;
353  if ((*leaf_map)[leaf] != -1 && (*leaf_map)[leaf] != i)
354  KALDI_ERR << "Inconsistent mapping for big tree: "
355  << i << " vs. " << (*leaf_map)[leaf];
356  (*leaf_map)[leaf] = i;
357  }
358  }
359  }
360  // Now make sure that all leaves in the big tree have a leaf in the small tree
361  // assigned to them. If not we try to clean up... this should never normally
362  // happen and if it does it's due to trying to assign tree roots to unseen phones,
363  // which will anyway cause an error in a later stage of system building.
364  for (int32 leaf = 0; leaf < num_leaves_big; leaf++) {
365  int32 small_leaf = (*leaf_map)[leaf];
366  if (small_leaf == -1) {
367  KALDI_WARN << "In ComputeTreeMapping, could not get mapping from leaf "
368  << leaf;
369  if (!small_leaves_unseen.empty()) {
370  small_leaf = small_leaves_unseen.back();
371  KALDI_WARN << "Assigning it to unseen small-tree leaf " << small_leaf;
372  small_leaves_unseen.pop_back();
373  (*leaf_map)[leaf] = small_leaf;
374  } else {
375  KALDI_WARN << "Could not find any unseen small-tree leaf to assign "
376  << "it to. Making it zero, but this is bad. ";
377  (*leaf_map)[leaf] = 0;
378  }
379  } else if (small_leaf < 0 || small_leaf >= num_leaves_small)
380  KALDI_ERR << "Leaf in leaf mapping out of range: for big-map leaf "
381  << leaf << ", mapped to " << small_leaf << ", vs. "
382  << num_leaves_small;
383  }
384 }
void SplitStatsByMap(const BuildTreeStatsType &stats, const EventMap &e, std::vector< BuildTreeStatsType > *stats_out)
Splits stats according to the EventMap, indexing them at output by the leaf type. ...
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeVadEnergy()

void ComputeVadEnergy ( const VadEnergyOptions opts,
const MatrixBase< BaseFloat > &  input_features,
Vector< BaseFloat > *  output_voiced 
)

Compute voice-activity vector for a file: 1 if we judge the frame as voiced, 0 otherwise.

There are no continuity constraints. This method is a very simple energy-based method which only looks at the first coefficient of "input_features", which is assumed to be a log-energy or something similar. A cutoff is set– we use a formula of the general type: cutoff = 5.0 + 0.5 * (average log-energy in this file), and for each frame the decision is based on the proportion of frames in a context window around the current frame, which are above this cutoff.

Definition at line 27 of file voice-activity-detection.cc.

References VectorBase< Real >::CopyColFromMat(), VectorBase< Real >::Data(), KALDI_ASSERT, KALDI_WARN, MatrixBase< Real >::NumRows(), Vector< Real >::Resize(), VectorBase< Real >::Sum(), VadEnergyOptions::vad_energy_mean_scale, VadEnergyOptions::vad_energy_threshold, VadEnergyOptions::vad_frames_context, and VadEnergyOptions::vad_proportion_threshold.

Referenced by main(), and VadEnergyOptions::Register().

29  {
30  int32 T = feats.NumRows();
31  output_voiced->Resize(T);
32  if (T == 0) {
33  KALDI_WARN << "Empty features";
34  return;
35  }
36  Vector<BaseFloat> log_energy(T);
37  log_energy.CopyColFromMat(feats, 0); // column zero is log-energy.
38 
39  BaseFloat energy_threshold = opts.vad_energy_threshold;
40  if (opts.vad_energy_mean_scale != 0.0) {
41  KALDI_ASSERT(opts.vad_energy_mean_scale > 0.0);
42  energy_threshold += opts.vad_energy_mean_scale * log_energy.Sum() / T;
43  }
44 
45  KALDI_ASSERT(opts.vad_frames_context >= 0);
46  KALDI_ASSERT(opts.vad_proportion_threshold > 0.0 &&
47  opts.vad_proportion_threshold < 1.0);
48  for (int32 t = 0; t < T; t++) {
49  const BaseFloat *log_energy_data = log_energy.Data();
50  int32 num_count = 0, den_count = 0, context = opts.vad_frames_context;
51  for (int32 t2 = t - context; t2 <= t + context; t2++) {
52  if (t2 >= 0 && t2 < T) {
53  den_count++;
54  if (log_energy_data[t2] > energy_threshold)
55  num_count++;
56  }
57  }
58  if (num_count >= den_count * opts.vad_proportion_threshold)
59  (*output_voiced)(t) = 1.0;
60  else
61  (*output_voiced)(t) = 0.0;
62  }
63 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ConcatFeats()

void kaldi::ConcatFeats ( const std::vector< Matrix< BaseFloat > > &  in,
Matrix< BaseFloat > *  out 
)

Definition at line 35 of file concat-feats.cc.

References rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::Range(), and Matrix< Real >::Resize().

Referenced by main().

36  {
37  KALDI_ASSERT(in.size() >= 1);
38  int32 tot_len = in[0].NumRows(),
39  dim = in[0].NumCols();
40  for (int32 i = 1; i < in.size(); i++) {
41  KALDI_ASSERT(in[i].NumCols() == dim);
42  tot_len += in[i].NumRows();
43  }
44  out->Resize(tot_len, dim);
45  int32 len_offset = 0;
46  for (int32 i = 0; i < in.size(); i++) {
47  int32 this_len = in[i].NumRows();
48  out->Range(len_offset, this_len, 0, dim).CopyFromMat(
49  in[i]);
50  len_offset += this_len;
51  }
52 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ ContainsNullPointers()

bool kaldi::ContainsNullPointers ( const std::vector< A *> &  v)

Returns true if the vector of pointers contains NULL pointers.

Definition at line 197 of file stl-utils.h.

Referenced by ClusterBottomUp(), ClusterBottomUpCompartmentalized(), ClusterKMeans(), RefineClusters(), TestContainsNullPointers(), and TreeCluster().

197  {
198  typename std::vector<A*>::const_iterator iter = v.begin(), end = v.end();
199  for (; iter != end; ++iter)
200  if (*iter == static_cast<A*> (NULL)) return true;
201  return false;
202 }

◆ ConvertAddShiftComponent()

nnet2::Component* kaldi::ConvertAddShiftComponent ( const nnet1::Component nnet1_component)

Definition at line 99 of file nnet1-to-raw-nnet.cc.

References AddShift::GetParams(), FixedBiasComponent::Init(), KALDI_ASSERT, and AddShift::NumParams().

Referenced by ConvertComponent().

100  {
101  const nnet1::AddShift *add_shift =
102  dynamic_cast<const nnet1::AddShift*>(&nnet1_component);
103  KALDI_ASSERT(add_shift != NULL);
104  Vector<BaseFloat> bias(add_shift->NumParams());
105 
106  add_shift->GetParams(&bias);
107  CuVector<BaseFloat> cu_bias(bias);
108 
110  res->Init(cu_bias);
111  return res;
112 }
void Init(const CuVectorBase< BaseFloat > &scales)
void GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,.
Definition: nnet-various.h:344
int32 NumParams() const
Number of trainable parameters,.
Definition: nnet-various.h:337
Adds shift to all the lines of the matrix (can be used for global mean normalization) ...
Definition: nnet-various.h:291
FixedBiasComponent applies a fixed per-element bias; it&#39;s similar to the AddShift component in the nn...
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ConvertAffineTransformComponent()

nnet2::Component* kaldi::ConvertAffineTransformComponent ( const nnet1::Component nnet1_component,
const bool  use_preconditioned_affine_component 
)

Definition at line 32 of file nnet1-to-raw-nnet.cc.

References AffineTransform::GetBias(), AffineTransform::GetLinearity(), and KALDI_ASSERT.

Referenced by ConvertComponent().

34  {
35  const nnet1::AffineTransform *affine =
36  dynamic_cast<const nnet1::AffineTransform*>(&nnet1_component);
37  KALDI_ASSERT(affine != NULL);
38  // default learning rate is 1.0e-05, you can use the --learning-rate or
39  // --learning-rates option to nnet-am-copy to change it if you need.
40  BaseFloat learning_rate = 1.0e-05;
41  if (use_preconditioned_affine_component) {
42  int32 rank_in = 20,
43  rank_out = 80,
44  update_period = 4;
45  BaseFloat num_samples_history = 2000.,
46  alpha = 4.;
49  affine->GetBias(),
50  learning_rate),
51  rank_in,
52  rank_out,
53  update_period,
54  num_samples_history,
55  alpha);
56  } else {
57  return new nnet2::AffineComponent(affine->GetLinearity(),
58  affine->GetBias(),
59  learning_rate);
60  }
61 }
const CuMatrixBase< BaseFloat > & GetLinearity() const
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const CuVectorBase< BaseFloat > & GetBias() const
Accessors to the component parameters,.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Keywords: natural gradient descent, NG-SGD, naturalgradient.

◆ ConvertAlignmentForPhone()

static void kaldi::ConvertAlignmentForPhone ( const TransitionModel old_trans_model,
const TransitionModel new_trans_model,
const ContextDependencyInterface new_ctx_dep,
const std::vector< int32 > &  old_phone_alignment,
const std::vector< int32 > &  new_phone_window,
bool  old_is_reordered,
bool  new_is_reordered,
std::vector< int32 > *  new_phone_alignment 
)
inlinestatic

This function is used internally inside ConvertAlignment; it converts the alignment for a single phone.

'new_phone_window' is the window of phones as required by the tree. The size of 'new_phone_alignment' is the length requested, which may not always equal 'old_phone_alignment' (in case the 'subsample' value is not 1).

Definition at line 742 of file hmm-utils.cc.

References ContextDependencyInterface::CentralPosition(), ChangeReorderingOfAlignment(), ContextDependencyInterface::Compute(), GetRandomAlignmentForPhone(), TransitionModel::GetTopo(), rnnlm::j, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, TransitionModel::PairToTransitionId(), HmmTopology::TopologyForPhone(), TransitionModel::TransitionIdToHmmState(), TransitionModel::TransitionIdToPhone(), TransitionModel::TransitionIdToTransitionIndex(), TransitionModel::TransitionIdToTransitionState(), TransitionModel::TransitionStateToForwardPdfClass(), TransitionModel::TransitionStateToSelfLoopPdfClass(), TransitionModel::TupleToTransitionState(), and WriteIntegerVector().

Referenced by ConvertAlignmentInternal().

750  {
751  int32 alignment_size = old_phone_alignment.size();
752  static bool warned_topology = false;
753  int32 P = new_ctx_dep.CentralPosition(),
754  old_central_phone = old_trans_model.TransitionIdToPhone(
755  old_phone_alignment[0]),
756  new_central_phone = new_phone_window[P];
757  const HmmTopology &old_topo = old_trans_model.GetTopo(),
758  &new_topo = new_trans_model.GetTopo();
759 
760  bool topology_mismatch = !(old_topo.TopologyForPhone(old_central_phone) ==
761  new_topo.TopologyForPhone(new_central_phone));
762  if (topology_mismatch) {
763  if (!warned_topology) {
764  warned_topology = true;
765  KALDI_WARN << "Topology mismatch detected; automatically converting. "
766  << "Won't warn again.";
767  }
768  }
769  bool length_mismatch =
770  (new_phone_alignment->size() != old_phone_alignment.size());
771  if (length_mismatch || topology_mismatch) {
772  // We generate a random path from this FST, ignoring the
773  // old alignment.
774  GetRandomAlignmentForPhone(new_ctx_dep, new_trans_model,
775  new_phone_window, new_phone_alignment);
776  if (new_is_reordered)
777  ChangeReorderingOfAlignment(new_trans_model, new_phone_alignment);
778  return;
779  }
780 
781  KALDI_ASSERT(!old_phone_alignment.empty());
782 
783  int32 new_num_pdf_classes = new_topo.NumPdfClasses(new_central_phone);
784  std::vector<int32> pdf_ids(new_num_pdf_classes); // Indexed by pdf-class
785  for (int32 pdf_class = 0; pdf_class < new_num_pdf_classes; pdf_class++) {
786  if (!new_ctx_dep.Compute(new_phone_window, pdf_class,
787  &(pdf_ids[pdf_class]))) {
788  std::ostringstream ss;
789  WriteIntegerVector(ss, false, new_phone_window);
790  KALDI_ERR << "tree did not succeed in converting phone window "
791  << ss.str();
792  }
793  }
794 
795  // the topologies and lengths match -> we can directly transfer
796  // the alignment.
797  for (int32 j = 0; j < alignment_size; j++) {
798  int32 old_tid = old_phone_alignment[j],
799  old_tstate = old_trans_model.TransitionIdToTransitionState(old_tid);
800  int32 forward_pdf_class =
801  old_trans_model.TransitionStateToForwardPdfClass(old_tstate),
802  self_loop_pdf_class =
803  old_trans_model.TransitionStateToSelfLoopPdfClass(old_tstate);
804  int32 hmm_state = old_trans_model.TransitionIdToHmmState(old_tid);
805  int32 trans_idx = old_trans_model.TransitionIdToTransitionIndex(old_tid);
806  int32 new_forward_pdf = pdf_ids[forward_pdf_class];
807  int32 new_self_loop_pdf = pdf_ids[self_loop_pdf_class];
808  int32 new_trans_state =
809  new_trans_model.TupleToTransitionState(new_central_phone, hmm_state,
810  new_forward_pdf, new_self_loop_pdf);
811  int32 new_tid =
812  new_trans_model.PairToTransitionId(new_trans_state, trans_idx);
813  (*new_phone_alignment)[j] = new_tid;
814  }
815 
816  if (new_is_reordered != old_is_reordered)
817  ChangeReorderingOfAlignment(new_trans_model, new_phone_alignment);
818 }
void GetRandomAlignmentForPhone(const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const std::vector< int32 > &phone_window, std::vector< int32 > *alignment)
Definition: hmm-utils.cc:1207
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
void ChangeReorderingOfAlignment(const TransitionModel &trans_model, std::vector< int32 > *alignment)
Definition: hmm-utils.cc:1260

◆ ConvertAlignmentInternal()

static bool kaldi::ConvertAlignmentInternal ( const TransitionModel old_trans_model,
const TransitionModel new_trans_model,
const ContextDependencyInterface new_ctx_dep,
const std::vector< int32 > &  old_alignment,
int32  conversion_shift,
int32  subsample_factor,
bool  new_is_reordered,
const std::vector< int32 > *  phone_map,
std::vector< int32 > *  new_alignment 
)
static

This function is the same as 'ConvertAligment', but instead of the 'repeat_frames' option it supports the 'conversion_shift' option; see the documentation of ComputeNewPhoneLengths() for what 'conversion_shift' is for.

Definition at line 926 of file hmm-utils.cc.

References ContextDependencyInterface::CentralPosition(), ComputeNewPhoneLengths(), ContextDependencyInterface::ContextWidth(), ConvertAlignmentForPhone(), TransitionModel::GetTopo(), rnnlm::i, IsReordered(), KALDI_ASSERT, KALDI_ERR, KALDI_WARN, SplitToPhones(), and TransitionModel::TransitionIdToPhone().

Referenced by ConvertAlignment().

934  {
935  KALDI_ASSERT(0 <= conversion_shift && conversion_shift < subsample_factor);
936  bool old_is_reordered = IsReordered(old_trans_model, old_alignment);
937  KALDI_ASSERT(new_alignment != NULL);
938  new_alignment->clear();
939  new_alignment->reserve(old_alignment.size());
940  std::vector<std::vector<int32> > old_split; // split into phones.
941  if (!SplitToPhones(old_trans_model, old_alignment, &old_split))
942  return false;
943  int32 phone_sequence_length = old_split.size();
944  std::vector<int32> mapped_phones(phone_sequence_length);
945  for (size_t i = 0; i < phone_sequence_length; i++) {
946  KALDI_ASSERT(!old_split[i].empty());
947  mapped_phones[i] = old_trans_model.TransitionIdToPhone(old_split[i][0]);
948  if (phone_map != NULL) { // Map the phone sequence.
949  int32 sz = phone_map->size();
950  if (mapped_phones[i] < 0 || mapped_phones[i] >= sz ||
951  (*phone_map)[mapped_phones[i]] == -1)
952  KALDI_ERR << "ConvertAlignment: could not map phone " << mapped_phones[i];
953  mapped_phones[i] = (*phone_map)[mapped_phones[i]];
954  }
955  }
956 
957  // the sizes of each element of 'new_split' indicate the length of alignment
958  // that we want for each phone in the new sequence.
959  std::vector<std::vector<int32> > new_split(phone_sequence_length);
960  if (subsample_factor == 1 &&
961  old_trans_model.GetTopo() == new_trans_model.GetTopo()) {
962  // we know the old phone lengths will be fine.
963  for (size_t i = 0; i < phone_sequence_length; i++)
964  new_split[i].resize(old_split[i].size());
965  } else {
966  // .. they may not be fine.
967  std::vector<int32> old_lengths(phone_sequence_length), new_lengths;
968  for (int32 i = 0; i < phone_sequence_length; i++)
969  old_lengths[i] = old_split[i].size();
970  if (!ComputeNewPhoneLengths(new_trans_model.GetTopo(),
971  mapped_phones, old_lengths, conversion_shift,
972  subsample_factor, &new_lengths)) {
973  KALDI_WARN << "Failed to produce suitable phone lengths";
974  return false;
975  }
976  for (int32 i = 0; i < phone_sequence_length; i++)
977  new_split[i].resize(new_lengths[i]);
978  }
979 
980  int32 N = new_ctx_dep.ContextWidth(),
981  P = new_ctx_dep.CentralPosition();
982 
983  // by starting at -N and going to phone_sequence_length + N, we're
984  // being generous and not bothering to work out the exact
985  // array bounds.
986  for (int32 win_start = -N;
987  win_start < static_cast<int32>(phone_sequence_length + N);
988  win_start++) { // start of a context window.
989  int32 central_pos = win_start + P;
990  if (static_cast<size_t>(central_pos) < phone_sequence_length) {
991  // i.e. if (central_pos >= 0 && central_pos < phone_sequence_length)
992  std::vector<int32> new_phone_window(N, 0);
993  for (int32 offset = 0; offset < N; offset++)
994  if (static_cast<size_t>(win_start+offset) < phone_sequence_length)
995  new_phone_window[offset] = mapped_phones[win_start+offset];
996  const std::vector<int32> &old_alignment_for_phone = old_split[central_pos];
997  std::vector<int32> &new_alignment_for_phone = new_split[central_pos];
998 
999  ConvertAlignmentForPhone(old_trans_model, new_trans_model, new_ctx_dep,
1000  old_alignment_for_phone, new_phone_window,
1001  old_is_reordered, new_is_reordered,
1002  &new_alignment_for_phone);
1003  new_alignment->insert(new_alignment->end(),
1004  new_alignment_for_phone.begin(),
1005  new_alignment_for_phone.end());
1006  }
1007  }
1008  KALDI_ASSERT(new_alignment->size() ==
1009  (old_alignment.size() + conversion_shift)/subsample_factor);
1010  return true;
1011 }
static bool IsReordered(const TransitionModel &trans_model, const std::vector< int32 > &alignment)
Definition: hmm-utils.cc:625
kaldi::int32 int32
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
Definition: hmm-utils.cc:723
static bool ComputeNewPhoneLengths(const HmmTopology &topology, const std::vector< int32 > &mapped_phones, const std::vector< int32 > &old_lengths, int32 conversion_shift, int32 subsample_factor, std::vector< int32 > *new_lengths)
This function, called from ConvertAlignmentInternal(), works out suitable new lengths of phones in th...
Definition: hmm-utils.cc:849
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
static void ConvertAlignmentForPhone(const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_phone_alignment, const std::vector< int32 > &new_phone_window, bool old_is_reordered, bool new_is_reordered, std::vector< int32 > *new_phone_alignment)
This function is used internally inside ConvertAlignment; it converts the alignment for a single phon...
Definition: hmm-utils.cc:742
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ConvertCompactLatticeToPhones()

void ConvertCompactLatticeToPhones ( const TransitionModel trans_model,
CompactLattice clat 
)

Given a lattice, and a transition model to map pdf-ids to phones, replace the sequences of transition-ids with sequences of phones.

Note that this is different from ConvertLatticeToPhones, in that we replace the transition-ids not the words.

Definition at line 700 of file lattice-functions.cc.

References TransitionModel::IsFinal(), and TransitionModel::TransitionIdToPhone().

Referenced by main().

701  {
702  typedef CompactLatticeArc Arc;
703  typedef Arc::Weight Weight;
704  int32 num_states = clat->NumStates();
705  for (int32 state = 0; state < num_states; state++) {
706  for (fst::MutableArcIterator<CompactLattice> aiter(clat, state);
707  !aiter.Done();
708  aiter.Next()) {
709  Arc arc(aiter.Value());
710  std::vector<int32> phone_seq;
711  const std::vector<int32> &tid_seq = arc.weight.String();
712  for (std::vector<int32>::const_iterator iter = tid_seq.begin();
713  iter != tid_seq.end(); ++iter) {
714  if (trans.IsFinal(*iter))// note: there is one of these per phone...
715  phone_seq.push_back(trans.TransitionIdToPhone(*iter));
716  }
717  arc.weight.SetString(phone_seq);
718  aiter.SetValue(arc);
719  } // end looping over arcs
720  Weight f = clat->Final(state);
721  if (f != Weight::Zero()) {
722  std::vector<int32> phone_seq;
723  const std::vector<int32> &tid_seq = f.String();
724  for (std::vector<int32>::const_iterator iter = tid_seq.begin();
725  iter != tid_seq.end(); ++iter) {
726  if (trans.IsFinal(*iter))// note: there is one of these per phone...
727  phone_seq.push_back(trans.TransitionIdToPhone(*iter));
728  }
729  f.SetString(phone_seq);
730  clat->SetFinal(state, f);
731  }
732  } // end looping over states
733 }
kaldi::int32 int32
fst::StdArc::Weight Weight
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ ConvertComponent()

nnet2::Component* kaldi::ConvertComponent ( const nnet1::Component nnet1_component,
const bool  use_preconditioned_affine_component 
)

Definition at line 130 of file nnet1-to-raw-nnet.cc.

References ConvertAddShiftComponent(), ConvertAffineTransformComponent(), ConvertRescaleComponent(), ConvertSigmoidComponent(), ConvertSoftmaxComponent(), ConvertSpliceComponent(), Component::GetType(), Component::kAddShift, Component::kAffineTransform, KALDI_ERR, Component::kRescale, Component::kSigmoid, Component::kSoftmax, Component::kSplice, and Component::TypeToMarker().

Referenced by ConvertNnet1ToNnet2().

131  {
132  nnet1::Component::ComponentType type_in = nnet1_component.GetType();
133  switch (type_in) {
134  case nnet1::Component::kAffineTransform:
135  return ConvertAffineTransformComponent(nnet1_component,
136  use_preconditioned_affine_component);
137  case nnet1::Component::kSoftmax:
138  return ConvertSoftmaxComponent(nnet1_component);
139  case nnet1::Component::kSigmoid:
140  return ConvertSigmoidComponent(nnet1_component);
141  case nnet1::Component::kSplice:
142  return ConvertSpliceComponent(nnet1_component); // note, this will for now only handle the
143  // special case nnet1::Component::where all splice indexes in nnet1_component are contiguous, e.g.
144  // -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 .
145  case nnet1::Component::kAddShift:
146  return ConvertAddShiftComponent(nnet1_component); // convert to FixedBiasComponent
147  case nnet1::Component::kRescale:
148  return ConvertRescaleComponent(nnet1_component); // convert to FixedScaleComponent
149  default: KALDI_ERR << "Un-handled nnet1 component type "
150  << nnet1::Component::TypeToMarker(type_in);
151  return NULL;
152  }
153 }
nnet2::Component * ConvertSoftmaxComponent(const nnet1::Component &nnet1_component)
ComponentType
Component type identification mechanism,.
nnet2::Component * ConvertSpliceComponent(const nnet1::Component &nnet1_component)
nnet2::Component * ConvertRescaleComponent(const nnet1::Component &nnet1_component)
#define KALDI_ERR
Definition: kaldi-error.h:147
nnet2::Component * ConvertAddShiftComponent(const nnet1::Component &nnet1_component)
nnet2::Component * ConvertAffineTransformComponent(const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)
virtual ComponentType GetType() const =0
Get Type Identification of the component,.
nnet2::Component * ConvertSigmoidComponent(const nnet1::Component &nnet1_component)

◆ ConvertIntToString()

std::string kaldi::ConvertIntToString ( const int &  number)

Definition at line 38 of file pitch-functions-test.cc.

Referenced by UnitTestComputeGPE(), UnitTestDiffSampleRate(), UnitTestKeele(), UnitTestKeeleNccfBallast(), UnitTestPenaltyFactor(), UnitTestPitchExtractionSpeed(), UnitTestPitchExtractorCompareKeele(), and UnitTestProcess().

38  {
39  std::stringstream ss; // create a stringstream
40  ss << number; // add number to the stream
41  return ss.str(); // return a string with the contents of the stream
42 }

◆ ConvertLatticeToPhones()

void ConvertLatticeToPhones ( const TransitionModel trans_model,
Lattice lat 
)

Given a lattice, and a transition model to map pdf-ids to phones, replace the output symbols (presumably words), with phones; we use the TransitionModel to work out the phone sequence.

Note that the phone labels are not exactly aligned with the phone boundaries. We put a phone label to coincide with any transition to the final, nonemitting state of a phone (this state always exists, we ensure this in HmmTopology::Check()). This would be the last transition-id in the phone if reordering is not done (but typically we do reorder). Also see PhoneAlignLattice, in phone-align-lattice.h.

Definition at line 423 of file lattice-functions.cc.

References TransitionModel::IsSelfLoop(), TransitionModel::TransitionIdToHmmState(), and TransitionModel::TransitionIdToPhone().

Referenced by main().

424  {
425  typedef LatticeArc Arc;
426  int32 num_states = lat->NumStates();
427  for (int32 state = 0; state < num_states; state++) {
428  for (fst::MutableArcIterator<Lattice> aiter(lat, state); !aiter.Done();
429  aiter.Next()) {
430  Arc arc(aiter.Value());
431  arc.olabel = 0; // remove any word.
432  if ((arc.ilabel != 0) // has a transition-id on input..
433  && (trans.TransitionIdToHmmState(arc.ilabel) == 0)
434  && (!trans.IsSelfLoop(arc.ilabel))) {
435  // && trans.IsFinal(arc.ilabel)) // there is one of these per phone...
436  arc.olabel = trans.TransitionIdToPhone(arc.ilabel);
437  }
438  aiter.SetValue(arc);
439  } // end looping over arcs
440  } // end looping over states
441 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
kaldi::int32 int32

◆ ConvertLatticeToUnweightedAcceptor()

void kaldi::ConvertLatticeToUnweightedAcceptor ( const kaldi::Lattice ilat,
const LabelPairVector wildcards,
fst::StdVectorFst ofst 
)

Definition at line 63 of file lattice-oracle.cc.

References fst::ConvertLattice().

Referenced by main().

65  {
66  // first convert from lattice to normal FST
67  fst::ConvertLattice(ilat, ofst);
68  // remove weights, project to output, sort according to input arg
69  fst::Map(ofst, fst::RmWeightMapper<fst::StdArc>());
70  fst::Project(ofst, fst::PROJECT_OUTPUT); // The words are on the output side
71  fst::Relabel(ofst, wildcards, wildcards);
72  fst::RmEpsilon(ofst); // Don't tolerate epsilons as they make it hard to
73  // tally errors
74  fst::ArcSort(ofst, fst::StdILabelCompare());
75 }
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.

◆ ConvertNnet1ToNnet2()

nnet2::Nnet* kaldi::ConvertNnet1ToNnet2 ( const nnet1::Nnet nnet1,
const bool  use_preconditioned_affine_component 
)

Definition at line 156 of file nnet1-to-raw-nnet.cc.

References ConvertComponent(), Nnet::GetComponent(), rnnlm::i, and Nnet::NumComponents().

Referenced by main().

157  {
158  // get a vector of nnet2::Component pointers and initialize the nnet2::Nnet with it.
159  size_t size = nnet1.NumComponents();
160  std::vector<nnet2::Component*> *components = new std::vector<nnet2::Component*>();
161  components->resize(size);
162  for (size_t i = 0; i < size; i++) {
163  (*components)[i] = ConvertComponent(nnet1.GetComponent(i),
164  use_preconditioned_affine_component);
165  }
166 
167  nnet2::Nnet *res = new nnet2::Nnet();
168  res->Init(components);
169  delete components;
170  return res;
171 }
int32 NumComponents() const
Returns the number of &#39;Components&#39; which form the NN.
Definition: nnet-nnet.h:66
const Component & GetComponent(int32 c) const
Component accessor,.
Definition: nnet-nnet.cc:153
nnet2::Component * ConvertComponent(const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)

◆ ConvertPostToGaussInfo()

static void kaldi::ConvertPostToGaussInfo ( const std::vector< std::vector< std::pair< int32, BaseFloat > > > &  gauss_post,
std::unordered_map< int32, GaussInfo > *  gauss_info 
)
static

Definition at line 594 of file ivector-extractor.cc.

References GaussInfo::frame_weights, and GaussInfo::tot_weight.

Referenced by OnlineIvectorEstimationStats::AccStats().

596  {
597  int32 num_frames = gauss_post.size();
598  for (int32 t = 0; t < num_frames; t++) {
599  const std::vector<std::pair<int32, BaseFloat> > &this_post = gauss_post[t];
600  auto iter = this_post.begin(), end = this_post.end();
601  for (; iter != end; ++iter) {
602  int32 gauss_idx = iter->first;
603  GaussInfo &info = (*gauss_info)[gauss_idx];
604  BaseFloat weight = iter->second;
605  info.tot_weight += weight;
606  info.frame_weights.push_back(std::pair<int32, BaseFloat>(t, weight));
607  }
608  }
609 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29

◆ ConvertRescaleComponent()

nnet2::Component* kaldi::ConvertRescaleComponent ( const nnet1::Component nnet1_component)

Definition at line 114 of file nnet1-to-raw-nnet.cc.

References Rescale::GetParams(), FixedScaleComponent::Init(), KALDI_ASSERT, and Rescale::NumParams().

Referenced by ConvertComponent().

115  {
116  const nnet1::Rescale *rescale =
117  dynamic_cast<const nnet1::Rescale*>(&nnet1_component);
118  KALDI_ASSERT(rescale != NULL);
119 
120  Vector<BaseFloat> scale(rescale->NumParams());
121  rescale->GetParams(&scale);
122 
123  CuVector<BaseFloat> cu_scale(scale);
124 
126  res->Init(cu_scale);
127  return res;
128 }
Rescale the data column-wise by a vector (can be used for global variance normalization) ...
Definition: nnet-various.h:404
FixedScaleComponent applies a fixed per-element scale; it&#39;s similar to the Rescale component in the n...
void GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,.
Definition: nnet-various.h:457
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Init(const CuVectorBase< BaseFloat > &scales)
int32 NumParams() const
Number of trainable parameters,.
Definition: nnet-various.h:450

◆ ConvertSigmoidComponent()

nnet2::Component* kaldi::ConvertSigmoidComponent ( const nnet1::Component nnet1_component)

Definition at line 71 of file nnet1-to-raw-nnet.cc.

References Component::InputDim(), and KALDI_ASSERT.

Referenced by ConvertComponent().

72  {
73  const nnet1::Sigmoid *sigmoid =
74  dynamic_cast<const nnet1::Sigmoid*>(&nnet1_component);
75  KALDI_ASSERT(sigmoid != NULL);
76  return new nnet2::SigmoidComponent(sigmoid->InputDim());
77 }
int32 InputDim() const
Get the dimension of the input,.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ConvertSoftmaxComponent()

nnet2::Component* kaldi::ConvertSoftmaxComponent ( const nnet1::Component nnet1_component)

Definition at line 63 of file nnet1-to-raw-nnet.cc.

References Component::InputDim(), and KALDI_ASSERT.

Referenced by ConvertComponent().

64  {
65  const nnet1::Softmax *softmax =
66  dynamic_cast<const nnet1::Softmax*>(&nnet1_component);
67  KALDI_ASSERT(softmax != NULL);
68  return new nnet2::SoftmaxComponent(softmax->InputDim());
69 }
int32 InputDim() const
Get the dimension of the input,.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ConvertSpliceComponent()

nnet2::Component* kaldi::ConvertSpliceComponent ( const nnet1::Component nnet1_component)

Definition at line 79 of file nnet1-to-raw-nnet.cc.

References SpliceComponent::Init(), Component::InputDim(), KALDI_ASSERT, ReadIntegerVector(), and Splice::WriteData().

Referenced by ConvertComponent().

80  {
81  const nnet1::Splice *splice =
82  dynamic_cast<const nnet1::Splice*>(&nnet1_component);
83  KALDI_ASSERT(splice != NULL);
84 // int32 low, high;
85  std::vector<int32> frame_offsets;
86 
87  std::ostringstream ostr;
88  splice->WriteData(ostr, false);
89 
90  std::istringstream istr(ostr.str());
91  ReadIntegerVector(istr, false, &frame_offsets);
92 
94  res->Init(splice->InputDim(), frame_offsets);
95  return res;
96 }
void Init(int32 input_dim, std::vector< int32 > context, int32 const_component_dim=0)
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
Splices the time context of the input features in N, out k*N, FrameOffset o_1,o_2,...,o_k FrameOffset example 11frames: -5 -4 -3 -2 -1 0 1 2 3 4 5.
Definition: nnet-various.h:42
int32 InputDim() const
Get the dimension of the input,.
void WriteData(std::ostream &os, bool binary) const
Writes the component content.
Definition: nnet-various.h:94
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Splices a context window of frames together [over time].

◆ ConvertStringToInteger()

bool kaldi::ConvertStringToInteger ( const std::string &  str,
Int *  out 
)

Converts a string into an integer via strtoll and returns false if there was any kind of problem (i.e.

the string was not an integer or contained extra non-whitespace junk, or the integer was too large to fit into the type it is being converted into). Only sets *out if everything was OK and it returns true.

Definition at line 118 of file text-utils.h.

References ConvertStringToReal(), rnnlm::i, IsLine(), IsToken(), KALDI_ASSERT_IS_INTEGER_TYPE, KALDI_STRTOLL, SplitStringOnFirstSpace(), StringsApproxEqual(), and Trim().

Referenced by ExampleMergingConfig::ComputeDerived(), ConfigLine::GetValue(), WordBoundaryInfo::Init(), MultiTaskLoss::InitFromString(), main(), GeneralDescriptor::ParseConst(), kaldi::nnet2::ParseFromString(), kaldi::nnet3::ProcessRangeFile(), ArpaFileParser::Read(), HmmTopology::Read(), fst::ReadFstKaldi(), kaldi::nnet3::ReadIntegerToken(), ReadPosterior(), LatticeReader::ReadText(), kaldi::nnet3::SelectFromExample(), Fmpe::SetContexts(), OffsetFileInputImpl::SplitFilename(), TestConvertStringToInteger(), ParseOptions::ToInt(), and ParseOptions::ToUint().

119  {
121  const char *this_str = str.c_str();
122  char *end = NULL;
123  errno = 0;
124  int64 i = KALDI_STRTOLL(this_str, &end);
125  if (end != this_str)
126  while (isspace(*end)) end++;
127  if (end == this_str || *end != '\0' || errno != 0)
128  return false;
129  Int iInt = static_cast<Int>(i);
130  if (static_cast<int64>(iInt) != i ||
131  (i < 0 && !std::numeric_limits<Int>::is_signed)) {
132  return false;
133  }
134  *out = iInt;
135  return true;
136 }
#define KALDI_ASSERT_IS_INTEGER_TYPE(I)
Definition: kaldi-utils.h:133
#define KALDI_STRTOLL(cur_cstr, end_cstr)
Definition: kaldi-utils.h:152

◆ ConvertStringToReal() [1/3]

bool ConvertStringToReal ( const std::string &  str,
T *  out 
)

ConvertStringToReal converts a string into either float or double and returns false if there was any kind of problem (i.e.

the string was not a floating point number or contained extra non-whitespace junk). Be careful- this function will successfully read inf's or nan's.

Definition at line 238 of file text-utils.cc.

References rnnlm::i.

Referenced by ConvertStringToInteger(), kaldi::nnet3::DescriptorTokenize(), ConfigLine::GetValue(), MultiTaskLoss::InitFromString(), main(), GeneralDescriptor::ParseConst(), kaldi::nnet2::ParseFromString(), GeneralDescriptor::ParseScale(), ArpaFileParser::Read(), ReadCommaSeparatedCommand(), Fmpe::SetContexts(), SplitStringToFloats(), TestConvertStringToReal(), TestInf(), TestNan(), ParseOptions::ToDouble(), and ParseOptions::ToFloat().

239  {
240  std::istringstream iss(str);
241 
242  NumberIstream<T> i(iss);
243 
244  i >> *out;
245 
246  if (iss.fail()) {
247  // Number conversion failed.
248  return false;
249  }
250 
251  return true;
252 }

◆ ConvertStringToReal() [2/3]

template bool kaldi::ConvertStringToReal ( const std::string &  str,
float out 
)

◆ ConvertStringToReal() [3/3]

template bool kaldi::ConvertStringToReal ( const std::string &  str,
double *  out 
)

◆ ConvertToCompactLattice() [1/2]

CompactLattice* kaldi::ConvertToCompactLattice ( fst::VectorFst< OrigWeightType > *  ifst)

Converts lattice types if necessary, deleting its input.

Definition at line 29 of file kaldi-lattice.cc.

References fst::ConvertLattice().

Referenced by ReadCompactLattice(), and ReadCompactLatticeText().

29  {
30  if (!ifst) return NULL;
31  CompactLattice *ofst = new CompactLattice();
32  ConvertLattice(*ifst, ofst);
33  delete ifst;
34  return ofst;
35 }
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46

◆ ConvertToCompactLattice() [2/2]

CompactLattice* kaldi::ConvertToCompactLattice ( CompactLattice ifst)

Definition at line 40 of file kaldi-lattice.cc.

40  {
41  return ifst;
42 }

◆ ConvertToLattice() [1/2]

Lattice* kaldi::ConvertToLattice ( fst::VectorFst< OrigWeightType > *  ifst)

Converts lattice types if necessary, deleting its input.

Definition at line 46 of file kaldi-lattice.cc.

References fst::ConvertLattice().

Referenced by ReadLattice(), and ReadLatticeText().

46  {
47  if (!ifst) return NULL;
48  Lattice *ofst = new Lattice();
49  ConvertLattice(*ifst, ofst);
50  delete ifst;
51  return ofst;
52 }
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44

◆ ConvertToLattice() [2/2]

Lattice* kaldi::ConvertToLattice ( Lattice ifst)

Definition at line 57 of file kaldi-lattice.cc.

57  {
58  return ifst;
59 }

◆ ConvolveSignals()

void ConvolveSignals ( const Vector< BaseFloat > &  filter,
Vector< BaseFloat > *  signal 
)

Definition at line 34 of file signal.cc.

References VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), rnnlm::i, rnnlm::j, Vector< Real >::Resize(), and VectorBase< Real >::SetZero().

Referenced by UnitTestFFTbasedConvolution().

34  {
35  int32 signal_length = signal->Dim();
36  int32 filter_length = filter.Dim();
37  int32 output_length = signal_length + filter_length - 1;
38  Vector<BaseFloat> signal_padded(output_length);
39  signal_padded.SetZero();
40  for (int32 i = 0; i < signal_length; i++) {
41  for (int32 j = 0; j < filter_length; j++) {
42  signal_padded(i + j) += (*signal)(i) * filter(j);
43  }
44  }
45  signal->Resize(output_length);
46  signal->CopyFromVec(signal_padded);
47 }
kaldi::int32 int32

◆ CopyMapKeysToSet()

void kaldi::CopyMapKeysToSet ( const std::map< A, B > &  m,
std::set< A > *  s 
)

Copies the keys in a map to a set.

Definition at line 150 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by TestCopyMapKeysToSet(), and TestFindAllKeys().

150  {
151  KALDI_ASSERT(s != NULL);
152  s->clear();
153  typename std::map<A, B>::const_iterator miter = m.begin(), mend = m.end();
154  for (; miter != mend; ++miter) {
155  s->insert(s->end(), miter->first);
156  }
157 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopyMapKeysToVector()

void kaldi::CopyMapKeysToVector ( const std::map< A, B > &  m,
std::vector< A > *  v 
)

Copies the keys in a map to a vector.

Definition at line 126 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by Questions::GetKeysWithQuestions(), TestCopyMapKeysToSet(), and TestCopyMapKeysToVector().

126  {
127  KALDI_ASSERT(v != NULL);
128  v->resize(m.size());
129  typename std::map<A, B>::const_iterator miter = m.begin(), mend = m.end();
130  typename std::vector<A>::iterator viter = v->begin();
131  for (; miter != mend; ++miter, ++viter) {
132  *viter = miter->first;
133  }
134 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopyMapToVector()

void kaldi::CopyMapToVector ( const std::map< A, B > &  m,
std::vector< std::pair< A, B > > *  v 
)

Copies the (key, value) pairs in a map to a vector of pairs.

Definition at line 112 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by GenRandStats(), TestCopyMapToVector(), TestFindAllKeys(), and TestPossibleValues().

113  {
114  KALDI_ASSERT(v != NULL);
115  v->resize(m.size());
116  typename std::map<A, B>::const_iterator miter = m.begin(), mend = m.end();
117  typename std::vector<std::pair<A, B> >::iterator viter = v->begin();
118  for (; miter != mend; ++miter, ++viter) {
119  *viter = std::make_pair(miter->first, miter->second);
120  // do it like this because of const casting.
121  }
122 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopyMapValuesToSet()

void kaldi::CopyMapValuesToSet ( const std::map< A, B > &  m,
std::set< B > *  s 
)

Copies the values in a map to a set.

Definition at line 161 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by TestCopyMapValuesToSet().

161  {
162  KALDI_ASSERT(s != NULL);
163  s->clear();
164  typename std::map<A, B>::const_iterator miter = m.begin(), mend = m.end();
165  for (; miter != mend; ++miter)
166  s->insert(s->end(), miter->second);
167 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopyMapValuesToVector()

void kaldi::CopyMapValuesToVector ( const std::map< A, B > &  m,
std::vector< B > *  v 
)

Copies the values in a map to a vector.

Definition at line 138 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by TestCopyMapValuesToSet(), and TestCopyMapValuesToVector().

138  {
139  KALDI_ASSERT(v != NULL);
140  v->resize(m.size());
141  typename std::map<A, B>::const_iterator miter = m.begin(), mend = m.end();
142  typename std::vector<B>::iterator viter = v->begin();
143  for (; miter != mend; ++miter, ++viter) {
144  *viter = miter->second;
145  }
146 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopySetToVector() [1/2]

void kaldi::CopySetToVector ( const std::set< T > &  s,
std::vector< T > *  v 
)

Copies the elements of a set to a vector.

Definition at line 86 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by ConstIntegerSet< EventValueType >::ConstIntegerSet(), fst::GetInputSymbols(), kaldi::nnet3::GetIoNames(), fst::GetOutputSymbols(), GetSeenPhones(), ConstIntegerSet< EventValueType >::Init(), PossibleValues(), RandomEventMap(), TestClusterEventMapRestricted(), fst::TestContextFst(), TestCopySetToVector(), TestEventMapIo(), TestFindAllKeys(), TestGenRandContextDependency(), TestMonophoneContextDependency(), TestPossibleValues(), TestQuestionsInitRand(), TestShareEventMapLeaves(), and TestSplitDecisionTree().

86  {
87  // copies members of s into v, in sorted order from lowest to highest
88  // (because the set was in sorted order).
89  KALDI_ASSERT(v != NULL);
90  v->resize(s.size());
91  typename std::set<T>::const_iterator siter = s.begin(), send = s.end();
92  typename std::vector<T>::iterator viter = v->begin();
93  for (; siter != send; ++siter, ++viter) {
94  *viter = *siter;
95  }
96 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopySetToVector() [2/2]

void kaldi::CopySetToVector ( const unordered_set< T > &  s,
std::vector< T > *  v 
)

Definition at line 99 of file stl-utils.h.

References KALDI_ASSERT.

99  {
100  KALDI_ASSERT(v != NULL);
101  v->resize(s.size());
102  typename unordered_set<T>::const_iterator siter = s.begin(), send = s.end();
103  typename std::vector<T>::iterator viter = v->begin();
104  for (; siter != send; ++siter, ++viter) {
105  *viter = *siter;
106  }
107 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopySubsetLattices() [1/2]

int32 kaldi::CopySubsetLattices ( std::string  filename,
SequentialLatticeReader lattice_reader,
LatticeWriter lattice_writer,
bool  include = true,
bool  ignore_missing = false,
bool  sorted = false 
)

Definition at line 28 of file lattice-copy.cc.

References SequentialTableReader< Holder >::Done(), KALDI_ASSERT, KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), SplitStringToVector(), Input::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

Referenced by main().

32  {
33  unordered_set<std::string, StringHasher> subset;
34  std::set<std::string> subset_list;
35 
36  bool binary;
37  Input ki(filename, &binary);
38  KALDI_ASSERT(!binary);
39  std::string line;
40  while (std::getline(ki.Stream(), line)) {
41  std::vector<std::string> split_line;
42  SplitStringToVector(line, " \t\r", true, &split_line);
43  if(split_line.empty()) {
44  KALDI_ERR << "Unable to parse line \"" << line << "\" encountered in input in " << filename;
45  }
46  subset.insert(split_line[0]);
47  subset_list.insert(split_line[0]);
48  }
49 
50  int32 num_total = 0;
51  size_t num_success = 0;
52  for (; !lattice_reader->Done(); lattice_reader->Next(), num_total++) {
53  if (include && sorted && subset_list.size() > 0
54  && lattice_reader->Key() > *(subset_list.rbegin())) {
55  KALDI_LOG << "The utterance " << lattice_reader->Key()
56  << " is larger than "
57  << "the last key in the include list. Not reading further.";
58  KALDI_LOG << "Wrote " << num_success << " utterances";
59  return 0;
60  }
61 
62  if (include && subset.count(lattice_reader->Key()) > 0) {
63  lattice_writer->Write(lattice_reader->Key(), lattice_reader->Value());
64  num_success++;
65  } else if (!include && subset.count(lattice_reader->Key()) == 0) {
66  lattice_writer->Write(lattice_reader->Key(), lattice_reader->Value());
67  num_success++;
68  }
69  }
70 
71  KALDI_LOG << "Wrote " << num_success << " out of " << num_total
72  << " utterances.";
73 
74  if (ignore_missing) return 0;
75 
76  return (num_success != 0 ? 0 : 1);
77  }
kaldi::int32 int32
void Write(const std::string &key, const T &value) const
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
Definition: text-utils.cc:63
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ CopySubsetLattices() [2/2]

int32 kaldi::CopySubsetLattices ( std::string  filename,
SequentialCompactLatticeReader lattice_reader,
CompactLatticeWriter lattice_writer,
bool  include = true,
bool  ignore_missing = false,
bool  sorted = false 
)

Definition at line 79 of file lattice-copy.cc.

References SequentialTableReader< Holder >::Done(), KALDI_ASSERT, KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), SplitStringToVector(), Input::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

83  {
84  unordered_set<std::string, StringHasher> subset;
85  std::set<std::string> subset_list;
86 
87  bool binary;
88  Input ki(filename, &binary);
89  KALDI_ASSERT(!binary);
90  std::string line;
91  while (std::getline(ki.Stream(), line)) {
92  std::vector<std::string> split_line;
93  SplitStringToVector(line, " \t\r", true, &split_line);
94  if(split_line.empty()) {
95  KALDI_ERR << "Unable to parse line \"" << line << "\" encountered in input in " << filename;
96  }
97  subset.insert(split_line[0]);
98  subset_list.insert(split_line[0]);
99  }
100 
101  int32 num_total = 0;
102  size_t num_success = 0;
103  for (; !lattice_reader->Done(); lattice_reader->Next(), num_total++) {
104  if (include && sorted && subset_list.size() > 0
105  && lattice_reader->Key() > *(subset_list.rbegin())) {
106  KALDI_LOG << "The utterance " << lattice_reader->Key()
107  << " is larger than "
108  << "the last key in the include list. Not reading further.";
109  KALDI_LOG << "Wrote " << num_success << " utterances";
110  return 0;
111  }
112 
113  if (include && subset.count(lattice_reader->Key()) > 0) {
114  lattice_writer->Write(lattice_reader->Key(), lattice_reader->Value());
115  num_success++;
116  } else if (!include && subset.count(lattice_reader->Key()) == 0) {
117  lattice_writer->Write(lattice_reader->Key(), lattice_reader->Value());
118  num_success++;
119  }
120  }
121 
122  KALDI_LOG << " Wrote " << num_success << " out of " << num_total
123  << " utterances.";
124 
125  if (ignore_missing) return 0;
126 
127  return (num_success != 0 ? 0 : 1);
128  }
kaldi::int32 int32
void Write(const std::string &key, const T &value) const
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
Definition: text-utils.cc:63
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ CopyVectorToSet()

void kaldi::CopyVectorToSet ( const std::vector< A > &  v,
std::set< A > *  s 
)

Copies the contents of a vector to a set.

Definition at line 172 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by kaldi::nnet3::ComputeCommandPairs(), TestCopyMapKeysToSet(), and TestCopyMapValuesToSet().

172  {
173  KALDI_ASSERT(s != NULL);
174  s->clear();
175  typename std::vector<A>::const_iterator iter = v.begin(), end = v.end();
176  for (; iter != end; ++iter)
177  s->insert(s->end(), *iter);
178  // s->end() is a hint in case v was sorted. will work regardless.
179 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CopyVectorToVector()

void kaldi::CopyVectorToVector ( const std::vector< A > &  vec_in,
std::vector< B > *  vec_out 
)

Copies the contents a vector of one type to a vector of another type.

Definition at line 207 of file stl-utils.h.

References rnnlm::i, and KALDI_ASSERT.

207  {
208  KALDI_ASSERT(vec_out != NULL);
209  vec_out->resize(vec_in.size());
210  for (size_t i = 0; i < vec_in.size(); i++)
211  (*vec_out)[i] = static_cast<B> (vec_in[i]);
212 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CountErrors()

void kaldi::CountErrors ( const fst::StdVectorFst fst,
int32 correct,
int32 substitutions,
int32 insertions,
int32 deletions,
int32 num_words 
)

Definition at line 114 of file lattice-oracle.cc.

References KALDI_ASSERT.

Referenced by main().

119  {
121  typedef fst::StdArc::Weight Weight;
122  *correct = *substitutions = *insertions = *deletions = *num_words = 0;
123 
124  // go through the first complete path in fst (there should be only one)
125  StateId src = fst.Start();
126  while (fst.Final(src)== Weight::Zero()) { // while not final
127  for (fst::ArcIterator<fst::StdVectorFst> aiter(fst, src);
128  !aiter.Done(); aiter.Next()) {
129  fst::StdArc arc = aiter.Value();
130  if (arc.ilabel == arc.olabel && arc.ilabel != 0) {
131  (*correct)++;
132  (*num_words)++;
133  } else if (arc.ilabel == 0 && arc.olabel != 0) {
134  (*deletions)++;
135  (*num_words)++;
136  } else if (arc.ilabel != 0 && arc.olabel == 0) {
137  (*insertions)++;
138  } else if (arc.ilabel != 0 && arc.olabel != 0) {
139  (*substitutions)++;
140  (*num_words)++;
141  } else {
142  KALDI_ASSERT(arc.ilabel == 0 && arc.olabel == 0);
143  }
144  src = arc.nextstate;
145  continue; // jump to next state
146  }
147  }
148 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CoverageTest()

bool kaldi::CoverageTest ( bool  seps,
const std::string &  infile 
)

Definition at line 119 of file arpa-lm-compiler-test.cc.

References AddSelfLoops(), Compile(), CreateGenFst(), ArpaLmCompiler::Fst(), rnnlm::i, KALDI_WARN, kRandomSentences, and ArpaLmCompiler::MutableFst().

Referenced by RunAllTests().

119  {
120  // Compile ARPA model.
121  ArpaLmCompiler* lm_compiler = Compile(seps, infile);
122 
123  // Create an FST that generates any sequence of symbols taken from the model
124  // output.
125  fst::StdVectorFst* genFst =
126  CreateGenFst(seps, lm_compiler->Fst().OutputSymbols());
127 
128  int num_successes = 0;
129  for (int32 i = 0; i < kRandomSentences; ++i) {
130  // Generate a random sentence FST.
131  fst::StdVectorFst sentence;
132  RandGen(*genFst, &sentence);
133  if (seps)
134  AddSelfLoops(&sentence);
135 
136  fst::ArcSort(lm_compiler->MutableFst(), fst::StdOLabelCompare());
137 
138  // The past must successfully compose with the LM FST.
139  fst::StdVectorFst composition;
140  Compose(sentence, lm_compiler->Fst(), &composition);
141  if (composition.Start() != fst::kNoStateId)
142  ++num_successes;
143  }
144 
145  delete genFst;
146  delete lm_compiler;
147 
148  bool ok = num_successes == kRandomSentences;
149  if (!ok) {
150  KALDI_WARN << "Coverage test failed on " << infile << ": composed "
151  << num_successes << "/" << kRandomSentences;
152  }
153  return ok;
154 }
void AddSelfLoops(fst::StdMutableFst *fst)
ArpaLmCompiler * Compile(bool seps, const std::string &infile)
static fst::StdVectorFst * CreateGenFst(bool seps, const fst::SymbolTable *pst)
kaldi::int32 int32
fst::StdVectorFst StdVectorFst
#define KALDI_WARN
Definition: kaldi-error.h:150
static const int kRandomSentences

◆ CreateEditDistance()

void kaldi::CreateEditDistance ( const fst::StdVectorFst fst1,
const fst::StdVectorFst fst2,
fst::StdVectorFst pfst 
)

Definition at line 77 of file lattice-oracle.cc.

References fst::GetInputSymbols(), fst::GetOutputSymbols(), rnnlm::i, and rnnlm::j.

Referenced by main().

79  {
80  typedef fst::StdArc StdArc;
82  typedef fst::StdArc::Label Label;
83  Weight correct_cost(0.0);
84  Weight substitution_cost(1.0);
85  Weight insertion_cost(1.0);
86  Weight deletion_cost(1.0);
87 
88  // create set of output symbols in fst1
89  std::vector<Label> fst1syms, fst2syms;
90  GetOutputSymbols(fst1, false /*no epsilons*/, &fst1syms);
91  GetInputSymbols(fst2, false /*no epsilons*/, &fst2syms);
92 
93  pfst->AddState();
94  pfst->SetStart(0);
95  for (size_t i = 0; i < fst1syms.size(); i++)
96  pfst->AddArc(0, StdArc(fst1syms[i], 0, deletion_cost, 0)); // deletions
97 
98  for (size_t i = 0; i < fst2syms.size(); i++)
99  pfst->AddArc(0, StdArc(0, fst2syms[i], insertion_cost, 0)); // insertions
100 
101  // stupid implementation O(N^2)
102  for (size_t i = 0; i < fst1syms.size(); i++) {
103  Label label1 = fst1syms[i];
104  for (size_t j = 0; j < fst2syms.size(); j++) {
105  Label label2 = fst2syms[j];
106  Weight cost(label1 == label2 ? correct_cost : substitution_cost);
107  pfst->AddArc(0, StdArc(label1, label2, cost, 0)); // substitutions
108  }
109  }
110  pfst->SetFinal(0, Weight::One());
111  ArcSort(pfst, fst::StdOLabelCompare());
112 }
fst::StdArc::Label Label
fst::StdArc StdArc
void GetInputSymbols(const Fst< Arc > &fst, bool include_eps, std::vector< I > *symbols)
GetInputSymbols gets the list of symbols on the input of fst (including epsilon, if include_eps == tr...
fst::StdArc::Weight Weight
void GetOutputSymbols(const Fst< Arc > &fst, bool include_eps, std::vector< I > *symbols)
GetOutputSymbols gets the list of symbols on the output of fst (including epsilon, if include_eps == true)

◆ CreateEigenvalueMatrix() [1/2]

template void kaldi::CreateEigenvalueMatrix ( const VectorBase< float > &  re,
const VectorBase< float > &  im,
MatrixBase< float > *  D 
)

◆ CreateEigenvalueMatrix() [2/2]

template void kaldi::CreateEigenvalueMatrix ( const VectorBase< double > &  re,
const VectorBase< double > &  im,
MatrixBase< double > *  D 
)

◆ CreateFactorTransducer()

bool CreateFactorTransducer ( const CompactLattice clat,
const std::vector< int32 > &  state_times,
int32  utterance_id,
KwsProductFst factor_transducer 
)

Definition at line 160 of file kws-functions.cc.

References ComputeCompactLatticeAlphas(), ComputeCompactLatticeBetas(), fst::ComputeStateInfo(), rnnlm::i, KALDI_WARN, fst::kStateHasEpsilonArcsEntering, fst::kStateHasEpsilonArcsLeaving, fst::kStateHasNonEpsilonArcsEntering, fst::kStateHasNonEpsilonArcsLeaving, and ArcticWeightTpl< T >::One().

Referenced by main().

163  {
164  using namespace fst;
166 
167  // We first compute the alphas and betas
168  bool success = false;
169  std::vector<double> alpha;
170  std::vector<double> beta;
171  success = ComputeCompactLatticeAlphas(clat, &alpha);
172  success = success && ComputeCompactLatticeBetas(clat, &beta);
173  if (!success)
174  return false;
175 
176  // Now we map the CompactLattice to VectorFst<KwsProductArc>. We drop the
177  // alignment information and only keep the negated log-probs
178  Map(clat, factor_transducer, CompactLatticeToKwsProductFstMapper());
179 
180  // Now do the weight pushing manually on the CompactLattice format. Note that
181  // the alphas and betas in Kaldi are stored as the log-probs, not the negated
182  // log-probs, so the equation for weight pushing is a little different from
183  // the original algorithm (pay attention to the sign). We push the weight to
184  // initial and remove the total weight, i.e., the sum of all the outgoing
185  // transitions and final weight at any state is equal to One() (push only the
186  // negated log-prob, not the alignments)
187  for (StateIterator<KwsProductFst>
188  siter(*factor_transducer); !siter.Done(); siter.Next()) {
189  KwsProductArc::StateId state_id = siter.Value();
190  for (MutableArcIterator<KwsProductFst>
191  aiter(factor_transducer, state_id); !aiter.Done(); aiter.Next()) {
192  KwsProductArc arc = aiter.Value();
193  BaseFloat w = arc.weight.Value1().Value();
194  w += beta[state_id] - beta[arc.nextstate];
195  KwsProductWeight weight(w, arc.weight.Value2());
196  arc.weight = weight;
197  aiter.SetValue(arc);
198  }
199  // Weight of final state
200  if (factor_transducer->Final(state_id) != KwsProductWeight::Zero()) {
201  BaseFloat w = factor_transducer->Final(state_id).Value1().Value();
202  w += beta[state_id];
203  KwsProductWeight weight(w, factor_transducer->Final(state_id).Value2());
204  factor_transducer->SetFinal(state_id, weight);
205  }
206  }
207 
208  // Modify the alphas and set betas to zero. After that, we get the alphas and
209  // betas for the pushed FST. Since I will not use beta anymore, here I don't
210  // set them to zero. This can be derived from the weight pushing formula.
211  for (int32 s = 0; s < alpha.size(); s++) {
212  alpha[s] += beta[s] - beta[0];
213 
214  if (alpha[s] > 0.1) {
215  KALDI_WARN << "Positive alpha " << alpha[s];
216  }
217  }
218 
219  // to understand the next part, look at the comment in
220  // ../kwsbin/lattice-to-kws-index.cc just above the call to
221  // EnsureEpsilonProperty(). We use the bool has_epsilon_property mainly to
222  // handle the case when someone comments out that call. It should always be
223  // true in the normal case.
224  std::vector<char> state_properties;
225  ComputeStateInfo(*factor_transducer, &state_properties);
226  bool has_epsilon_property = true;
227  for (size_t i = 0; i < state_properties.size(); i++) {
228  char c = state_properties[i];
229  if ((c & kStateHasEpsilonArcsEntering) != 0 &&
231  has_epsilon_property = false;
232  if ((c & kStateHasEpsilonArcsLeaving) != 0 &&
234  has_epsilon_property = false;
235  }
236  if (!has_epsilon_property) {
237  KALDI_WARN << "Epsilon property does not hold, reverting to old behavior.";
238  }
239 
240  // OK, after the above preparation, we finally come to the factor generation
241  // step.
242  StateId ns = factor_transducer->NumStates();
243  StateId ss = factor_transducer->AddState();
244  StateId fs = factor_transducer->AddState();
245  factor_transducer->SetStart(ss);
246  factor_transducer->SetFinal(fs, KwsProductWeight::One());
247 
248  for (StateId s = 0; s < ns; s++) {
249  // Add arcs from initial state to current state
250  if (!has_epsilon_property ||
251  (state_properties[s] & kStateHasNonEpsilonArcsLeaving))
252  factor_transducer->AddArc(ss, KwsProductArc(0, 0, KwsProductWeight(-alpha[s], StdXStdprimeWeight(state_times[s], ArcticWeight::One())), s));
253  // Add arcs from current state to final state
254  if (!has_epsilon_property ||
255  (state_properties[s] & kStateHasNonEpsilonArcsEntering))
256  factor_transducer->AddArc(s, KwsProductArc(0, utterance_id, KwsProductWeight(0, StdXStdprimeWeight(TropicalWeight::One(), state_times[s])), fs));
257  // The old final state is not final any more
258  if (factor_transducer->Final(s) != KwsProductWeight::Zero())
259  factor_transducer->SetFinal(s, KwsProductWeight::Zero());
260  }
261 
262  return true;
263 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
LogXStdXStdprimeWeight KwsProductWeight
Definition: kaldi-kws.h:47
void ComputeStateInfo(const VectorFst< Arc > &fst, std::vector< char > *epsilon_info)
This function will set epsilon_info to have size equal to the NumStates() of the FST, containing a logical-or of the enum values kStateHasEpsilonArcsEntering, kStateHasNonEpsilonArcsEntering, kStateHasEpsilonArcsLeaving, and kStateHasNonEpsilonArcsLeaving.
fst::ProductWeight< TropicalWeight, ArcticWeight > StdXStdprimeWeight
Definition: kaldi-kws.h:39
static const ArcticWeightTpl< T > One()
Definition: arctic-weight.h:48
bool ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
#define KALDI_WARN
Definition: kaldi-error.h:150
float BaseFloat
LogXStdXStdprimeArc KwsProductArc
Definition: kaldi-kws.h:48
bool ComputeCompactLatticeAlphas(const CompactLattice &clat, vector< double > *alpha)

◆ CreateGenFst()

static fst::StdVectorFst* kaldi::CreateGenFst ( bool  seps,
const fst::SymbolTable *  pst 
)
static

Definition at line 44 of file arpa-lm-compiler-test.cc.

References kBos, kDisambig, kEos, and kEps.

Referenced by CoverageTest().

44  {
46  genFst->SetInputSymbols(pst);
47  genFst->SetOutputSymbols(pst);
48 
49  fst::StdArc::StateId midId = genFst->AddState();
50  if (!seps) {
51  fst::StdArc::StateId initId = genFst->AddState();
52  fst::StdArc::StateId finalId = genFst->AddState();
53  genFst->SetStart(initId);
54  genFst->SetFinal(finalId, fst::StdArc::Weight::One());
55  genFst->AddArc(initId, fst::StdArc(kBos, kBos, 0, midId));
56  genFst->AddArc(midId, fst::StdArc(kEos, kEos, 0, finalId));
57  } else {
58  genFst->SetStart(midId);
59  genFst->SetFinal(midId, fst::StdArc::Weight::One());
60  }
61 
62  // Add a loop for each symbol in the table except the four special ones.
63  fst::SymbolTableIterator si(*pst);
64  for (si.Reset(); !si.Done(); si.Next()) {
65  if (si.Value() == kBos || si.Value() == kEos ||
66  si.Value() == kEps || si.Value() == kDisambig)
67  continue;
68  genFst->AddArc(midId, fst::StdArc(si.Value(), si.Value(),
69  fst::StdArc::Weight::One(), midId));
70  }
71  return genFst;
72 }
fst::StdArc::StateId StateId
fst::StdArc StdArc
fst::StdVectorFst StdVectorFst

◆ CsvResult()

static void kaldi::CsvResult ( std::string  test,
int  dim,
BaseFloat  measure,
std::string  units 
)
static

Definition at line 34 of file matrix-lib-speed-test.cc.

34  {
35  std::cout << test << "," << (sizeof(Real) == 8 ? "double" : "float") << "," << dim << "," << measure << "," << units << "\n";
36 }

◆ CuBlockMatrixUnitTest()

void kaldi::CuBlockMatrixUnitTest ( )

Definition at line 173 of file cu-block-matrix-test.cc.

173  {
174  UnitTestCuBlockMatrixIO<Real>();
175  UnitTestCuBlockMatrixAddMatBlock<Real>();
176  UnitTestCuBlockMatrixAddMatMat<Real>();
177 }

◆ CuCompressedMatrixTestNonnegative()

void kaldi::CuCompressedMatrixTestNonnegative ( )

Definition at line 54 of file cu-compressed-matrix-test.cc.

References CuMatrixBase< Real >::Add(), CuMatrixBase< Real >::AddMat(), CuCompressedMatrixBase::CopyFromMat(), CuCompressedMatrixBase::CopyToMat(), KALDI_ASSERT, kCompressedMatrixUint16, kCompressedMatrixUint8, kUndefined, CuMatrixBase< Real >::Max(), CuMatrixBase< Real >::Min(), NewCuCompressedMatrix(), RandInt(), CuMatrixBase< Real >::Scale(), and CuMatrixBase< Real >::SetRandUniform().

Referenced by main().

54  {
55  int32 num_rows = RandInt(80, 100),
56  num_cols = RandInt(80, 100);
57  CuMatrix<BaseFloat> M(num_rows, num_cols);
58  M.SetRandUniform();
59 
60  BaseFloat range = 0.5 * RandInt(1, 5);
61  M.Scale(range);
62 
63  CuCompressedMatrixType t = (RandInt(0, 1) == 0 ?
66 
67  // since the input is in the correct range, truncating or not should make no
68  // difference.
69  bool truncate = (RandInt(0, 1) == 0);
70 
71  BaseFloat extra_error = 0.0;
72  if (truncate && (RandInt(0, 1) == 0)) {
73  // this tests that with truncate == true, adding a small offset, which would
74  // take us outside the representable range, will not add too much extra
75  // error. (with truncate == false this would not be true because we wouldn't
76  // round to the edges of the range, it would wrap around).
77  extra_error = -0.01 * (RandInt(0, 1) == 0 ? 1.0 : -1.0);
78  M.Add(extra_error);
79  }
80 
81  CuCompressedMatrixBase *cm = NewCuCompressedMatrix(t, range, truncate);
82 
83  CuMatrix<BaseFloat> M2(num_rows, num_cols, kUndefined);
84 
85  cm->CopyFromMat(M);
86  cm->CopyToMat(&M2);
87 
88 
89  M2.AddMat(-1.0, M);
90 
91  BaseFloat diff_max = M2.Max(),
92  diff_min = M2.Min();
93 
94  BaseFloat
95  headroom = 1.1,
96  max_expected_error = fabs(extra_error) + headroom * 0.5 *
97  range / (t == kCompressedMatrixUint8 ? 255 : 65535);
98 
99  KALDI_ASSERT(diff_max < max_expected_error &&
100  diff_min > -1.0 * max_expected_error);
101 
102  delete cm;
103 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
virtual void CopyFromMat(const CuMatrixBase< BaseFloat > &mat)=0
Sets *this to an appropriately compressed copy of &#39;mat&#39;, which includes resizing *this.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Class CuCompressedMatrixBase is an abstract base class that allows you to compress a matrix of type C...
CuCompressedMatrixBase * NewCuCompressedMatrix(CuCompressedMatrixType t, BaseFloat range, bool truncat)
This function allocates a new CuCompressedMatrix with type determined by t, and with the &#39;range&#39; and ...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95
virtual void CopyToMat(CuMatrixBase< BaseFloat > *mat) const =0
Copies the contents of *this to &#39;mat&#39;, which should be correctly sized beforehand.

◆ CuCompressedMatrixTestSign()

void kaldi::CuCompressedMatrixTestSign ( )

Definition at line 34 of file cu-compressed-matrix-test.cc.

References AssertEqual(), CuCompressedMatrixBase::CopyFromMat(), CuCompressedMatrixBase::CopyToMat(), CuMatrixBase< Real >::Heaviside(), kCompressedMatrixUint8, kUndefined, NewCuCompressedMatrix(), RandInt(), and CuMatrixBase< Real >::SetRandn().

Referenced by main().

34  {
35  int32 num_rows = RandInt(80, 100),
36  num_cols = RandInt(80, 100);
37  CuMatrix<BaseFloat> M(num_rows, num_cols);
38  M.SetRandn();
39 
40  CuMatrix<BaseFloat> M2(num_rows, num_cols, kUndefined);
41 
43 
44  // this just stores (M(i, j) > 0 ? 1 : 0).
45  cm->CopyFromMat(M);
46  cm->CopyToMat(&M2);
47 
48  M.Heaviside(M);
49 
50  AssertEqual(M, M2);
51  delete cm;
52 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
virtual void CopyFromMat(const CuMatrixBase< BaseFloat > &mat)=0
Sets *this to an appropriately compressed copy of &#39;mat&#39;, which includes resizing *this.
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
Class CuCompressedMatrixBase is an abstract base class that allows you to compress a matrix of type C...
CuCompressedMatrixBase * NewCuCompressedMatrix(CuCompressedMatrixType t, BaseFloat range, bool truncat)
This function allocates a new CuCompressedMatrix with type determined by t, and with the &#39;range&#39; and ...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95
virtual void CopyToMat(CuMatrixBase< BaseFloat > *mat) const =0
Copies the contents of *this to &#39;mat&#39;, which should be correctly sized beforehand.

◆ CuCompressedMatrixTestSymmetric()

void kaldi::CuCompressedMatrixTestSymmetric ( )

Definition at line 107 of file cu-compressed-matrix-test.cc.

References CuMatrixBase< Real >::Add(), CuMatrixBase< Real >::AddMat(), CuCompressedMatrixBase::CopyFromMat(), CuCompressedMatrixBase::CopyToMat(), KALDI_ASSERT, kCompressedMatrixInt16, kCompressedMatrixInt8, kUndefined, CuMatrixBase< Real >::Max(), CuMatrixBase< Real >::Min(), NewCuCompressedMatrix(), RandInt(), CuMatrixBase< Real >::Scale(), and CuMatrixBase< Real >::SetRandUniform().

Referenced by main().

107  {
108  int32 num_rows = RandInt(80, 100),
109  num_cols = RandInt(80, 100);
110  CuMatrix<BaseFloat> M(num_rows, num_cols);
111  M.SetRandUniform();
112  M.Scale(2.0);
113  M.Add(-1.0);
114 
115  BaseFloat range = 0.5 * RandInt(1, 5);
116  M.Scale(range);
117 
118  CuCompressedMatrixType t = (RandInt(0, 1) == 0 ?
121 
122  // since the input is in the correct range, truncating or not should make no
123  // difference.
124  bool truncate = (RandInt(0, 1) == 0);
125 
126  BaseFloat extra_error = 0.0;
127  if (truncate && (RandInt(0, 1) == 0)) {
128  // this tests that with truncate == true, adding a small offset, which would
129  // take us outside the representable range, will not add too much extra
130  // error. (with truncate == false this would not be true because we wouldn't
131  // round to the edges of the range, it would wrap around).
132  extra_error = -0.01 * (RandInt(0, 1) == 0 ? 1.0 : -1.0);
133  M.Add(extra_error);
134  }
135 
136  CuCompressedMatrixBase *cm = NewCuCompressedMatrix(t, range, truncate);
137 
138  CuMatrix<BaseFloat> M2(num_rows, num_cols, kUndefined);
139 
140  cm->CopyFromMat(M);
141  cm->CopyToMat(&M2);
142 
143 
144  M2.AddMat(-1.0, M);
145 
146  BaseFloat diff_max = M2.Max(),
147  diff_min = M2.Min();
148 
149  BaseFloat
150  headroom = 1.1,
151  max_expected_error = fabs(extra_error) + headroom * 0.5 *
152  range / (t == kCompressedMatrixInt8 ? 127 : 32767);
153 
154  KALDI_ASSERT(diff_max < max_expected_error &&
155  diff_min > -1.0 * max_expected_error);
156 
157  delete cm;
158 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
virtual void CopyFromMat(const CuMatrixBase< BaseFloat > &mat)=0
Sets *this to an appropriately compressed copy of &#39;mat&#39;, which includes resizing *this.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Class CuCompressedMatrixBase is an abstract base class that allows you to compress a matrix of type C...
CuCompressedMatrixBase * NewCuCompressedMatrix(CuCompressedMatrixType t, BaseFloat range, bool truncat)
This function allocates a new CuCompressedMatrix with type determined by t, and with the &#39;range&#39; and ...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95
virtual void CopyToMat(CuMatrixBase< BaseFloat > *mat) const =0
Copies the contents of *this to &#39;mat&#39;, which should be correctly sized beforehand.

◆ CudaMathUnitTest()

void kaldi::CudaMathUnitTest ( )

Definition at line 694 of file cu-math-test.cc.

References UnitTestLstmNonlinearity().

694  {
695 #if HAVE_CUDA == 1
696  if (CuDevice::Instantiate().DoublePrecisionSupported())
697 #endif
698 
699  UnitTestCuMathComputeLstmNonlinearity<Real>();
700  UnitTestCuMathRandomize<Real>();
701  UnitTestCuMathSplice<Real>();
702  UnitTestCuMathCopy<Real>();
704  UnitTestEnsureNonzero<Real>();
705  UnitTestBackpropLstmNonlinearity<Real>();
706  UnitTestCuMathNormalizePerRow<Real>();
707  UnitTestCuMathNormalizePerRow_v2<Real>();
708  UnitTestCuDiffNormalizePerRow<Real>();
709 }
void UnitTestLstmNonlinearity()

◆ CudaMatrixResizeTest()

void kaldi::CudaMatrixResizeTest ( )

Definition at line 81 of file cu-device-test.cc.

81  {
82  std::vector<int32> sizes;
83  sizes.push_back(1);
84  sizes.push_back(2);
85  sizes.push_back(4);
86  sizes.push_back(8);
87  sizes.push_back(16);
88  //sizes.push_back(24);
89  //sizes.push_back(32);
90  //sizes.push_back(40);
91 
92  int32 ns = sizes.size();
93  for (int32 s = 0; s < ns; s++)
94  TestCuMatrixResize<Real>(sizes[s]);
95 }
kaldi::int32 int32

◆ CudaMatrixSpeedTest()

void kaldi::CudaMatrixSpeedTest ( )

Definition at line 1012 of file cu-matrix-speed-test.cc.

References kNoTrans, and kTrans.

1012  {
1013  std::vector<int32> sizes;
1014  sizes.push_back(16);
1015  sizes.push_back(32);
1016  sizes.push_back(64);
1017  sizes.push_back(128);
1018  sizes.push_back(256);
1019  sizes.push_back(512);
1020  sizes.push_back(1024);
1021  int32 ns = sizes.size();
1022  for (int32 s = 0; s < ns; s++)
1023  TestCuMatrixDivRowsVec<Real>(sizes[s]);
1024  for (int32 s = 0; s < ns; s++)
1025  TestCuMatrixResize<Real>(sizes[s]);
1026  for (int32 s = 0; s < ns; s++)
1027  TestCuMatrixAddMat<Real>(sizes[s], 3, 3);
1028  for (int32 s = 0; s < ns; s++)
1029  TestCuMatrixAddMatBlocks<Real>(sizes[s], 3, 3);
1030  for (int32 s = 0; s < ns; s++)
1031  TestCuMatrixMatMat<Real>(sizes[s]);
1032  for (int32 s = 0; s + 1 < ns; s++)
1033  TestCuMatrixMatMatBatched<Real>(sizes[s], 10);
1034  for (int32 s = 0; s < ns; s++) {
1035  TestCuMatrixAddDiagVecMat<Real>(sizes[s], kNoTrans);
1036  TestCuMatrixAddDiagVecMat<Real>(sizes[s], kTrans);
1037  }
1038  for (int32 s = 0; s < ns; s++)
1039  TestSymInvertPosDef<Real>(sizes[s]);
1040  for (int32 s = 0; s < ns; s++)
1041  TestCuMatrixCholesky<Real>(sizes[s]);
1042  for (int32 s = 0; s < ns; s++)
1043  TestCuMatrixSigmoid<Real>(sizes[s]);
1044  for (int32 s = 0; s < ns; s++)
1045  TestCuMatrixHeaviside<Real>(sizes[s]);
1046  for (int32 s = 0; s < ns; s++)
1047  TestCuFindRowMaxId<Real>(sizes[s]);
1048  for (int32 s = 0; s < ns; s++)
1049  TestCuMatrixCompObjfAndDeriv<Real>(sizes[s]);
1050  for (int32 s = 0; s < ns; s++)
1051  TestCuMatrixMulRowsGroupMat<Real>(sizes[s]);
1052  for (int32 s = 0; s < ns; s++)
1053  TestCuMatrixSoftmax<Real>(sizes[s]);
1054  for (int32 s = 0; s < ns; s++)
1055  TestCuMatrixDiffSoftmax<Real>(sizes[s]);
1056  for (int32 s = 0; s < ns; s++)
1057  TestCuMatrixDiffLogSoftmax<Real>(sizes[s]);
1058  for (int32 s = 0; s < ns; s++)
1059  TestCuMatrixLogSoftmax<Real>(sizes[s]);
1060  for (int32 s = 0; s < ns; s++)
1061  TestCuMatrixGroupPnorm<Real>(sizes[s]);
1062  for (int32 s = 0; s < ns; s++)
1063  TestCuMatrixDiffGroupPnorm<Real>(sizes[s]);
1064  for (int32 s = 0; s < ns; s++)
1065  TestCuMatrixGroupMax<Real>(sizes[s]);
1066  for (int32 s = 0; s < ns; s++)
1067  TestCuMatrixGroupMaxAllGroupSizes<Real>(sizes[s]);
1068  for (int32 s = 0; s < ns; s++)
1069  TestCuMatrixGroupMaxDeriv<Real>(sizes[s]);
1070  for (int32 s = 0; s < ns; s++)
1071  TestCuMatrixTraceMatMat<Real>(sizes[s]);
1072  for (int32 s = 0; s < ns; s++)
1073  TestCuSparseMatrixTraceMatSmat<Real>(sizes[s]);
1074  for (int32 s = 0; s < ns; s++)
1075  TestCuMatrixCopyLowerToUpper<Real>(sizes[s]);
1076  for (int32 s = 0; s < ns; s++)
1077  TestCuMatrixCopyFromTp<Real>(sizes[s], kNoTrans);
1078  for (int32 s = 0; s < ns; s++)
1079  TestCuMatrixCopyFromTp<Real>(sizes[s], kTrans);
1080  for (int32 s = 0; s < ns; s++)
1081  TestCuMatrixCopyFromSp<Real>(sizes[s]);
1082  for (int32 s = 0; s < ns; s++)
1083  TestCuMatrixCopyUpperToLower<Real>(sizes[s]);
1084  for (int32 s = 0; s < ns; s++)
1085  TestCuMatrixSetZeroAboveDiag<Real>(sizes[s]);
1086  for (int32 s = 0; s + 2 < ns; s++)
1087  TestCuMatrixLookup<Real>(sizes[s]);
1088  for (int32 s = 0; s < ns; s++)
1089  TestCuMatrixCopyRows1<Real>(sizes[s]);
1090  for (int32 s = 0; s < ns; s++)
1091  TestCuMatrixCopyRows2<Real>(sizes[s]);
1092  for (int32 s = 0; s < ns; s++)
1093  TestCuMatrixCopyToRows<Real>(sizes[s]);
1094  for (int32 s = 0; s < ns; s++)
1095  TestCuMatrixAddRows1<Real>(sizes[s]);
1096  for (int32 s = 0; s < ns; s++)
1097  TestCuMatrixAddRows2<Real>(sizes[s]);
1098  for (int32 s = 0; s < ns; s++)
1099  TestCuMatrixAddToRows<Real>(sizes[s]);
1100  for (int32 s = 0; s < ns; s++)
1101  TestCuMatrixAddRowRanges<Real>(sizes[s]);
1102  for (int32 s = 0; s < ns; s++)
1103  TestCuMatrixTransposeCross<Real>(sizes[s]);
1104  for (int32 s = 0; s < ns; s++)
1105  TestCuMatrixTransposeS<Real>(sizes[s]);
1106  for (int32 s = 0; s < ns; s++)
1107  TestCuMatrixTransposeNS<Real>(sizes[s]);
1108  for (int32 s = 0; s < ns; s++)
1109  TestCuMatrixSum<Real>(sizes[s]);
1110  for (int32 s = 0; s < ns; s++)
1111  TestCuMatrixMax<Real>(sizes[s]);
1112  for (int32 s = 0; s < ns; s++)
1113  TestCuMatrixMin<Real>(sizes[s]);
1114 }
kaldi::int32 int32

◆ CudaMatrixUnitTest()

void kaldi::CudaMatrixUnitTest ( )

Definition at line 2941 of file cu-matrix-test.cc.

2941  {
2942  UnitTestCuMatrixApplyExpSpecial<Real>();
2943  UnitTestCuMatrixApplyExpLimited<Real>();
2944  UnitTextCuMatrixAddSmatMat<Real>();
2945  UnitTextCuMatrixAddMatSmat<Real>();
2946  UnitTextCuMatrixAddSmat<Real>();
2947  UnitTestCuMatrixTraceMatMat<Real>();
2948  UnitTestCuMatrixObjfDeriv<Real>();
2949  //test CuMatrix<Real> methods by cross-check with Matrix
2950  UnitTestCuMatrixCopyCross<Real>();
2951  UnitTestCuMatrixCopyCross2<Real>();
2952  UnitTestCuMatrixApplyLog<Real>();
2953  UnitTestCuMatrixApplyExp<Real>();
2954  UnitTestCuMatrixSetRandn<Real>();
2955  UnitTestCuMatrixSetRandUniform<Real>();
2956  UnitTestCuMatrixScale<Real>();
2957  UnitTestCuMatrixSigmoid<Real>();
2958  UnitTestCuMatrixSoftHinge<Real>();
2959  UnitTestCuMatrixApplyPow<Real>();
2960  UnitTestCuMatrixApplyPowAbs<Real>();
2961  UnitTestCuMatrixSet<Real>();
2962  UnitTestCuMatrixAdd<Real>();
2963  UnitTestCuMatrixApplyFloor<Real>();
2964  UnitTestCuMatrixApplyCeiling<Real>();
2965  UnitTestCuMatrixApplyHeaviside<Real>();
2966  UnitTestCuMatrixHeaviside<Real>();
2967  UnitTestCuMatrixMulElements<Real>();
2968  UnitTestCuMatrixDivElements<Real>();
2969  UnitTestCuMatrixMax<Real>();
2970  UnitTestCuMatrixMin<Real>();
2971  UnitTestCuMatrixMulColsVec<Real>();
2972  UnitTestCuMatrixMulRowsVec<Real>();
2973  UnitTestCuMatrixDivRowsVec<Real>();
2974  UnitTestCuMatrixAddMat<Real>();
2975  UnitTestCuMatrixAddMatBlocks1<Real>();
2976  UnitTestCuMatrixAddMatBlocks1Trans<Real>();
2977  UnitTestCuMatrixAddMatBlocks2<Real>();
2978  UnitTestCuMatrixReduceSum<Real>();
2979  UnitTestCuMatrixReduceMax<Real>();
2980  UnitTestCuMatrixReduceMin<Real>();
2981  UnitTestCuMatrixAddVecToCols<Real>();
2982  UnitTestCuMatrixAddVecToRows<Real>();
2983  UnitTestCuMatrixAddMatMat<Real>();
2984  UnitTestCuMatrixAddVecVec<Real>();
2985  UnitTestCuMatrixSymAddMat2<Real>();
2986  UnitTestCuMatrixAddMatMatBatched<Real>();
2987  UnitTestCuMatrixSymInvertPosDef<Real>();
2988  UnitTestCuMatrixCopyFromMat<Real>();
2989  UnitTestCuMatrixCopyFromTp<Real>();
2990  UnitTestCuMatrixAddMatTp<Real>();
2991  UnitTestCuMatrixCopyCols<Real>();
2992  UnitTestCuMatrixAddCols<Real>();
2993  UnitTestCuMatrixSumColumnRanges<Real>();
2994  UnitTestCuMatrixCopyRows<Real>();
2995  UnitTestCuMatrixCopyRowsFromVec<Real>();
2996  UnitTestCuMatrixCopyColsFromVec<Real>();
2997  UnitTestCuMatrixCopyToRows<Real>();
2998  UnitTestCuMatrixAddRows<Real>();
2999  UnitTestCuMatrixMulRows<Real>();
3000  UnitTestCuMatrixAddToRows<Real>();
3001  UnitTestCuMatrixAddRowRanges<Real>();
3002  UnitTestCuMatrixAddTpMat<Real>();
3003  UnitTestCuMatrixTranspose<Real>();
3004  UnitTestCuMatrixCopyUpperToLower<Real>();
3005  UnitTestCuMatrixCopyLowerToUpper<Real>();
3006  UnitTestCuMatrixSetZeroAboveDiag<Real>();
3007  UnitTestCuMatrixAddElements<Real>();
3008  UnitTestCuMatrixAddToElements<Real>();
3009  UnitTestCuMatrixLookup<Real>();
3010  UnitTestCuMatrixEqualElementMask<Real>();
3011  // test CuVector<Real> methods
3012  UnitTestCuVectorAddVec<Real>();
3013  UnitTestCuVectorAddRowSumMat<Real>();
3014  UnitTestCuVectorAddRowSumMatLarge<Real>();
3015  UnitTestCuVectorAddColSumMat<Real>();
3016  UnitTestCuVectorAddColSumMatLarge<Real>();
3017  UnitTestCuSubMatrix<Real>();
3018  UnitTestCuMatrixInvertElements<Real>();
3019  UnitTestCuVectorInvertElements<Real>();
3020  UnitTestCuMatrixIO<Real>();
3021  UnitTestCuSigmoid<Real>();
3022  UnitTestCuApproxEqual<Real>();
3023  UnitTestCuCopy<Real, float>();
3024 #if HAVE_CUDA == 1
3025  if (CuDevice::Instantiate().DoublePrecisionSupported())
3026 #endif
3027  UnitTestCuCopy<Real, double>();
3028  UnitTestCuMatrixAddToDiag<Real>();
3029  UnitTestCuMatrixAdd2<Real>();
3030  UnitTestCuDiffSigmoid<Real>();
3031  UnitTestCuDiffSoftmax<Real>();
3032  UnitTestCuDiffLogSoftmax<Real>();
3033  UnitTestCuMatrixGroupPnorm<Real>();
3034  UnitTestCuMatrixDiffGroupPnorm<Real>();
3035  UnitTestCuMatrixGroupMax<Real>();
3036  UnitTestCuMatrixGroupMaxDeriv<Real>();
3037  UnitTestCuMatrixMulRowsVec<Real>();
3038  UnitTestCuMatrixMulRowsGroupMat<Real>();
3039  UnitTestCuFindRowMaxId<Real>();
3040  UnitTestCuSoftmax<Real>();
3041  UnitTestCuLogSoftmax<Real>();
3042  UnitTestCuDiffXent<Real>();
3043  UnitTestCheck<Real>();
3044  UnitTestSwapCu2Cu<Real>();
3045  UnitTestSwapCu2M<Real>();
3046  UnitTestCuMatrixAddDiagVecMat<Real>();
3047  UnitTestCuMatrixAddMatDiagVec<Real>();
3048  UnitTestCuMatrixAddMatMatElements<Real>();
3049  UnitTestCuMatrixSetMatMatDivMat<Real>();
3050  UnitTestCuTanh<Real>();
3051  UnitTestCuCholesky<Real>();
3052  UnitTestCuDiffTanh<Real>();
3053  UnitTestCuVectorAddTpVec<Real>();
3054  UnitTestCuVectorMulTp<Real>();
3055 }

◆ CudaPackedMatrixUnitTest()

void kaldi::CudaPackedMatrixUnitTest ( )

Definition at line 231 of file cu-packed-matrix-test.cc.

231  {
232  UnitTestCuPackedMatrixConstructor<Real>();
233  //UnitTestCuPackedMatrixCopy<Real>();
234  UnitTestCuPackedMatrixTrace<Real>();
235  UnitTestCuPackedMatrixScale<Real>();
236  UnitTestCuPackedMatrixAddToDiag<Real>();
237  UnitTestCuPackedMatrixSetUnit<Real>();
238 }

◆ CudaSparseMatrixUnitTest()

void kaldi::CudaSparseMatrixUnitTest ( )

Definition at line 271 of file cu-sparse-matrix-test.cc.

271  {
272  UnitTestCuSparseMatrixConstructFromIndexes<Real>();
273  UnitTestCuSparseMatrixSelectRowsAndTranspose<Real>();
274  UnitTestCuSparseMatrixTraceMatSmat<Real>();
275  UnitTestCuSparseMatrixSum<Real>();
276  UnitTestCuSparseMatrixFrobeniusNorm<Real>();
277  UnitTestCuSparseMatrixCopyToSmat<Real>();
278  UnitTestCuSparseMatrixSwap<Real>();
279 }

◆ CudaSpMatrixUnitTest() [1/2]

void kaldi::CudaSpMatrixUnitTest ( )

Definition at line 342 of file cu-sp-matrix-test.cc.

342  {
343  UnitTestCuSpMatrixIO<Real>();
344  UnitTestCuSpMatrixConstructor<Real>();
345  UnitTestCuSpMatrixOperator<Real>();
346  UnitTestCuSpMatrixApproxEqual<Real>();
347  UnitTestCuSpMatrixInvert<Real>();
348  UnitTestCuSpMatrixCopyFromMat<Real>();
349  UnitTestCuSpMatrixAddVec2<Real>();
350  UnitTestCuSpMatrixAddMat2<Real>();
351  UnitTestCuSpMatrixAddSp<Real>();
352  UnitTestCuSpMatrixAddToDiag<Real>();
353  UnitTestCuSpMatrixSetUnit<Real>();
354 }

◆ CudaSpMatrixUnitTest() [2/2]

void kaldi::CudaSpMatrixUnitTest ( )

Definition at line 356 of file cu-sp-matrix-test.cc.

356  {
357  UnitTestCuSpMatrixTraceSpSp<Real, OtherReal>();
358 
359 }

◆ CudaTpMatrixUnitTest()

void kaldi::CudaTpMatrixUnitTest ( )

Definition at line 176 of file cu-tp-matrix-test.cc.

176  {
177  UnitTestCuTpMatrixIO<Real>();
178  UnitTestCuTpMatrixInvert<Real>();
179  UnitTestCuTpMatrixCopyFromTp<Real>();
180  UnitTestCuTpMatrixCholesky<Real>();
181  UnitTestCuTpMatrixCopyFromMat<Real>();
182 }

◆ CudaVectorSpeedTest()

void kaldi::CudaVectorSpeedTest ( )

Definition at line 402 of file cu-vector-speed-test.cc.

References rnnlm::i, rnnlm::j, kNoTrans, and kTrans.

402  {
403  const size_t a = 1 << 5;
404  const size_t b = 1 << 8;
405  for (size_t i = a; i <= b; i *= 2) {
406  for (size_t j = a; j <= b; j *= 2) {
407  if (i * j <= a * b) {
408  TestCuVectorAddDiagMatMatShape<Real>(i, j, kNoTrans, kNoTrans);
409  TestCuVectorAddDiagMatMatShape<Real>(i, j, kNoTrans, kTrans);
410  TestCuVectorAddDiagMatMatShape<Real>(i, j, kTrans, kNoTrans);
411  TestCuVectorAddDiagMatMatShape<Real>(i, j, kTrans, kTrans);
412  }
413  }
414  }
415 
416  std::vector<int32> sizes;
417  for (int i = 32; i <= 1024; i *= 2) {
418  sizes.push_back(i);
419  }
420  int32 ns = sizes.size();
421  for (int32 s = 0; s < ns; s++)
422  TestCuVectorSoftmax<Real>(sizes[s]);
423 #if HAVE_CUDA == 1
424  TestCuVectorSumChooseMinLength<Real>();
425 #endif
426  for (int32 s = 0; s < ns; s++)
427  TestCuVectorSum<Real>(sizes[s]);
428  for (int32 s = 0; s < ns; s++)
429  TestCuVectorVecVecOne<Real>(sizes[s]);
430  for (int32 s = 0; s < ns; s++)
431  TestCuVectorCopyFromVec<Real, float>(sizes[s]);
432  for (int32 s = 0; s < ns; s++)
433  TestCuVectorCopyFromVec<Real, double>(sizes[s]);
434  for (int32 s = 0; s < ns; s++) {
435  TestCuVectorAddDiagMatMat<Real>(sizes[s], kNoTrans, kNoTrans);
436  TestCuVectorAddDiagMatMat<Real>(sizes[s], kNoTrans, kTrans);
437  TestCuVectorAddDiagMatMat<Real>(sizes[s], kTrans, kNoTrans);
438  TestCuVectorAddDiagMatMat<Real>(sizes[s], kTrans, kTrans);
439  }
440  for (int32 s = 0; s < ns; s++) {
441  TestCuVectorAddDiagMat2OnVariousShapes<Real>(sizes[s], kNoTrans);
442  TestCuVectorAddDiagMat2OnVariousShapes<Real>(sizes[s], kTrans);
443  }
444  for (int32 s = 0; s < ns; s++) {
445  TestCuVectorAddDiagMat2<Real>(sizes[s], kNoTrans);
446  TestCuVectorAddDiagMat2<Real>(sizes[s], kTrans);
447  }
448  for (int32 s = 0; s < ns; s++) {
449  TestCuVectorAddRowSumMat<Real>(sizes[s], kNoTrans);
450  TestCuVectorAddRowSumMat<Real>(sizes[s], kTrans);
451  }
452  for (int32 s = 0; s < ns; s++) {
453  TestCuVectorAddColSumMat<Real>(sizes[s], kNoTrans);
454  TestCuVectorAddColSumMat<Real>(sizes[s], kTrans);
455  }
456  for (int32 s = 0; s < ns; s++) {
457  TestCuVectorApplyFloor<Real>(sizes[s]);
458  TestCuVectorApplyFloorNoCount<Real>(sizes[s]);
459  }
460  for (int32 s = 0; s < ns; s++) {
461  TestCuVectorApplyCeiling<Real>(sizes[s]);
462  TestCuVectorApplyCeilingNoCount<Real>(sizes[s]);
463  }
464 
465 }
kaldi::int32 int32

◆ CuMatrixUnitTest()

static void kaldi::CuMatrixUnitTest ( )
static

Definition at line 561 of file cu-test.cc.

561  {
562  UnitTestTrace<Real>();
563  UnitTestCholesky<Real>();
564  UnitTestInvert<Real>();
565  UnitInvert<Real>();
566  UnitTestCopyFromMat<Real>();
567  UnitTestCopySp<Real>();
568  UnitTestConstructor<Real>();
569  UnitTestVector<Real>();
570  UnitTestMulTp<Real>();
571  UnitTestMatrix<Real>();
572  UnitTestSetZeroAboveDiag<Real>();
573 }

◆ CuRandGaussianMatrixBaseSpeedTest()

void kaldi::CuRandGaussianMatrixBaseSpeedTest ( const int32  iter)

Definition at line 129 of file cu-rand-speed-test.cc.

References Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuRand< Real >::RandGaussian().

129  {
130  Timer t;
131  CuRand<Real> rand;
132  CuMatrix<Real> m(249,1001, kUndefined);
133  for (int32 i = 0; i < iter; i++) {
134  rand.RandGaussian(dynamic_cast<CuMatrixBase<Real>*>(&m));
135  }
136  CuMatrix<Real> m2(256,1024, kUndefined);
137  for (int32 i = 0; i < iter; i++) {
138  rand.RandGaussian(dynamic_cast<CuMatrixBase<Real>*>(&m2));
139  }
140  // flops = number of generated random numbers per second,
141  Real flops = iter * (m.NumRows() * m.NumCols() + m2.NumRows() * m2.NumCols()) / t.Elapsed();
142  KALDI_LOG << __func__ << NameOf<Real>()
143  << " Speed was " << flops << " rand_elems/s. "
144  << "(debug " << MeanVariance(m) << ")";
145 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
std::string MeanVariance(const CuVectorBase< Real > &v)
void RandGaussian(CuMatrixBase< Real > *tgt)
Fill with Normal random numbers,.
Definition: cu-rand.cc:116
Matrix for CUDA computing.
Definition: matrix-common.h:69
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuRandGaussianMatrixSpeedTest()

void kaldi::CuRandGaussianMatrixSpeedTest ( const int32  iter)

Definition at line 110 of file cu-rand-speed-test.cc.

References Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuRand< Real >::RandGaussian().

110  {
111  Timer t;
112  CuRand<Real> rand;
113  CuMatrix<Real> m(249,1001, kUndefined);
114  for (int32 i = 0; i < iter; i++) {
115  rand.RandGaussian(&m);
116  }
117  CuMatrix<Real> m2(256,1024, kUndefined);
118  for (int32 i = 0; i < iter; i++) {
119  rand.RandGaussian(&m2);
120  }
121  // flops = number of generated random numbers per second,
122  Real flops = iter * (m.NumRows() * m.NumCols() + m2.NumRows() * m2.NumCols()) / t.Elapsed();
123  KALDI_LOG << __func__ << NameOf<Real>()
124  << " Speed was " << flops << " rand_elems/s. "
125  << "(debug " << MeanVariance(m) << ")";
126 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
std::string MeanVariance(const CuVectorBase< Real > &v)
void RandGaussian(CuMatrixBase< Real > *tgt)
Fill with Normal random numbers,.
Definition: cu-rand.cc:116
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuRandGaussianVectorSpeedTest()

void kaldi::CuRandGaussianVectorSpeedTest ( const int32  iter)

Definition at line 167 of file cu-rand-speed-test.cc.

References CuVectorBase< Real >::Dim(), Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), and CuRand< Real >::RandGaussian().

167  {
168  Timer t;
169  CuRand<Real> rand;
170  CuVector<Real> v(2011, kUndefined);
171  for (int32 i = 0; i < iter; i++) {
172  rand.RandGaussian(&v);
173  }
174  CuVector<Real> v2(2048, kUndefined);
175  for (int32 i = 0; i < iter; i++) {
176  rand.RandGaussian(&v2);
177  }
178  // flops = number of generated random numbers per second,
179  Real flops = iter * (v.Dim() + v2.Dim()) / t.Elapsed();
180  KALDI_LOG << __func__ << NameOf<Real>()
181  << " Speed was " << flops << " rand_elems/s. "
182  << "(debug " << MeanVariance(v) << ")";
183 }
kaldi::int32 int32
std::string MeanVariance(const CuVectorBase< Real > &v)
void RandGaussian(CuMatrixBase< Real > *tgt)
Fill with Normal random numbers,.
Definition: cu-rand.cc:116
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuRandUniformMatrixBaseSpeedTest()

void kaldi::CuRandUniformMatrixBaseSpeedTest ( const int32  iter)

Definition at line 91 of file cu-rand-speed-test.cc.

References Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuRand< Real >::RandUniform().

91  {
92  Timer t;
93  CuRand<Real> rand;
94  CuMatrix<Real> m(249,1001, kUndefined);
95  for (int32 i = 0; i < iter; i++) {
96  rand.RandUniform(dynamic_cast<CuMatrixBase<Real>*>(&m));
97  }
98  CuMatrix<Real> m2(256,1024, kUndefined);
99  for (int32 i = 0; i < iter; i++) {
100  rand.RandUniform(dynamic_cast<CuMatrixBase<Real>*>(&m2));
101  }
102  // flops = number of generated random numbers per second,
103  Real flops = iter * (m.NumRows() * m.NumCols() + m2.NumRows() * m2.NumCols()) / t.Elapsed();
104  KALDI_LOG << __func__ << NameOf<Real>()
105  << " Speed was " << flops << " rand_elems/s. "
106  << "(debug " << MeanVariance(m) << ")";
107 }
void RandUniform(CuMatrixBase< Real > *tgt)
Fill with uniform [0..1] floats,.
Definition: cu-rand.cc:60
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
std::string MeanVariance(const CuVectorBase< Real > &v)
Matrix for CUDA computing.
Definition: matrix-common.h:69
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuRandUniformMatrixSpeedTest()

void kaldi::CuRandUniformMatrixSpeedTest ( const int32  iter)

Definition at line 72 of file cu-rand-speed-test.cc.

References Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuRand< Real >::RandUniform().

72  {
73  Timer t;
74  CuRand<Real> rand;
75  CuMatrix<Real> m(249,1001, kUndefined);
76  for (int32 i = 0; i < iter; i++) {
77  rand.RandUniform(&m);
78  }
79  CuMatrix<Real> m2(256,1024, kUndefined);
80  for (int32 i = 0; i < iter; i++) {
81  rand.RandUniform(&m2);
82  }
83  // flops = number of generated random numbers per second,
84  Real flops = iter * (m.NumRows() * m.NumCols() + m2.NumRows() * m2.NumCols()) / t.Elapsed();
85  KALDI_LOG << __func__ << NameOf<Real>()
86  << " Speed was " << flops << " rand_elems/s. "
87  << "(debug " << MeanVariance(m) << ")";
88 }
void RandUniform(CuMatrixBase< Real > *tgt)
Fill with uniform [0..1] floats,.
Definition: cu-rand.cc:60
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
std::string MeanVariance(const CuVectorBase< Real > &v)
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuRandUniformVectorSpeedTest()

void kaldi::CuRandUniformVectorSpeedTest ( const int32  iter)

Definition at line 148 of file cu-rand-speed-test.cc.

References CuVectorBase< Real >::Dim(), Timer::Elapsed(), rnnlm::i, kUndefined, MeanVariance(), and CuRand< Real >::RandUniform().

148  {
149  Timer t;
150  CuRand<Real> rand;
151  CuVector<Real> v(2011, kUndefined);
152  for (int32 i = 0; i < iter; i++) {
153  rand.RandUniform(&v);
154  }
155  CuVector<Real> v2(2048, kUndefined);
156  for (int32 i = 0; i < iter; i++) {
157  rand.RandUniform(&v2);
158  }
159  // flops = number of generated random numbers per second,
160  Real flops = iter * (v.Dim() + v2.Dim()) / t.Elapsed();
161  KALDI_LOG << __func__ << NameOf<Real>()
162  << " Speed was " << flops << " rand_elems/s. "
163  << "(debug " << MeanVariance(v) << ")";
164 }
void RandUniform(CuMatrixBase< Real > *tgt)
Fill with uniform [0..1] floats,.
Definition: cu-rand.cc:60
kaldi::int32 int32
std::string MeanVariance(const CuVectorBase< Real > &v)
double Elapsed() const
Returns time in seconds.
Definition: timer.h:74

◆ CuSpMatrixSpeedTest()

void kaldi::CuSpMatrixSpeedTest ( )

Definition at line 107 of file cu-sp-matrix-speed-test.cc.

References kTakeLower, kTakeMean, and kTakeUpper.

107  {
108  std::vector<int32> sizes;
109  sizes.push_back(16);
110  sizes.push_back(32);
111  sizes.push_back(64);
112  sizes.push_back(128);
113  sizes.push_back(256);
114  sizes.push_back(512);
115  sizes.push_back(1024);
116  int32 ns = sizes.size();
117 
118  for (int32 s = 0; s < ns; s++) {
119  UnitTestCuSpMatrixInvert<Real>(sizes[s]);
120  UnitTestCuSpMatrixCopyFromMat<Real>(sizes[s], kTakeLower);
121  UnitTestCuSpMatrixCopyFromMat<Real>(sizes[s], kTakeUpper);
122  UnitTestCuSpMatrixCopyFromMat<Real>(sizes[s], kTakeMean);
123  }
124 }
kaldi::int32 int32

◆ CuVectorUnitTest()

void kaldi::CuVectorUnitTest ( )

Definition at line 780 of file cu-vector-test.cc.

780  {
781  UnitTestCuVectorCopyFromVec<Real, float>();
782 #if HAVE_CUDA == 1
783  if (CuDevice::Instantiate().DoublePrecisionSupported())
784 #endif
785  UnitTestCuVectorCopyFromVec<Real, double>();
786  UnitTestCuVectorIO<Real>();
787  CuVectorUnitTestVecVec<Real>();
788  CuVectorUnitTestAddVec<Real>();
789  CuVectorUnitTestAddVecCross<Real>();
790  CuVectorUnitTestAddVecExtra<Real>();
791  CuVectorUnitTestApproxEqual<Real>();
792  CuVectorUnitTestScale<Real>();
793  CuVectorUnitTestSum<Real>();
794  CuVectorUnitTestInvertElements<Real>();
795  UnitTestCuVectorSum<Real>();
796  CuVectorUnitTestAddRowSumMat<Real>();
797  CuVectorUnitTestAddColSumMat<Real>();
798  UnitTestCuVectorReplaceValue<Real>();
799  UnitTestCuVectorAddTp<Real>();
800  UnitTestCuVectorMulTp<Real>();
801  UnitTestCuSubVector<Real>();
802  CuVectorUnitTestCopyFromMat<Real>();
803  CuVectorUnitTestMin<Real>();
804  CuVectorUnitTestMax<Real>();
805  CuVectorUnitTestApplySoftMax<Real>();
806  CuVectorUnitTestCopyDiagFromPacked<Real>();
807  CuVectorUnitTestCopyDiagFromMat<Real>();
808  CuVectorUnitTestCopyCross<Real>();
809  CuVectorUnitTestCopyCross2<Real>();
810  CuVectorUnitTestNorm<Real>();
811  CuVectorUnitTestApplyExp<Real>();
812  CuVectorUnitTestApplyLog<Real>();
813  CuVectorUnitTestApplyFloor<Real>();
814  CuVectorUnitTestApplyFloorNoCount<Real>();
815  CuVectorUnitTestApplyCeilingNoCount<Real>();
816  CuVectorUnitTestApplyCeiling<Real>();
817  CuVectorUnitTestApplyPow<Real>();
818  CuVectorUnitTestAddMatVec<Real>();
819  CuVectorUnitTestAddSpVec<Real>();
820  CuVectorUnitTestAddVecVec<Real>();
821  CuVectorUnitTestAddDiagMat2<Real>();
822  CuVectorUnitTestAddDiagMatMat<Real>();
823  CuVectorUnitTestCopyElements<Real>();
824  UnitTestVecMatVec<Real>();
825 }

◆ CuVectorUnitTestAddColSumMat()

void kaldi::CuVectorUnitTestAddColSumMat ( )

Definition at line 264 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddColSumMat(), VectorBase< Real >::AddColSumMat(), AssertEqual(), Rand(), and CuMatrixBase< Real >::SetRandn().

264  {
265  int32 M = 10 + Rand() % 280, N = 10 + Rand() % 20;
266  BaseFloat alpha = 10.0143432, beta = 43.4321;
267  CuMatrix<Real> mat(M, N);
268  mat.SetRandn();
269  CuVector<Real> vec(M);
270  mat.SetRandn();
271  Matrix<Real> mat2(mat);
272  Vector<Real> vec2(M);
273  vec.AddColSumMat(alpha, mat, beta);
274  vec2.AddColSumMat(alpha, mat2, beta);
275  Vector<Real> vec3(vec);
276  AssertEqual(vec2, vec3);
277 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddDiagMat2()

void kaldi::CuVectorUnitTestAddDiagMat2 ( )

Definition at line 668 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddDiagMat2(), VectorBase< Real >::AddDiagMat2(), AssertEqual(), kNoTrans, kTrans, Rand(), CuVectorBase< Real >::SetRandn(), and CuMatrixBase< Real >::SetRandn().

668  {
669  for (int p = 0; p < 4; p++) {
670  int32 M = 230 + Rand() % 100, N = 230 + Rand() % 100;
671  BaseFloat alpha = 0.2 + Rand() % 3, beta = 0.3 + Rand() % 2;
672  CuVector<Real> cu_vector(M);
673  cu_vector.SetRandn();
674 
675  CuMatrix<Real> cu_mat_orig(M, N);
676  cu_mat_orig.SetRandn();
677  MatrixTransposeType trans = (p % 2 == 0 ? kNoTrans : kTrans);
678  CuMatrix<Real> cu_mat(cu_mat_orig, trans);
679 
680  Vector<Real> vector(cu_vector);
681  Matrix<Real> mat(cu_mat);
682 
683  vector.AddDiagMat2(alpha, mat, trans, beta);
684  cu_vector.AddDiagMat2(alpha, cu_mat, trans, beta);
685 
686  Vector<Real> vector2(cu_vector);
687  AssertEqual(vector, vector2);
688  }
689 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
MatrixTransposeType
Definition: matrix-common.h:32
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddDiagMatMat()

static void kaldi::CuVectorUnitTestAddDiagMatMat ( )
static

Definition at line 692 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddDiagMatMat(), CuMatrixBase< Real >::AddMatMat(), CuVectorBase< Real >::AddVec(), AssertEqual(), CuVectorBase< Real >::CopyDiagFromMat(), rnnlm::d, kNoTrans, kTrans, Rand(), CuVectorBase< Real >::Scale(), CuVectorBase< Real >::SetRandn(), and CuMatrixBase< Real >::SetRandn().

692  {
693  for (MatrixIndexT iter = 0; iter < 4; iter++) {
694  BaseFloat alpha = 0.432 + Rand() % 5, beta = 0.043 + Rand() % 2;
695  MatrixIndexT dimM = 10 + Rand() % 300,
696  dimN = 5 + Rand() % 300;
697  CuVector<Real> v(dimM);
698  CuMatrix<Real> M_orig(dimM, dimN), N_orig(dimN, dimM);
699  M_orig.SetRandn();
700  N_orig.SetRandn();
701  MatrixTransposeType transM = (iter % 2 == 0 ? kNoTrans : kTrans);
702  MatrixTransposeType transN = ((iter/2) % 2 == 0 ? kNoTrans : kTrans);
703  CuMatrix<Real> M(M_orig, transM), N(N_orig, transN);
704 
705  v.SetRandn();
706  CuVector<Real> w(v);
707 
708  w.AddDiagMatMat(alpha, M, transM, N, transN, beta);
709 
710  {
711  CuVector<Real> w2(v);
712  CuMatrix<Real> MN(dimM, dimM);
713  MN.AddMatMat(1.0, M, transM, N, transN, 0.0);
714  CuVector<Real> d(dimM);
715  d.CopyDiagFromMat(MN);
716  w2.Scale(beta);
717  w2.AddVec(alpha, d);
718  AssertEqual(w, w2);
719  }
720  }
721 }
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:98
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
MatrixTransposeType
Definition: matrix-common.h:32
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddMatVec()

void kaldi::CuVectorUnitTestAddMatVec ( )

Definition at line 725 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddMatVec(), VectorBase< Real >::AddMatVec(), AssertEqual(), rnnlm::i, kNoTrans, kTrans, Rand(), CuVectorBase< Real >::SetRandn(), and CuMatrixBase< Real >::SetRandn().

725  {
726  for (int32 i = 0; i < 10; i++) {
727  int32 M = 10 + Rand() % 500, N = 10 + Rand() % 400;
728 
729  bool transpose = (i % 2 == 0);
730 
731  CuVector<Real> src_cu(M);
732  src_cu.SetRandn();
733  Vector<Real> src(src_cu);
734 
735  CuVector<Real> dst_cu(N);
736  dst_cu.SetRandn();
737  Vector<Real> dst(dst_cu);
738 
739  CuMatrix<Real> mat_cu(transpose ? M : N, transpose ? N : M);
740  mat_cu.SetRandn();
741  Matrix<Real> mat(mat_cu);
742 
743  BaseFloat alpha = 0.5 * (Rand() % 10), beta = 0.5 * (Rand() % 10);
744  dst_cu.AddMatVec(alpha, mat_cu, transpose ? kTrans : kNoTrans,
745  src_cu, beta);
746  dst.AddMatVec(alpha, mat, transpose ? kTrans : kNoTrans,
747  src, beta);
748  Vector<Real> dst2(dst_cu);
749  AssertEqual(dst, dst2);
750  }
751 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddRowSumMat()

void kaldi::CuVectorUnitTestAddRowSumMat ( )

Definition at line 249 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddRowSumMat(), VectorBase< Real >::AddRowSumMat(), AssertEqual(), Rand(), and CuMatrixBase< Real >::SetRandn().

249  {
250  int32 M = 10 + Rand() % 280, N = 10 + Rand() % 20;
251  BaseFloat alpha = 10.0143432, beta = 43.4321;
252  CuMatrix<Real> mat(N, M);
253  mat.SetRandn();
254  CuVector<Real> vec(M);
255  mat.SetRandn();
256  Matrix<Real> mat2(mat);
257  Vector<Real> vec2(M);
258  vec.AddRowSumMat(alpha, mat, beta);
259  vec2.AddRowSumMat(alpha, mat2, beta);
260  Vector<Real> vec3(vec);
261  AssertEqual(vec2, vec3);
262 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddSpVec()

void kaldi::CuVectorUnitTestAddSpVec ( )

Definition at line 754 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddSpVec(), VectorBase< Real >::AddSpVec(), AssertEqual(), rnnlm::i, Rand(), CuPackedMatrix< Real >::SetRandn(), and CuVectorBase< Real >::SetRandn().

754  {
755  for (int32 i = 0; i < 5; i++) {
756  int32 M = 100 + Rand() % 256;
757 
758  CuVector<Real> src_cu(M);
759  src_cu.SetRandn();
760  Vector<Real> src(src_cu);
761 
762  CuVector<Real> dst_cu(M);
763  dst_cu.SetRandn();
764  Vector<Real> dst(dst_cu);
765 
766  CuSpMatrix<Real> mat_cu(M);
767  mat_cu.SetRandn();
768  SpMatrix<Real> mat(mat_cu);
769 
770  BaseFloat alpha = 0.5 * (Rand() % 5), beta = 0.5 * (Rand() % 5);
771  dst_cu.AddSpVec(alpha, mat_cu, src_cu, beta);
772  dst.AddSpVec(alpha, mat, src, beta);
773  Vector<Real> dst2(dst_cu);
774  AssertEqual(dst, dst2);
775  }
776 }
Packed symetric matrix class.
Definition: matrix-common.h:62
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddVec()

void kaldi::CuVectorUnitTestAddVec ( )

Definition at line 155 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddVec(), AssertEqual(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

155  {
156  int32 M = 10 + Rand() % 100;
157  CuVector<Real> vec1(M);
158  CuVector<Real> vec2(M);
159  vec1.SetRandn();
160  vec2.SetRandn();
161  CuVector<Real> vec1_orig(vec1);
162  BaseFloat alpha = 0.43243;
163  vec1.AddVec(alpha, vec2);
164 
165  for (int32 i = 0; i < M; i++)
166  AssertEqual(vec1_orig(i) + alpha * vec2(i), vec1(i));
167 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddVecCross()

void kaldi::CuVectorUnitTestAddVecCross ( )

Definition at line 169 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddVec(), AssertEqual(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

169  {
170  for (int32 i = 0; i < 4; i++) {
171  int32 M = 10 + Rand() % 100;
172  CuVector<float> vec1(M);
173  CuVector<Real> vec2(M);
174  vec1.SetRandn();
175  vec2.SetRandn();
176 
177  if (i == 0) {
178  CuVector<Real> vec1_orig(vec1);
179  Real alpha = 0.43243;
180  vec1.AddVec(alpha, vec2);
181 
182  for (int32 i = 0; i < M; i++)
183  AssertEqual(vec1_orig(i) + alpha * vec2(i), vec1(i));
184  } else {
185  CuVector<Real> vec2_orig(vec2);
186  Real alpha = 0.43243;
187  vec2.AddVec(alpha, vec1);
188  for (int32 i = 0; i < M; i++)
189  AssertEqual(vec2_orig(i) + alpha * vec1(i), vec2(i));
190  }
191  }
192 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddVecExtra()

void kaldi::CuVectorUnitTestAddVecExtra ( )

Definition at line 194 of file cu-vector-test.cc.

References AssertEqual(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

194  {
195  int32 M = 10 + Rand() % 100;
196  CuVector<Real> vec1(M), vec2(M);
197  vec1.SetRandn();
198  vec2.SetRandn();
199  CuVector<Real> vec1_orig(vec1);
200  BaseFloat alpha = 0.43243, beta = 1.4321;
201  vec1.AddVec(alpha, vec2, beta);
202 
203  for (int32 i = 0; i < M; i++)
204  AssertEqual(beta * vec1_orig(i) + alpha * vec2(i), vec1(i));
205 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestAddVecVec()

void kaldi::CuVectorUnitTestAddVecVec ( )

Definition at line 647 of file cu-vector-test.cc.

References CuVectorBase< Real >::AddVecVec(), VectorBase< Real >::AddVecVec(), AssertEqual(), Rand(), VectorBase< Real >::SetRandn(), and CuVectorBase< Real >::SetRandn().

647  {
648  int32 dim = 100;
649  CuVector<Real> cu_vector(dim);
650  cu_vector.SetRandn();
651  Vector<Real> vector(cu_vector);
652 
653  Real beta = Rand();
654  Real alpha = Rand();
655  Vector<Real> v(dim), r(dim);
656  v.SetRandn(); r.SetRandn();
657  CuVector<Real> cuV(v), cuR(r);
658 
659 
660  cu_vector.AddVecVec(alpha, cuR, cuV, beta);
661  vector.AddVecVec(alpha, r, v, beta);
662 
663  CuVector<Real> cu2(vector);
664  std::cout<<cu2(0)<<' '<<cu_vector(0)<<std::endl;
665  AssertEqual(cu2, cu_vector);
666 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplyCeiling()

void kaldi::CuVectorUnitTestApplyCeiling ( )

Definition at line 591 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyCeiling(), VectorBase< Real >::ApplyCeiling(), AssertEqual(), rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_WARN, Rand(), and CuVectorBase< Real >::SetRandn().

591  {
592  for (int32 l = 0; l < 10; l++) {
593  int32 dim = 100 + Rand() % 700;
594  CuVector<Real> cu_vector(dim);
595  cu_vector.SetRandn();
596 
597  Vector<Real> vector(cu_vector);
598  BaseFloat floor = 0.33 * (-5 + Rand() % 10);
599  MatrixIndexT i, j;
600  cu_vector.ApplyCeiling(floor, &i);
601  vector.ApplyCeiling(floor, &j);
602 
603  CuVector<Real> cu2(vector);
604 
605  AssertEqual(cu2, cu_vector);
606  if (i != j) {
607  KALDI_WARN << "ApplyCeiling return code broken...";
608  }
609  KALDI_ASSERT(i==j);
610  }
611 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_WARN
Definition: kaldi-error.h:150
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplyCeilingNoCount()

void kaldi::CuVectorUnitTestApplyCeilingNoCount ( )

Definition at line 613 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyCeiling(), AssertEqual(), Rand(), and CuVectorBase< Real >::SetRandn().

613  {
614  for (int32 l = 0; l < 10; l++) {
615  int32 dim = 100 + Rand() % 700;
616  CuVector<Real> cu_vector1(dim);
617  cu_vector1.SetRandn();
618  CuVector<Real> cu_vector2(cu_vector1);
619 
620  BaseFloat floor = 0.33 * (-5 + Rand() % 10);
621  MatrixIndexT dummy_count;
622  cu_vector1.ApplyCeiling(floor, &dummy_count);
623  cu_vector2.ApplyCeiling(floor, nullptr);
624  AssertEqual(cu_vector1, cu_vector2);
625  }
626 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:98
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplyExp()

void kaldi::CuVectorUnitTestApplyExp ( )

Definition at line 522 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyExp(), Exp(), rnnlm::j, KALDI_ASSERT, and CuVectorBase< Real >::SetRandn().

522  {
523  int32 dim = 100;
524  CuVector<Real> vector(dim);
525  vector.SetRandn();
526  CuVector<Real> vector2(vector);
527 
528  vector.ApplyExp();
529  for(int32 j = 0; j < dim; j++) {
530  //std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;;
531  KALDI_ASSERT(std::abs(Exp(vector2(j))-vector(j)) < 0.00001);
532  }
533 
534 }
double Exp(double x)
Definition: kaldi-math.h:83
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestApplyFloor()

void kaldi::CuVectorUnitTestApplyFloor ( )

Definition at line 554 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplyFloor(), AssertEqual(), rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_WARN, Rand(), and CuVectorBase< Real >::SetRandn().

554  {
555  for (int32 l = 0; l < 10; l++) {
556  int32 dim = 100 + Rand() % 700;
557  CuVector<Real> cu_vector(dim);
558  cu_vector.SetRandn();
559 
560  Vector<Real> vector(cu_vector);
561  BaseFloat floor = 0.33 * (-5 + Rand() % 10);
562  MatrixIndexT i, j;
563  cu_vector.ApplyFloor(floor, &i);
564  vector.ApplyFloor(floor, &j);
565 
566  CuVector<Real> cu2(vector);
567 
568  AssertEqual(cu2, cu_vector);
569  if (i != j) {
570  KALDI_WARN << "ApplyFloor return code broken...";
571  }
572  KALDI_ASSERT(i==j);
573  }
574 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:98
#define KALDI_WARN
Definition: kaldi-error.h:150
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplyFloorNoCount()

void kaldi::CuVectorUnitTestApplyFloorNoCount ( )

Definition at line 576 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyFloor(), AssertEqual(), Rand(), and CuVectorBase< Real >::SetRandn().

576  {
577  for (int32 l = 0; l < 10; l++) {
578  int32 dim = 100 + Rand() % 700;
579  CuVector<Real> cu_vector1(dim);
580  cu_vector1.SetRandn();
581  CuVector<Real> cu_vector2(cu_vector1);
582 
583  BaseFloat floor = 0.33 * (-5 + Rand() % 10);
584  MatrixIndexT dummy_count;
585  cu_vector1.ApplyFloor(floor, &dummy_count);
586  cu_vector2.ApplyFloor(floor, nullptr);
587  AssertEqual(cu_vector1, cu_vector2);
588  }
589 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:98
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplyLog()

void kaldi::CuVectorUnitTestApplyLog ( )

Definition at line 536 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyLog(), rnnlm::j, KALDI_ASSERT, Log(), and CuVectorBase< Real >::SetRandn().

536  {
537  int32 dim = 100;
538  CuVector<Real> vector(dim);
539  vector.SetRandn();
540  for(int32 j = 0; j < dim; j++) {
541  if(vector(j) <= 0.0)
542  vector(j) = 1.0 - vector(j);
543  }
544 
545  CuVector<Real> vector2(vector);
546 
547  vector.ApplyLog();
548  for(int32 j = 0; j < dim; j++) {
549  //std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;;
550  KALDI_ASSERT(std::abs(Log(vector2(j))-vector(j)) < 0.000001 );
551  }
552 }
kaldi::int32 int32
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestApplyPow()

void kaldi::CuVectorUnitTestApplyPow ( )

Definition at line 628 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplyPow(), VectorBase< Real >::ApplyPow(), AssertEqual(), Rand(), and CuVectorBase< Real >::SetRandn().

628  {
629  for (int32 l = 0; l < 10; l++) {
630  int32 dim = 100 + Rand() % 700;
631 
632  CuVector<Real> cu_vector(dim);
633  cu_vector.SetRandn();
634 
635  Vector<Real> vector(cu_vector);
636 
637  BaseFloat pow = -2 + (Rand() % 5);
638  cu_vector.ApplyPow(pow);
639  vector.ApplyPow(pow);
640 
641  CuVector<Real> cu2(vector);
642 
643  AssertEqual(cu2, cu_vector);
644  }
645 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApplySoftMax()

void kaldi::CuVectorUnitTestApplySoftMax ( )

Definition at line 506 of file cu-vector-test.cc.

References CuVectorBase< Real >::ApplySoftMax(), VectorBase< Real >::ApplySoftMax(), AssertEqual(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

506  {
507  for (int32 i = 0; i < 10; i++) {
508  int32 dim = 100 + Rand() % 300;
509  //int32 dim = 1024;
510  CuVector<Real> cu_vector(dim);
511  cu_vector.SetRandn();
512  Vector<Real> vector(cu_vector);
513 
514  cu_vector.ApplySoftMax();
515  vector.ApplySoftMax();
516  CuVector<Real> cu_vector2(vector);
517  //std::cout<<cu_vector <<"\n"<<cu_vector2<<std::endl;
518  AssertEqual(cu_vector, cu_vector2);
519  }
520 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestApproxEqual()

void kaldi::CuVectorUnitTestApproxEqual ( )

Definition at line 280 of file cu-vector-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, Rand(), and CuVectorBase< Real >::SetRandn().

280  {
281  int32 M = 10 + Rand() % 100;
282  CuVector<Real> vec1(M), vec2(M);
283  vec1.SetRandn();
284  vec2.SetRandn();
285  Real tol = 0.5;
286  for (int32 i = 0; i < 10; i++) {
287  Real sumsq = 0.0, sumsq_orig = 0.0;
288  for (int32 j = 0; j < M; j++) {
289  sumsq += (vec1(j) - vec2(j)) * (vec1(j) - vec2(j));
290  sumsq_orig += vec1(j) * vec1(j);
291  }
292  Real rms = sqrt(sumsq), rms_orig = sqrt(sumsq_orig);
293  KALDI_ASSERT(vec1.ApproxEqual(vec2, tol) == (rms <= tol * rms_orig));
294  tol *= 2.0;
295  }
296 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestCopyCross()

void kaldi::CuVectorUnitTestCopyCross ( )

Definition at line 424 of file cu-vector-test.cc.

References AssertEqual(), CuVectorBase< Real >::CopyFromVec(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

424  {
425  for (int32 i = 0; i < 10; i++) {
426  int32 M = 100 + Rand() % 255;
427  if (Rand() % 3 == 0) M = 0;
428  CuVector<Real> v1(M);
429  v1.SetRandn();
430  CuVector<float> v2(M);
431  v2.CopyFromVec(v1);
432  CuVector<Real> v3(M);
433  v3.CopyFromVec(v2);
434  AssertEqual(v1, v3);
435  }
436 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestCopyCross2()

void kaldi::CuVectorUnitTestCopyCross2 ( )

Definition at line 438 of file cu-vector-test.cc.

References AssertEqual(), CuVectorBase< Real >::CopyFromVec(), VectorBase< Real >::CopyFromVec(), rnnlm::i, Rand(), and CuVectorBase< Real >::SetRandn().

438  {
439  for (int32 i = 0; i < 10; i++) {
440  int32 M = 100 + Rand() % 255;
441  if (Rand() % 3 == 0) M = 0;
442  CuVector<Real> v1(M);
443  v1.SetRandn();
444  Vector<float> v2(M);
445  v2.CopyFromVec(v1);
446  CuVector<Real> v3(M);
447  v3.CopyFromVec(v2);
448  AssertEqual(v1, v3);
449  }
450 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestCopyDiagFromMat()

void kaldi::CuVectorUnitTestCopyDiagFromMat ( )

Definition at line 452 of file cu-vector-test.cc.

References AssertEqual(), CuVectorBase< Real >::CopyDiagFromMat(), VectorBase< Real >::CopyDiagFromMat(), rnnlm::i, kUndefined, Rand(), MatrixBase< Real >::SetRandn(), CuVectorBase< Real >::Sum(), VectorBase< Real >::Sum(), MatrixBase< Real >::Trace(), CuMatrixBase< Real >::Trace(), and Matrix< Real >::Transpose().

452  {
453  for (int32 i = 0; i < 5; i++) {
454  int32 M = 100 + Rand() % 255, N = M + Rand() % 2;
455  Matrix<Real> matrix(M, N);
456  if (i % 2 == 0) matrix.Transpose();
457  matrix.SetRandn();
458  Vector<Real> vector(M, kUndefined);
459  vector.CopyDiagFromMat(matrix);
460 
461  CuMatrix<Real> cuda_matrix(matrix);
462  CuVector<Real> cuda_vector(M, kUndefined);
463  cuda_vector.CopyDiagFromMat(cuda_matrix);
464  Vector<Real> vector2(cuda_vector);
465  AssertEqual(vector, vector2);
466  AssertEqual(vector.Sum(), cuda_matrix.Trace(false));
467  AssertEqual(cuda_vector.Sum(), matrix.Trace(false));
468  }
469 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276

◆ CuVectorUnitTestCopyDiagFromPacked()

void kaldi::CuVectorUnitTestCopyDiagFromPacked ( )

Definition at line 409 of file cu-vector-test.cc.

References VectorBase< Real >::ApproxEqual(), CuVectorBase< Real >::CopyDiagFromPacked(), VectorBase< Real >::CopyDiagFromPacked(), rnnlm::i, KALDI_ASSERT, kUndefined, Rand(), and CuPackedMatrix< Real >::SetRandn().

409  {
410  for (int32 i = 0; i < 5; i++) {
411  int32 N = 100 + Rand() % 255;
412  CuSpMatrix<Real> S(N);
413  S.SetRandn();
415  V.CopyDiagFromPacked(S);
416  SpMatrix<Real> cpu_S(S);
417  Vector<Real> cpu_V(N);
418  cpu_V.CopyDiagFromPacked(cpu_S);
419  Vector<Real> cpu_V2(V);
420  KALDI_ASSERT(cpu_V.ApproxEqual(cpu_V2));
421  }
422 }
Packed symetric matrix class.
Definition: matrix-common.h:62
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestCopyElements()

void kaldi::CuVectorUnitTestCopyElements ( )

Definition at line 207 of file cu-vector-test.cc.

References AssertEqual(), CuVectorBase< Real >::CopyElements(), rnnlm::i, rnnlm::j, kNoTrans, kTrans, kUndefined, rnnlm::n, Rand(), CuMatrix< Real >::Resize(), CuVectorBase< Real >::SetRandn(), and CuMatrixBase< Real >::SetRandn().

207  {
208  int32 dim = 10 + Rand() % 100, N = 20 + Rand() % 50;
209  CuVector<Real> V(dim);
210  V.SetRandn();
211  CuVector<Real> V_copy(V);
212  for (int n = 0; n < 2; n++) {
213  bool transpose = (n == 0);
214  CuMatrix<Real> M;
215  if (!transpose)
216  M.Resize(dim, N, kUndefined);
217  else
218  M.Resize(N, dim, kUndefined);
219  M.SetRandn();
220  std::vector<int32> elements(dim);
221  for (int32 i = 0; i < dim; i++) {
222  int32 j = elements[i] = Rand() % N;
223  if (!transpose)
224  V_copy(i) = M(i, j);
225  else
226  V_copy(i) = M(j, i);
227  }
228  CuArray<int32> cu_elements(elements);
229  V.CopyElements(M, transpose ? kTrans : kNoTrans, cu_elements);
230  AssertEqual(V, V_copy);
231  }
232 }
kaldi::int32 int32
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
struct rnnlm::@11::@12 n
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
Definition: cu-matrix.cc:50

◆ CuVectorUnitTestCopyFromMat()

void kaldi::CuVectorUnitTestCopyFromMat ( )

Definition at line 375 of file cu-vector-test.cc.

References CuVectorBase< Real >::CopyColFromMat(), CuVectorBase< Real >::CopyRowsFromMat(), VectorBase< Real >::CopyRowsFromMat(), MatrixBase< Real >::CopyRowsFromVec(), CuMatrixBase< Real >::CopyRowsFromVec(), rnnlm::i, rnnlm::j, KALDI_ASSERT, Rand(), and CuMatrixBase< Real >::SetRandn().

375  {
376  int32 M = 100 + Rand() % 255, N = 100 + Rand() % 255;
377  CuMatrix<Real> cu_matrix(M, N);
378  cu_matrix.SetRandn();
379  for(int32 i = 0; i < N; i++) {
380  CuVector<Real> vector(M);
381  vector.CopyColFromMat(cu_matrix, i);
382  for(int32 j = 0; j < M; j++) {
383  KALDI_ASSERT(vector(j)==cu_matrix(j, i));
384  }
385  }
386  Matrix<Real> matrix(cu_matrix), matrix2(M, N);
387  CuMatrix<Real> matrix3(M, N);
388 
389  CuVector<Real> vector(M * N), vector2(M * N);
390  vector.CopyRowsFromMat(cu_matrix);
391  vector2.CopyRowsFromMat(matrix);
392  matrix2.CopyRowsFromVec(vector2);
393  matrix3.CopyRowsFromVec(Vector<Real>(vector2));
394  Vector<Real> vector3(M * N);
395  vector3.CopyRowsFromMat(cu_matrix);
396 
397 
398  for(int32 j = 0; j < M*N; j++) {
399  if (Rand() % 500 == 0) { // random small subset (it was slow)
400  KALDI_ASSERT(vector(j) == cu_matrix(j/N, j%N));
401  KALDI_ASSERT(vector2(j) == cu_matrix(j/N, j%N));
402  KALDI_ASSERT(vector2(j) == matrix2(j/N, j%N));
403  KALDI_ASSERT(vector3(j) == matrix2(j/N, j%N));
404  KALDI_ASSERT(vector3(j) == matrix3(j/N, j%N));
405  }
406  }
407 }
kaldi::int32 int32
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestInvertElements()

void kaldi::CuVectorUnitTestInvertElements ( )

Definition at line 327 of file cu-vector-test.cc.

References AssertEqual(), CuVectorBase< Real >::InvertElements(), CuVectorBase< Real >::MulElements(), Rand(), CuVectorBase< Real >::SetRandn(), and VecVec().

327  {
328  // Also tests MulElements();
329  int32 M = 256 + Rand() % 100;
330  CuVector<Real> vec1(M);
331  vec1.SetRandn();
332  CuVector<Real> vec2(vec1);
333  vec2.InvertElements();
334  CuVector<Real> vec3(vec1);
335  vec3.MulElements(vec2);
336  // vec3 should be all ones.
337  Real prod = VecVec(vec3, vec3);
338  AssertEqual(prod, static_cast<Real>(M));
339 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ CuVectorUnitTestMax()

void kaldi::CuVectorUnitTestMax ( )

Definition at line 494 of file cu-vector-test.cc.

References KALDI_ASSERT, CuVectorBase< Real >::Max(), VectorBase< Real >::Max(), Rand(), and CuVectorBase< Real >::SetRandn().

494  {
495  for (int32 p = 1; p <= 1000000; p *= 2) {
496  int32 dim = p + Rand() % 500;
497  CuVector<Real> cu_vector(dim);
498  cu_vector.SetRandn();
499  Vector<Real> vector(cu_vector);
500  Real max1 = cu_vector.Max(), max2 = vector.Max();
501  KALDI_ASSERT(max1 == max2);
502  }
503 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestMin()

void kaldi::CuVectorUnitTestMin ( )

Definition at line 482 of file cu-vector-test.cc.

References KALDI_ASSERT, CuVectorBase< Real >::Min(), VectorBase< Real >::Min(), Rand(), and CuVectorBase< Real >::SetRandn().

482  {
483  for (int32 p = 1; p <= 1000000; p *= 2) {
484  int32 dim = p + Rand() % 500;
485  CuVector<Real> cu_vector(dim);
486  cu_vector.SetRandn();
487  Vector<Real> vector(cu_vector);
488  Real min1 = cu_vector.Min(), min2 = vector.Min();
489  KALDI_ASSERT(min1 == min2);
490  }
491 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuVectorUnitTestNorm()

void kaldi::CuVectorUnitTestNorm ( )

Definition at line 472 of file cu-vector-test.cc.

References ApproxEqual(), KALDI_ASSERT, and CuVectorBase< Real >::Norm().

472  {
473  int32 dim = 2;
474  CuVector<Real> cu_vector(dim);
475  cu_vector(0) = 1.0;
476  cu_vector(1) = -2.0;
477  KALDI_ASSERT(ApproxEqual(cu_vector.Norm(1.0), 3.0));
478  KALDI_ASSERT(ApproxEqual(cu_vector.Norm(2.0), sqrt(5.0)));
479 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ CuVectorUnitTestScale()

void kaldi::CuVectorUnitTestScale ( )

Definition at line 361 of file cu-vector-test.cc.

References ApproxEqual(), rnnlm::i, KALDI_ASSERT, Rand(), CuVectorBase< Real >::Scale(), VectorBase< Real >::Scale(), and CuVectorBase< Real >::SetRandn().

361  {
362  for (int32 i = 0; i < 4; i++) {
363  int32 dim = 100 + Rand() % 400;
364  CuVector<Real> cu_vec(dim);
365  cu_vec.SetRandn();
366  Vector<Real> vec(cu_vec);
367  BaseFloat scale = 0.333;
368  cu_vec.Scale(scale);
369  vec.Scale(scale);
370  Vector<Real> vec2(cu_vec);
371  KALDI_ASSERT(ApproxEqual(vec, vec2));
372  }
373 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ CuVectorUnitTestSum()

void kaldi::CuVectorUnitTestSum ( )

Definition at line 341 of file cu-vector-test.cc.

References VectorBase< Real >::ApplyAbs(), KALDI_ASSERT, Rand(), CuVectorBase< Real >::Set(), VectorBase< Real >::Sum(), and VecVec().

341  {
342  for (int32 p = 1; p <= 1000000; p *= 2) {
343  MatrixIndexT dim = p + Rand() % 500;
344  CuVector<Real> A(dim), ones(dim);
345  A.SetRandn();
346  ones.Set(1.0);
347 
348  Real x = VecVec(A, ones);
349  Real y = A.Sum();
350  Real diff = std::abs(x - y);
351  // Note: CuVectorBase<> does not have an ApplyAbs() member
352  // function, so we copy back to a host vector for simplicity in
353  // this test case.
354  Vector<Real> A_host(A);
355  A_host.ApplyAbs();
356  Real s = A_host.Sum();
357  KALDI_ASSERT ( diff <= 1.0e-04 * s);
358  }
359 }
kaldi::int32 int32
int32 MatrixIndexT
Definition: matrix-common.h:98
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ CuVectorUnitTestVecVec()

void kaldi::CuVectorUnitTestVecVec ( )

Definition at line 144 of file cu-vector-test.cc.

References AssertEqual(), rnnlm::i, Rand(), CuVectorBase< Real >::SetRandn(), and VecVec().

144  {
145  int32 M = 10 + Rand() % 100;
146  CuVector<Real> vec1(M), vec2(M);
147  vec1.SetRandn();
148  vec2.SetRandn();
149  Real prod = 0.0;
150  for (int32 i = 0; i < M; i++)
151  prod += vec1(i) * vec2(i);
152  AssertEqual(prod, VecVec(vec1, vec2));
153 }
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ cygprefix()

static std::string kaldi::cygprefix ( "/cygdrive/"  )
static

Referenced by prefixp().

◆ CygwinCompatPopen()

static FILE* kaldi::CygwinCompatPopen ( const char *  command,
const char *  mode 
)
static

Definition at line 110 of file kaldi-cygwin-io-inl.h.

110  {
111  // To speed up command launch marginally, optionally accept full path
112  // to bash.exe. This will not work if the path contains spaces, but
113  // no sane person would install cygwin into a space-ridden path.
114  const char* bash_exe = std::getenv("BASH_EXE");
115  std::string qcmd(bash_exe != nullptr ? bash_exe : "bash.exe");
116  qcmd += " -c \"";
117  for (; *command; ++command) {
118  if (*command == '\"')
119  qcmd += '\"';
120  qcmd += *command;
121  }
122  qcmd += '\"';
123 
124  return _popen(qcmd.c_str(), mode);
125 }

◆ DecodeLabelUid()

StateId kaldi::DecodeLabelUid ( uint64  osymbol)

Definition at line 42 of file kws-search.cc.

Referenced by main(), and OutputDetailedStatistics().

42  {
43  return static_cast<StateId>(osymbol >> 32);
44 }
fst::StdArc::StateId StateId

◆ DecodeUtterance()

bool kaldi::DecodeUtterance ( LatticeBiglmFasterDecoder decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

Definition at line 36 of file gmm-latgen-biglm-faster.cc.

References fst::AcousticLatticeScale(), LatticeBiglmFasterDecoder::Decode(), LatticeFasterDecoderConfig::det_opts, fst::DeterminizeLatticePhonePrunedWrapper(), LatticeBiglmFasterDecoder::GetBestPath(), fst::GetLinearSymbolSequence(), LatticeBiglmFasterDecoder::GetOptions(), LatticeBiglmFasterDecoder::GetRawLattice(), rnnlm::i, TableWriter< Holder >::IsOpen(), KALDI_ERR, KALDI_LOG, KALDI_VLOG, KALDI_WARN, LatticeFasterDecoderConfig::lattice_beam, LatticeBiglmFasterDecoder::ReachedFinal(), fst::ScaleLattice(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), words, and TableWriter< Holder >::Write().

Referenced by main().

48  { // puts utterance's like in like_ptr on success.
49  using fst::VectorFst;
50 
51  if (!decoder.Decode(&decodable)) {
52  KALDI_WARN << "Failed to decode file " << utt;
53  return false;
54  }
55  if (!decoder.ReachedFinal()) {
56  if (allow_partial) {
57  KALDI_WARN << "Outputting partial output for utterance " << utt
58  << " since no final-state reached\n";
59  } else {
60  KALDI_WARN << "Not producing output for utterance " << utt
61  << " since no final-state reached and "
62  << "--allow-partial=false.\n";
63  return false;
64  }
65  }
66 
67  double likelihood;
68  LatticeWeight weight;
69  int32 num_frames;
70  { // First do some stuff with word-level traceback...
71  VectorFst<LatticeArc> decoded;
72  decoder.GetBestPath(&decoded);
73  if (decoded.NumStates() == 0)
74  // Shouldn't really reach this point as already checked success.
75  KALDI_ERR << "Failed to get traceback for utterance " << utt;
76 
77  std::vector<int32> alignment;
78  std::vector<int32> words;
79  GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
80  num_frames = alignment.size();
81  if (words_writer->IsOpen())
82  words_writer->Write(utt, words);
83  if (alignment_writer->IsOpen())
84  alignment_writer->Write(utt, alignment);
85  if (word_syms != NULL) {
86  std::cerr << utt << ' ';
87  for (size_t i = 0; i < words.size(); i++) {
88  std::string s = word_syms->Find(words[i]);
89  if (s == "")
90  KALDI_ERR << "Word-id " << words[i] <<" not in symbol table.";
91  std::cerr << s << ' ';
92  }
93  std::cerr << '\n';
94  }
95  likelihood = -(weight.Value1() + weight.Value2());
96  }
97 
98  // Get lattice, and do determinization if requested.
99  Lattice lat;
100  decoder.GetRawLattice(&lat);
101  if (lat.NumStates() == 0)
102  KALDI_ERR << "Unexpected problem getting lattice for utterance " << utt;
103  fst::Connect(&lat);
104  if (determinize) {
105  CompactLattice clat;
107  trans_model,
108  &lat,
109  decoder.GetOptions().lattice_beam,
110  &clat,
111  decoder.GetOptions().det_opts))
112  KALDI_WARN << "Determinization finished earlier than the beam for "
113  << "utterance " << utt;
114  // We'll write the lattice without acoustic scaling.
115  if (acoustic_scale != 0.0)
116  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &clat);
117  compact_lattice_writer->Write(utt, clat);
118  } else {
119  Lattice fst;
120  decoder.GetRawLattice(&fst);
121  if (fst.NumStates() == 0)
122  KALDI_ERR << "Unexpected problem getting lattice for utterance "
123  << utt;
124  fst::Connect(&fst); // Will get rid of this later... shouldn't have any
125  // disconnected states there, but we seem to.
126  if (acoustic_scale != 0.0) // We'll write the lattice without acoustic scaling
127  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &fst);
128  lattice_writer->Write(utt, fst);
129  }
130  KALDI_LOG << "Log-like per frame for utterance " << utt << " is "
131  << (likelihood / num_frames) << " over "
132  << num_frames << " frames.";
133  KALDI_VLOG(2) << "Cost for utterance " << utt << " is "
134  << weight.Value1() << " + " << weight.Value2();
135  *like_ptr = likelihood;
136  return true;
137 }
int32 words[kMaxOrder]
bool GetBestPath(fst::MutableFst< LatticeArc > *ofst, bool use_final_probs=true) const
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
bool Decode(DecodableInterface *decodable)
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
void Write(const std::string &key, const T &value) const
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
LatticeBiglmFasterDecoderConfig GetOptions()
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
bool ReachedFinal() const
says whether a final-state was active on the last frame.
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
bool GetRawLattice(fst::MutableFst< LatticeArc > *ofst, bool use_final_probs=true) const
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
fst::DeterminizeLatticePhonePrunedOptions det_opts
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
#define KALDI_LOG
Definition: kaldi-error.h:153
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...

◆ DecodeUtteranceLatticeFaster() [1/3]

bool DecodeUtteranceLatticeFaster ( LatticeFasterDecoderTpl< FST > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignments_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

This function DecodeUtteranceLatticeFaster is used in several decoders, and we have moved it here.

Note: this is really "binary-level" code as it involves table readers and writers; we've just put it here as there is no other obvious place to put it. If determinize == false, it writes to lattice_writer, else to compact_lattice_writer. The writers for alignments and words will only be written to if they are open.

Caution: this will only link correctly if FST is either fst::Fst<fst::StdArc>, or fst::GrammarFst, as the template function is defined in the .cc file and only instantiated for those two types.

Definition at line 287 of file decoder-wrappers.cc.

References fst::AcousticLatticeScale(), LatticeFasterDecoderTpl< FST, Token >::Decode(), DecodeUtteranceLatticeIncremental(), fst::DeterminizeLatticePhonePrunedWrapper(), LatticeFasterDecoderTpl< FST, Token >::GetBestPath(), fst::GetLinearSymbolSequence(), LatticeFasterDecoderTpl< FST, Token >::GetOptions(), LatticeFasterDecoderTpl< FST, Token >::GetRawLattice(), rnnlm::i, TableWriter< Holder >::IsOpen(), KALDI_ERR, KALDI_LOG, KALDI_VLOG, KALDI_WARN, LatticeFasterDecoderTpl< FST, Token >::ReachedFinal(), fst::ScaleLattice(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), words, and TableWriter< Holder >::Write().

Referenced by main(), ProcessUtterance(), and AlignConfig::Register().

300  { // puts utterance's like in like_ptr on success.
301  using fst::VectorFst;
302 
303  if (!decoder.Decode(&decodable)) {
304  KALDI_WARN << "Failed to decode utterance with id " << utt;
305  return false;
306  }
307  if (!decoder.ReachedFinal()) {
308  if (allow_partial) {
309  KALDI_WARN << "Outputting partial output for utterance " << utt
310  << " since no final-state reached\n";
311  } else {
312  KALDI_WARN << "Not producing output for utterance " << utt
313  << " since no final-state reached and "
314  << "--allow-partial=false.\n";
315  return false;
316  }
317  }
318 
319  double likelihood;
320  LatticeWeight weight;
321  int32 num_frames;
322  { // First do some stuff with word-level traceback...
323  VectorFst<LatticeArc> decoded;
324  if (!decoder.GetBestPath(&decoded))
325  // Shouldn't really reach this point as already checked success.
326  KALDI_ERR << "Failed to get traceback for utterance " << utt;
327 
328  std::vector<int32> alignment;
329  std::vector<int32> words;
330  GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
331  num_frames = alignment.size();
332  if (words_writer->IsOpen())
333  words_writer->Write(utt, words);
334  if (alignment_writer->IsOpen())
335  alignment_writer->Write(utt, alignment);
336  if (word_syms != NULL) {
337  std::cerr << utt << ' ';
338  for (size_t i = 0; i < words.size(); i++) {
339  std::string s = word_syms->Find(words[i]);
340  if (s == "")
341  KALDI_ERR << "Word-id " << words[i] << " not in symbol table.";
342  std::cerr << s << ' ';
343  }
344  std::cerr << '\n';
345  }
346  likelihood = -(weight.Value1() + weight.Value2());
347  }
348 
349  // Get lattice, and do determinization if requested.
350  Lattice lat;
351  decoder.GetRawLattice(&lat);
352  if (lat.NumStates() == 0)
353  KALDI_ERR << "Unexpected problem getting lattice for utterance " << utt;
354  fst::Connect(&lat);
355  if (determinize) {
356  CompactLattice clat;
358  trans_model,
359  &lat,
360  decoder.GetOptions().lattice_beam,
361  &clat,
362  decoder.GetOptions().det_opts))
363  KALDI_WARN << "Determinization finished earlier than the beam for "
364  << "utterance " << utt;
365  // We'll write the lattice without acoustic scaling.
366  if (acoustic_scale != 0.0)
367  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &clat);
368  compact_lattice_writer->Write(utt, clat);
369  } else {
370  // We'll write the lattice without acoustic scaling.
371  if (acoustic_scale != 0.0)
372  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &lat);
373  lattice_writer->Write(utt, lat);
374  }
375  KALDI_LOG << "Log-like per frame for utterance " << utt << " is "
376  << (likelihood / num_frames) << " over "
377  << num_frames << " frames.";
378  KALDI_VLOG(2) << "Cost for utterance " << utt << " is "
379  << weight.Value1() << " + " << weight.Value2();
380  *like_ptr = likelihood;
381  return true;
382 }
int32 words[kMaxOrder]
kaldi::int32 int32
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
LatticeWeightTpl< BaseFloat > LatticeWeight
#define KALDI_LOG
Definition: kaldi-error.h:153
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...

◆ DecodeUtteranceLatticeFaster() [2/3]

template bool kaldi::DecodeUtteranceLatticeFaster ( LatticeFasterDecoderTpl< fst::Fst< fst::StdArc > > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

◆ DecodeUtteranceLatticeFaster() [3/3]

template bool kaldi::DecodeUtteranceLatticeFaster ( LatticeFasterDecoderTpl< fst::GrammarFst > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

◆ DecodeUtteranceLatticeIncremental() [1/3]

bool DecodeUtteranceLatticeIncremental ( LatticeIncrementalDecoderTpl< FST > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

TODO.

Definition at line 199 of file decoder-wrappers.cc.

References fst::AcousticLatticeScale(), CompactLatticeShortestPath(), fst::ConvertLattice(), LatticeIncrementalDecoderTpl< FST, Token >::Decode(), LatticeIncrementalDecoderTpl< FST, Token >::GetLattice(), fst::GetLinearSymbolSequence(), rnnlm::i, TableWriter< Holder >::IsOpen(), KALDI_ASSERT, KALDI_ERR, KALDI_LOG, KALDI_VLOG, KALDI_WARN, LatticeIncrementalDecoderTpl< FST, Token >::NumFramesDecoded(), LatticeIncrementalDecoderTpl< FST, Token >::ReachedFinal(), fst::ScaleLattice(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), words, and TableWriter< Holder >::Write().

Referenced by DecodeUtteranceLatticeFaster(), main(), and AlignConfig::Register().

212  { // puts utterance's like in like_ptr on success.
213  using fst::VectorFst;
214  if (!decoder.Decode(&decodable)) {
215  KALDI_WARN << "Failed to decode utterance with id " << utt;
216  return false;
217  }
218  if (!decoder.ReachedFinal()) {
219  if (allow_partial) {
220  KALDI_WARN << "Outputting partial output for utterance " << utt
221  << " since no final-state reached\n";
222  } else {
223  KALDI_WARN << "Not producing output for utterance " << utt
224  << " since no final-state reached and "
225  << "--allow-partial=false.\n";
226  return false;
227  }
228  }
229 
230  // Get lattice
231  CompactLattice clat = decoder.GetLattice(decoder.NumFramesDecoded(), true);
232  if (clat.NumStates() == 0)
233  KALDI_ERR << "Unexpected problem getting lattice for utterance " << utt;
234 
235  double likelihood;
236  LatticeWeight weight;
237  int32 num_frames;
238  { // First do some stuff with word-level traceback...
239  CompactLattice decoded_clat;
240  CompactLatticeShortestPath(clat, &decoded_clat);
241  Lattice decoded;
242  fst::ConvertLattice(decoded_clat, &decoded);
243 
244  if (decoded.Start() == fst::kNoStateId)
245  // Shouldn't really reach this point as already checked success.
246  KALDI_ERR << "Failed to get traceback for utterance " << utt;
247 
248  std::vector<int32> alignment;
249  std::vector<int32> words;
250  GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
251  num_frames = alignment.size();
252  KALDI_ASSERT(num_frames == decoder.NumFramesDecoded());
253  if (words_writer->IsOpen())
254  words_writer->Write(utt, words);
255  if (alignment_writer->IsOpen())
256  alignment_writer->Write(utt, alignment);
257  if (word_syms != NULL) {
258  std::cerr << utt << ' ';
259  for (size_t i = 0; i < words.size(); i++) {
260  std::string s = word_syms->Find(words[i]);
261  if (s == "")
262  KALDI_ERR << "Word-id " << words[i] << " not in symbol table.";
263  std::cerr << s << ' ';
264  }
265  std::cerr << '\n';
266  }
267  likelihood = -(weight.Value1() + weight.Value2());
268  }
269 
270  // We'll write the lattice without acoustic scaling.
271  if (acoustic_scale != 0.0)
272  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &clat);
273  Connect(&clat);
274  compact_lattice_writer->Write(utt, clat);
275  KALDI_LOG << "Log-like per frame for utterance " << utt << " is "
276  << (likelihood / num_frames) << " over "
277  << num_frames << " frames.";
278  KALDI_VLOG(2) << "Cost for utterance " << utt << " is "
279  << weight.Value1() << " + " << weight.Value2();
280  *like_ptr = likelihood;
281  return true;
282 }
int32 words[kMaxOrder]
kaldi::int32 int32
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
void CompactLatticeShortestPath(const CompactLattice &clat, CompactLattice *shortest_path)
A form of the shortest-path/best-path algorithm that&#39;s specially coded for CompactLattice.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
LatticeWeightTpl< BaseFloat > LatticeWeight
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ DecodeUtteranceLatticeIncremental() [2/3]

template bool kaldi::DecodeUtteranceLatticeIncremental ( LatticeIncrementalDecoderTpl< fst::Fst< fst::StdArc > > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

◆ DecodeUtteranceLatticeIncremental() [3/3]

template bool kaldi::DecodeUtteranceLatticeIncremental ( LatticeIncrementalDecoderTpl< fst::GrammarFst > &  decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

◆ DecodeUtteranceLatticeSimple()

bool DecodeUtteranceLatticeSimple ( LatticeSimpleDecoder decoder,
DecodableInterface decodable,
const TransitionModel trans_model,
const fst::SymbolTable *  word_syms,
std::string  utt,
double  acoustic_scale,
bool  determinize,
bool  allow_partial,
Int32VectorWriter alignment_writer,
Int32VectorWriter words_writer,
CompactLatticeWriter compact_lattice_writer,
LatticeWriter lattice_writer,
double *  like_ptr 
)

Definition at line 448 of file decoder-wrappers.cc.

References fst::AcousticLatticeScale(), LatticeSimpleDecoder::Decode(), LatticeSimpleDecoderConfig::det_opts, fst::DeterminizeLatticePhonePrunedWrapper(), LatticeSimpleDecoder::GetBestPath(), fst::GetLinearSymbolSequence(), LatticeSimpleDecoder::GetOptions(), LatticeSimpleDecoder::GetRawLattice(), rnnlm::i, TableWriter< Holder >::IsOpen(), KALDI_ERR, KALDI_LOG, KALDI_VLOG, KALDI_WARN, LatticeSimpleDecoderConfig::lattice_beam, LatticeSimpleDecoder::ReachedFinal(), fst::ScaleLattice(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), words, TableWriter< Holder >::Write(), and LatticeWeightTpl< BaseFloat >::Zero().

Referenced by main().

461  { // puts utterance's like in like_ptr on success.
462  using fst::VectorFst;
463 
464  if (!decoder.Decode(&decodable)) {
465  KALDI_WARN << "Failed to decode utterance with id " << utt;
466  return false;
467  }
468  if (!decoder.ReachedFinal()) {
469  if (allow_partial) {
470  KALDI_WARN << "Outputting partial output for utterance " << utt
471  << " since no final-state reached\n";
472  } else {
473  KALDI_WARN << "Not producing output for utterance " << utt
474  << " since no final-state reached and "
475  << "--allow-partial=false.\n";
476  return false;
477  }
478  }
479 
480  double likelihood;
481  LatticeWeight weight = LatticeWeight::Zero();
482  int32 num_frames;
483  { // First do some stuff with word-level traceback...
484  VectorFst<LatticeArc> decoded;
485  if (!decoder.GetBestPath(&decoded))
486  // Shouldn't really reach this point as already checked success.
487  KALDI_ERR << "Failed to get traceback for utterance " << utt;
488 
489  std::vector<int32> alignment;
490  std::vector<int32> words;
491  GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
492  num_frames = alignment.size();
493  if (words_writer->IsOpen())
494  words_writer->Write(utt, words);
495  if (alignment_writer->IsOpen())
496  alignment_writer->Write(utt, alignment);
497  if (word_syms != NULL) {
498  std::cerr << utt << ' ';
499  for (size_t i = 0; i < words.size(); i++) {
500  std::string s = word_syms->Find(words[i]);
501  if (s == "")
502  KALDI_ERR << "Word-id " << words[i] << " not in symbol table.";
503  std::cerr << s << ' ';
504  }
505  std::cerr << '\n';
506  }
507  likelihood = -(weight.Value1() + weight.Value2());
508  }
509 
510  // Get lattice, and do determinization if requested.
511  Lattice lat;
512  if (!decoder.GetRawLattice(&lat))
513  KALDI_ERR << "Unexpected problem getting lattice for utterance " << utt;
514  fst::Connect(&lat);
515  if (determinize) {
516  CompactLattice clat;
518  trans_model,
519  &lat,
520  decoder.GetOptions().lattice_beam,
521  &clat,
522  decoder.GetOptions().det_opts))
523  KALDI_WARN << "Determinization finished earlier than the beam for "
524  << "utterance " << utt;
525  // We'll write the lattice without acoustic scaling.
526  if (acoustic_scale != 0.0)
527  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &clat);
528  compact_lattice_writer->Write(utt, clat);
529  } else {
530  // We'll write the lattice without acoustic scaling.
531  if (acoustic_scale != 0.0)
532  fst::ScaleLattice(fst::AcousticLatticeScale(1.0 / acoustic_scale), &lat);
533  lattice_writer->Write(utt, lat);
534  }
535  KALDI_LOG << "Log-like per frame for utterance " << utt << " is "
536  << (likelihood / num_frames) << " over "
537  << num_frames << " frames.";
538  KALDI_VLOG(2) << "Cost for utterance " << utt << " is "
539  << weight.Value1() << " + " << weight.Value2();
540  *like_ptr = likelihood;
541  return true;
542 }
int32 words[kMaxOrder]
kaldi::int32 int32
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
LatticeWeightTpl< BaseFloat > LatticeWeight
#define KALDI_LOG
Definition: kaldi-error.h:153
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...

◆ DeletePointers()

void kaldi::DeletePointers ( std::vector< A *> *  v)

Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL.

Definition at line 184 of file stl-utils.h.

References KALDI_ASSERT.

Referenced by AutomaticallyObtainQuestions(), BlockAffineComponent::Backprop(), RegressionTree::BuildTree(), ClusterEventMap(), ClusterEventMapGetMapping(), ClusterEventMapRestrictedByKeys(), ClusterEventMapRestrictedByMap(), ClusterEventMapToNClustersRestrictedByMap(), ClusterGaussiansToUbm(), ClusterKMeans(), ComputeInitialSplit(), AmDiagGmm::CopyFromAmDiagGmm(), DoTableSplit(), FindBestSplitForKey(), RegressionTree::GatherStats(), GetHTransducer(), AmDiagGmm::Init(), AccumAmDiagGmm::Init(), RegtreeMllrDiagGmmAccs::Init(), RegtreeFmllrDiagGmmAccs::Init(), CompositeComponent::Init(), InitAmGmm(), DecodableAmDiagGmmRegtreeMllr::InitCache(), CompositeComponent::InitFromConfig(), KMeansClusterPhones(), main(), MapEventMapLeaves(), DiagGmm::MergeKmeans(), ObjfGivenMap(), BlockAffineComponent::Propagate(), Questions::Read(), RenumberEventMap(), ShareEventMapLeaves(), TestAddToClusters(), TestAddToClustersOptimized(), TestClusterBottomUp(), TestClusterEventMapGetMappingAndRenumberEventMap(), TestClusterEventMapGetMappingAndRenumberEventMap2(), TestClusterKMeans(), TestClusterKMeansVector(), TestClusterTopDown(), TestEnsureClusterableVectorNotNull(), TestRefineClusters(), TestTreeCluster(), TypeOneUsage(), TypeOneUsageAverage(), UnitTestRegtreeFmllrDiagGmm(), RegtreeMllrDiagGmmAccs::Update(), RegtreeFmllrDiagGmmAccs::Update(), AccumAmDiagGmm::~AccumAmDiagGmm(), AmDiagGmm::~AmDiagGmm(), BottomUpClusterer::~BottomUpClusterer(), CompartmentalizedBottomUpClusterer::~CompartmentalizedBottomUpClusterer(), CompositeComponent::~CompositeComponent(), DecodableAmDiagGmmRegtreeMllr::~DecodableAmDiagGmmRegtreeMllr(), DecodableAmNnetSimpleParallel::~DecodableAmNnetSimpleParallel(), GeneralDescriptor::~GeneralDescriptor(), Questions::~Questions(), RegtreeFmllrDiagGmmAccs::~RegtreeFmllrDiagGmmAccs(), RegtreeMllrDiagGmmAccs::~RegtreeMllrDiagGmmAccs(), SwitchingForwardingDescriptor::~SwitchingForwardingDescriptor(), TableEventMap::~TableEventMap(), and TreeClusterer::~TreeClusterer().

184  {
185  KALDI_ASSERT(v != NULL);
186  typename std::vector<A*>::iterator iter = v->begin(), end = v->end();
187  for (; iter != end; ++iter) {
188  if (*iter != NULL) {
189  delete *iter;
190  *iter = NULL; // set to NULL for extra safety.
191  }
192  }
193 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ DeterminizeLatticeWrapper()

bool DeterminizeLatticeWrapper ( const Lattice lat,
const std::string &  key,
bool  prune,
BaseFloat  beam,
BaseFloat  beam_ratio,
int32  max_mem,
int32  max_loop,
BaseFloat  delta,
int32  num_loops,
CompactLattice clat 
)

Definition at line 38 of file lattice-determinize-non-compact.cc.

References DeterminizeLatticeOptions::delta, fst::DeterminizeLattice(), rnnlm::i, KALDI_WARN, DeterminizeLatticeOptions::max_loop, DeterminizeLatticeOptions::max_mem, fst::NumArcs(), and PruneLattice().

Referenced by main().

47  {
49  lat_opts.max_mem = max_mem;
50  lat_opts.max_loop = max_loop;
51  lat_opts.delta = delta;
52  BaseFloat cur_beam = beam;
53  for (int32 i = 0; i < num_loops;) { // we increment i below.
54 
55  if (lat.Start() == fst::kNoStateId) {
56  KALDI_WARN << "Detected empty lattice, skipping " << key;
57  return false;
58  }
59 
60  // The work gets done in the next line.
61  if (DeterminizeLattice(lat, clat, lat_opts, NULL)) {
62  if (prune) PruneLattice(cur_beam, clat);
63  return true;
64  } else { // failed to determinize..
65  KALDI_WARN << "Failed to determinize lattice (presumably max-states "
66  << "reached), reducing lattice-beam to "
67  << (cur_beam*beam_ratio) << " and re-trying.";
68  for (; i < num_loops; i++) {
69  cur_beam *= beam_ratio;
70  Lattice pruned_lat(lat);
71  PruneLattice(cur_beam, &pruned_lat);
72  if (NumArcs(lat) == NumArcs(pruned_lat)) {
73  cur_beam *= beam_ratio;
74  KALDI_WARN << "Pruning did not have an effect on the original "
75  << "lattice size; reducing beam to "
76  << cur_beam << " and re-trying.";
77  } else if (DeterminizeLattice(pruned_lat, clat, lat_opts, NULL)) {
78  if (prune) PruneLattice(cur_beam, clat);
79  return true;
80  } else {
81  KALDI_WARN << "Determinization failed again; reducing beam again to "
82  << (cur_beam*beam_ratio) << " and re-trying.";
83  }
84  }
85  }
86  }
87  KALDI_WARN << "Decreased pruning beam --num-loops=" << num_loops
88  << " times and was not able to determinize: failed for "
89  << key;
90  return false;
91 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
bool PruneLattice(BaseFloat beam, LatType *lat)
bool DeterminizeLattice(const Fst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< Weight > > *ofst, DeterminizeLatticeOptions opts, bool *debug_ptr)
This function implements the normal version of DeterminizeLattice, in which the output strings are re...
Arc::StateId NumArcs(const ExpandedFst< Arc > &fst)
Returns the total number of arcs in an FST.

◆ DiagGmmToStats()

void DiagGmmToStats ( const DiagGmm gmm,
GmmFlagsType  flags,
double  state_occ,
AccumDiagGmm dst_stats 
)

Creates stats from the GMM. Resizes them as needed.

Definition at line 339 of file ebw-diag-gmm.cc.

References AccumDiagGmm::AddStatsForComponent(), VectorBase< Real >::AddVec(), VectorBase< Real >::AddVec2(), AugmentGmmFlags(), DiagGmm::Dim(), DiagGmmNormal::means_, DiagGmm::NumGauss(), AccumDiagGmm::Resize(), MatrixBase< Real >::Row(), VectorBase< Real >::SetZero(), DiagGmmNormal::vars_, and DiagGmmNormal::weights_.

Referenced by IsmoothStatsAmDiagGmmFromModel(), and EbwWeightOptions::Register().

342  {
343  dst_stats->Resize(gmm, AugmentGmmFlags(flags));
344  int32 num_gauss = gmm.NumGauss(), dim = gmm.Dim();
345  DiagGmmNormal gmmnormal(gmm);
346  Vector<double> x_stats(dim), x2_stats(dim);
347  for (int32 g = 0; g < num_gauss; g++) {
348  double occ = state_occ * gmmnormal.weights_(g);
349  x_stats.SetZero();
350  x_stats.AddVec(occ, gmmnormal.means_.Row(g));
351  x2_stats.SetZero();
352  x2_stats.AddVec2(occ, gmmnormal.means_.Row(g));
353  x2_stats.AddVec(occ, gmmnormal.vars_.Row(g));
354  dst_stats->AddStatsForComponent(g, occ, x_stats, x2_stats);
355  }
356 }
GmmFlagsType AugmentGmmFlags(GmmFlagsType f)
Returns "augmented" version of flags: e.g.
Definition: model-common.cc:52
kaldi::int32 int32

◆ DifferenceWrapper()

static void kaldi::DifferenceWrapper ( const fst::VectorFst< Arc > &  fst1,
const fst::VectorFst< Arc > &  fst2,
fst::VectorFst< Arc > *  difference 
)
static

Definition at line 303 of file kws-functions.cc.

References fst::RemoveWeights().

Referenced by MaybeDoSanityCheck().

305  {
306  using namespace fst;
307  if (!fst2.Properties(kAcceptor, true)) {
308  // make it an acceptor by encoding the weights.
309  EncodeMapper<Arc> encoder(kEncodeLabels, ENCODE);
310  VectorFst<Arc> fst1_copy(fst1);
311  VectorFst<Arc> fst2_copy(fst2);
312  Encode(&fst1_copy, &encoder);
313  Encode(&fst2_copy, &encoder);
314  DifferenceWrapper(fst1_copy, fst2_copy, difference);
315  Decode(difference, encoder);
316  } else {
317  VectorFst<Arc> fst2_copy(fst2);
318  RmEpsilon(&fst2_copy); // or Difference will crash.
319  RemoveWeights(&fst2_copy); // or Difference will crash.
320  Difference(fst1, fst2_copy, difference);
321  }
322 }
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
static void DifferenceWrapper(const fst::VectorFst< Arc > &fst1, const fst::VectorFst< Arc > &fst2, fst::VectorFst< Arc > *difference)
void RemoveWeights(MutableFst< Arc > *ifst)

◆ DirExist()

bool kaldi::DirExist ( const std::string &  dirname)

Definition at line 43 of file pitch-functions-test.cc.

References KALDI_LOG.

Referenced by main().

43  {
44  struct stat st;
45  if (stat(dirname.c_str(), &st) != 0) {
46  KALDI_LOG << " directory " << dirname << " does not exist!";
47  return false;
48  }
49  return true;
50 }
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ DivideRoundingDown()

static int32 kaldi::DivideRoundingDown ( int32  a,
int32  b 
)
inlinestatic

Returns a / b, rounding towards negative infinity in all cases.

Definition at line 287 of file kaldi-math.h.

References KALDI_ASSERT.

Referenced by BackpropTruncationComponent::PrecomputeIndexes(), GeneralDropoutComponent::PrecomputeIndexes(), kaldi::nnet3::time_height_convolution::RoundDownToMultipleOf(), and UnitTestDivideRoundingDown().

287  {
288  KALDI_ASSERT(b != 0);
289  if (a * b >= 0)
290  return a / b;
291  else if (a < 0)
292  return (a - b + 1) / b;
293  else
294  return (a - b - 1) / b;
295 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ DoFactorDisambiguation()

void DoFactorDisambiguation ( KwsLexicographicFst index_transducer)

Definition at line 98 of file kws-functions2.cc.

Referenced by main().

98  {
99  using namespace fst;
101 
102  StateId ns = index_transducer->NumStates();
103  for (StateId s = 0; s < ns; s++) {
104  for (MutableArcIterator<KwsLexicographicFst>
105  aiter(index_transducer, s); !aiter.Done(); aiter.Next()) {
106  KwsLexicographicArc arc = aiter.Value();
107  if (index_transducer->Final(arc.nextstate) != KwsLexicographicWeight::Zero())
108  arc.ilabel = s;
109  else
110  arc.olabel = 0;
111  aiter.SetValue(arc);
112  }
113  }
114 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
StdLStdLStdArc KwsLexicographicArc
Definition: kaldi-kws.h:45

◆ DoFactorMerging()

void DoFactorMerging ( KwsProductFst factor_transducer,
KwsLexicographicFst index_transducer 
)

Definition at line 53 of file kws-functions2.cc.

References fst::DeterminizeStar(), KALDI_VLOG, MaybeDoSanityCheck(), and ReplaceSymbolWithEpsilon().

Referenced by main().

54  {
55  using namespace fst;
57 
58  // Encode the transducer first
59  EncodeMapper<KwsProductArc> encoder(kEncodeLabels, ENCODE);
60  Encode(factor_transducer, &encoder);
61 
62 
63  // We want DeterminizeStar to remove epsilon arcs, so turn whatever it encoded
64  // epsilons as, into actual epsilons.
65  {
66  KwsProductArc epsilon_arc(0, 0, KwsProductWeight::One(), 0);
67  Label epsilon_label = encoder(epsilon_arc).ilabel;
68  ReplaceSymbolWithEpsilon(epsilon_label, factor_transducer);
69  }
70 
71 
72  MaybeDoSanityCheck(*factor_transducer);
73 
74  // Use DeterminizeStar
75  KALDI_VLOG(2) << "DoFactorMerging: determinization...";
76  KwsProductFst dest_transducer;
77  DeterminizeStar(*factor_transducer, &dest_transducer);
78 
79  MaybeDoSanityCheck(dest_transducer);
80 
81  // Commenting the minimization out, as it moves states/arcs in a way we don't
82  // want in some rare cases. For example, if we have two arcs from starting
83  // state, which have same words on the input side, but different cluster IDs
84  // on the output side, it may make the two arcs sharing a common final arc,
85  // which will cause problem in the factor disambiguation stage (we will not
86  // be able to add disambiguation symbols for both paths). We do a final step
87  // optimization anyway so commenting this out shouldn't matter too much.
88  // KALDI_VLOG(2) << "DoFactorMerging: minimization...";
89  // Minimize(&dest_transducer);
90 
91  MaybeDoSanityCheck(dest_transducer);
92 
93  Decode(&dest_transducer, encoder);
94 
95  Map(dest_transducer, index_transducer, KwsProductFstToKwsLexicographicFstMapper());
96 }
fst::VectorFst< KwsProductArc > KwsProductFst
Definition: kaldi-kws.h:49
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
static void ReplaceSymbolWithEpsilon(typename Arc::Label symbol, fst::VectorFst< Arc > *fst)
fst::StdArc::Label Label
void MaybeDoSanityCheck(const KwsLexicographicFst &index_transducer)
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
LogXStdXStdprimeArc KwsProductArc
Definition: kaldi-kws.h:48
bool DeterminizeStar(F &ifst, MutableFst< typename F::Arc > *ofst, float delta, bool *debug_ptr, int max_states, bool allow_partial)
This function implements the normal version of DeterminizeStar, in which the output strings are repre...

◆ DoRescalingUpdate() [1/2]

void kaldi::DoRescalingUpdate ( const AccumDiagGmm old_ml_acc,
const AccumDiagGmm new_ml_acc,
BaseFloat  min_variance,
BaseFloat  min_gaussian_occupancy,
DiagGmm gmm,
double *  tot_count,
double *  tot_divergence 
)

Definition at line 177 of file indirect-diff-diag-gmm.cc.

References DiagGmmNormal::CopyToDiagGmm(), rnnlm::d, DiagGmm::Dim(), AccumDiagGmm::Dim(), AccumDiagGmm::Flags(), KALDI_ASSERT, KALDI_WARN, kGmmMeans, kGmmVariances, Log(), AccumDiagGmm::mean_accumulator(), DiagGmmNormal::means_, DiagGmm::NumGauss(), AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy(), AccumDiagGmm::variance_accumulator(), and DiagGmmNormal::vars_.

Referenced by DoRescalingUpdate(), and main().

183  {
184  int32 num_gauss = gmm->NumGauss(), dim = gmm->Dim();
185  KALDI_ASSERT(old_ml_acc.NumGauss() == num_gauss &&
186  old_ml_acc.Dim() == dim);
187  KALDI_ASSERT(new_ml_acc.NumGauss() == num_gauss &&
188  new_ml_acc.Dim() == dim);
189  KALDI_ASSERT((old_ml_acc.Flags() & (kGmmMeans|kGmmVariances)) ==
191  KALDI_ASSERT((new_ml_acc.Flags() & (kGmmMeans|kGmmVariances)) ==
193 
194  DiagGmmNormal gmm_normal(*gmm);
195  for (int32 gauss = 0; gauss < num_gauss; gauss++) {
196  double old_ml_count = old_ml_acc.occupancy()(gauss),
197  new_ml_count = new_ml_acc.occupancy()(gauss);
198  if (old_ml_count <= min_gaussian_occupancy ||
199  new_ml_count <= min_gaussian_occupancy) {
200  KALDI_WARN << "Gaussian being skipped because it has small count: (old,new) = "
201  << old_ml_count << ", " << new_ml_count;
202  continue;
203  }
204  *tot_count += new_ml_count;
205  for (int32 d = 0; d < dim; d++) {
206  double old_model_mean = gmm_normal.means_(gauss, d),
207  old_model_var = gmm_normal.vars_(gauss, d),
208  old_ml_mean = old_ml_acc.mean_accumulator()(gauss, d) / old_ml_count,
209  old_ml_var = old_ml_acc.variance_accumulator()(gauss, d) / old_ml_count
210  - old_ml_mean*old_ml_mean,
211  new_ml_mean = new_ml_acc.mean_accumulator()(gauss, d) / new_ml_count,
212  new_ml_var = new_ml_acc.variance_accumulator()(gauss, d) / new_ml_count
213  - new_ml_mean*new_ml_mean,
214  new_model_mean = old_model_mean + new_ml_mean - old_ml_mean,
215  new_model_var = std::max(static_cast<double>(min_variance),
216  old_model_var * new_ml_var / old_ml_var);
217  double divergence =
218  0.5 *(((new_model_mean-old_model_mean)*(new_model_mean-old_model_mean) +
219  new_model_var - old_model_var)/old_model_var +
220  Log(old_model_var / new_model_var));
221  if (divergence < 0.0)
222  KALDI_WARN << "Negative divergence " << divergence;
223  *tot_divergence += divergence * new_ml_count;
224  gmm_normal.means_(gauss, d) = new_model_mean;
225  gmm_normal.vars_(gauss, d) = new_model_var;
226  }
227  }
228  gmm_normal.CopyToDiagGmm(gmm);
229 }
kaldi::int32 int32
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ DoRescalingUpdate() [2/2]

void DoRescalingUpdate ( const AccumAmDiagGmm old_ml_accs,
const AccumAmDiagGmm new_ml_accs,
BaseFloat  min_variance,
BaseFloat  min_gaussian_occupancy,
AmDiagGmm am_gmm 
)

Definition at line 232 of file indirect-diff-diag-gmm.cc.

References AmDiagGmm::ComputeGconsts(), DoRescalingUpdate(), AccumAmDiagGmm::GetAcc(), AmDiagGmm::GetPdf(), KALDI_ASSERT, KALDI_LOG, AccumAmDiagGmm::NumAccs(), and AmDiagGmm::NumPdfs().

236  {
237  int32 num_pdfs = am_gmm->NumPdfs();
238  KALDI_ASSERT(old_ml_accs.NumAccs() == num_pdfs);
239  KALDI_ASSERT(new_ml_accs.NumAccs() == num_pdfs);
240  double tot_count = 0.0, tot_divergence = 0.0;
241  for (int32 pdf = 0; pdf < num_pdfs; pdf++)
242  DoRescalingUpdate(old_ml_accs.GetAcc(pdf), new_ml_accs.GetAcc(pdf),
243  min_variance, min_gaussian_occupancy, &am_gmm->GetPdf(pdf),
244  &tot_count, &tot_divergence);
245  KALDI_LOG << "K-L divergence from old to new model is "
246  << (tot_divergence/tot_count) << " over "
247  << tot_count << " frames.";
248  am_gmm->ComputeGconsts();
249 }
kaldi::int32 int32
void DoRescalingUpdate(const AccumAmDiagGmm &old_ml_accs, const AccumAmDiagGmm &new_ml_accs, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AmDiagGmm *am_gmm)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ DoReverberation()

float kaldi::DoReverberation ( const Vector< BaseFloat > &  rir,
BaseFloat  samp_freq,
Vector< BaseFloat > *  signal 
)

Definition at line 93 of file wav-reverberate.cc.

References ComputeEarlyReverbEnergy(), and FFTbasedBlockConvolveSignals().

Referenced by main().

94  {
95  float signal_power = ComputeEarlyReverbEnergy(rir, *signal, samp_freq);
96  FFTbasedBlockConvolveSignals(rir, signal);
97  return signal_power;
98 }
BaseFloat ComputeEarlyReverbEnergy(const Vector< BaseFloat > &rir, const Vector< BaseFloat > &signal, BaseFloat samp_freq)
void FFTbasedBlockConvolveSignals(const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
Definition: signal.cc:77

◆ DoubleFactorial() [1/2]

static int32 kaldi::DoubleFactorial ( int32  i)
static

Definition at line 444 of file matrix-lib-test.cc.

Referenced by DoubleFactorial(), UnitTestCuMatrixSetRandn(), and UnitTestSetRandn().

444  {
445  if (i <= 0) { return 1; } else { return i * DoubleFactorial(i - 2); }
446 }
static int32 DoubleFactorial(int32 i)

◆ DoubleFactorial() [2/2]

static int32 kaldi::DoubleFactorial ( int32  i)
static

Definition at line 2622 of file cu-matrix-test.cc.

References DoubleFactorial().

2622  {
2623  if (i <= 0) { return 1; } else { return i * DoubleFactorial(i - 2); }
2624 }
static int32 DoubleFactorial(int32 i)

◆ EBWUpdateGaussian()

static bool kaldi::EBWUpdateGaussian ( BaseFloat  D,
GmmFlagsType  flags,
const VectorBase< double > &  orig_mean,
const VectorBase< double > &  orig_var,
const VectorBase< double > &  x_stats,
const VectorBase< double > &  x2_stats,
double  occ,
VectorBase< double > *  mean,
VectorBase< double > *  var,
double *  auxf_impr 
)
static

Definition at line 31 of file ebw-diag-gmm.cc.

References VectorBase< Real >::AddVec(), VectorBase< Real >::AddVec2(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, kGmmMeans, kGmmVariances, Log(), VectorBase< Real >::Min(), VectorBase< Real >::Scale(), and VectorBase< Real >::SetZero().

Referenced by UpdateEbwDiagGmm().

41  {
42  if (! (flags&(kGmmMeans|kGmmVariances))) { // nothing to do.
43  if (auxf_impr) *auxf_impr = 0.0;
44  mean->CopyFromVec(orig_mean);
45  var->CopyFromVec(orig_var);
46  return true;
47  }
48  KALDI_ASSERT(!( (flags&kGmmVariances) && !(flags&kGmmMeans))
49  && "We didn't make the update cover this case sensibly (update vars not means)");
50 
51  mean->SetZero();
52  var->SetZero();
53  mean->AddVec(D, orig_mean);
54  var->AddVec2(D, orig_mean);
55  var->AddVec(D, orig_var);
56  mean->AddVec(1.0, x_stats);
57  var->AddVec(1.0, x2_stats);
58  BaseFloat scale = 1.0 / (occ + D);
59  mean->Scale(scale);
60  var->Scale(scale);
61  var->AddVec2(-1.0, *mean);
62 
63  if (!(flags&kGmmVariances)) var->CopyFromVec(orig_var);
64  if (!(flags&kGmmMeans)) mean->CopyFromVec(orig_mean);
65 
66  // Return false if any NaN's.
67  for (int32 i = 0; i < mean->Dim(); i++) {
68  double m = ((*mean)(i)), v = ((*var)(i));
69  if (m!=m || v!=v || m-m != 0 || v-v != 0) {
70  return false;
71  }
72  }
73 
74  if (var->Min() > 0.0) {
75  if (auxf_impr != NULL) {
76  // work out auxf improvement.
77  BaseFloat old_auxf = 0.0, new_auxf = 0.0;
78  int32 dim = orig_mean.Dim();
79  for (int32 i = 0; i < dim; i++) {
80  BaseFloat mean_diff = (*mean)(i) - orig_mean(i);
81  old_auxf += (occ+D) * -0.5 * (Log(orig_var(i)) +
82  ((*var)(i) + mean_diff*mean_diff)
83  / orig_var(i));
84  new_auxf += (occ+D) * -0.5 * (Log((*var)(i)) + 1.0);
85 
86  }
87  *auxf_impr = new_auxf - old_auxf;
88  }
89  return true;
90  } else return false;
91 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ElementwiseProductOfFft()

void kaldi::ElementwiseProductOfFft ( const Vector< BaseFloat > &  a,
Vector< BaseFloat > *  b 
)

Definition at line 26 of file signal.cc.

References ComplexMul(), VectorBase< Real >::Dim(), and rnnlm::i.

Referenced by FFTbasedBlockConvolveSignals(), and FFTbasedConvolveSignals().

26  {
27  int32 num_fft_bins = a.Dim() / 2;
28  for (int32 i = 0; i < num_fft_bins; i++) {
29  // do complex multiplication
30  ComplexMul(a(2*i), a(2*i + 1), &((*b)(2*i)), &((*b)(2*i + 1)));
31  }
32 }
kaldi::int32 int32
void ComplexMul(const Real &a_re, const Real &a_im, Real *b_re, Real *b_im)
ComplexMul implements, inline, the complex multiplication b *= a.

◆ EncodeLabel()

uint64 kaldi::EncodeLabel ( StateId  ilabel,
StateId  olabel 
)

Definition at line 35 of file kws-search.cc.

Referenced by main().

35  {
36  return (static_cast<int64>(olabel) << 32) + static_cast<int64>(ilabel);
37 }

◆ EndpointDetected< fst::Fst< fst::StdArc > >() [1/2]

template bool kaldi::EndpointDetected< fst::Fst< fst::StdArc > > ( const OnlineEndpointConfig config,
const TransitionModel tmodel,
BaseFloat  frame_shift_in_seconds,
const LatticeFasterOnlineDecoderTpl< fst::Fst< fst::StdArc > > &  decoder 
)

◆ EndpointDetected< fst::Fst< fst::StdArc > >() [2/2]

template bool kaldi::EndpointDetected< fst::Fst< fst::StdArc > > ( const OnlineEndpointConfig config,
const TransitionModel tmodel,
BaseFloat  frame_shift_in_seconds,
const LatticeIncrementalOnlineDecoderTpl< fst::Fst< fst::StdArc > > &  decoder 
)

◆ EndpointDetected< fst::GrammarFst >() [1/2]

template bool kaldi::EndpointDetected< fst::GrammarFst > ( const OnlineEndpointConfig config,
const TransitionModel tmodel,
BaseFloat  frame_shift_in_seconds,
const LatticeFasterOnlineDecoderTpl< fst::GrammarFst > &  decoder 
)

◆ EndpointDetected< fst::GrammarFst >() [2/2]

template bool kaldi::EndpointDetected< fst::GrammarFst > ( const OnlineEndpointConfig config,
const TransitionModel tmodel,
BaseFloat  frame_shift_in_seconds,
const LatticeIncrementalOnlineDecoderTpl< fst::GrammarFst > &  decoder 
)

◆ EstimateIvectorsOnline()

double EstimateIvectorsOnline ( const Matrix< BaseFloat > &  feats,
const Posterior post,
const IvectorExtractor extractor,
int32  ivector_period,
int32  num_cg_iters,
BaseFloat  max_count,
Matrix< BaseFloat > *  ivectors 
)

Definition at line 1778 of file ivector-extractor.cc.

References IvectorExtractor::IvectorDim(), KALDI_ASSERT, MatrixBase< Real >::NumRows(), IvectorExtractor::PriorOffset(), Matrix< Real >::Resize(), and MatrixBase< Real >::Row().

Referenced by main().

1785  {
1786 
1787  KALDI_ASSERT(ivector_period > 0);
1788  KALDI_ASSERT(static_cast<int32>(post.size()) == feats.NumRows());
1789  int32 num_frames = feats.NumRows(),
1790  num_ivectors = (num_frames + ivector_period - 1) / ivector_period;
1791 
1792  ivectors->Resize(num_ivectors, extractor.IvectorDim());
1793 
1794  OnlineIvectorEstimationStats online_stats(extractor.IvectorDim(),
1795  extractor.PriorOffset(),
1796  max_count);
1797 
1798  double ans = 0.0;
1799 
1800  Vector<double> cur_ivector(extractor.IvectorDim());
1801  cur_ivector(0) = extractor.PriorOffset();
1802  for (int32 frame = 0; frame < num_frames; frame++) {
1803  online_stats.AccStats(extractor,
1804  feats.Row(frame),
1805  post[frame]);
1806  if (frame % ivector_period == 0) {
1807  online_stats.GetIvector(num_cg_iters, &cur_ivector);
1808  int32 ivector_index = frame / ivector_period;
1809  ivectors->Row(ivector_index).CopyFromVec(cur_ivector);
1810  if (ivector_index == num_ivectors - 1) // last iVector
1811  ans = online_stats.ObjfChange(cur_ivector);
1812  }
1813  }
1814  return ans;
1815 }
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ EstimateSgmm2FmllrSubspace()

void EstimateSgmm2FmllrSubspace ( const SpMatrix< double > &  fmllr_grad_scatter,
int32  num_fmllr_bases,
int32  feat_dim,
Sgmm2FmllrGlobalParams fmllr_globals,
double  min_eig = 0.0 
)

Computes the fMLLR basis matrices given the scatter of the vectorized gradients (eq: B.10).

The result is stored in 'fmllr_globals'. The actual number of bases may be less than 'num_fmllr_bases' depending on the feature dimension and number of eigenvalues greater than 'min_eig'.

Definition at line 506 of file fmllr-sgmm2.cc.

References VectorBase< Real >::Dim(), SpMatrix< Real >::Eig(), Sgmm2FmllrGlobalParams::fmllr_bases_, KALDI_ASSERT, KALDI_LOG, KALDI_VLOG, KALDI_WARN, kSetZero, PackedMatrix< Real >::NumRows(), and SortSvd().

Referenced by TestSgmm2FmllrSubspace().

508  {
509  KALDI_ASSERT(num_fmllr_bases > 0 && feat_dim > 0);
510  if (num_fmllr_bases > feat_dim * (feat_dim + 1)) {
511  num_fmllr_bases = feat_dim * (feat_dim + 1);
512  KALDI_WARN << "Limiting number of fMLLR bases to be the same as transform "
513  << "dimension.";
514  }
515 
516  vector< Matrix<BaseFloat> > &fmllr_bases(globals->fmllr_bases_);
517 
518  Vector<double> s(fmllr_grad_scatter.NumRows());
519  Matrix<double> U(fmllr_grad_scatter.NumRows(),
520  fmllr_grad_scatter.NumRows());
521  try {
522  fmllr_grad_scatter.Eig(&s, &U);
523  SortSvd(&s, &U); // in case was not exactly sorted.
524  KALDI_VLOG(1) << "Eigenvalues (max 200) of CMLLR scatter are: "
525  << (SubVector<double>(s, 0,
526  std::min(static_cast<MatrixIndexT>(200),
527  s.Dim())));
528 
529 
530 // for (int32 b = 2; b < num_fmllr_bases; b++) {
531 // if (s(b) < min_eig) {
532 // num_fmllr_bases = b;
533 // KALDI_WARN << "Limiting number of fMLLR bases to " << num_fmllr_bases
534 // << " because of small eigenvalues.";
535 // break;
536 // }
537 // }
538 
539  U.Transpose(); // Now the rows of U correspond to the basis vectors.
540  fmllr_bases.resize(num_fmllr_bases);
541  for (int32 b = 0; b < num_fmllr_bases; b++) {
542  fmllr_bases[b].Resize(feat_dim, feat_dim + 1, kSetZero);
543  fmllr_bases[b].CopyRowsFromVec(U.Row(b));
544  }
545  KALDI_LOG << "Estimated " << num_fmllr_bases << " fMLLR basis matrices.";
546  } catch(const std::exception &e) {
547  KALDI_WARN << "Not estimating FMLLR bases because of a thrown exception:\n"
548  << e.what();
549  fmllr_bases.resize(0);
550  }
551 } // End of EstimateSgmm2FmllrSubspace
kaldi::int32 int32
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
Definition: qr.cc:433
MatrixIndexT NumRows() const
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
#define KALDI_LOG
Definition: kaldi-error.h:153
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.

◆ EstPca()

bool kaldi::EstPca ( const Matrix< BaseFloat > &  ivector_mat,
BaseFloat  target_energy,
const std::string &  reco,
Matrix< BaseFloat > *  mat 
)

Definition at line 29 of file ivector-plda-scoring-dense.cc.

References SpMatrix< Real >::AddMat2(), VectorBase< Real >::AddRowSumMat(), SpMatrix< Real >::AddVec2(), ApproxEqual(), MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::Dim(), SpMatrix< Real >::Eig(), KALDI_WARN, kCopyData, kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), SpMatrix< Real >::Resize(), Vector< Real >::Resize(), Matrix< Real >::Resize(), PackedMatrix< Real >::Scale(), VectorBase< Real >::Scale(), SortSvd(), and VectorBase< Real >::Sum().

Referenced by main().

30  {
31 
32  // If the target_energy is 1.0, it's equivalent to not applying the
33  // conversation-dependent PCA at all, so it's better to exit this
34  // function before doing any computation.
35  if (ApproxEqual(target_energy, 1.0, 0.001))
36  return false;
37 
38  int32 num_rows = ivector_mat.NumRows(),
39  num_cols = ivector_mat.NumCols();
41  SpMatrix<BaseFloat> sumsq;
42  sum.Resize(num_cols);
43  sumsq.Resize(num_cols);
44  sum.AddRowSumMat(1.0, ivector_mat);
45  sumsq.AddMat2(1.0, ivector_mat, kTrans, 1.0);
46  sum.Scale(1.0 / num_rows);
47  sumsq.Scale(1.0 / num_rows);
48  sumsq.AddVec2(-1.0, sum); // now sumsq is centered covariance.
49  int32 full_dim = sum.Dim();
50 
51  Matrix<BaseFloat> P(full_dim, full_dim);
52  Vector<BaseFloat> s(full_dim);
53 
54  try {
55  if (num_rows > num_cols)
56  sumsq.Eig(&s, &P);
57  else
58  Matrix<BaseFloat>(sumsq).Svd(&s, &P, NULL);
59  } catch (...) {
60  KALDI_WARN << "Unable to compute conversation dependent PCA for"
61  << " recording " << reco << ".";
62  return false;
63  }
64 
65  SortSvd(&s, &P);
66 
67  Matrix<BaseFloat> transform(P, kTrans); // Transpose of P. This is what
68  // appears in the transform.
69 
70  // We want the PCA transform to retain target_energy amount of the total
71  // energy.
72  BaseFloat total_energy = s.Sum();
73  BaseFloat energy = 0.0;
74  int32 dim = 1;
75  while (energy / total_energy <= target_energy) {
76  energy += s(dim-1);
77  dim++;
78  }
79  Matrix<BaseFloat> transform_float(transform);
80  mat->Resize(transform.NumCols(), transform.NumRows());
81  mat->CopyFromMat(transform);
82  mat->Resize(dim, transform_float.NumCols(), kCopyData);
83  return true;
84 }
void AddMat2(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const Real beta)
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTr...
Definition: sp-matrix.cc:1110
Packed symetric matrix class.
Definition: matrix-common.h:62
void Scale(Real c)
void AddRowSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of rows of M) + beta * *this.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
Definition: qr.cc:433
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v&#39;
Definition: sp-matrix.cc:946
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
void Scale(Real alpha)
Multiplies all elements by this constant.
A class representing a vector.
Definition: kaldi-vector.h:406
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
void Resize(MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero)
Definition: sp-matrix.h:81
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.

◆ EventTypeToString()

std::string EventTypeToString ( const EventType evec)

Definition at line 253 of file event-map.cc.

Referenced by FilterStatsByKey(), MakeEventPair(), SplitStatsByKey(), and SplitStatsByMap().

253  {
254  std::stringstream ss;
255  EventType::const_iterator iter = evec.begin(), end = evec.end();
256  std::string sep = "";
257  for (; iter != end; ++iter) {
258  ss << sep << iter->first <<":"<<iter->second;
259  sep = " ";
260  }
261  return ss.str();
262 }

◆ Exp() [1/2]

◆ Exp() [2/2]

float kaldi::Exp ( float  x)
inline

Definition at line 85 of file kaldi-math.h.

References Exp().

85 { return expf(x); }

◆ ExpectOneOrTwoTokens()

void ExpectOneOrTwoTokens ( std::istream &  is,
bool  binary,
const std::string &  token1,
const std::string &  token2 
)

This function is like ExpectToken but for two tokens, and it will either accept token1 and then token2, or just token2.

This is useful in Read functions where the first token may already have been consumed.

Definition at line 536 of file text-utils.cc.

References ExpectToken(), KALDI_ASSERT, KALDI_ERR, and ReadToken().

Referenced by PnormComponent::Read(), DistributeComponent::Read(), DistributeComponentPrecomputedIndexes::Read(), RestrictedAttentionComponent::Read(), ElementwiseProductComponent::Read(), RestrictedAttentionComponent::PrecomputedIndexes::Read(), BatchNormComponent::Read(), StatisticsExtractionComponent::Read(), ConvolutionModel::Read(), TimeHeightConvolutionComponent::PrecomputedIndexes::Read(), StatisticsExtractionComponentPrecomputedIndexes::Read(), ConvolutionComputation::Read(), StatisticsPoolingComponent::Read(), StatisticsPoolingComponentPrecomputedIndexes::Read(), BackpropTruncationComponent::Read(), MaxpoolingComponent::Read(), TdnnComponent::PrecomputedIndexes::Read(), BackpropTruncationComponentPrecomputedIndexes::Read(), NonlinearComponent::Read(), DropoutMaskComponent::Read(), GeneralDropoutComponent::Read(), GeneralDropoutComponentPrecomputedIndexes::Read(), FixedAffineComponent::Read(), SpecAugmentTimeMaskComponent::Read(), SumGroupComponent::Read(), SpecAugmentTimeMaskComponentPrecomputedIndexes::Read(), FixedScaleComponent::Read(), FixedBiasComponent::Read(), NoOpComponent::Read(), SumBlockComponent::Read(), ClipGradientComponent::Read(), and PermuteComponent::Read().

538  {
539  KALDI_ASSERT(token1 != token2);
540  std::string temp;
541  ReadToken(is, binary, &temp);
542  if (temp == token1) {
543  ExpectToken(is, binary, token2);
544  } else {
545  if (temp != token2) {
546  KALDI_ERR << "Expecting token " << token1 << " or " << token2
547  << " but got " << temp;
548  }
549  }
550 }
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
Definition: io-funcs.cc:154
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:191
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ExtendWaveWithSilence()

void ExtendWaveWithSilence ( const Vector< BaseFloat > &  wav_in,
BaseFloat  samp_rate,
Vector< BaseFloat > *  wav_out,
BaseFloat  sil_search_len,
BaseFloat  sil_extract_len,
BaseFloat  sil_extract_shift 
)

Definition at line 152 of file extend-wav-with-silence.cc.

References VectorBase< Real >::AddVecVec(), VectorBase< Real >::Dim(), FindQuietestSegment(), rnnlm::i, KALDI_ASSERT, M_2PI, and VectorBase< Real >::Range().

Referenced by main().

157  {
158  Vector<BaseFloat> quietest_seg;
159  FindQuietestSegment(wav_in, samp_rate, &quietest_seg,
160  sil_search_len, sil_extract_len, sil_extract_shift);
161 
162  int32 window_size = quietest_seg.Dim(),
163  window_size_half = window_size / 2;
164  KALDI_ASSERT(window_size > 0);
165  Vector<BaseFloat> window(window_size);
166  Vector<BaseFloat> windowed_silence(window_size);
167  Vector<BaseFloat> half_window(window_size_half);
168  for(int32 i = 0; i < window.Dim(); i++){
169  BaseFloat i_fl = static_cast<BaseFloat>(i);
170  window(i) = 0.54 - 0.46*cos(M_2PI * i_fl / (window_size-1));
171  }
172  half_window = window.Range(window_size_half, window_size_half);
173  windowed_silence.AddVecVec(1.0, window, quietest_seg, 0.0);
174 
175  wav_out->Range(0, wav_in.Dim()).CopyFromVec(wav_in);
176  SubVector<BaseFloat> wav_ext(*wav_out, wav_in.Dim() - window_size_half,
177  wav_out->Dim() - wav_in.Dim() + window_size_half);
178  for(int32 i = 0; i < window_size_half; i++) // windowing the first half window
179  wav_ext(i) *= half_window(i);
180 
181  int32 tmp_offset = 0;
182  for(; tmp_offset + window_size < wav_ext.Dim();) {
183  wav_ext.Range(tmp_offset, window_size).AddVec(1.0, windowed_silence);
184  tmp_offset += window_size_half;
185  }
186 
187  for(int32 i = tmp_offset; i < wav_ext.Dim(); i++)
188  wav_ext(i) += windowed_silence(i-tmp_offset);
189 
190 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define M_2PI
Definition: kaldi-math.h:52
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Definition: kaldi-vector.h:501
void FindQuietestSegment(const Vector< BaseFloat > &wav_in, BaseFloat samp_rate, Vector< BaseFloat > *wav_sil, BaseFloat search_dur=0.5, BaseFloat seg_dur=0.1, BaseFloat seg_shift_dur=0.05)

◆ ExtractObjectRange() [1/6]

template bool kaldi::ExtractObjectRange ( const CompressedMatrix ,
const std::string &  ,
Matrix< float > *   
)

◆ ExtractObjectRange() [2/6]

template bool kaldi::ExtractObjectRange ( const CompressedMatrix ,
const std::string &  ,
Matrix< double > *   
)

◆ ExtractObjectRange() [3/6]

template bool kaldi::ExtractObjectRange ( const Matrix< double > &  ,
const std::string &  ,
Matrix< double > *   
)

◆ ExtractObjectRange() [4/6]

template bool kaldi::ExtractObjectRange ( const Matrix< float > &  ,
const std::string &  ,
Matrix< float > *   
)

◆ ExtractObjectRange() [5/6]

template bool kaldi::ExtractObjectRange ( const Vector< double > &  ,
const std::string &  ,
Vector< double > *   
)

◆ ExtractObjectRange() [6/6]

template bool kaldi::ExtractObjectRange ( const Vector< float > &  ,
const std::string &  ,
Vector< float > *   
)

◆ Factorize()

void kaldi::Factorize ( m,
std::vector< I > *  factors 
)

Definition at line 325 of file kaldi-math.h.

References rnnlm::i, rnnlm::j, and KALDI_ASSERT.

Referenced by ComplexFft(), and UnitTestFactorizeTpl().

325  {
326  // Splits a number into its prime factors, in sorted order from
327  // least to greatest, with duplication. A very inefficient
328  // algorithm, which is mainly intended for use in the
329  // mixed-radix FFT computation (where we assume most factors
330  // are small).
331  KALDI_ASSERT(factors != NULL);
332  KALDI_ASSERT(m >= 1); // Doesn't work for zero or negative numbers.
333  factors->clear();
334  I small_factors[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
335 
336  // First try small factors.
337  for (I i = 0; i < 10; i++) {
338  if (m == 1) return; // We're done.
339  while (m % small_factors[i] == 0) {
340  m /= small_factors[i];
341  factors->push_back(small_factors[i]);
342  }
343  }
344  // Next try all odd numbers starting from 31.
345  for (I j = 31;; j += 2) {
346  if (m == 1) return;
347  while (m % j == 0) {
348  m /= j;
349  factors->push_back(j);
350  }
351  }
352 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ FakeStatsForSomeDims()

void FakeStatsForSomeDims ( const std::vector< int32 > &  dims,
MatrixBase< double > *  stats 
)

Modify the stats so that for some dimensions (specified in "dims"), we replace them with "fake" stats that have zero mean and unit variance; this is done to disable CMVN for those dimensions.

Definition at line 168 of file cmvn.cc.

References count, rnnlm::d, rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by OnlineCmvn::GetFrame(), and main().

169  {
170  KALDI_ASSERT(stats->NumRows() == 2 && stats->NumCols() > 1);
171  int32 dim = stats->NumCols() - 1;
172  double count = (*stats)(0, dim);
173  for (size_t i = 0; i < dims.size(); i++) {
174  int32 d = dims[i];
175  KALDI_ASSERT(d >= 0 && d < dim);
176  (*stats)(0, d) = 0.0;
177  (*stats)(1, d) = count;
178  }
179 }
kaldi::int32 int32
const size_t count
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ FFTbasedBlockConvolveSignals()

void FFTbasedBlockConvolveSignals ( const Vector< BaseFloat > &  filter,
Vector< BaseFloat > *  signal 
)

Definition at line 77 of file signal.cc.

References SplitRadixRealFft< Real >::Compute(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), ElementwiseProductOfFft(), KALDI_VLOG, kCopyData, VectorBase< Real >::Range(), Vector< Real >::Resize(), RoundUpToNearestPowerOfTwo(), VectorBase< Real >::Scale(), and VectorBase< Real >::SetZero().

Referenced by ComputeEarlyReverbEnergy(), DoReverberation(), and UnitTestFFTbasedBlockConvolution().

77  {
78  int32 signal_length = signal->Dim();
79  int32 filter_length = filter.Dim();
80  int32 output_length = signal_length + filter_length - 1;
81  signal->Resize(output_length, kCopyData);
82 
83  KALDI_VLOG(1) << "Length of the filter is " << filter_length;
84 
85  int32 fft_length = RoundUpToNearestPowerOfTwo(4 * filter_length);
86  KALDI_VLOG(1) << "Best FFT length is " << fft_length;
87 
88  int32 block_length = fft_length - filter_length + 1;
89  KALDI_VLOG(1) << "Block size is " << block_length;
90  SplitRadixRealFft<BaseFloat> srfft(fft_length);
91 
92  Vector<BaseFloat> filter_padded(fft_length);
93  filter_padded.Range(0, filter_length).CopyFromVec(filter);
94  srfft.Compute(filter_padded.Data(), true);
95 
96  Vector<BaseFloat> temp_pad(filter_length - 1);
97  temp_pad.SetZero();
98  Vector<BaseFloat> signal_block_padded(fft_length);
99 
100  for (int32 po = 0; po < output_length; po += block_length) {
101  // get a block of the signal
102  int32 process_length = std::min(block_length, output_length - po);
103  signal_block_padded.SetZero();
104  signal_block_padded.Range(0, process_length).CopyFromVec(signal->Range(po, process_length));
105 
106  srfft.Compute(signal_block_padded.Data(), true);
107 
108  ElementwiseProductOfFft(filter_padded, &signal_block_padded);
109 
110  srfft.Compute(signal_block_padded.Data(), false);
111  signal_block_padded.Scale(1.0 / fft_length);
112 
113  // combine the block
114  if (po + block_length < output_length) { // current block is not the last block
115  signal->Range(po, block_length).CopyFromVec(signal_block_padded.Range(0, block_length));
116  signal->Range(po, filter_length - 1).AddVec(1.0, temp_pad);
117  temp_pad.CopyFromVec(signal_block_padded.Range(block_length, filter_length - 1));
118  } else {
119  signal->Range(po, output_length - po).CopyFromVec(
120  signal_block_padded.Range(0, output_length - po));
121  if (filter_length - 1 < output_length - po)
122  signal->Range(po, filter_length - 1).AddVec(1.0, temp_pad);
123  else
124  signal->Range(po, output_length - po).AddVec(1.0, temp_pad.Range(0, output_length - po));
125  }
126  }
127 }
kaldi::int32 int32
int32 RoundUpToNearestPowerOfTwo(int32 n)
Definition: kaldi-math.cc:32
void ElementwiseProductOfFft(const Vector< BaseFloat > &a, Vector< BaseFloat > *b)
Definition: signal.cc:26
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ FFTbasedConvolveSignals()

void FFTbasedConvolveSignals ( const Vector< BaseFloat > &  filter,
Vector< BaseFloat > *  signal 
)

Definition at line 50 of file signal.cc.

References SplitRadixRealFft< Real >::Compute(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), ElementwiseProductOfFft(), KALDI_VLOG, VectorBase< Real >::Range(), Vector< Real >::Resize(), RoundUpToNearestPowerOfTwo(), and VectorBase< Real >::Scale().

Referenced by UnitTestFFTbasedBlockConvolution(), and UnitTestFFTbasedConvolution().

50  {
51  int32 signal_length = signal->Dim();
52  int32 filter_length = filter.Dim();
53  int32 output_length = signal_length + filter_length - 1;
54 
55  int32 fft_length = RoundUpToNearestPowerOfTwo(output_length);
56  KALDI_VLOG(1) << "fft_length for full signal convolution is " << fft_length;
57 
58  SplitRadixRealFft<BaseFloat> srfft(fft_length);
59 
60  Vector<BaseFloat> filter_padded(fft_length);
61  filter_padded.Range(0, filter_length).CopyFromVec(filter);
62  srfft.Compute(filter_padded.Data(), true);
63 
64  Vector<BaseFloat> signal_padded(fft_length);
65  signal_padded.Range(0, signal_length).CopyFromVec(*signal);
66  srfft.Compute(signal_padded.Data(), true);
67 
68  ElementwiseProductOfFft(filter_padded, &signal_padded);
69 
70  srfft.Compute(signal_padded.Data(), false);
71  signal_padded.Scale(1.0 / fft_length);
72 
73  signal->Resize(output_length);
74  signal->CopyFromVec(signal_padded.Range(0, output_length));
75 }
kaldi::int32 int32
int32 RoundUpToNearestPowerOfTwo(int32 n)
Definition: kaldi-math.cc:32
void ElementwiseProductOfFft(const Vector< BaseFloat > &a, Vector< BaseFloat > *b)
Definition: signal.cc:26
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ FilterMatrixRows() [1/2]

template void kaldi::FilterMatrixRows ( const Matrix< float > &  in,
const std::vector< bool > &  keep_rows,
Matrix< float > *  out 
)

◆ FilterMatrixRows() [2/2]

template void kaldi::FilterMatrixRows ( const Matrix< double > &  in,
const std::vector< bool > &  keep_rows,
Matrix< double > *  out 
)

◆ FilterSparseMatrixRows() [1/2]

template void kaldi::FilterSparseMatrixRows ( const SparseMatrix< float > &  in,
const std::vector< bool > &  keep_rows,
SparseMatrix< float > *  out 
)

◆ FilterSparseMatrixRows() [2/2]

template void kaldi::FilterSparseMatrixRows ( const SparseMatrix< double > &  in,
const std::vector< bool > &  keep_rows,
SparseMatrix< double > *  out 
)

◆ FindQuietestSegment()

void FindQuietestSegment ( const Vector< BaseFloat > &  wav_in,
BaseFloat  samp_rate,
Vector< BaseFloat > *  wav_sil,
BaseFloat  search_dur = 0.5,
BaseFloat  seg_dur = 0.1,
BaseFloat  seg_shift_dur = 0.05 
)

Definition at line 195 of file extend-wav-with-silence.cc.

References VectorBase< Real >::Dim(), KALDI_ASSERT, KALDI_WARN, VectorBase< Real >::Range(), and VecVec().

Referenced by ExtendWaveWithSilence().

200  {
201  KALDI_ASSERT(seg_dur < search_dur);
202 
203  int32 search_len = (int32) (search_dur * samp_rate),
204  seg_len = (int32) (seg_dur * samp_rate),
205  seg_shift = (int32) (seg_shift_dur *samp_rate),
206  start = 0;
207  double min_energy;
208  Vector<BaseFloat> wav_min_energy;
209  Vector<BaseFloat> seg_tmp(wav_in.Range(0, seg_len));
210  wav_min_energy = seg_tmp;
211  min_energy = VecVec(seg_tmp, seg_tmp);
212  for(start = 0; start + seg_len < search_len; ){
213  SubVector<BaseFloat> seg_this(wav_in, start, seg_len);
214  seg_tmp = seg_this;
215  double energy_this = VecVec(seg_this, seg_this);
216  if(energy_this < min_energy && energy_this > 0.0){
217  min_energy = energy_this;
218  wav_min_energy = seg_tmp;
219  }
220  start += seg_shift;
221  }
222 
223  for(start = wav_in.Dim() - search_len; start + seg_len < wav_in.Dim(); ){
224  SubVector<BaseFloat> seg_this(wav_in, start, seg_len);
225  seg_tmp = seg_this;
226  double energy_this = VecVec(seg_this, seg_this);
227  if(energy_this < min_energy && energy_this > 0.0){
228  min_energy = energy_this;
229  wav_min_energy = seg_tmp;
230  }
231  start += seg_shift;
232  }
233 
234  if (min_energy == 0.0) {
235  KALDI_WARN << "Zero energy silence being used.";
236  }
237  *wav_sil = wav_min_energy;
238 }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Definition: kaldi-vector.h:501

◆ FmllrAuxfGradient()

BaseFloat FmllrAuxfGradient ( const MatrixBase< BaseFloat > &  xform,
const AffineXformStats stats,
MatrixBase< BaseFloat > *  grad_out 
)

Returns the (diagonal-GMM) FMLLR auxiliary function value given the transform and the stats.

Definition at line 510 of file fmllr-diag-gmm.cc.

References MatrixBase< Real >::AddMat(), VectorBase< Real >::AddSpVec(), AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), MatrixBase< Real >::CopyRowFromVec(), rnnlm::d, AffineXformStats::G_, AffineXformStats::K_, kNoTrans, kTrans, MatrixBase< Real >::LogDet(), MatrixBase< Real >::Range(), MatrixBase< Real >::Row(), MatrixBase< Real >::Scale(), TraceMatMat(), and VecVec().

Referenced by ComputeFmllrLogDet().

514  {
515  int32 dim = static_cast<int32>(stats.G_.size());
516  Matrix<double> xform_d(xform);
517  Vector<double> xform_row_g(dim + 1);
518  SubMatrix<double> A(xform_d, 0, dim, 0, dim);
519  double obj = stats.beta_ * A.LogDet() +
520  TraceMatMat(xform_d, stats.K_, kTrans);
521  Matrix<double> S(dim, dim + 1);
522  for (int32 d = 0; d < dim; d++) {
523  xform_row_g.AddSpVec(1.0, stats.G_[d], xform_d.Row(d), 0.0);
524  obj -= 0.5 * VecVec(xform_row_g, xform_d.Row(d));
525  S.CopyRowFromVec(xform_row_g, d);
526  }
527 
528  // Compute the gradient: P = \beta [(A^{-1})^{T} , 0] + K - S
529  // grad_out->Resize(dim, dim + 1);
530  Matrix<double> tmp_grad(dim, dim + 1);
531  tmp_grad.Range(0, dim, 0, dim).CopyFromMat(A);
532  tmp_grad.Range(0, dim, 0, dim).Invert();
533  tmp_grad.Range(0, dim, 0, dim).Transpose();
534  tmp_grad.Scale(stats.beta_);
535  tmp_grad.AddMat(-1.0, S, kNoTrans);
536  tmp_grad.AddMat(1.0, stats.K_, kNoTrans);
537  grad_out->CopyFromMat(tmp_grad, kNoTrans);
538 
539  return obj;
540 }
kaldi::int32 int32
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ FmllrAuxFuncDiagGmm() [1/2]

float FmllrAuxFuncDiagGmm ( const MatrixBase< float > &  xform,
const AffineXformStats stats 
)

Returns the (diagonal-GMM) FMLLR auxiliary function value given the transform and the stats.

Definition at line 481 of file fmllr-diag-gmm.cc.

References VectorBase< Real >::AddSpVec(), AffineXformStats::beta_, rnnlm::d, AffineXformStats::G_, AffineXformStats::K_, kTrans, MatrixBase< Real >::LogDet(), MatrixBase< Real >::Row(), TraceMatMat(), and VecVec().

Referenced by ComputeFmllrLogDet(), ComputeFmllrMatrixDiagGmmDiagonal(), ComputeFmllrMatrixDiagGmmFull(), LinearVtln::ComputeTransform(), and BasisFmllrEstimate::ComputeTransform().

482  {
483  int32 dim = static_cast<int32>(stats.G_.size());
484  Matrix<double> xform_d(xform);
485  Vector<double> xform_row_g(dim + 1);
486  SubMatrix<double> A(xform_d, 0, dim, 0, dim);
487  double obj = stats.beta_ * A.LogDet() +
488  TraceMatMat(xform_d, stats.K_, kTrans);
489  for (int32 d = 0; d < dim; d++) {
490  xform_row_g.AddSpVec(1.0, stats.G_[d], xform_d.Row(d), 0.0);
491  obj -= 0.5 * VecVec(xform_row_g, xform_d.Row(d));
492  }
493  return obj;
494 }
kaldi::int32 int32
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ FmllrAuxFuncDiagGmm() [2/2]

double FmllrAuxFuncDiagGmm ( const MatrixBase< double > &  xform,
const AffineXformStats stats 
)

Definition at line 496 of file fmllr-diag-gmm.cc.

References VectorBase< Real >::AddSpVec(), AffineXformStats::beta_, rnnlm::d, AffineXformStats::G_, AffineXformStats::K_, kTrans, MatrixBase< Real >::LogDet(), MatrixBase< Real >::Row(), TraceMatMat(), and VecVec().

497  {
498  int32 dim = static_cast<int32>(stats.G_.size());
499  Vector<double> xform_row_g(dim + 1);
500  SubMatrix<double> A(xform, 0, dim, 0, dim);
501  double obj = stats.beta_ * A.LogDet() +
502  TraceMatMat(xform, stats.K_, kTrans);
503  for (int32 d = 0; d < dim; d++) {
504  xform_row_g.AddSpVec(1.0, stats.G_[d], xform.Row(d), 0.0);
505  obj -= 0.5 * VecVec(xform_row_g, xform.Row(d));
506  }
507  return obj;
508 }
kaldi::int32 int32
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ FmllrInnerUpdate()

void FmllrInnerUpdate ( SpMatrix< double > &  inv_G,
VectorBase< double > &  k,
double  beta,
int32  row,
MatrixBase< double > *  transform 
)

This function does one row of the inner-loop fMLLR transform update.

We export it because it's needed in the RawFmllr code. Here, if inv_G is the inverse of the G matrix indexed by this row, and k is the corresponding row of the K matrix.

Definition at line 193 of file fmllr-diag-gmm.cc.

References VectorBase< Real >::AddSpVec(), VectorBase< Real >::AddVec(), MatrixBase< Real >::CopyFromMat(), MatrixBase< Real >::Invert(), KALDI_ASSERT, kTrans, Log(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), VectorBase< Real >::Range(), MatrixBase< Real >::Range(), MatrixBase< Real >::Row(), VectorBase< Real >::Scale(), and VecVec().

Referenced by ComputeFmllrLogDet(), ComputeFmllrMatrixDiagGmmFull(), and FmllrRawAccs::Update().

197  {
198  int32 dim = transform->NumRows();
199  KALDI_ASSERT(transform->NumCols() == dim + 1);
200  KALDI_ASSERT(row >= 0 && row < dim);
201 
202  double logdet;
203  // Calculating the matrix of cofactors (transpose of adjugate)
204  Matrix<double> cofact_mat(dim, dim);
205  cofact_mat.CopyFromMat(transform->Range(0, dim, 0, dim), kTrans);
206  cofact_mat.Invert(&logdet);
207  // Removed this step because it's not necessary and could lead to
208  // under/overflow [Dan]
209  // cofact_mat.Scale(exp(logdet));
210 
211  // The extended cofactor vector for the current row
212  Vector<double> cofact_row(dim + 1);
213  cofact_row.Range(0, dim).CopyRowFromMat(cofact_mat, row);
214  cofact_row(dim) = 0;
215  Vector<double> cofact_row_invg(dim + 1);
216  cofact_row_invg.AddSpVec(1.0, inv_G, cofact_row, 0.0);
217 
218  // Solve the quadratic equation for step size
219  double e1 = VecVec(cofact_row_invg, cofact_row);
220  double e2 = VecVec(cofact_row_invg, k);
221  double discr = std::sqrt(e2 * e2 + 4 * e1 * beta);
222  double alpha1 = (-e2 + discr) / (2 * e1);
223  double alpha2 = (-e2 - discr) / (2 * e1);
224  double auxf1 = beta * Log(std::abs(alpha1 * e1 + e2)) -
225  0.5 * alpha1 * alpha1 * e1;
226  double auxf2 = beta * Log(std::abs(alpha2 * e1 + e2)) -
227  0.5 * alpha2 * alpha2 * e1;
228  double alpha = (auxf1 > auxf2) ? alpha1 : alpha2;
229 
230  // Update transform row: w_d = (\alpha cofact_d + k_d) G_d^{-1}
231  cofact_row.Scale(alpha);
232  cofact_row.AddVec(1.0, k);
233  transform->Row(row).AddSpVec(1.0, inv_G, cofact_row, 0.0);
234 }
kaldi::int32 int32
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ FrameLevelLpp()

void kaldi::FrameLevelLpp ( const SubVector< BaseFloat > &  prob_row,
const std::vector< std::set< int32 > > &  pdf2phones,
const std::vector< int32 > *  phone_map,
Vector< BaseFloat > *  out_frame_level_lpp 
)

FrameLevelLpp compute a log posterior for pure-phones by sum the posterior of the states belonging to those triphones whose current phone is the canonical phone:

p(p|o_t) = {s p} p(s|o_t),

where s is the senone label, {s|s p} is the states belonging to those riphones whose current phone is the canonical phone p.

Definition at line 76 of file compute-gop.cc.

References VectorBase< Real >::ApplyLog(), VectorBase< Real >::Dim(), rnnlm::i, and KALDI_ASSERT.

Referenced by main().

79  {
80  for (int32 i = 0; i < prob_row.Dim(); i++) {
81  std::set<int32> dest_idxs;
82  for (int32 ph : pdf2phones.at(i)) {
83  dest_idxs.insert((phone_map != NULL) ? (*phone_map)[ph] - 1 : ph - 1);
84  }
85 
86  for (int32 idx : dest_idxs) {
87  KALDI_ASSERT(idx < out_frame_level_lpp->Dim());
88  (*out_frame_level_lpp)(idx) += prob_row(i);
89  }
90  }
91  out_frame_level_lpp->ApplyLog();
92 }
kaldi::int32 int32
void ApplyLog()
Apply natural log to all elements.
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Gcd()

I kaldi::Gcd ( m,
n 
)

Definition at line 297 of file kaldi-math.h.

References KALDI_ASSERT, KALDI_ERR, and rnnlm::n.

Referenced by ClusterKMeansOnce(), ConvolutionModel::ComputeDerived(), kaldi::nnet3::time_height_convolution::FindGcdOfDifferences(), RestrictedAttentionComponent::GetComputationStructure(), Lcm(), LinearResample::LinearResample(), kaldi::nnet3::time_height_convolution::PadComputationInputTime(), and UnitTestGcdLcmTpl().

297  {
298  if (m == 0 || n == 0) {
299  if (m == 0 && n == 0) { // gcd not defined, as all integers are divisors.
300  KALDI_ERR << "Undefined GCD since m = 0, n = 0.";
301  }
302  return (m == 0 ? (n > 0 ? n : -n) : ( m > 0 ? m : -m));
303  // return absolute value of whichever is nonzero
304  }
305  // could use compile-time assertion
306  // but involves messing with complex template stuff.
307  KALDI_ASSERT(std::numeric_limits<I>::is_integer);
308  while (1) {
309  m %= n;
310  if (m == 0) return (n > 0 ? n : -n);
311  n %= m;
312  if (n == 0) return (m > 0 ? m : -m);
313  }
314 }
struct rnnlm::@11::@12 n
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ generate_features()

static void kaldi::generate_features ( cova_type  covariance_type,
size_t  n_gaussians,
size_t  dim,
Matrix< BaseFloat > &  trans_mat,
size_t  frames_per_gaussian,
std::vector< Vector< BaseFloat > *> &  train_feats,
std::vector< Vector< BaseFloat > *> &  adapt_feats 
)
static

Definition at line 64 of file regtree-fmllr-diag-gmm-test.cc.

References MatrixBase< Real >::AddMatMat(), VectorBase< Real >::AddMatVec(), VectorBase< Real >::CopyColFromMat(), MatrixBase< Real >::CopyFromMat(), rnnlm::d, diag, Exp(), full, rnnlm::i, MatrixBase< Real >::Invert(), rnnlm::j, kNoTrans, RandFullCova(), RandGauss(), MatrixBase< Real >::Scale(), MatrixBase< Real >::SetRandn(), and MatrixBase< Real >::SetZero().

Referenced by UnitTestRegtreeFmllrDiagGmm().

71  {
72  // compute inverse of the transformation matrix
73  Matrix<BaseFloat> inv_trans_mat(dim, dim);
74  inv_trans_mat.CopyFromMat(trans_mat, kNoTrans);
75  inv_trans_mat.Invert();
76  // the untransformed means are random
77  Matrix<BaseFloat> untransformed_means(dim, n_gaussians);
78  untransformed_means.SetRandn();
79  untransformed_means.Scale(10);
80 
81  // the actual means result from
82  // transformation with inv_trans_mat
83  Matrix<BaseFloat> actual_means(dim, n_gaussians);
84 
85  // actual_means = inv_trans_mat * untransformed_means
86  actual_means.AddMatMat(1.0, inv_trans_mat, kNoTrans,
87  untransformed_means, kNoTrans, 0.0);
88 
89  size_t train_counter = 0;
90 
91  // temporary variables
92  Vector<BaseFloat> randomvec(dim);
93  Matrix<BaseFloat> Sj(dim, dim);
94 
95  // loop over all gaussians
96  for (size_t j = 0; j < n_gaussians; j++) {
97  if (covariance_type == diag) {
98  // random diagonal covariance for gaussian j
99  Sj.SetZero();
100  for (size_t d = 0; d < dim; d++) {
101  Sj(d, d) = 2*Exp(RandGauss());
102  }
103  }
104  if (covariance_type == full) {
105  // random full covariance for gaussian j
106  RandFullCova(&Sj);
107  }
108  // compute inv_trans_mat * Sj
109  Matrix<BaseFloat> tmp_matrix(dim, dim);
110  tmp_matrix.AddMatMat(1.0, inv_trans_mat, kNoTrans, Sj, kNoTrans, 0.0);
111 
112  // compute features
113  for (size_t i = 0; i < frames_per_gaussian; i++) {
114  train_feats[train_counter] = new Vector<BaseFloat>(dim);
115  adapt_feats[train_counter] = new Vector<BaseFloat>(dim);
116 
117  // initalize feature vector with mean of class j
118  train_feats[train_counter]->CopyColFromMat(untransformed_means, j);
119  adapt_feats[train_counter]->CopyColFromMat(actual_means, j);
120 
121  // determine random vector and
122  // multiply the random vector with SJ
123  // and add it to train_feats:
124  // train_feats = train_feats + SJ * random
125  // for adapt_feats we include the invtrans_mat:
126  // adapt_feats = adapt_feats + invtrans_mat * SJ * random
127  for (size_t d = 0; d < dim; d++) {
128  randomvec(d) = RandGauss();
129  }
130  train_feats[train_counter]->AddMatVec(1.0, Sj, kNoTrans,
131  randomvec, 1.0);
132  adapt_feats[train_counter]->AddMatVec(1.0, tmp_matrix, kNoTrans,
133  randomvec, 1.0);
134  train_counter++;
135  }
136  }
137  return;
138 }
double Exp(double x)
Definition: kaldi-math.h:83
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
static void RandFullCova(Matrix< BaseFloat > *matrix)

◆ GenerateActivePaths()

bool kaldi::GenerateActivePaths ( const KwsLexicographicFst proxy,
std::vector< ActivePath > *  paths,
KwsLexicographicFst::StateId  cur_state,
std::vector< KwsLexicographicArc::Label >  cur_path,
KwsLexicographicArc::Weight  cur_weight 
)

Definition at line 90 of file kws-search.cc.

References ActivePath::last, ActivePath::path, fst::Times(), and ActivePath::weight.

Referenced by OutputDetailedStatistics().

94  {
95  for (fst::ArcIterator<KwsLexicographicFst> aiter(proxy, cur_state);
96  !aiter.Done(); aiter.Next()) {
97  const Arc &arc = aiter.Value();
98  Weight temp_weight = Times(arc.weight, cur_weight);
99 
100  cur_path.push_back(arc.ilabel);
101 
102  if ( arc.olabel != 0 ) {
103  ActivePath path;
104  path.path = cur_path;
105  path.weight = temp_weight;
106  path.last = arc.olabel;
107  paths->push_back(path);
108  } else {
109  GenerateActivePaths(proxy, paths,
110  arc.nextstate, cur_path, temp_weight);
111  }
112  cur_path.pop_back();
113  }
114 
115  return true;
116 }
KwsLexicographicArc::Weight weight
Definition: kws-search.cc:86
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
KwsLexicographicArc::Label last
Definition: kws-search.cc:87
bool GenerateActivePaths(const KwsLexicographicFst &proxy, std::vector< ActivePath > *paths, KwsLexicographicFst::StateId cur_state, std::vector< KwsLexicographicArc::Label > cur_path, KwsLexicographicArc::Weight cur_weight)
Definition: kws-search.cc:90
fst::StdArc::Weight Weight
std::vector< KwsLexicographicArc::Label > path
Definition: kws-search.cc:85

◆ GenerateCompactLatticeRandomly()

void kaldi::GenerateCompactLatticeRandomly ( const std::vector< int32 > &  alignment,
const std::vector< int32 > &  words,
CompactLattice clat 
)

Definition at line 132 of file word-align-lattice-lexicon-test.cc.

References rnnlm::i, LatticeWeightTpl< BaseFloat >::One(), CompactLatticeWeightTpl< WeightType, IntType >::One(), and RandInt().

Referenced by TestWordAlignLatticeLexicon().

134  {
135  clat->DeleteStates();
136  clat->AddState();
137  clat->SetStart(0);
138  int32 cur_state = 0;
139  size_t word_start = 0, alignment_start = 0,
140  num_words = words.size(), num_transition_ids = alignment.size();
141  for (; word_start < num_words; word_start++) {
142  int32 word = words[word_start];
143  int32 ali_length = RandInt(0, num_transition_ids - alignment_start);
144  std::vector<int32> this_ali(ali_length);
145  for (int32 i = 0; i < ali_length; i++)
146  this_ali[i] = alignment[alignment_start + i];
147  alignment_start += ali_length;
148  CompactLatticeWeight weight(LatticeWeight::One(), this_ali);
149  int32 ilabel = word;
150  int32 next_state = clat->AddState();
151  CompactLatticeArc arc(ilabel, ilabel, weight, next_state);
152  clat->AddArc(cur_state, arc);
153  cur_state = next_state;
154  }
155  if (alignment_start < alignment.size()) {
156  int32 ali_length = num_transition_ids - alignment_start;
157  std::vector<int32> this_ali(ali_length);
158  for (int32 i = 0; i < ali_length; i++)
159  this_ali[i] = alignment[alignment_start + i];
160  alignment_start += ali_length;
161  CompactLatticeWeight weight(LatticeWeight::One(), this_ali);
162  int32 ilabel = 0;
163  int32 next_state = clat->AddState();
164  CompactLatticeArc arc(ilabel, ilabel, weight, next_state);
165  clat->AddArc(cur_state, arc);
166  cur_state = next_state;
167  }
168  clat->SetFinal(cur_state, CompactLatticeWeight::One());
169 }
int32 words[kMaxOrder]
kaldi::int32 int32
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
CompactLatticeWeightTpl< LatticeWeight, int32 > CompactLatticeWeight
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GenerateLexicon()

void kaldi::GenerateLexicon ( const std::vector< int32 > &  phones,
bool  allow_zero_words,
bool  allow_empty_word,
bool  allow_multiple_prons,
std::vector< std::vector< int32 > > *  lexicon 
)

Definition at line 32 of file word-align-lattice-lexicon-test.cc.

References rnnlm::i, rnnlm::j, KALDI_ASSERT, RandInt(), and SortAndUniq().

Referenced by TestWordAlignLatticeLexicon().

36  {
37  KALDI_ASSERT(!phones.empty());
38  lexicon->clear();
39  int32 num_words = RandInt(1, 20);
40  for (int32 word = 1; word <= num_words; word++) {
41  int32 num_prons = RandInt(1, (allow_multiple_prons ? 2 : 1));
42  bool is_zero_word = allow_zero_words && (RandInt(1, 5) == 1);
43 
44  for (int32 j = 0; j < num_prons; j++) {
45  // don't allow empty pron if this word isn't labeled in the lattice (zero word,
46  // like optional silence). This doesn't make sense.
47  int32 pron_length = RandInt(((allow_empty_word && !is_zero_word) ? 0 : 1),
48  4);
49  std::vector<int32> this_entry;
50  this_entry.push_back(is_zero_word ? 0 : word);
51  this_entry.push_back(word);
52  for (int32 p = 0; p < pron_length; p++)
53  this_entry.push_back(phones[RandInt(0, phones.size() - 1)]);
54  lexicon->push_back(this_entry);
55  }
56  }
57  SortAndUniq(lexicon);
58  // randomize the order.
59  std::random_shuffle(lexicon->begin(), lexicon->end());
60 
61 
62  for (size_t i = 0; i < lexicon->size(); i++) {
63  if ((*lexicon)[i].size() > 2) {
64  // ok, this lexicon has at least one nonempty word: potentially OK. Do
65  // further check that the info object doesn't complain.
66  try {
67  WordAlignLatticeLexiconInfo info(*lexicon);
68  return; // OK, we're satisfied with this lexicon.
69  } catch (...) {
70  break; // will re-try, see below.
71  }
72  }
73  }
74  // there were no nonempty words in the lexicon -> try again.
75  // recursing is the easiest way.
76  GenerateLexicon(phones, allow_zero_words, allow_empty_word, allow_multiple_prons,
77  lexicon);
78 
79 
80 }
kaldi::int32 int32
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq&#39;s (removes duplicates) from a vector.
Definition: stl-utils.h:39
void GenerateLexicon(const std::vector< int32 > &phones, bool allow_zero_words, bool allow_empty_word, bool allow_multiple_prons, std::vector< std::vector< int32 > > *lexicon)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GeneratePathThroughHmm()

void GeneratePathThroughHmm ( const HmmTopology topology,
bool  reorder,
int32  phone,
std::vector< std::pair< int32, int32 > > *  path 
)

This function generates a random path through the HMM for the given phone.

The 'path' output is a list of pairs (HMM-state, transition-index) in which any nonemitting states will have been removed. This is used in other test code. the 'reorder' option is as described in the documentation; if true, the self-loops from a state are reordered to come after the forward-transition.

Definition at line 190 of file hmm-test-utils.cc.

References HmmTopology::HmmState::forward_pdf_class, KALDI_ASSERT, RandInt(), HmmTopology::TopologyForPhone(), and HmmTopology::HmmState::transitions.

Referenced by GenerateRandomAlignment().

193  {
194  path->clear();
195  const HmmTopology::TopologyEntry &this_entry =
196  topology.TopologyForPhone(phone);
197  int32 cur_state = 0; // start-state is always state zero.
198  int32 num_states = this_entry.size(), final_state = num_states - 1;
199  KALDI_ASSERT(num_states > 1); // there has to be a final nonemitting state
200  // that's different from the start state.
201  std::vector<std::pair<int32, int32> > pending_self_loops;
202  while (cur_state != final_state) {
203  const HmmTopology::HmmState &cur_hmm_state = this_entry[cur_state];
204  int32 num_transitions = cur_hmm_state.transitions.size(),
205  transition_index = RandInt(0, num_transitions - 1);
206  if (cur_hmm_state.forward_pdf_class != -1) {
207  std::pair<int32, int32> pr(cur_state, transition_index);
208  if (!reorder) {
209  path->push_back(pr);
210  } else {
211  bool is_self_loop = (cur_state ==
212  cur_hmm_state.transitions[transition_index].first);
213  if (is_self_loop) { // save these up, we'll put them after the forward
214  // transition.
215  pending_self_loops.push_back(pr);
216  } else {
217  // non-self-loop: output it and then flush out any self-loops we
218  // stored up.
219  path->push_back(pr);
220  path->insert(path->end(), pending_self_loops.begin(),
221  pending_self_loops.end());
222  pending_self_loops.clear();
223  }
224  }
225  }
226  cur_state = cur_hmm_state.transitions[transition_index].first;
227  }
228  KALDI_ASSERT(pending_self_loops.empty());
229 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GenerateRandomAlignment()

void GenerateRandomAlignment ( const ContextDependencyInterface ctx_dep,
const TransitionModel trans_model,
bool  reorder,
const std::vector< int32 > &  phone_sequence,
std::vector< int32 > *  alignment 
)

For use in test code, this function generates an alignment (a sequence of transition-ids) corresponding to a given phone sequence.

Definition at line 232 of file hmm-test-utils.cc.

References ContextDependencyInterface::CentralPosition(), ContextDependencyInterface::Compute(), ContextDependencyInterface::ContextWidth(), GeneratePathThroughHmm(), TransitionModel::GetTopo(), rnnlm::i, rnnlm::j, KALDI_ASSERT, TransitionModel::PairToTransitionId(), HmmTopology::TopologyForPhone(), and TransitionModel::TupleToTransitionState().

Referenced by TestConvertAlignment(), TestSplitToPhones(), and TestWordAlignLatticeLexicon().

236  {
237  int32 context_width = ctx_dep.ContextWidth(),
238  central_position = ctx_dep.CentralPosition(),
239  num_phones = phone_sequence.size();
240  alignment->clear();
241  for (int32 i = 0; i < num_phones; i++) {
242  std::vector<int32> context_window;
243  context_window.reserve(context_width);
244  for (int32 j = i - central_position;
245  j < i - central_position + context_width;
246  j++) {
247  if (j >= 0 && j < num_phones) context_window.push_back(phone_sequence[j]);
248  else context_window.push_back(0); // zero for out-of-window phones
249  }
250  // 'path' is the path through this phone's HMM, represented as
251  // (emitting-HMM-state, transition-index) pairs
252  std::vector<std::pair<int32, int32> > path;
253  int32 phone = phone_sequence[i];
254  GeneratePathThroughHmm(trans_model.GetTopo(), reorder, phone, &path);
255  for (size_t k = 0; k < path.size(); k++) {
256  const HmmTopology::TopologyEntry &entry =
257  trans_model.GetTopo().TopologyForPhone(phone);
258  int32 hmm_state = path[k].first,
259  transition_index = path[k].second,
260  forward_pdf_class = entry[hmm_state].forward_pdf_class,
261  self_loop_pdf_class = entry[hmm_state].self_loop_pdf_class,
262  forward_pdf_id, self_loop_pdf_id;
263  bool ans = ctx_dep.Compute(context_window, forward_pdf_class, &forward_pdf_id);
264  KALDI_ASSERT(ans && "context-dependency computation failed.");
265  ans = ctx_dep.Compute(context_window, self_loop_pdf_class, &self_loop_pdf_id);
266  KALDI_ASSERT(ans && "context-dependency computation failed.");
267  int32 transition_state = trans_model.TupleToTransitionState(
268  phone, hmm_state, forward_pdf_id, self_loop_pdf_id),
269  transition_id = trans_model.PairToTransitionId(transition_state,
270  transition_index);
271  alignment->push_back(transition_id);
272  }
273  }
274 }
kaldi::int32 int32
void GeneratePathThroughHmm(const HmmTopology &topology, bool reorder, int32 phone, std::vector< std::pair< int32, int32 > > *path)
This function generates a random path through the HMM for the given phone.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GenerateWordAndPhoneSequence()

void kaldi::GenerateWordAndPhoneSequence ( std::vector< std::vector< int32 > > &  lexicon,
std::vector< int32 > *  phone_seq,
std::vector< int32 > *  word_seq 
)

Definition at line 109 of file word-align-lattice-lexicon-test.cc.

References rnnlm::i, and RandInt().

Referenced by TestWordAlignLatticeLexicon().

111  {
112  int32 num_words = RandInt(0, 5);
113  phone_seq->clear();
114  word_seq->clear();
115  for (int32 i = 0; i < num_words; i++) {
116  const std::vector<int32> &lexicon_entry =
117  lexicon[RandInt(0, lexicon.size() - 1)];
118  // the zeroth element of 'lexicon_entry' is how it appears in
119  // the lattice prior to word alignment.
120  int32 word = lexicon_entry[0];
121  if (word != 0) word_seq->push_back(word);
122  // add everything from position 2 in the lexicon entry, to the
123  // phone sequence.
124  phone_seq->insert(phone_seq->end(),
125  lexicon_entry.begin() + 2,
126  lexicon_entry.end());
127  }
128 }
kaldi::int32 int32
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GenRandContextDependency()

ContextDependency * GenRandContextDependency ( const std::vector< int32 > &  phones,
bool  ensure_all_covered,
std::vector< int32 > *  num_pdf_classes 
)

GenRandContextDependency is mainly of use for debugging.

Phones must be sorted and uniq on input.

Parameters
phones[in] A vector of phone id's [must be sorted and uniq].
ensure_all_covered[in] boolean argument; if true, GenRandContextDependency generates a context-dependency object that "works" for all phones [no gaps].
num_pdf_classes[out] outputs a vector indexed by phone, of the number of pdf classes (e.g. states) for that phone.
Returns
Returns the a context dependency object.

Definition at line 46 of file context-dep.cc.

References BuildTree(), ContextDependency::ContextDependency(), DeleteBuildTreeStats(), GenRandStats(), rnnlm::i, Questions::InitRand(), IsSortedAndUniq(), KALDI_ASSERT, KALDI_VLOG, kAllKeysUnion, Rand(), and RandUniform().

Referenced by TestGenRandContextDependency().

48  {
49  KALDI_ASSERT(IsSortedAndUniq(phone_ids));
50  int32 num_phones = phone_ids.size();
51  int32 num_stats = 1 + (Rand() % 15) * (Rand() % 15); // up to 14^2 + 1 separate stats.
52  int32 N = 2 + Rand() % 3; // 2, 3 or 4.
53  int32 P = Rand() % N;
54  float ctx_dep_prob = 0.7 + 0.3*RandUniform();
55  int32 max_phone = *std::max_element(phone_ids.begin(), phone_ids.end());
56  hmm_lengths->clear();
57  hmm_lengths->resize(max_phone + 1, -1);
58  std::vector<bool> is_ctx_dep(max_phone + 1);
59 
60  for (int32 i = 0; i <= max_phone; i++) {
61  (*hmm_lengths)[i] = 1 + Rand() % 3;
62  is_ctx_dep[i] = (RandUniform() < ctx_dep_prob); // true w.p. ctx_dep_prob.
63  }
64  for (size_t i = 0; i < (size_t) num_phones; i++)
65  KALDI_VLOG(2) << "For idx = " << i
66  << ", (phone_id, hmm_length, is_ctx_dep) == "
67  << (phone_ids[i]) << " " << ((*hmm_lengths)[phone_ids[i]])
68  << " " << (is_ctx_dep[phone_ids[i]]);
69  // Generate rand stats.
70  BuildTreeStatsType stats;
71  size_t dim = 3 + Rand() % 20;
72  GenRandStats(dim, num_stats, N, P, phone_ids, *hmm_lengths,
73  is_ctx_dep, ensure_all_covered, &stats);
74 
75  // Now build the tree.
76 
77  Questions qopts;
78  int32 num_quest = Rand() % 10, num_iters = rand () % 5;
79  qopts.InitRand(stats, num_quest, num_iters, kAllKeysUnion); // This was tested in build-tree-utils-test.cc
80 
81  float thresh = 100.0 * RandUniform();
82 
83  EventMap *tree = NULL;
84  std::vector<std::vector<int32> > phone_sets(phone_ids.size());
85  for (size_t i = 0; i < phone_ids.size(); i++)
86  phone_sets[i].push_back(phone_ids[i]);
87  std::vector<bool> share_roots(phone_sets.size(), true),
88  do_split(phone_sets.size(), true);
89 
90  tree = BuildTree(qopts, phone_sets, *hmm_lengths, share_roots,
91  do_split, stats, thresh, 1000, 0.0, P);
92  DeleteBuildTreeStats(&stats);
93  return new ContextDependency(N, P, tree);
94 }
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
Definition: kaldi-math.h:151
kaldi::int32 int32
void GenRandStats(int32 dim, int32 num_stats, int32 N, int32 P, const std::vector< int32 > &phone_ids, const std::vector< int32 > &phone2hmm_length, const std::vector< bool > &is_ctx_dep, bool ensure_all_phones_covered, BuildTreeStatsType *stats_out)
GenRandStats generates random statistics of the form used by BuildTree.
Definition: build-tree.cc:30
void DeleteBuildTreeStats(BuildTreeStatsType *stats)
This frees the Clusterable* pointers in "stats", where non-NULL, and sets them to NULL...
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
EventMap * BuildTree(Questions &qopts, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, const std::vector< bool > &do_split, const BuildTreeStatsType &stats, BaseFloat thresh, int32 max_leaves, BaseFloat cluster_thresh, int32 P, bool round_num_leaves)
BuildTree is the normal way to build a set of decision trees.
Definition: build-tree.cc:136
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ GenRandContextDependencyLarge()

ContextDependency * GenRandContextDependencyLarge ( const std::vector< int32 > &  phones,
int  N,
int  P,
bool  ensure_all_covered,
std::vector< int32 > *  num_pdf_classes 
)

GenRandContextDependencyLarge is like GenRandContextDependency but generates a larger tree with specified N and P for use in "one-time" larger-scale tests.

Definition at line 97 of file context-dep.cc.

References BuildTree(), ContextDependency::ContextDependency(), DeleteBuildTreeStats(), GenRandStats(), rnnlm::i, Questions::InitRand(), IsSortedAndUniq(), KALDI_ASSERT, KALDI_VLOG, kAllKeysUnion, Rand(), and RandUniform().

Referenced by GenRandTransitionModel(), TestConvertAlignment(), kaldi::nnet2::UnitTestAmNnet(), and kaldi::nnet2::UnitTestNnetDecodable().

100  {
101  KALDI_ASSERT(IsSortedAndUniq(phone_ids));
102  int32 num_phones = phone_ids.size();
103  int32 num_stats = 3000; // each is a separate context.
104  float ctx_dep_prob = 0.9;
105  KALDI_ASSERT(num_phones > 0);
106  hmm_lengths->clear();
107  int32 max_phone = *std::max_element(phone_ids.begin(), phone_ids.end());
108  hmm_lengths->resize(max_phone + 1, -1);
109  std::vector<bool> is_ctx_dep(max_phone + 1);
110 
111  for (int32 i = 0; i <= max_phone; i++) {
112  (*hmm_lengths)[i] = 1 + Rand() % 3;
113  is_ctx_dep[i] = (RandUniform() < ctx_dep_prob); // true w.p. ctx_dep_prob.
114  }
115  for (size_t i = 0; i < (size_t) num_phones; i++) {
116  KALDI_VLOG(2) << "For idx = "<< i << ", (phone_id, hmm_length, is_ctx_dep) == " << (phone_ids[i]) << " " << ((*hmm_lengths)[phone_ids[i]]) << " " << (is_ctx_dep[phone_ids[i]]);
117  }
118  // Generate rand stats.
119  BuildTreeStatsType stats;
120  size_t dim = 3 + Rand() % 20;
121  GenRandStats(dim, num_stats, N, P, phone_ids, *hmm_lengths, is_ctx_dep, ensure_all_covered, &stats);
122 
123  // Now build the tree.
124 
125  Questions qopts;
126  int32 num_quest = 40, num_iters = 0;
127  qopts.InitRand(stats, num_quest, num_iters, kAllKeysUnion); // This was tested in build-tree-utils-test.cc
128 
129  float thresh = 100.0 * RandUniform();
130 
131  EventMap *tree = NULL;
132  std::vector<std::vector<int32> > phone_sets(phone_ids.size());
133  for (size_t i = 0; i < phone_ids.size(); i++)
134  phone_sets[i].push_back(phone_ids[i]);
135  std::vector<bool> share_roots(phone_sets.size(), true),
136  do_split(phone_sets.size(), true);
137 
138  tree = BuildTree(qopts, phone_sets, *hmm_lengths, share_roots,
139  do_split, stats, thresh, 1000, 0.0, P);
140  DeleteBuildTreeStats(&stats);
141  return new ContextDependency(N, P, tree);
142 }
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
Definition: kaldi-math.h:151
kaldi::int32 int32
void GenRandStats(int32 dim, int32 num_stats, int32 N, int32 P, const std::vector< int32 > &phone_ids, const std::vector< int32 > &phone2hmm_length, const std::vector< bool > &is_ctx_dep, bool ensure_all_phones_covered, BuildTreeStatsType *stats_out)
GenRandStats generates random statistics of the form used by BuildTree.
Definition: build-tree.cc:30
void DeleteBuildTreeStats(BuildTreeStatsType *stats)
This frees the Clusterable* pointers in "stats", where non-NULL, and sets them to NULL...
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
EventMap * BuildTree(Questions &qopts, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, const std::vector< bool > &do_split, const BuildTreeStatsType &stats, BaseFloat thresh, int32 max_leaves, BaseFloat cluster_thresh, int32 P, bool round_num_leaves)
BuildTree is the normal way to build a set of decision trees.
Definition: build-tree.cc:136
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ GenRandTopology() [1/2]

HmmTopology GenRandTopology ( const std::vector< int32 > &  phones,
const std::vector< int32 > &  num_pdf_classes 
)

This method of generating an arbitrary HmmTopology object allows you to specify the number of pdf-classes for each phone separately.

'num_pdf_classes' is indexed by the phone-index (so the length will be longer than the length of the 'phones' vector, which for example lacks the zero index and may have gaps).

Definition at line 87 of file hmm-test-utils.cc.

References rnnlm::i, IsSortedAndUniq(), rnnlm::j, KALDI_ASSERT, rnnlm::n, RandInt(), and HmmTopology::Read().

Referenced by GenRandTopology(), GenRandTransitionModel(), TestConvertAlignment(), and TestHmmTopology().

88  {
89  std::vector<int32> phones(phones_in);
90  std::sort(phones.begin(), phones.end());
91  KALDI_ASSERT(IsSortedAndUniq(phones) && !phones.empty());
92 
93  std::ostringstream topo_string;
94 
95  std::map<int32, std::vector<int32> > num_pdf_classes_to_phones;
96  for (size_t i = 0; i < phones.size(); i++) {
97  int32 p = phones[i];
98  KALDI_ASSERT(static_cast<size_t>(p) < num_pdf_classes.size());
99  int32 n = num_pdf_classes[p];
100  KALDI_ASSERT(n > 0 && "num-pdf-classes cannot be zero.");
101  num_pdf_classes_to_phones[n].push_back(p);
102  }
103 
104  topo_string << "<Topology>\n";
105  std::map<int32, std::vector<int32> >::const_iterator
106  iter = num_pdf_classes_to_phones.begin(),
107  end = num_pdf_classes_to_phones.end();
108  for (; iter != end; ++iter) {
109  topo_string << "<TopologyEntry>\n"
110  "<ForPhones> ";
111  int32 this_num_pdf_classes = iter->first;
112  const std::vector<int32> &phones = iter->second;
113  for (size_t i = 0; i < phones.size(); i++)
114  topo_string << phones[i] << " ";
115  topo_string << "</ForPhones> ";
116  bool ergodic = (RandInt(0, 1) == 0);
117  if (ergodic) {
118  // Note, this type of topology is not something we ever use in practice- it
119  // has an initial nonemitting state (no PdfClass specified). But it's
120  // supported so we're testing it.
121  std::vector<int32> state_to_pdf_class;
122  state_to_pdf_class.push_back(-1); // state zero, nonemitting.
123  for (int32 i = 0; i < this_num_pdf_classes; i++) {
124  int32 num_states = RandInt(1, 2);
125  for (int32 j = 0; j < num_states; j++)
126  state_to_pdf_class.push_back(i);
127  }
128  state_to_pdf_class.push_back(-1); // final non-emitting state.
129  { // state zero is nonemitting. This is not something used in any current
130  // example script.
131  topo_string << "<State> 0\n";
132  BaseFloat prob = 1.0 / (state_to_pdf_class.size() - 2);
133  for (size_t i = 1; i + 1 < state_to_pdf_class.size(); i++) {
134  topo_string << "<Transition> " << i << ' ' << prob << '\n';
135  }
136  topo_string << "</State>\n";
137  }
138  // ergodic part.
139  for (size_t i = 1; i + 1 < state_to_pdf_class.size(); i++) {
140  BaseFloat prob = 1.0 / (state_to_pdf_class.size() - 1);
141  topo_string << "<State> " << i << " <PdfClass> "
142  << state_to_pdf_class[i] << '\n';
143  for (size_t j = 1; j < state_to_pdf_class.size(); j++)
144  topo_string << "<Transition> " << j << ' ' << prob << '\n';
145  topo_string << "</State>\n";
146  }
147  // final, nonemitting state. No pdf-class, no transitions.
148  topo_string << "<State> " << (state_to_pdf_class.size() - 1) << " </State>\n";
149  } else {
150  // feedforward topology.
151  int32 cur_state = 0;
152  for (int32 pdf_class = 0; pdf_class < this_num_pdf_classes; pdf_class++) {
153  int32 this_num_states = RandInt(1, 2);
154  for (int32 s = 0; s < this_num_states; s++) {
155  topo_string << "<State> " << cur_state << " <PdfClass> " << pdf_class
156  << "\n<Transition> " << cur_state << " 0.5\n<Transition> "
157  << (cur_state + 1) << " 0.5\n</State>\n";
158  cur_state++;
159  }
160  }
161  // final, non-emitting state.
162  topo_string << "<State> " << cur_state << " </State>\n";
163  }
164  topo_string << "</TopologyEntry>\n";
165  }
166  topo_string << "</Topology>\n";
167 
168  HmmTopology topo;
169  std::istringstream iss(topo_string.str());
170  topo.Read(iss, false);
171  return topo;
172 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GenRandTopology() [2/2]

HmmTopology GenRandTopology ( )

This version of GenRandTopology() generates the phone list and number of pdf classes randomly.

Definition at line 174 of file hmm-test-utils.cc.

References GenRandTopology(), GetDefaultTopology(), rnnlm::i, and RandInt().

174  {
175  std::vector<int32> phones;
176  phones.push_back(1);
177  for (int32 i = 2; i < 20; i++)
178  if (rand() % 2 == 0)
179  phones.push_back(i);
180  if (RandInt(0, 1) == 0) {
181  return GetDefaultTopology(phones);
182  } else {
183  std::vector<int32> num_pdf_classes(phones.back() + 1, -1);
184  for (int32 i = 0; i < phones.size(); i++)
185  num_pdf_classes[phones[i]] = RandInt(1, 5);
186  return GenRandTopology(phones, num_pdf_classes);
187  }
188 }
HmmTopology GetDefaultTopology(const std::vector< int32 > &phones_in)
This function returns a HmmTopology object giving a normal 3-state topology, covering all phones in t...
kaldi::int32 int32
HmmTopology GenRandTopology()
This version of GenRandTopology() generates the phone list and number of pdf classes randomly...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GenRandTransitionModel()

TransitionModel * GenRandTransitionModel ( ContextDependency **  ctx_dep_out)

Definition at line 26 of file hmm-test-utils.cc.

References GenRandContextDependencyLarge(), GenRandTopology(), and rnnlm::i.

Referenced by TestSplitToPhones(), TestTransitionModel(), and TestWordAlignLatticeLexicon().

26  {
27  std::vector<int32> phones;
28  phones.push_back(1);
29  for (int32 i = 2; i < 20; i++)
30  if (rand() % 2 == 0)
31  phones.push_back(i);
32  int32 N = 2 + rand() % 2, // context-size N is 2 or 3.
33  P = rand() % N; // Central-phone is random on [0, N)
34 
35  std::vector<int32> num_pdf_classes;
36 
37  ContextDependency *ctx_dep =
38  GenRandContextDependencyLarge(phones, N, P,
39  true, &num_pdf_classes);
40 
41  HmmTopology topo = GenRandTopology(phones, num_pdf_classes);
42 
43  TransitionModel *trans_model = new TransitionModel(*ctx_dep, topo);
44 
45  if (ctx_dep_out == NULL) delete ctx_dep;
46  else *ctx_dep_out = ctx_dep;
47  return trans_model;
48 }
ContextDependency * GenRandContextDependencyLarge(const std::vector< int32 > &phone_ids, int N, int P, bool ensure_all_covered, std::vector< int32 > *hmm_lengths)
GenRandContextDependencyLarge is like GenRandContextDependency but generates a larger tree with speci...
Definition: context-dep.cc:97
kaldi::int32 int32
HmmTopology GenRandTopology()
This version of GenRandTopology() generates the phone list and number of pdf classes randomly...

◆ GetActiveParents()

static bool kaldi::GetActiveParents ( int32  node,
const vector< int32 > &  parents,
const vector< bool > &  is_active,
vector< int32 > *  active_parents_out 
)
static

Definition at line 129 of file regression-tree.cc.

References KALDI_ASSERT.

Referenced by RegressionTree::GatherStats().

131  {
132  KALDI_ASSERT(parents.size() == is_active.size());
133  KALDI_ASSERT(static_cast<size_t>(node) < parents.size());
134  active_parents_out->clear();
135 
136  if (node == static_cast<int32> (parents.size() - 1)) { // root node
137  if (is_active[node]) {
138  active_parents_out->push_back(node);
139  return true;
140  } else {
141  return false;
142  }
143  }
144 
145  bool ret_val = false;
146  while (node < static_cast<int32> (parents.size() - 1)) { // exclude the root
147  node = parents[node];
148  if (is_active[node]) {
149  active_parents_out->push_back(node);
150  ret_val = true;
151  }
152  }
153  return ret_val; // will return if not starting from root
154 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetBootstrapWERInterval()

void kaldi::GetBootstrapWERInterval ( const std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp,
int32  replications,
BaseFloat mean,
BaseFloat interval 
)

Definition at line 113 of file compute-wer-bootci.cc.

References rnnlm::i, rnnlm::j, and RandInt().

Referenced by main().

116  {
117  BaseFloat wer_accum = 0.0, wer_mult_accum = 0.0;
118 
119  for (int32 i = 0; i < replications; ++i) {
120  int32 num_words = 0, word_errs = 0;
121  for (int32 j = 0; j < edit_word_per_hyp.size(); ++j) {
122  int32 random_pos = kaldi::RandInt(0, edit_word_per_hyp.size() - 1);
123  word_errs += edit_word_per_hyp[random_pos].first;
124  num_words += edit_word_per_hyp[random_pos].second;
125  }
126 
127  BaseFloat wer_rep = static_cast<BaseFloat>(word_errs) / num_words;
128  wer_accum += wer_rep;
129  wer_mult_accum += wer_rep*wer_rep;
130  }
131 
132  // Compute mean WER and std WER
133  *mean = wer_accum / replications;
134  *interval = 1.96*sqrt(wer_mult_accum/replications-(*mean)*(*mean));
135 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GetBootstrapWERTwoSystemComparison()

void kaldi::GetBootstrapWERTwoSystemComparison ( const std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp,
const std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp2,
int32  replications,
BaseFloat p_improv 
)

Definition at line 137 of file compute-wer-bootci.cc.

References rnnlm::i, rnnlm::j, and RandInt().

Referenced by main().

140  {
141  int32 improv_accum = 0.0;
142 
143  for (int32 i = 0; i < replications; ++i) {
144  int32 word_errs = 0;
145  for (int32 j = 0; j < edit_word_per_hyp.size(); ++j) {
146  int32 random_pos = kaldi::RandInt(0, edit_word_per_hyp.size() - 1);
147  word_errs += edit_word_per_hyp[random_pos].first -
148  edit_word_per_hyp2[random_pos].first;
149  }
150  if(word_errs > 0)
151  ++improv_accum;
152  }
153  // Compute mean WER and std WER
154  *p_improv = static_cast<BaseFloat>(improv_accum) / replications;
155 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ GetCount()

int32 kaldi::GetCount ( double  expected_count)

Definition at line 29 of file nnet3-discriminative-copy-egs.cc.

References KALDI_ASSERT, and WithProb().

29  {
30  KALDI_ASSERT(expected_count >= 0.0);
31  int32 ans = floor(expected_count);
32  expected_count -= ans;
33  if (WithProb(expected_count))
34  ans++;
35  return ans;
36 }
bool WithProb(BaseFloat prob, struct RandomState *state)
Definition: kaldi-math.cc:72
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetDefaultTopology()

HmmTopology GetDefaultTopology ( const std::vector< int32 > &  phones)

This function returns a HmmTopology object giving a normal 3-state topology, covering all phones in the list "phones".

This is mainly of use in testing code.

Definition at line 50 of file hmm-test-utils.cc.

References rnnlm::i, IsSortedAndUniq(), KALDI_ASSERT, and HmmTopology::Read().

Referenced by GenRandTopology(), TestHmmTopology(), kaldi::nnet2::UnitTestAmNnet(), and kaldi::nnet2::UnitTestNnetDecodable().

50  {
51  std::vector<int32> phones(phones_in);
52  std::sort(phones.begin(), phones.end());
53  KALDI_ASSERT(IsSortedAndUniq(phones) && !phones.empty());
54 
55  std::ostringstream topo_string;
56  topo_string << "<Topology>\n"
57  "<TopologyEntry>\n"
58  "<ForPhones> ";
59  for (size_t i = 0; i < phones.size(); i++)
60  topo_string << phones[i] << " ";
61 
62  topo_string << "</ForPhones>\n"
63  "<State> 0 <PdfClass> 0\n"
64  "<Transition> 0 0.5\n"
65  "<Transition> 1 0.5\n"
66  "</State> \n"
67  "<State> 1 <PdfClass> 1 \n"
68  "<Transition> 1 0.5\n"
69  "<Transition> 2 0.5\n"
70  "</State> \n"
71  " <State> 2 <PdfClass> 2\n"
72  " <Transition> 2 0.5\n"
73  " <Transition> 3 0.5\n"
74  " </State> \n"
75  " <State> 3 </State>\n"
76  " </TopologyEntry>\n"
77  " </Topology>\n";
78 
79  HmmTopology topo;
80  std::istringstream iss(topo_string.str());
81  topo.Read(iss, false);
82  return topo;
83 
84 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ GetDiagnosticsAndPrintOutput()

void GetDiagnosticsAndPrintOutput ( const std::string &  utt,
const fst::SymbolTable *  word_syms,
const CompactLattice clat,
int64 *  tot_num_frames,
double *  tot_like 
)

Definition at line 31 of file online2-wav-gmm-latgen-faster.cc.

References CompactLatticeShortestPath(), fst::ConvertLattice(), fst::GetLinearSymbolSequence(), rnnlm::i, KALDI_ERR, KALDI_VLOG, KALDI_WARN, LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), and words.

Referenced by main().

35  {
36  if (clat.NumStates() == 0) {
37  KALDI_WARN << "Empty lattice.";
38  return;
39  }
40  CompactLattice best_path_clat;
41  CompactLatticeShortestPath(clat, &best_path_clat);
42 
43  Lattice best_path_lat;
44  ConvertLattice(best_path_clat, &best_path_lat);
45 
46  double likelihood;
47  LatticeWeight weight;
48  int32 num_frames;
49  std::vector<int32> alignment;
50  std::vector<int32> words;
51  GetLinearSymbolSequence(best_path_lat, &alignment, &words, &weight);
52  num_frames = alignment.size();
53  likelihood = -(weight.Value1() + weight.Value2());
54  *tot_num_frames += num_frames;
55  *tot_like += likelihood;
56  KALDI_VLOG(2) << "Likelihood per frame for utterance " << utt << " is "
57  << (likelihood / num_frames) << " over " << num_frames
58  << " frames.";
59 
60  if (word_syms != NULL) {
61  std::cerr << utt << ' ';
62  for (size_t i = 0; i < words.size(); i++) {
63  std::string s = word_syms->Find(words[i]);
64  if (s == "")
65  KALDI_ERR << "Word-id " << words[i] << " not in symbol table.";
66  std::cerr << s << ' ';
67  }
68  std::cerr << std::endl;
69  }
70 }
int32 words[kMaxOrder]
kaldi::int32 int32
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
void CompactLatticeShortestPath(const CompactLattice &clat, CompactLattice *shortest_path)
A form of the shortest-path/best-path algorithm that&#39;s specially coded for CompactLattice.
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ GetEditsDualHyp()

void kaldi::GetEditsDualHyp ( const std::string &  hyp_rspecifier,
const std::string &  hyp_rspecifier2,
const std::string &  ref_rspecifier,
const std::string &  mode,
std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp,
std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp2 
)

Definition at line 63 of file compute-wer-bootci.cc.

References SequentialTableReader< Holder >::Done(), RandomAccessTableReader< Holder >::HasKey(), KALDI_ERR, SequentialTableReader< Holder >::Key(), LevenshteinEditDistance(), SequentialTableReader< Holder >::Next(), RandomAccessTableReader< Holder >::Value(), and SequentialTableReader< Holder >::Value().

Referenced by main().

68  {
69 
70  // Both text and integers are loaded as vector of strings,
71  SequentialTokenVectorReader ref_reader(ref_rspecifier);
72  RandomAccessTokenVectorReader hyp_reader(hyp_rspecifier);
73  RandomAccessTokenVectorReader hyp_reader2(hyp_rspecifier2);
74  int32 num_words = 0, word_errs = 0,
75  num_ins = 0, num_del = 0, num_sub = 0;
76 
77  // Main loop, store WER stats per hyp,
78  for (; !ref_reader.Done(); ref_reader.Next()) {
79  std::string key = ref_reader.Key();
80  const std::vector<std::string> &ref_sent = ref_reader.Value();
81  std::vector<std::string> hyp_sent, hyp_sent2;
82  if (mode == "strict" &&
83  (!hyp_reader.HasKey(key) || !hyp_reader2.HasKey(key))) {
84  KALDI_ERR << "No hypothesis for key " << key << " in both transcripts "
85  "comparison is not possible.";
86  } else if (mode == "present" &&
87  (!hyp_reader.HasKey(key) || !hyp_reader2.HasKey(key)))
88  continue;
89 
90  num_words = ref_sent.size();
91 
92  //all mode, if a hypothesis is not present, consider as an error
93  if(hyp_reader.HasKey(key)){
94  hyp_sent = hyp_reader.Value(key);
95  word_errs = LevenshteinEditDistance(ref_sent, hyp_sent,
96  &num_ins, &num_del, &num_sub);
97  }
98  else
99  word_errs = num_words;
100  edit_word_per_hyp.push_back(std::pair<int32, int32>(word_errs, num_words));
101 
102  if(hyp_reader2.HasKey(key)){
103  hyp_sent2 = hyp_reader2.Value(key);
104  word_errs = LevenshteinEditDistance(ref_sent, hyp_sent2,
105  &num_ins, &num_del, &num_sub);
106  }
107  else
108  word_errs = num_words;
109  edit_word_per_hyp2.push_back(std::pair<int32, int32>(word_errs, num_words));
110  }
111 }
kaldi::int32 int32
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
int32 LevenshteinEditDistance(const std::vector< T > &a, const std::vector< T > &b)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ GetEditsSingleHyp()

void kaldi::GetEditsSingleHyp ( const std::string &  hyp_rspecifier,
const std::string &  ref_rspecifier,
const std::string &  mode,
std::vector< std::pair< int32, int32 > > &  edit_word_per_hyp 
)

Definition at line 32 of file compute-wer-bootci.cc.

References SequentialTableReader< Holder >::Done(), RandomAccessTableReader< Holder >::HasKey(), KALDI_ERR, SequentialTableReader< Holder >::Key(), LevenshteinEditDistance(), SequentialTableReader< Holder >::Next(), RandomAccessTableReader< Holder >::Value(), and SequentialTableReader< Holder >::Value().

Referenced by main().

35  {
36 
37  // Both text and integers are loaded as vector of strings,
38  SequentialTokenVectorReader ref_reader(ref_rspecifier);
39  RandomAccessTokenVectorReader hyp_reader(hyp_rspecifier);
40  int32 num_words = 0, word_errs = 0, num_ins = 0, num_del = 0, num_sub = 0;
41 
42  // Main loop, store WER stats per hyp,
43  for (; !ref_reader.Done(); ref_reader.Next()) {
44  std::string key = ref_reader.Key();
45  const std::vector<std::string> &ref_sent = ref_reader.Value();
46  std::vector<std::string> hyp_sent;
47  if (!hyp_reader.HasKey(key)) {
48  if (mode == "strict")
49  KALDI_ERR << "No hypothesis for key " << key << " and strict "
50  "mode specifier.";
51  if (mode == "present") // do not score this one.
52  continue;
53  } else {
54  hyp_sent = hyp_reader.Value(key);
55  }
56  num_words = ref_sent.size();
57  word_errs = LevenshteinEditDistance(ref_sent, hyp_sent,
58  &num_ins, &num_del, &num_sub);
59  edit_word_per_hyp.push_back(std::pair<int32, int32>(word_errs, num_words));
60  }
61 }
kaldi::int32 int32
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
int32 LevenshteinEditDistance(const std::vector< T > &a, const std::vector< T > &b)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ GetEventKeys()

static void kaldi::GetEventKeys ( const EventType vec,
std::vector< EventKeyType > *  keys 
)
static

Definition at line 81 of file build-tree-utils.cc.

Referenced by FindAllKeys().

81  {
82  keys->resize(vec.size());
83  EventType::const_iterator iter = vec.begin(), end = vec.end();
84  std::vector<EventKeyType>::iterator out_iter = keys->begin();
85  for (; iter!= end; ++iter, ++out_iter)
86  *out_iter = iter->first;
87 }

◆ GetFeatDeriv()

void kaldi::GetFeatDeriv ( const DiagGmm gmm,
const Matrix< BaseFloat > &  feats,
Matrix< BaseFloat > *  deriv 
)

Definition at line 32 of file fmpe-test.cc.

References VectorBase< Real >::AddMatVec(), VectorBase< Real >::AddVecVec(), DiagGmm::ComponentPosteriors(), rnnlm::i, DiagGmm::inv_vars(), kTrans, DiagGmm::means_invvars(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), Matrix< Real >::Resize(), and VectorBase< Real >::Scale().

Referenced by TestFmpe().

34  {
35 
36  deriv->Resize(feats.NumRows(), feats.NumCols());
37 
38  Vector<BaseFloat> gauss_posteriors;
39  Vector<BaseFloat> temp_vec(feats.NumCols());
40  for (int32 i = 0; i < feats.NumRows(); i++) {
41  SubVector<BaseFloat> this_feat(feats, i);
42  SubVector<BaseFloat> this_deriv(*deriv, i);
43  gmm.ComponentPosteriors(this_feat, &gauss_posteriors);
44  BaseFloat weight = 1.0;
45  gauss_posteriors.Scale(weight);
46  // The next line does: to i'th row of deriv, add
47  // means_invvars^T * gauss_posteriors,
48  // where each row of means_invvars is the mean times
49  // diagonal inverse covariance... after transposing,
50  // this becomes a weighted of these rows, weighted by
51  // the posteriors. This comes from the term
52  // feat^T * inv_var * mean
53  // in the objective function.
54  this_deriv.AddMatVec(1.0, gmm.means_invvars(), kTrans,
55  gauss_posteriors, 1.0);
56 
57  // next line does temp_vec == inv_vars^T * gauss_posteriors,
58  // which sets temp_vec to a weighted sum of the inv_vars,
59  // weighed by Gaussian posterior.
60  temp_vec.AddMatVec(1.0, gmm.inv_vars(), kTrans,
61  gauss_posteriors, 0.0);
62  // Add to the derivative, -(this_feat .* temp_vec),
63  // which is the term that comes from the -0.5 * inv_var^T feat_sq,
64  // in the objective function (where inv_var is a vector, and feat_sq
65  // is a vector of squares of the feature values).
66  this_deriv.AddVecVec(-1.0, this_feat, temp_vec, 1.0);
67  }
68 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ GetFeatureMeanAndVariance()

void kaldi::GetFeatureMeanAndVariance ( const std::string &  feat_rspecifier,
Vector< BaseFloat > *  inv_var_out,
Vector< BaseFloat > *  mean_out 
)

Definition at line 33 of file gmm-init-model-flat.cc.

References VectorBase< Real >::AddVec(), VectorBase< Real >::AddVec2(), VectorBase< Real >::CopyFromVec(), count, VectorBase< Real >::Dim(), SequentialTableReader< Holder >::Done(), rnnlm::i, VectorBase< Real >::InvertElements(), KALDI_ERR, VectorBase< Real >::Min(), SequentialTableReader< Holder >::Next(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), Vector< Real >::Resize(), MatrixBase< Real >::Row(), VectorBase< Real >::Scale(), and SequentialTableReader< Holder >::Value().

Referenced by main().

35  {
36  double count = 0.0;
37  Vector<double> x_stats, x2_stats;
38 
39  SequentialDoubleMatrixReader feat_reader(feat_rspecifier);
40  for (; !feat_reader.Done(); feat_reader.Next()) {
41  const Matrix<double> &mat = feat_reader.Value();
42  if (x_stats.Dim() == 0) {
43  int32 dim = mat.NumCols();
44  x_stats.Resize(dim);
45  x2_stats.Resize(dim);
46  }
47  for (int32 i = 0; i < mat.NumRows(); i++) {
48  count += 1.0;
49  x_stats.AddVec(1.0, mat.Row(i));
50  x2_stats.AddVec2(1.0, mat.Row(i));
51  }
52  }
53  if (count == 0) { KALDI_ERR << "No features were read!"; }
54  x_stats.Scale(1.0/count);
55  x2_stats.Scale(1.0/count);
56  x2_stats.AddVec2(-1.0, x_stats);
57  if (x2_stats.Min() <= 0.0)
58  KALDI_ERR << "Variance is zero or negative!";
59  x2_stats.InvertElements();
60  int32 dim = x_stats.Dim();
61  inv_var_out->Resize(dim);
62  mean_out->Resize(dim);
63  inv_var_out->CopyFromVec(x2_stats);
64  mean_out->CopyFromVec(x_stats);
65 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
const size_t count
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:147
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
void Scale(Real alpha)
Multiplies all elements by this constant.
void InvertElements()
Invert all elements.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...

◆ GetFullBiphoneStubMap()

EventMap* kaldi::GetFullBiphoneStubMap ( const std::vector< std::vector< int32 > > &  phone_sets,
const std::vector< int32 > &  phone2num_pdf_classes,
const std::vector< int32 > &  ci_phones_list,
const std::vector< std::vector< int32 > > &  bi_counts,
int32  biphone_min_count,
const std::vector< int32 > &  mono_counts,
int32  mono_min_count 
)

Definition at line 53 of file gmm-init-biphone.cc.

References rnnlm::i, IsSortedAndUniq(), rnnlm::j, KALDI_ASSERT, KALDI_LOG, KALDI_VLOG, and kPdfClass.

Referenced by BiphoneContextDependencyFull().

59  {
60 
61  { // Check the inputs
62  KALDI_ASSERT(!phone_sets.empty());
63  std::set<int32> all_phones;
64  for (size_t i = 0; i < phone_sets.size(); i++) {
65  KALDI_ASSERT(IsSortedAndUniq(phone_sets[i]));
66  KALDI_ASSERT(!phone_sets[i].empty());
67  for (size_t j = 0; j < phone_sets[i].size(); j++) {
68  KALDI_ASSERT(all_phones.count(phone_sets[i][j]) == 0); // Check not present.
69  all_phones.insert(phone_sets[i][j]);
70  }
71  }
72  }
73 
74 
75  int32 numpdfs_per_phone = phone2num_pdf_classes[1];
76  int32 current_pdfid = 0;
77  std::map<EventValueType, EventMap*> level1_map; // key is 1
78 
79  for (size_t i = 0; i < ci_phones_list.size(); i++) {
80  std::map<EventValueType, EventAnswerType> level2_map;
81  level2_map[0] = current_pdfid++;
82  if (numpdfs_per_phone == 2) level2_map[1] = current_pdfid++;
83  level1_map[ci_phones_list[i]] = new TableEventMap(kPdfClass, level2_map);
84  }
85 
86  // If there is not enough data for a biphone, we will revert to monophone
87  // and if there is not enough data for the monophone either, we will revert
88  // to zerophone (which is like a global garbage pdf) after initializing it.
89  int32 zerophone_pdf = -1;
90  // If a monophone state is created for a phone-set, the corresponding pdf will
91  // be stored in this vector.
92  std::vector<int32> monophone_pdf(phone_sets.size(), -1);
93 
94  for (size_t i = 0; i < phone_sets.size(); i++) {
95 
96  if (numpdfs_per_phone == 1) {
97  // Create an event map for level2:
98  std::map<EventValueType, EventAnswerType> level2_map; // key is 0
99  level2_map[0] = current_pdfid++; // no-left-context case
100  for (size_t j = 0; j < phone_sets.size(); j++) {
101  int32 pdfid = current_pdfid++;
102  std::vector<int32> pset = phone_sets[j]; // All these will have a
103  // shared pdf with id=pdfid
104  for (size_t k = 0; k < pset.size(); k++)
105  level2_map[pset[k]] = pdfid;
106  }
107  std::vector<int32> pset = phone_sets[i]; // All these will have a
108  // shared event-map child
109  for (size_t k = 0; k < pset.size(); k++)
110  level1_map[pset[k]] = new TableEventMap(0, level2_map);
111  } else {
112  KALDI_ASSERT(numpdfs_per_phone == 2);
113  std::vector<int32> right_phoneset = phone_sets[i]; // All these will have a shared
114  // event-map child
115  // Create an event map for level2:
116  std::map<EventValueType, EventMap*> level2_map; // key is 0
117  { // Handle CI phones
118  std::map<EventValueType, EventAnswerType> level3_map; // key is kPdfClass
119  level3_map[0] = current_pdfid++;
120  level3_map[1] = current_pdfid++;
121  level2_map[0] = new TableEventMap(kPdfClass, level3_map); // no-left-context case
122  for (size_t i = 0; i < ci_phones_list.size(); i++) // ci-phone left-context cases
123  level2_map[ci_phones_list[i]] = new TableEventMap(kPdfClass, level3_map);
124  }
125  for (size_t j = 0; j < phone_sets.size(); j++) {
126  std::vector<int32> left_phoneset = phone_sets[j]; // All these will have a
127  // shared subtree with 2 pdfids
128  std::map<EventValueType, EventAnswerType> level3_map; // key is kPdfClass
129  if (bi_counts.empty() ||
130  bi_counts[left_phoneset[0]][right_phoneset[0]] >= biphone_min_count) {
131  level3_map[0] = current_pdfid++;
132  level3_map[1] = current_pdfid++;
133  } else if (mono_counts.empty() ||
134  mono_counts[right_phoneset[0]] > mono_min_count) {
135  // Revert to mono.
136  KALDI_VLOG(2) << "Reverting to mono for biphone (" << left_phoneset[0]
137  << "," << right_phoneset[0] << ")";
138  if (monophone_pdf[i] == -1) {
139  KALDI_VLOG(1) << "Reserving mono PDFs for phone-set " << i;
140  monophone_pdf[i] = current_pdfid++;
141  current_pdfid++; // num-pdfs-per-phone is 2
142  }
143  level3_map[0] = monophone_pdf[i];
144  level3_map[1] = monophone_pdf[i] + 1;
145  } else {
146  KALDI_VLOG(2) << "Reverting to zerophone for biphone ("
147  << left_phoneset[0]
148  << "," << right_phoneset[0] << ")";
149  // Revert to zerophone
150  if (zerophone_pdf == -1) {
151  KALDI_VLOG(1) << "Reserving zero PDFs.";
152  zerophone_pdf = current_pdfid++;
153  current_pdfid++; // num-pdfs-per-phone is 2
154  }
155  level3_map[0] = zerophone_pdf;
156  level3_map[1] = zerophone_pdf + 1;
157  }
158 
159  for (size_t k = 0; k < left_phoneset.size(); k++) {
160  int32 left_phone = left_phoneset[k];
161  level2_map[left_phone] = new TableEventMap(kPdfClass, level3_map);
162  }
163  }
164  for (size_t k = 0; k < right_phoneset.size(); k++) {
165  std::map<EventValueType, EventMap*> level2_copy;
166  for (auto const& kv: level2_map)
167  level2_copy[kv.first] = kv.second->Copy(std::vector<EventMap*>());
168  int32 right_phone = right_phoneset[k];
169  level1_map[right_phone] = new TableEventMap(0, level2_copy);
170  }
171  }
172 
173  }
174  KALDI_LOG << "Num PDFs: " << current_pdfid;
175  return new TableEventMap(1, level1_map);
176 }
kaldi::int32 int32
static const EventKeyType kPdfClass
Definition: context-dep.h:39
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ GetGmmLike()

BaseFloat kaldi::GetGmmLike ( const DiagGmm gmm,
const Matrix< BaseFloat > &  feats 
)

Definition at line 71 of file fmpe-test.cc.

References rnnlm::i, DiagGmm::LogLikelihood(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Row().

Referenced by TestFmpe().

72  {
73  BaseFloat ans = 0.0;
74  for (int32 i = 0; i < feats.NumRows(); i++)
75  ans += gmm.LogLikelihood(feats.Row(i));
76  return ans;
77 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ GetLatticeTimeSpan()

int32 kaldi::GetLatticeTimeSpan ( const Lattice lat)

Definition at line 96 of file online2-tcp-nnet3-decode-faster.cc.

References LatticeStateTimes().

Referenced by main().

96  {
97  std::vector<int32> times;
98  LatticeStateTimes(lat, &times);
99  return times.back();
100 }
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...

◆ GetLogDetNoFailure()

static double kaldi::GetLogDetNoFailure ( const SpMatrix< double > &  var)
static

Definition at line 345 of file ivector-extractor.cc.

References SpMatrix< Real >::Eig(), KALDI_WARN, SpMatrix< Real >::LogPosDefDet(), and PackedMatrix< Real >::NumRows().

Referenced by IvectorExtractor::GetPriorAuxf().

345  {
346  try {
347  return var.LogPosDefDet();
348  } catch (...) {
349  Vector<double> eigs(var.NumRows());
350  var.Eig(&eigs);
351  int32 floored;
352  eigs.ApplyFloor(1.0e-20, &floored);
353  if (floored > 0)
354  KALDI_WARN << "Floored " << floored << " eigenvalues of variance.";
355  eigs.ApplyLog();
356  return eigs.Sum();
357  }
358 }
kaldi::int32 int32
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
Definition: qr.cc:433
MatrixIndexT NumRows() const
Real LogPosDefDet() const
Computes log determinant but only for +ve-def matrices (it uses Cholesky).
Definition: sp-matrix.cc:36
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ GetOccs()

void kaldi::GetOccs ( const BuildTreeStatsType stats,
const EventMap to_pdf_map,
Vector< BaseFloat > *  occs 
)

Get state occupation counts.

Definition at line 92 of file gmm-init-model.cc.

References VectorBase< Real >::Dim(), KALDI_ASSERT, EventMap::MaxResult(), Vector< Real >::Resize(), SplitStatsByMap(), and SumNormalizer().

Referenced by main().

94  {
95 
96  // Get stats split by tree-leaf ( == pdf):
97  std::vector<BuildTreeStatsType> split_stats;
98  SplitStatsByMap(stats, to_pdf_map, &split_stats);
99  if (split_stats.size() != to_pdf_map.MaxResult()+1) {
100  KALDI_ASSERT(split_stats.size() < to_pdf_map.MaxResult()+1);
101  split_stats.resize(to_pdf_map.MaxResult()+1);
102  }
103  occs->Resize(split_stats.size());
104  for (int32 pdf = 0; pdf < occs->Dim(); pdf++)
105  (*occs)(pdf) = SumNormalizer(split_stats[pdf]);
106 }
BaseFloat SumNormalizer(const BuildTreeStatsType &stats_in)
Sums the normalizer [typically, data-count] over the stats.
virtual EventAnswerType MaxResult() const
Definition: event-map.h:142
void SplitStatsByMap(const BuildTreeStatsType &stats, const EventMap &e, std::vector< BuildTreeStatsType > *stats_out)
Splits stats according to the EventMap, indexing them at output by the leaf type. ...
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetOptionImpl()

static bool kaldi::GetOptionImpl ( const std::string &  key,
T *  value,
std::map< std::string, T *> &  some_map 
)
static

Definition at line 130 of file simple-options.cc.

Referenced by SimpleOptions::GetOption().

131  {
132  typename std::map<std::string, T*>::iterator it = some_map.find(key);
133  if (it != some_map.end()) {
134  *value = *(it->second);
135  return true;
136  }
137  return false;
138 }

◆ GetOutput() [1/2]

void kaldi::GetOutput ( OnlineFeatureInterface a,
Matrix< BaseFloat > *  output 
)

Definition at line 29 of file online-feature-test.cc.

References OnlineCacheFeature::ClearCache(), MatrixBase< Real >::CopyRowFromVec(), OnlineFeatureInterface::Dim(), OnlineCacheFeature::GetFrame(), rnnlm::i, OnlineCacheFeature::IsLastFrame(), KALDI_ASSERT, OnlineFeatureInterface::NumFramesReady(), and Matrix< Real >::Resize().

Referenced by PldaEstimator::Dim(), TestOnlineAppendFeature(), TestOnlineCmnInput(), TestOnlineDeltaFeature(), TestOnlineDeltaInput(), TestOnlineLdaInput(), TestOnlineMatrixCacheFeature(), TestOnlineMatrixInput(), TestOnlineMfcc(), TestOnlinePlp(), TestOnlineSpliceFrames(), and TestOnlineTransform().

30  {
31  int32 dim = a->Dim();
32  int32 frame_num = 0;
33  OnlineCacheFeature cache(a);
34 
35  std::vector<Vector<BaseFloat>* > cached_frames;
36  while (true) {
37  Vector<BaseFloat> garbage(dim);
38  cache.GetFrame(frame_num, &garbage);
39  cached_frames.push_back(new Vector<BaseFloat>(garbage));
40  if (cache.IsLastFrame(frame_num))
41  break;
42  frame_num++;
43  }
44 
45  KALDI_ASSERT(cached_frames.size() == a->NumFramesReady());
46 
47  output->Resize(cached_frames.size(), dim);
48  for (int32 i = 0; i < cached_frames.size(); i++) {
49  output->CopyRowFromVec(*(cached_frames[i]), i);
50  delete cached_frames[i];
51  }
52  cached_frames.clear();
53  cache.ClearCache();
54 }
kaldi::int32 int32
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void CopyRowFromVec(const VectorBase< Real > &v, const MatrixIndexT row)
Copy vector into specific row of matrix.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
This feature type can be used to cache its input, to avoid repetition of computation in a multi-pass ...
virtual int32 NumFramesReady() const =0
returns the feature dimension.
virtual int32 Dim() const =0

◆ GetOutput() [2/2]

void kaldi::GetOutput ( OnlineFeatInputItf a,
Matrix< BaseFloat > *  output 
)

Definition at line 81 of file online-feat-test.cc.

References OnlineCacheInput::Compute(), OnlineFeatInputItf::Dim(), OnlineCacheInput::GetCachedData(), Rand(), and Matrix< Real >::Resize().

82  {
83  int32 dim = a->Dim();
84  OnlineCacheInput cache(a);
85  while (true) {
86  Matrix<BaseFloat> garbage;
87  int32 batch_size = 1 + Rand() % 10;
88  garbage.Resize(batch_size, dim); // some random requested amount.
89  if (!cache.Compute(&garbage)) // returns false when done.
90  break;
91  }
92  cache.GetCachedData(output);
93 }
virtual int32 Dim() const =0
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ GetPerFrameAcousticCosts()

void GetPerFrameAcousticCosts ( const Lattice nbest,
Vector< BaseFloat > *  per_frame_loglikes 
)

This function extracts the per-frame log likelihoods from a linear lattice (which we refer to as an 'nbest' lattice elsewhere in Kaldi code).

The dimension of *per_frame_loglikes will be set to the number of input symbols in 'nbest'. The elements of '*per_frame_loglikes' will be set to the .Value2() elements of the lattice weights, which represent the acoustic costs; you may want to scale this vector afterward by -1/acoustic_scale to get the original loglikes. If there are acoustic costs on input-epsilon arcs or the final-prob in 'nbest' (and this should not normally be the case in situations where it makes sense to call this function), they will be included to the cost of the preceding input symbol, or the following input symbol for input-epsilons encountered prior to any input symbol. If 'nbest' has no input symbols, 'per_frame_loglikes' will be set to the empty vector.

Definition at line 36 of file lattice-functions.cc.

References KALDI_ASSERT.

Referenced by AlignUtteranceWrapper().

36  {
37  using namespace fst;
39  vector<BaseFloat> loglikes;
40 
41  int32 cur_state = nbest.Start();
42  int32 prev_frame = -1;
43  BaseFloat eps_acwt = 0.0;
44  while(1) {
45  Weight w = nbest.Final(cur_state);
46  if (w != Weight::Zero()) {
47  KALDI_ASSERT(nbest.NumArcs(cur_state) == 0);
48  if (per_frame_loglikes != NULL) {
49  SubVector<BaseFloat> subvec(&(loglikes[0]), loglikes.size());
50  Vector<BaseFloat> vec(subvec);
51  *per_frame_loglikes = vec;
52  }
53  break;
54  } else {
55  KALDI_ASSERT(nbest.NumArcs(cur_state) == 1);
56  fst::ArcIterator<Lattice> iter(nbest, cur_state);
57  const Lattice::Arc &arc = iter.Value();
58  BaseFloat acwt = arc.weight.Value2();
59  if (arc.ilabel != 0) {
60  if (eps_acwt > 0) {
61  acwt += eps_acwt;
62  eps_acwt = 0.0;
63  }
64  loglikes.push_back(acwt);
65  prev_frame++;
66  } else if (acwt == acwt){
67  if (prev_frame > -1) {
68  loglikes[prev_frame] += acwt;
69  } else {
70  eps_acwt += acwt;
71  }
72  }
73  cur_state = arc.nextstate;
74  }
75  }
76 }
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
float BaseFloat
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetRandChar()

char kaldi::GetRandChar ( )

Definition at line 28 of file text-utils-test.cc.

References Rand().

Referenced by TestSplitStringToVector().

28  {
29  return static_cast<char>(32 + Rand() % 95); // between ' ' and '~'
30 }
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45

◆ GetRandDelim()

char kaldi::GetRandDelim ( )

Definition at line 33 of file text-utils-test.cc.

References Rand().

Referenced by TestSplitStringToVector().

33  {
34  if (Rand() % 2 == 0)
35  return static_cast<char>(33 + Rand() % 94); // between '!' and '~';
36  else
37  return ws_delim[Rand() % 4];
38 }
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
const char * ws_delim

◆ GetScaledTransitionLogProb()

static BaseFloat kaldi::GetScaledTransitionLogProb ( const TransitionModel trans_model,
int32  trans_id,
BaseFloat  transition_scale,
BaseFloat  self_loop_scale 
)
static

Definition at line 1065 of file hmm-utils.cc.

References TransitionModel::GetNonSelfLoopLogProb(), TransitionModel::GetTransitionLogProb(), TransitionModel::GetTransitionLogProbIgnoringSelfLoops(), TransitionModel::IsSelfLoop(), and TransitionModel::TransitionIdToTransitionState().

Referenced by AddTransitionProbs().

1068  {
1069  if (transition_scale == self_loop_scale) {
1070  return trans_model.GetTransitionLogProb(trans_id) * transition_scale;
1071  } else {
1072  if (trans_model.IsSelfLoop(trans_id)) {
1073  return self_loop_scale * trans_model.GetTransitionLogProb(trans_id);
1074  } else {
1075  int32 trans_state = trans_model.TransitionIdToTransitionState(trans_id);
1076  return self_loop_scale * trans_model.GetNonSelfLoopLogProb(trans_state)
1077  + transition_scale * trans_model.GetTransitionLogProbIgnoringSelfLoops(trans_id);
1078  // This could be simplified to
1079  // (self_loop_scale - transition_scale) * trans_model.GetNonSelfLoopLogProb(trans_state)
1080  // + trans_model.GetTransitionLogProb(trans_id);
1081  // this simplifies if self_loop_scale == 0.0
1082  }
1083  }
1084 }
kaldi::int32 int32

◆ GetSeenPhones()

void kaldi::GetSeenPhones ( BuildTreeStatsType stats,
int  P,
std::vector< int32 > *  phones_out 
)

Definition at line 32 of file build-tree-two-level.cc.

References CopySetToVector(), rnnlm::i, rnnlm::j, and KALDI_ASSERT.

Referenced by main().

32  {
33  // Get list of phones that we saw (in the central position P, although it
34  // shouldn't matter what position).
35 
36  std::set<int32> phones_set;
37  for (size_t i = 0 ; i < stats.size(); i++) {
38  const EventType &evec = stats[i].first;
39  for (size_t j = 0; j < evec.size(); j++) {
40  if (evec[j].first == P) { // "key" is position P
41  KALDI_ASSERT(evec[j].second != 0);
42  phones_set.insert(evec[j].second); // insert "value" of this
43  // phone.
44  }
45  }
46  CopySetToVector(phones_set, phones_out);
47  }
48 }
void CopySetToVector(const std::set< T > &s, std::vector< T > *v)
Copies the elements of a set to a vector.
Definition: stl-utils.h:86
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetShortFileName()

static const char* kaldi::GetShortFileName ( const char *  path)
static

Definition at line 63 of file kaldi-error.cc.

Referenced by MessageLogger::MessageLogger().

63  {
64  if (path == nullptr)
65  return "";
66 
67  const char *prev = path, *last = path;
68  while ((path = std::strpbrk(path, "\\/")) != nullptr) {
69  ++path;
70  prev = last;
71  last = path;
72  }
73  return prev;
74 }

◆ GetSingleStatsDerivative()

void kaldi::GetSingleStatsDerivative ( double  ml_count,
double  ml_x_stats,
double  ml_x2_stats,
double  disc_count,
double  disc_x_stats,
double  disc_x2_stats,
double  model_mean,
double  model_var,
BaseFloat  min_variance,
double *  ml_x_stats_deriv,
double *  ml_x2_stats_deriv 
)

Definition at line 25 of file indirect-diff-diag-gmm.cc.

References KALDI_VLOG.

Referenced by GetStatsDerivative().

29  {
30 
31  double model_inv_var = 1.0/model_var,
32  model_inv_var_sq = model_inv_var*model_inv_var,
33  model_mean_sq = model_mean*model_mean;
34 
35  // First get derivative of discriminative objective function w.r.t. the
36  // model mean and variance.
37  // Below: eqs. 11 and 13 in 2005 ICASSP paper on fMPE. Note: the factor of
38  // kappa (in the fMPE case) is assumed to have been accounted for by
39  // scaling the num and den accs at the command-line level. We substituted
40  // eq. 12 into 13 and rearranged to get the second expression.
41  double diff_wrt_model_mean = (1.0/model_var) * (disc_x_stats - model_mean*disc_count),
42  diff_wrt_model_var =
43  0.5 * ((disc_x2_stats - 2*model_mean*disc_x_stats + disc_count*model_mean_sq)
44  * model_inv_var_sq
45  - disc_count*model_inv_var);
46 
47  double stats_mean = ml_x_stats / ml_count,
48  stats_var = ml_x2_stats / ml_count - (ml_x_stats / ml_count)*(ml_x_stats / ml_count);
49 
50  // We assume the "rescaling" update will be as follows. Apologies if this is
51  // a bit confusing. The idea is that if the mean and var from (stats versus
52  // model) differ we assume that the model will be updated with
53  // DoRescalingUpdate(), which takes two sets of ML accs (old and new). The old ML
54  // accs given to the update will be the current ml accumulators we have here in
55  // this function, and the new ML accs will be affected by change in fMPE transform.
56  // The update in DoRescalingUpdate() will preserve any current difference between
57  // the ml stats and the model [represented as a shift in mean and factor in variance].
58  // Concretely: the update in DoRescalingUpdate() will do:
59  //
60  // new_model_mean := old_model_mean + new_stats_mean - old_stats_mean (eq. 1)
61  // new_model_var := max(min_variance, old_model_var * new_stats_var / old_stats_var). (eq. 2)
62  //
63  // We're differentiating back through this process to new_stats_mean.
64  // If the model and the stats were actually the same (e.g. we had been doing ML updates),
65  // then all this is equivalent to what was in the original fMPE paper. It's just
66  // extended to make sense outside of that scenario where you're doing ML.
67 
68  double diff_wrt_stats_mean = diff_wrt_model_mean; // This comes from eq. 1 above.
69  double diff_wrt_stats_var;
70  if (model_var <= min_variance*1.01) {
71  diff_wrt_stats_var = 0.0; // model would be "pinned" at minimum variance.
72  KALDI_VLOG(2) << "Variance derivative is zero (min variance)";
73  } else {
74  diff_wrt_stats_var = diff_wrt_model_var * model_var / stats_var; // note:
75  // the factor "model_var / stats_var" comes from "old_model_var / old_stats_var" in eq. 2.
76  // Also note: the {old_,new_} versions of variables are numerically the same here, at the
77  // point where we're differentiating.
78  }
79 
80  // The next equations don't appear in the paper but represent the backpropagation
81  // of the derivative through the equations:
82  // stats_mean := ml_x_stats / ml_count
83  // stats_var := ml_x2_stats / ml_count - (ml_x_stats/ml_count)^2
84  // [we use stats_mean = ml_x_stats/ml_count, here].
85  *ml_x_stats_deriv = diff_wrt_stats_mean / ml_count - 2 * diff_wrt_stats_var * stats_mean / ml_count;
86  *ml_x2_stats_deriv = diff_wrt_stats_var / ml_count;
87 }
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ GetSkipLayers()

std::vector<bool> kaldi::GetSkipLayers ( const std::string &  skip_layers_str,
const int32  first_layer_idx,
const int32  last_layer_idx 
)

Definition at line 58 of file nnet-am-average.cc.

References KALDI_ERR, and SplitStringToIntegers().

Referenced by main().

60  {
61 
62  std::vector<bool> skip_layers(last_layer_idx, false);
63 
64  if (skip_layers_str.empty()) {
65  return skip_layers;
66  }
67 
68  std::vector<int> layer_indices;
69  bool ret = SplitStringToIntegers(skip_layers_str, ":", true, &layer_indices);
70  if (!ret) {
71  KALDI_ERR << "Cannot parse the skip layers specifier. It should be"
72  << "colon-separated list of integers";
73  }
74 
75  int min_elem = std::numeric_limits<int>().max(),
76  max_elem = std::numeric_limits<int>().min();
77 
78  std::vector<int>::iterator it;
79  for ( it = layer_indices.begin(); it != layer_indices.end(); ++it ) {
80  if ( *it < 0 )
81  *it = last_layer_idx + *it; // convert the negative indices to
82  // correct indices -- -1 would be the
83  // last one, -2 the one before the last
84  // and so on.
85  if (*it > max_elem)
86  max_elem = *it;
87 
88  if (*it < min_elem)
89  min_elem = *it;
90  }
91 
92  if (max_elem >= last_layer_idx) {
93  KALDI_ERR << "--skip-layers option has to be a colon-separated list"
94  << "of indices which are supposed to be skipped.\n"
95  << "Maximum expected index: " << last_layer_idx
96  << " got: " << max_elem ;
97  }
98  if (min_elem < first_layer_idx) {
99  KALDI_ERR << "--skip-layers option has to be a colon-separated list"
100  << "of indices which are supposed to be skipped.\n"
101  << "Minimum expected index: " << first_layer_idx
102  << " got: " << min_elem ;
103  }
104 
105  for ( it = layer_indices.begin(); it != layer_indices.end(); ++it ) {
106  skip_layers[*it] = true;
107  }
108  return skip_layers;
109 }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ GetSplitTargets()

void GetSplitTargets ( const Vector< BaseFloat > &  state_occs,
int32  target_components,
BaseFloat  power,
BaseFloat  min_count,
std::vector< int32 > *  targets 
)

Get Gaussian-mixture or substate-mixture splitting targets, according to a power rule (e.g.

typically power = 0.2). Returns targets for number of mixture components (Gaussians, or sub-states), allocating the Gaussians or whatever according to a power of occupancy in order to acheive the total supplied "target". During splitting we ensure that each Gaussian [or sub-state] would get a count of at least "min-count", assuming counts were evenly distributed between Gaussians in a state. The vector "targets" will be resized to the appropriate dimension; its value at input is ignored.

Definition at line 116 of file model-common.cc.

References CountStats::CountStats(), VectorBase< Real >::Dim(), KALDI_WARN, CountStats::num_components, CountStats::occupancy, and CountStats::pdf_index.

Referenced by AmDiagGmm::MergeByCount(), LogisticRegression::MixUp(), SoftmaxComponent::MixUp(), AmDiagGmm::SplitByCount(), and AmSgmm2::SplitSubstates().

120  {
121  std::priority_queue<CountStats> split_queue;
122  int32 num_pdfs = state_occs.Dim();
123 
124  for (int32 pdf_index = 0; pdf_index < num_pdfs; pdf_index++) {
125  BaseFloat occ = pow(state_occs(pdf_index), power);
126  // initialize with one Gaussian per PDF, to put a floor
127  // of 1 on the #Gauss
128  split_queue.push(CountStats(pdf_index, 1, occ));
129  }
130 
131  for (int32 num_gauss = num_pdfs; num_gauss < target_components;) {
132  CountStats state_to_split = split_queue.top();
133  if (state_to_split.occupancy == 0) {
134  KALDI_WARN << "Could not split up to " << target_components
135  << " due to min-count = " << min_count
136  << " (or no counts at all)\n";
137  break;
138  }
139  split_queue.pop();
140  BaseFloat orig_occ = state_occs(state_to_split.pdf_index);
141  if ((state_to_split.num_components+1) * min_count >= orig_occ) {
142  state_to_split.occupancy = 0; // min-count active -> disallow splitting
143  // this state any more by setting occupancy = 0.
144  } else {
145  state_to_split.num_components++;
146  num_gauss++;
147  }
148  split_queue.push(state_to_split);
149  }
150  targets->resize(num_pdfs);
151  while (!split_queue.empty()) {
152  int32 pdf_index = split_queue.top().pdf_index;
153  int32 pdf_tgt_comp = split_queue.top().num_components;
154  (*targets)[pdf_index] = pdf_tgt_comp;
155  split_queue.pop();
156  }
157 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ GetStatsDerivative() [1/2]

void kaldi::GetStatsDerivative ( const DiagGmm gmm,
const AccumDiagGmm num_acc,
const AccumDiagGmm den_acc,
const AccumDiagGmm ml_acc,
BaseFloat  min_variance,
BaseFloat  min_gaussian_occupancy,
AccumDiagGmm out_accs 
)

Definition at line 94 of file indirect-diff-diag-gmm.cc.

References AccumDiagGmm::AddStatsForComponent(), rnnlm::d, DiagGmm::Dim(), AccumDiagGmm::Dim(), AccumDiagGmm::Flags(), GetSingleStatsDerivative(), KALDI_ASSERT, KALDI_WARN, kGmmAll, kGmmMeans, kGmmVariances, AccumDiagGmm::mean_accumulator(), DiagGmmNormal::means_, DiagGmm::NumGauss(), AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy(), AccumDiagGmm::Resize(), AccumDiagGmm::variance_accumulator(), and DiagGmmNormal::vars_.

Referenced by GetStatsDerivative(), and main().

100  {
101  out_accs->Resize(gmm, kGmmAll);
102  int32 num_gauss = gmm.NumGauss(), dim = gmm.Dim();
103  KALDI_ASSERT(num_gauss == num_acc.NumGauss() && dim == num_acc.Dim());
104  KALDI_ASSERT(num_gauss == den_acc.NumGauss()); // don't check den dim--
105  // in the "compressed" form of stats (where num acc stores diff),
106  // it could be zero.
107  KALDI_ASSERT(num_gauss == ml_acc.NumGauss() && dim == ml_acc.Dim());
108 
109  KALDI_ASSERT((ml_acc.Flags() & (kGmmMeans|kGmmVariances)) ==
111  KALDI_ASSERT((num_acc.Flags() & (kGmmMeans|kGmmVariances)) ==
113  DiagGmmNormal gmm_normal(gmm);
114 
115  // if have_den_stats == false, we assume the num and den have been
116  // "compressed" by putting the difference in mean and var stats in num.
117  bool have_den_stats = ((den_acc.Flags() & (kGmmMeans|kGmmVariances)) != 0);
118 
119  for (int32 gauss = 0; gauss < num_gauss; gauss++) {
120  Vector<double> x_stats_deriv(dim), x2_stats_deriv(dim);
121  double num_count = num_acc.occupancy()(gauss),
122  den_count = den_acc.occupancy()(gauss),
123  ml_count = ml_acc.occupancy()(gauss);
124 
125  if (ml_count <= min_gaussian_occupancy) {
126  // This Gaussian won't be updated since has small count
127  KALDI_WARN << "Skipping Gaussian because very small ML count: (num,den,ml) = "
128  << num_count << ", " << den_count << ", " << ml_count;
129  } else {
130  double disc_count = num_count - den_count;
131  for (int32 d = 0; d < dim; d++) {
132  double disc_x_acc = num_acc.mean_accumulator()(gauss, d)
133  - (have_den_stats ? den_acc.mean_accumulator()(gauss, d) : 0.0),
134  disc_x2_acc = num_acc.variance_accumulator()(gauss, d)
135  - (have_den_stats ? den_acc.variance_accumulator()(gauss, d) : 0.0),
136  ml_x_acc = ml_acc.mean_accumulator()(gauss, d),
137  ml_x2_acc = ml_acc.variance_accumulator()(gauss, d),
138  model_mean = gmm_normal.means_(gauss, d),
139  model_var = gmm_normal.vars_(gauss, d);
140 
141  double x_acc_deriv = 0.0, x2_acc_deriv = 0.0;
142  GetSingleStatsDerivative(ml_count, ml_x_acc, ml_x2_acc,
143  disc_count, disc_x_acc, disc_x2_acc,
144  model_mean, model_var, min_variance,
145  &x_acc_deriv, &x2_acc_deriv);
146 
147  x_stats_deriv(d) = x_acc_deriv;
148  x2_stats_deriv(d) = x2_acc_deriv;
149  }
150  // set the stats to these quantities (we're adding, but the stats
151  // are currently zero).
152  out_accs->AddStatsForComponent(gauss, 0.0, x_stats_deriv, x2_stats_deriv);
153  }
154  }
155 }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void GetSingleStatsDerivative(double ml_count, double ml_x_stats, double ml_x2_stats, double disc_count, double disc_x_stats, double disc_x2_stats, double model_mean, double model_var, BaseFloat min_variance, double *ml_x_stats_deriv, double *ml_x2_stats_deriv)

◆ GetStatsDerivative() [2/2]

void GetStatsDerivative ( const AmDiagGmm gmm,
const AccumAmDiagGmm num_accs,
const AccumAmDiagGmm den_accs,
const AccumAmDiagGmm ml_accs,
BaseFloat  min_variance,
BaseFloat  min_gaussian_occupancy,
AccumAmDiagGmm out_accs 
)

Definition at line 157 of file indirect-diff-diag-gmm.cc.

References AccumAmDiagGmm::GetAcc(), AmDiagGmm::GetPdf(), GetStatsDerivative(), AccumAmDiagGmm::Init(), KALDI_ASSERT, kGmmAll, AccumAmDiagGmm::NumAccs(), and AmDiagGmm::NumPdfs().

163  {
164  out_accs->Init(gmm, kGmmAll);
165  int32 num_pdfs = gmm.NumPdfs();
166  KALDI_ASSERT(num_accs.NumAccs() == num_pdfs);
167  KALDI_ASSERT(den_accs.NumAccs() == num_pdfs);
168  KALDI_ASSERT(ml_accs.NumAccs() == num_pdfs);
169  for (int32 pdf = 0; pdf < num_pdfs; pdf++)
170  GetStatsDerivative(gmm.GetPdf(pdf), num_accs.GetAcc(pdf), den_accs.GetAcc(pdf),
171  ml_accs.GetAcc(pdf), min_variance, min_gaussian_occupancy,
172  &(out_accs->GetAcc(pdf)));
173 
174 }
void GetStatsDerivative(const AmDiagGmm &gmm, const AccumAmDiagGmm &num_accs, const AccumAmDiagGmm &den_accs, const AccumAmDiagGmm &ml_accs, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AccumAmDiagGmm *out_accs)
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetTimeString()

std::string kaldi::GetTimeString ( int32  t_beg,
int32  t_end,
BaseFloat  time_unit 
)

Definition at line 88 of file online2-tcp-nnet3-decode-faster.cc.

Referenced by main().

88  {
89  char buffer[100];
90  double t_beg2 = t_beg * time_unit;
91  double t_end2 = t_end * time_unit;
92  snprintf(buffer, 100, "%.2f %.2f", t_beg2, t_end2);
93  return std::string(buffer);
94 }

◆ GetToLengthMap()

EventMap* kaldi::GetToLengthMap ( const BuildTreeStatsType stats,
int32  P,
const std::vector< EventValueType > *  phones,
int32  default_length 
)

Definition at line 760 of file build-tree-utils.cc.

References rnnlm::i, KALDI_ERR, kPdfClass, and SplitStatsByKey().

762  {
763  std::vector<BuildTreeStatsType> stats_by_phone;
764  try {
765  SplitStatsByKey(stats, P, &stats_by_phone);
766  } catch(const KaldiFatalError &) {
767  KALDI_ERR <<
768  "You seem to have provided invalid stats [no central-phone key].";
769  }
770  std::map<EventValueType, EventAnswerType> phone_to_length;
771  for (size_t p = 0; p < stats_by_phone.size(); p++) {
772  if (! stats_by_phone[p].empty()) {
773  std::vector<BuildTreeStatsType> stats_by_length;
774  try {
775  SplitStatsByKey(stats_by_phone[p], kPdfClass, &stats_by_length);
776  } catch(const KaldiFatalError &) {
777  KALDI_ERR <<
778  "You seem to have provided invalid stats [no position key].";
779  }
780  size_t length = stats_by_length.size();
781  for (size_t i = 0; i < length; i++) {
782  if (stats_by_length[i].empty()) {
783  KALDI_ERR << "There are no stats available for position " << i
784  << " of phone " << p;
785  }
786  }
787  phone_to_length[p] = length;
788  }
789  }
790  if (phones != NULL) { // set default length for unseen phones.
791  for (size_t i = 0; i < phones->size(); i++) {
792  if (phone_to_length.count( (*phones)[i] ) == 0) { // unseen.
793  phone_to_length[(*phones)[i]] = default_length;
794  }
795  }
796  }
797  EventMap *ans = new TableEventMap(P, phone_to_length);
798  return ans;
799 }
void SplitStatsByKey(const BuildTreeStatsType &stats_in, EventKeyType key, std::vector< BuildTreeStatsType > *stats_out)
SplitStatsByKey splits stats up according to the value of a particular key, which must be always defi...
static const EventKeyType kPdfClass
Definition: context-dep.h:39
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ GetTotalPosterior()

static BaseFloat kaldi::GetTotalPosterior ( const std::vector< std::pair< int32, BaseFloat > > &  post_entry)
inlinestatic

Definition at line 429 of file posterior.cc.

Referenced by VectorToPosteriorEntry().

430  {
431  BaseFloat tot = 0.0;
432  std::vector<std::pair<int32, BaseFloat> >::const_iterator
433  iter = post_entry.begin(), end = post_entry.end();
434  for (; iter != end; ++iter) {
435  tot += iter->second;
436  }
437  return tot;
438 }
float BaseFloat
Definition: kaldi-types.h:29

◆ GetTreeStructure()

bool GetTreeStructure ( const EventMap map,
int32 num_leaves,
std::vector< int32 > *  parents 
)

This function gets the tree structure of the EventMap "map" in a convenient form.

If "map" corresponds to a tree structure (not necessarily binary) with leaves uniquely numbered from 0 to num_leaves-1, then the function will return true, output "num_leaves", and set "parent" to a vector of size equal to the number of nodes in the tree (nonleaf and leaf), where each index corresponds to a node and the leaf indices correspond to the values returned by the EventMap from that leaf; for an index i, parent[i] equals the parent of that node in the tree structure, where parent[i] > i, except for the last (root) node where parent[i] == i. If the EventMap does not have this structure (e.g. if multiple different leaf nodes share the same number), then it will return false.

Definition at line 429 of file event-map.cc.

References GetTreeStructureInternal(), rnnlm::i, IsLeafNode(), KALDI_ASSERT, and EventMap::Map().

Referenced by TestEventMap().

431  {
432  KALDI_ASSERT (num_leaves != NULL && parents != NULL);
433 
434  if (IsLeafNode(&map)) { // handle degenerate case where root is a leaf.
435  int32 leaf;
436  if (!map.Map(EventType(), &leaf)
437  || leaf != 0) return false;
438  *num_leaves = 1;
439  parents->resize(1);
440  (*parents)[0] = 0;
441  return true;
442  }
443 
444 
445  // This vector gives the address of nonleaf nodes in the tree,
446  // in a numbering where 0 is the root and children always come
447  // after parents.
448  std::vector<const EventMap*> nonleaf_nodes;
449 
450  // Map from each nonleaf node to its parent node
451  // (or to itself for the root node).
452  std::map<const EventMap*, const EventMap*> nonleaf_parents;
453 
454  // Map from leaf nodes to their parent nodes.
455  std::vector<const EventMap*> leaf_parents;
456 
457  if (!GetTreeStructureInternal(map, &nonleaf_nodes,
458  &nonleaf_parents,
459  &leaf_parents)) return false;
460 
461  *num_leaves = leaf_parents.size();
462  int32 num_nodes = leaf_parents.size() + nonleaf_nodes.size();
463 
464  std::map<const EventMap*, int32> nonleaf_indices;
465 
466  // number the nonleaf indices so they come after the leaf
467  // indices and the root is last.
468  for (size_t i = 0; i < nonleaf_nodes.size(); i++)
469  nonleaf_indices[nonleaf_nodes[i]] = num_nodes - i - 1;
470 
471  parents->resize(num_nodes);
472  for (size_t i = 0; i < leaf_parents.size(); i++) {
473  KALDI_ASSERT(nonleaf_indices.count(leaf_parents[i]) != 0);
474  (*parents)[i] = nonleaf_indices[leaf_parents[i]];
475  }
476  for (size_t i = 0; i < nonleaf_nodes.size(); i++) {
477  KALDI_ASSERT(nonleaf_indices.count(nonleaf_nodes[i]) != 0);
478  KALDI_ASSERT(nonleaf_parents.count(nonleaf_nodes[i]) != 0);
479  KALDI_ASSERT(nonleaf_indices.count(nonleaf_parents[nonleaf_nodes[i]]) != 0);
480  int32 index = nonleaf_indices[nonleaf_nodes[i]],
481  parent_index = nonleaf_indices[nonleaf_parents[nonleaf_nodes[i]]];
482  KALDI_ASSERT(index > 0 && parent_index >= index);
483  (*parents)[index] = parent_index;
484  }
485  for (int32 i = 0; i < num_nodes; i++)
486  KALDI_ASSERT ((*parents)[i] > i || (i+1==num_nodes && (*parents)[i] == i));
487  return true;
488 }
kaldi::int32 int32
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
static bool GetTreeStructureInternal(const EventMap &map, std::vector< const EventMap *> *nonleaf_nodes, std::map< const EventMap *, const EventMap *> *nonleaf_parents, std::vector< const EventMap *> *leaf_parents)
Definition: event-map.cc:375
static bool IsLeafNode(const EventMap *e)
Definition: event-map.cc:354
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetTreeStructureInternal()

static bool kaldi::GetTreeStructureInternal ( const EventMap map,
std::vector< const EventMap *> *  nonleaf_nodes,
std::map< const EventMap *, const EventMap *> *  nonleaf_parents,
std::vector< const EventMap *> *  leaf_parents 
)
static

Definition at line 375 of file event-map.cc.

References EventMap::GetChildren(), rnnlm::i, IsLeafNode(), KALDI_ASSERT, KALDI_WARN, and EventMap::Map().

Referenced by GetTreeStructure().

379  {
380 
381  std::vector<const EventMap*> queue; // parents to be processed.
382 
383  const EventMap *top_node = &map;
384 
385  queue.push_back(top_node);
386  nonleaf_nodes->push_back(top_node);
387  (*nonleaf_parents)[top_node] = top_node;
388 
389  while (!queue.empty()) {
390  const EventMap *parent = queue.back();
391  queue.pop_back();
392  std::vector<EventMap*> children;
393  parent->GetChildren(&children);
394  KALDI_ASSERT(!children.empty());
395  for (size_t i = 0; i < children.size(); i++) {
396  EventMap *child = children[i];
397  if (IsLeafNode(child)) {
398  int32 leaf;
399  if (!child->Map(EventType(), &leaf)
400  || leaf < 0) return false;
401  if (static_cast<int32>(leaf_parents->size()) <= leaf)
402  leaf_parents->resize(leaf+1, NULL);
403  if ((*leaf_parents)[leaf] != NULL) {
404  KALDI_WARN << "Repeated leaf! Did you suppress leaf clustering when building the tree?";
405  return false; // repeated leaf.
406  }
407  (*leaf_parents)[leaf] = parent;
408  } else {
409  nonleaf_nodes->push_back(child);
410  (*nonleaf_parents)[child] = parent;
411  queue.push_back(child);
412  }
413  }
414  }
415 
416  for (size_t i = 0; i < leaf_parents->size(); i++)
417  if ((*leaf_parents)[i] == NULL) {
418  KALDI_WARN << "non-consecutively numbered leaves";
419  return false;
420  }
421  // non-consecutively numbered leaves.
422 
423  KALDI_ASSERT(!leaf_parents->empty()); // or no leaves.
424 
425  return true;
426 }
kaldi::int32 int32
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
#define KALDI_WARN
Definition: kaldi-error.h:150
static bool IsLeafNode(const EventMap *e)
Definition: event-map.cc:354
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetUtterancePairs()

void kaldi::GetUtterancePairs ( const std::string &  reco2file_and_channel_rxfilename,
std::vector< std::vector< std::string > > *  utt_pairs 
)

Definition at line 34 of file compute-cmvn-stats-two-channel.cc.

References rnnlm::i, KALDI_ERR, KALDI_WARN, PrintableRxfilename(), SplitStringToVector(), and Input::Stream().

Referenced by main().

35  {
36  Input ki(reco2file_and_channel_rxfilename);
37  std::string line;
38  std::map<std::string, std::vector<std::string> > call_to_uttlist;
39  while (std::getline(ki.Stream(), line)) {
40  std::vector<std::string> split_line;
41  SplitStringToVector(line, " \t\r", true, &split_line);
42  if (split_line.size() != 3) {
43  KALDI_ERR << "Expecting 3 fields per line of reco2file_and_channel file "
44  << PrintableRxfilename(reco2file_and_channel_rxfilename)
45  << ", got: " << line;
46  }
47  // lines like: sw02001-A sw02001 A
48  std::string utt = split_line[0],
49  call = split_line[1];
50  call_to_uttlist[call].push_back(utt);
51  }
52  for (std::map<std::string, std::vector<std::string> >::const_iterator
53  iter = call_to_uttlist.begin(); iter != call_to_uttlist.end(); ++iter) {
54  const std::vector<std::string> &uttlist = iter->second;
55  if (uttlist.size() == 2) {
56  utt_pairs->push_back(uttlist);
57  } else {
58  KALDI_WARN << "Call " << iter->first << " has " << uttlist.size()
59  << " utterances, expected two; treating them singly.";
60  for (size_t i = 0; i < uttlist.size(); i++) {
61  std::vector<std::string> singleton_list;
62  singleton_list.push_back(uttlist[i]);
63  utt_pairs->push_back(singleton_list);
64  }
65  }
66  }
67 }
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
Definition: text-utils.cc:63
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61

◆ GetWeights()

void GetWeights ( const std::string &  weights_str,
int32  num_inputs,
std::vector< BaseFloat > *  weights 
)

Definition at line 30 of file nnet-am-average.cc.

References rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, and SplitStringToFloats().

Referenced by main().

32  {
33  KALDI_ASSERT(num_inputs >= 1);
34  if (!weights_str.empty()) {
35  SplitStringToFloats(weights_str, ":", true, weights);
36  if (weights->size() != num_inputs) {
37  KALDI_ERR << "--weights option must be a colon-separated list "
38  << "with " << num_inputs << " elements, got: "
39  << weights_str;
40  }
41  } else {
42  for (int32 i = 0; i < num_inputs; i++)
43  weights->push_back(1.0 / num_inputs);
44  }
45  // normalize the weights to sum to one.
46  float weight_sum = 0.0;
47  for (int32 i = 0; i < num_inputs; i++)
48  weight_sum += (*weights)[i];
49  for (int32 i = 0; i < num_inputs; i++)
50  (*weights)[i] = (*weights)[i] / weight_sum;
51  if (fabs(weight_sum - 1.0) > 0.01) {
52  KALDI_WARN << "Normalizing weights to sum to one, sum was " << weight_sum;
53  }
54 }
bool SplitStringToFloats(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< F > *out)
Definition: text-utils.cc:30
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Givens()

void kaldi::Givens ( Real  a,
Real  b,
Real *  c,
Real *  s 
)
inline

Create Givens rotations, as in Golub and Van Loan 3rd ed., page 216.

Definition at line 221 of file qr.cc.

Referenced by QrStep().

221  {
222  if (b == 0) {
223  *c = 1;
224  *s = 0;
225  } else {
226  if (std::abs(b) > std::abs(a)) {
227  Real tau = -a / b;
228  *s = 1 / std::sqrt(1 + tau*tau);
229  *c = *s * tau;
230  } else {
231  Real tau = -b / a;
232  *c = 1 / std::sqrt(1 + tau*tau);
233  *s = *c * tau;
234  }
235  }
236 }

◆ GmmFlagsToString()

std::string GmmFlagsToString ( GmmFlagsType  flags)

Convert GMM flags to string.

Definition at line 43 of file model-common.cc.

References kGmmMeans, kGmmTransitions, kGmmVariances, and kGmmWeights.

Referenced by AccumFullGmm::Read(), AccumDiagGmm::Read(), UnitTestEstimateMmieDiagGmm(), and UpdateEbwDiagGmm().

43  {
44  std::string ans;
45  if (flags & kGmmMeans) ans += "m";
46  if (flags & kGmmVariances) ans += "v";
47  if (flags & kGmmWeights) ans += "w";
48  if (flags & kGmmTransitions) ans += "t";
49  return ans;
50 }

◆ HandleOutput()

void kaldi::HandleOutput ( bool  determinize,
const fst::SymbolTable *  word_syms,
nnet3::NnetBatchDecoder decoder,
CompactLatticeWriter clat_writer,
LatticeWriter lat_writer 
)

Definition at line 35 of file nnet3-latgen-faster-batch.cc.

References NnetBatchDecoder::GetOutput(), and TableWriter< Holder >::Write().

Referenced by main().

39  {
40  // Write out any lattices that are ready.
41  std::string output_utterance_id, sentence;
42  if (determinize) {
43  CompactLattice clat;
44  while (decoder->GetOutput(&output_utterance_id, &clat, &sentence)) {
45  if (word_syms != NULL)
46  std::cerr << output_utterance_id << ' ' << sentence << '\n';
47  clat_writer->Write(output_utterance_id, clat);
48  }
49  } else {
50  Lattice lat;
51  while (decoder->GetOutput(&output_utterance_id, &lat, &sentence)) {
52  if (word_syms != NULL)
53  std::cerr << output_utterance_id << ' ' << sentence << '\n';
54  lat_writer->Write(output_utterance_id, lat);
55  }
56  }
57 }
void Write(const std::string &key, const T &value) const
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
bool GetOutput(std::string *utterance_id, CompactLattice *clat, std::string *sentence)
The user should call this to obtain output (This version should only be called if config...

◆ HouseBackward()

void kaldi::HouseBackward ( MatrixIndexT  dim,
const Real *  x,
Real *  v,
Real *  beta 
)

Definition at line 102 of file qr.cc.

References cblas_Xscal(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_ISFINITE, KALDI_ISINF, and KALDI_ISNAN.

Referenced by SpMatrix< float >::Tridiagonalize().

102  {
103  KALDI_ASSERT(dim > 0);
104  // To avoid overflow, we first compute the max of x_ (or
105  // one if that's zero, and we'll replace "x" by x/max(x_i)
106  // below. The householder vector is anyway invariant to
107  // the magnitude of x. We could actually avoid this extra loop
108  // over x if we wanted to be a bit smarter, but anyway this
109  // doesn't dominate the O(N) performance of the algorithm.
110  Real s; // s is a scale on x.
111  {
112  Real max_x = std::numeric_limits<Real>::min();
113  for (MatrixIndexT i = 0; i < dim; i++)
114  max_x = std::max(max_x, (x[i] < 0 ? -x[i] : x[i]));
115  s = 1.0 / max_x;
116  }
117  Real sigma = 0.0;
118  v[dim-1] = 1.0;
119  for (MatrixIndexT i = 0; i + 1 < dim; i++) {
120  sigma += (x[i] * s) * (x[i] * s);
121  v[i] = x[i] * s;
122  }
123  KALDI_ASSERT(KALDI_ISFINITE(sigma) &&
124  "Tridiagonalizing matrix that is too large or has NaNs.");
125  if (sigma == 0.0) *beta = 0.0;
126  else {
127  Real x1 = x[dim-1] * s, mu = std::sqrt(x1 * x1 + sigma);
128  if (x1 <= 0) {
129  v[dim-1] = x1 - mu;
130  } else {
131  v[dim-1] = -sigma / (x1 + mu);
132  KALDI_ASSERT(KALDI_ISFINITE(v[dim-1]));
133  }
134  Real v1 = v[dim-1];
135  Real v1sq = v1 * v1;
136  *beta = 2 * v1sq / (sigma + v1sq);
137  Real inv_v1 = 1.0 / v1;
138  if (KALDI_ISINF(inv_v1)) {
139  // can happen if v1 is denormal.
140  KALDI_ASSERT(v1 == v1 && v1 != 0.0);
141  for (MatrixIndexT i = 0; i < dim; i++) v[i] /= v1;
142  } else {
143  cblas_Xscal(dim, inv_v1, v, 1);
144  }
145  if (KALDI_ISNAN(inv_v1)) {
146  KALDI_ERR << "NaN encountered in HouseBackward";
147  }
148  }
149 }
#define KALDI_ISINF
Definition: kaldi-math.h:73
#define KALDI_ISFINITE(x)
Definition: kaldi-math.h:74
int32 MatrixIndexT
Definition: matrix-common.h:98
void cblas_Xscal(const int N, const float alpha, float *data, const int inc)
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ISNAN
Definition: kaldi-math.h:72
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Hypot() [1/2]

double kaldi::Hypot ( double  x,
double  y 
)
inline

Definition at line 354 of file kaldi-math.h.

Referenced by EigenvalueDecomposition< Real >::Tql2().

354 { return hypot(x, y); }

◆ Hypot() [2/2]

float kaldi::Hypot ( float  x,
float  y 
)
inline

Definition at line 355 of file kaldi-math.h.

355 { return hypotf(x, y); }

◆ IncreaseTransformDimension()

void IncreaseTransformDimension ( int32  new_dimension,
Matrix< BaseFloat > *  mat 
)

Definition at line 26 of file extend-transform-dim.cc.

References VectorBase< Real >::CopyColFromMat(), rnnlm::d, rnnlm::i, KALDI_ERR, kCopyData, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by main().

27  {
28  int32 d = mat->NumRows();
29  if (new_dimension < d)
30  KALDI_ERR << "--new-dimension argument invalid or not specified: "
31  << new_dimension << " < " << d;
32  if (mat->NumCols() == d) { // linear transform d->d
33  mat->Resize(new_dimension, new_dimension, kCopyData);
34  for (int32 i = d; i < new_dimension; i++)
35  (*mat)(i, i) = 1.0; // set new dims to unit matrix.
36  } else if (mat->NumCols() == d+1) { // affine transform d->d.
37  Vector<BaseFloat> offset(mat->NumRows());
38  offset.CopyColFromMat(*mat, d);
39  mat->Resize(d, d, kCopyData); // remove offset from mat->
40  mat->Resize(new_dimension, new_dimension+1, kCopyData); // extend with zeros.
41  for (int32 i = d; i < new_dimension; i++)
42  (*mat)(i, i) = 1.0; // set new dims to unit matrix.
43  for (int32 i = 0; i < d; i++) // and set offset [last column]
44  (*mat)(i, new_dimension) = offset(i);
45  } else {
46  KALDI_ERR << "Input matrix has unexpected dimension " << d
47  << " x " << mat->NumCols();
48  }
49 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
Definition: kaldi-vector.h:406
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ InitAmGmm()

void kaldi::InitAmGmm ( const BuildTreeStatsType stats,
const EventMap to_pdf_map,
AmDiagGmm am_gmm,
const TransitionModel trans_model,
BaseFloat  var_floor 
)

InitAmGmm initializes the GMM with one Gaussian per state.

Definition at line 35 of file gmm-init-model.cc.

References AmDiagGmm::AddPdf(), count, GaussClusterable::count(), DeletePointers(), GetPhonesForPdfs(), rnnlm::i, KALDI_ASSERT, KALDI_WARN, EventMap::MaxResult(), SplitStatsByMap(), SumClusterable(), and SumStatsVec().

Referenced by main().

39  {
40  // Get stats split by tree-leaf ( == pdf):
41  std::vector<BuildTreeStatsType> split_stats;
42  SplitStatsByMap(stats, to_pdf_map, &split_stats);
43 
44  split_stats.resize(to_pdf_map.MaxResult() + 1); // ensure that
45  // if the last leaf had no stats, this vector still has the right size.
46 
47  // Make sure each leaf has stats.
48  for (size_t i = 0; i < split_stats.size(); i++) {
49  if (split_stats[i].empty()) {
50  std::vector<int32> bad_pdfs(1, i), bad_phones;
51  GetPhonesForPdfs(trans_model, bad_pdfs, &bad_phones);
52  std::ostringstream ss;
53  for (int32 idx = 0; idx < bad_phones.size(); idx ++)
54  ss << bad_phones[idx] << ' ';
55  KALDI_WARN << "Tree has pdf-id " << i
56  << " with no stats; corresponding phone list: " << ss.str();
57  /*
58  This probably means you have phones that were unseen in training
59  and were not shared with other phones in the roots file.
60  You should modify your roots file as necessary to fix this.
61  (i.e. share that phone with a similar but seen phone on one line
62  of the roots file). Be sure to regenerate roots.int from roots.txt,
63  if using s5 scripts. To work out the phone, search for
64  pdf-id i in the output of show-transitions (for this model). */
65  }
66  }
67  std::vector<Clusterable*> summed_stats;
68  SumStatsVec(split_stats, &summed_stats);
69  Clusterable *avg_stats = SumClusterable(summed_stats);
70  KALDI_ASSERT(avg_stats != NULL && "No stats available in gmm-init-model.");
71  for (size_t i = 0; i < summed_stats.size(); i++) {
72  GaussClusterable *c =
73  static_cast<GaussClusterable*>(summed_stats[i] != NULL ? summed_stats[i] : avg_stats);
74  DiagGmm gmm(*c, var_floor);
75  am_gmm->AddPdf(gmm);
76  BaseFloat count = c->count();
77  if (count < 100) {
78  std::vector<int32> bad_pdfs(1, i), bad_phones;
79  GetPhonesForPdfs(trans_model, bad_pdfs, &bad_phones);
80  std::ostringstream ss;
81  for (int32 idx = 0; idx < bad_phones.size(); idx ++)
82  ss << bad_phones[idx] << ' ';
83  KALDI_WARN << "Very small count for state " << i << ": "
84  << count << "; corresponding phone list: " << ss.str();
85  }
86  }
87  DeletePointers(&summed_stats);
88  delete avg_stats;
89 }
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
Definition: am-diag-gmm.cc:57
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:184
virtual EventAnswerType MaxResult() const
Definition: event-map.h:142
void SplitStatsByMap(const BuildTreeStatsType &stats, const EventMap &e, std::vector< BuildTreeStatsType > *stats_out)
Splits stats according to the EventMap, indexing them at output by the leaf type. ...
kaldi::int32 int32
const size_t count
bool GetPhonesForPdfs(const TransitionModel &trans_model, const std::vector< int32 > &pdfs, std::vector< int32 > *phones)
Works out which phones might correspond to the given pdfs.
float BaseFloat
Definition: kaldi-types.h:29
void SumStatsVec(const std::vector< BuildTreeStatsType > &stats_in, std::vector< Clusterable *> *stats_out)
Sum a vector of stats.
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
Clusterable * SumClusterable(const std::vector< Clusterable *> &vec)
Sums stats (ptrs may be NULL). Returns NULL if no non-NULL stats present.

◆ InitAmGmmFromOld()

void kaldi::InitAmGmmFromOld ( const BuildTreeStatsType stats,
const EventMap to_pdf_map,
int32  N,
int32  P,
const std::string &  old_tree_rxfilename,
const std::string &  old_model_rxfilename,
BaseFloat  var_floor,
AmDiagGmm am_gmm 
)

InitAmGmmFromOld initializes the GMM based on a previously trained model and tree, which must require no more phonetic context than the current tree.

It does this by finding the closest PDF in the old model, to any given PDF in the new model. Here, "closest" is defined as: has the largest count in common from the tree stats.

Definition at line 116 of file gmm-init-model.cc.

References AmDiagGmm::AddPdf(), ContextDependency::CentralPosition(), ContextDependency::ContextWidth(), ConvertStats(), AmDiagGmm::GetPdf(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, EventMap::Map(), EventMap::MaxResult(), AmDiagGmm::NumPdfs(), AmDiagGmm::Read(), ContextDependency::Read(), TransitionModel::Read(), SplitStatsByMap(), Input::Stream(), SumStats(), and ContextDependency::ToPdfMap().

Referenced by main().

123  {
124 
125  AmDiagGmm old_am_gmm;
126  ContextDependency old_tree;
127  { // Read old_gm_gmm
128  bool binary_in;
129  TransitionModel old_trans_model;
130  Input ki(old_model_rxfilename, &binary_in);
131  old_trans_model.Read(ki.Stream(), binary_in);
132  old_am_gmm.Read(ki.Stream(), binary_in);
133  }
134  { // Read tree.
135  bool binary_in;
136  Input ki(old_tree_rxfilename, &binary_in);
137  old_tree.Read(ki.Stream(), binary_in);
138  }
139 
140 
141  // Get stats split by (new) tree-leaf ( == pdf):
142  std::vector<BuildTreeStatsType> split_stats;
143  SplitStatsByMap(stats, to_pdf_map, &split_stats);
144  // Make sure each leaf has stats.
145  for (size_t i = 0; i < split_stats.size(); i++) {
146  if (split_stats[i].empty()) {
147  KALDI_WARN << "Leaf " << i << " of new tree has no stats.";
148  }
149  }
150  if (static_cast<int32>(split_stats.size()) != to_pdf_map.MaxResult() + 1) {
151  KALDI_ASSERT(static_cast<int32>(split_stats.size()) <
152  to_pdf_map.MaxResult() + 1);
153  KALDI_WARN << "Tree may have final leaf with no stats.";
154  split_stats.resize(to_pdf_map.MaxResult() + 1);
155  // avoid indexing errors later.
156  }
157 
158  int32 oldN = old_tree.ContextWidth(), oldP = old_tree.CentralPosition();
159 
160  // avg_stats will be used for leaves that have no stats.
161  Clusterable *avg_stats = SumStats(stats);
162  GaussClusterable *avg_stats_gc = dynamic_cast<GaussClusterable*>(avg_stats);
163  KALDI_ASSERT(avg_stats_gc != NULL && "Empty stats input.");
164  DiagGmm avg_gmm(*avg_stats_gc, var_floor);
165  delete avg_stats;
166  avg_stats = NULL;
167  avg_stats_gc = NULL;
168 
169  const EventMap &old_map = old_tree.ToPdfMap();
170 
171  KALDI_ASSERT(am_gmm->NumPdfs() == 0);
172  int32 num_pdfs = static_cast<int32>(split_stats.size());
173  for (int32 pdf = 0; pdf < num_pdfs; pdf++) {
174  BuildTreeStatsType &my_stats = split_stats[pdf];
175  // The next statement converts the stats to a possibly narrower older
176  // context-width (e.g. triphone -> monophone).
177  // note: don't get confused by the "old" and "new" in the parameters
178  // to ConvertStats. The next line is correct.
179  bool ret = ConvertStats(N, P, oldN, oldP, &my_stats);
180  if (!ret)
181  KALDI_ERR << "InitAmGmmFromOld: old system has wider context "
182  "so cannot convert stats.";
183  // oldpdf_to_count works out a map from old pdf-id to count (for stats
184  // that align to this "new" pdf... we'll use it to work out the old pdf-id
185  // that's "closest" in stats overlap to this new pdf ("pdf").
186  std::map<int32, BaseFloat> oldpdf_to_count;
187  for (size_t i = 0; i < my_stats.size(); i++) {
188  EventType evec = my_stats[i].first;
189  EventAnswerType ans;
190  bool ret = old_map.Map(evec, &ans);
191  if (!ret) { KALDI_ERR << "Could not map context using old tree."; }
192  KALDI_ASSERT(my_stats[i].second != NULL);
193  BaseFloat stats_count = my_stats[i].second->Normalizer();
194  if (oldpdf_to_count.count(ans) == 0) oldpdf_to_count[ans] = stats_count;
195  else oldpdf_to_count[ans] += stats_count;
196  }
197  BaseFloat max_count = 0; int32 max_old_pdf = -1;
198  for (std::map<int32, BaseFloat>::const_iterator iter = oldpdf_to_count.begin();
199  iter != oldpdf_to_count.end();
200  ++iter) {
201  if (iter->second > max_count) {
202  max_count = iter->second;
203  max_old_pdf = iter->first;
204  }
205  }
206  if (max_count == 0) { // no overlap - probably a leaf with no stats at all.
207  KALDI_WARN << "Leaf " << pdf << " of new tree being initialized with "
208  << "globally averaged stats.";
209  am_gmm->AddPdf(avg_gmm);
210  } else {
211  am_gmm->AddPdf(old_am_gmm.GetPdf(max_old_pdf)); // Here is where we copy the relevant old PDF.
212  }
213  }
214 }
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
Definition: am-diag-gmm.cc:57
virtual int32 ContextWidth() const
ContextWidth() returns the value N (e.g.
Definition: context-dep.h:61
const EventMap & ToPdfMap() const
Definition: context-dep.h:98
bool ConvertStats(int32 oldN, int32 oldP, int32 newN, int32 newP, BuildTreeStatsType *stats)
Converts stats from a given context-window (N) and central-position (P) to a different N and P...
Clusterable * SumStats(const BuildTreeStatsType &stats_in)
Sums stats, or returns NULL stats_in has no non-NULL stats.
virtual EventAnswerType MaxResult() const
Definition: event-map.h:142
void SplitStatsByMap(const BuildTreeStatsType &stats, const EventMap &e, std::vector< BuildTreeStatsType > *stats_out)
Splits stats according to the EventMap, indexing them at output by the leaf type. ...
kaldi::int32 int32
virtual bool Map(const EventType &event, EventAnswerType *ans) const =0
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
float BaseFloat
Definition: kaldi-types.h:29
void Read(std::istream &is, bool binary)
virtual int32 CentralPosition() const
Central position P of the phone context, in 0-based numbering, e.g.
Definition: context-dep.h:62
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumPdfs() const
Definition: am-diag-gmm.h:82
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
A class that is capable of representing a generic mapping from EventType (which is a vector of (key...
Definition: event-map.h:86
void Read(std::istream &is, bool binary)
Read context-dependency object from disk; throws on error.
Definition: context-dep.cc:155
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
int32 EventAnswerType
As far as the event-map code itself is concerned, things of type EventAnswerType may take any value e...
Definition: event-map.h:56
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147

◆ InitCmvnStats()

void InitCmvnStats ( int32  dim,
Matrix< double > *  stats 
)

This function initializes the matrix to dimension 2 by (dim+1); 1st "dim" elements of 1st row are mean stats, 1st "dim" elements of 2nd row are var stats, last element of 1st row is count, last element of 2nd row is zero.

Definition at line 25 of file cmvn.cc.

References KALDI_ASSERT, and Matrix< Real >::Resize().

Referenced by main().

25  {
26  KALDI_ASSERT(dim > 0);
27  stats->Resize(2, dim+1);
28 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ InitFmllr()

void kaldi::InitFmllr ( int32  dim,
Matrix< BaseFloat > *  out_fmllr 
)
inline

Definition at line 161 of file fmllr-diag-gmm.h.

References ComputeFmllrDiagGmm(), Matrix< Real >::Resize(), and MatrixBase< Real >::SetUnit().

162  {
163  out_fmllr->Resize(dim, dim+1);
164  out_fmllr->SetUnit(); // sets diagonal elements to one.
165 }
void SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ InitGmmFromRandomFrames()

void kaldi::InitGmmFromRandomFrames ( const Matrix< BaseFloat > &  feats,
DiagGmm gmm 
)

Definition at line 32 of file gmm-global-init-from-feats.cc.

References VectorBase< Real >::AddVec2(), DiagGmm::ComputeGconsts(), DiagGmm::CopyFromNormal(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, VectorBase< Real >::Max(), DiagGmmNormal::means_, MatrixBase< Real >::NumCols(), DiagGmm::NumGauss(), MatrixBase< Real >::NumRows(), RandInt(), MatrixBase< Real >::Row(), DiagGmmNormal::vars_, and DiagGmmNormal::weights_.

Referenced by main().

32  {
33  int32 num_gauss = gmm->NumGauss(), num_frames = feats.NumRows(),
34  dim = feats.NumCols();
35  KALDI_ASSERT(num_frames >= 10 * num_gauss && "Too few frames to train on");
36  Vector<double> mean(dim), var(dim);
37  for (int32 i = 0; i < num_frames; i++) {
38  mean.AddVec(1.0 / num_frames, feats.Row(i));
39  var.AddVec2(1.0 / num_frames, feats.Row(i));
40  }
41  var.AddVec2(-1.0, mean);
42  if (var.Max() <= 0.0)
43  KALDI_ERR << "Features do not have positive variance " << var;
44 
45  DiagGmmNormal gmm_normal(*gmm);
46 
47  std::set<int32> used_frames;
48  for (int32 g = 0; g < num_gauss; g++) {
49  int32 random_frame = RandInt(0, num_frames - 1);
50  while (used_frames.count(random_frame) != 0)
51  random_frame = RandInt(0, num_frames - 1);
52  used_frames.insert(random_frame);
53  gmm_normal.weights_(g) = 1.0 / num_gauss;
54  gmm_normal.means_.Row(g).CopyFromVec(feats.Row(random_frame));
55  gmm_normal.vars_.Row(g).CopyFromVec(var);
56  }
57  gmm->CopyFromNormal(gmm_normal);
58  gmm->ComputeGconsts();
59 }
Definition for Gaussian Mixture Model with diagonal covariances in normal mode: where the parameters ...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
int32 ComputeGconsts()
Sets the gconsts.
Definition: diag-gmm.cc:114
kaldi::int32 int32
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: diag-gmm.h:72
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void CopyFromNormal(const DiagGmmNormal &diag_gmm_normal)
Copies from DiagGmmNormal; does not resize.
Definition: diag-gmm.cc:918
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ InitKaldiInputStream()

bool InitKaldiInputStream ( std::istream &  is,
bool binary 
)
inline

Initialize an opened stream for reading by detecting the binary header and.

InitKaldiInputStream initializes an opened stream for reading by detecting the binary header and setting the "binary" value appropriately; It will typically not be called by users directly.

Definition at line 306 of file io-funcs-inl.h.

Referenced by main(), Input::OpenInternal(), PosteriorHolder::Read(), KaldiObjectHolder< KaldiType >::Read(), GaussPostHolder::Read(), BasicHolder< BasicType >::Read(), BasicVectorHolder< BasicType >::Read(), BasicVectorVectorHolder< BasicType >::Read(), BasicPairVectorHolder< BasicType >::Read(), ReadBasicType(), UnitTestCompressedMatrix(), UnitTestGeneralMatrix(), UnitTestIo(), and UnitTestIoCross().

306  {
307  // Sets the 'binary' variable.
308  // Throws exception in the very unusual situation that stream
309  // starts with '\0' but not then 'B'.
310 
311  if (is.peek() == '\0') { // seems to be binary
312  is.get();
313  if (is.peek() != 'B') {
314  return false;
315  }
316  is.get();
317  *binary = true;
318  return true;
319  } else {
320  *binary = false;
321  return true;
322  }
323 }

◆ InitKaldiOutputStream()

void InitKaldiOutputStream ( std::ostream &  os,
bool  binary 
)
inline

InitKaldiOutputStream initializes an opened stream for writing by writing an optional binary header and modifying the floating-point precision; it will typically not be called by users directly.

Definition at line 291 of file io-funcs-inl.h.

Referenced by Output::Open(), ReadBasicType(), UnitTestCompressedMatrix(), UnitTestGeneralMatrix(), UnitTestIo(), UnitTestIoCross(), KaldiObjectHolder< KaldiType >::Write(), PosteriorHolder::Write(), GaussPostHolder::Write(), BasicHolder< BasicType >::Write(), BasicVectorHolder< BasicType >::Write(), BasicVectorVectorHolder< BasicType >::Write(), and BasicPairVectorHolder< BasicType >::Write().

291  {
292  // This does not throw exceptions (does not check for errors).
293  if (binary) {
294  os.put('\0');
295  os.put('B');
296  }
297  // Note, in non-binary mode we may at some point want to mess with
298  // the precision a bit.
299  // 7 is a bit more than the precision of float..
300  if (os.precision() < 7)
301  os.precision(7);
302 }

◆ InitRand() [1/4]

static void kaldi::InitRand ( SpMatrix< Real > *  M)
static

Definition at line 42 of file cu-test.cc.

References SpMatrix< Real >::Cond(), rnnlm::i, rnnlm::j, PackedMatrix< Real >::NumRows(), and RandGauss().

42  {
43  do {
44  for (MatrixIndexT i = 0; i < M->NumRows(); i++) {
45  for (MatrixIndexT j = 0; j <= i; j++ ) {
46  (*M)(i,j) = RandGauss();
47  }
48  }
49  } while (M->NumRows() != 0 && M->Cond() > 100);
50 }
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
Real Cond() const
Returns maximum ratio of singular values.
Definition: sp-matrix.h:145

◆ InitRand() [2/4]

◆ InitRand() [3/4]

static void kaldi::InitRand ( MatrixBase< Real > *  M)
static

Definition at line 53 of file cu-matrix-test.cc.

References MatrixBase< Real >::Cond(), rnnlm::i, rnnlm::j, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and RandGauss().

53  {
54  do {
55  for (MatrixIndexT i = 0;i < M->NumRows();i++)
56  for (MatrixIndexT j = 0;j < M->NumCols();j++)
57  (*M)(i, j) = RandGauss();
58  } while (M->NumRows() != 0 && M->Cond() > 100);
59 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Real Cond() const
Returns condition number by computing Svd.
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ InitRand() [4/4]

static void kaldi::InitRand ( VectorBase< Real > *  v)
static

Definition at line 53 of file cu-test.cc.

References VectorBase< Real >::Dim(), rnnlm::i, and RandGauss().

53  {
54  for (MatrixIndexT i = 0; i < v->Dim(); i++) {
55  (*v)(i) = RandGauss();
56  }
57 }
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64

◆ InitRandNonsingular() [1/2]

static void kaldi::InitRandNonsingular ( MatrixBase< Real > *  M)
static

Definition at line 56 of file matrix-lib-test.cc.

References MatrixBase< Real >::Cond(), rnnlm::i, rnnlm::j, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and RandGauss().

Referenced by CholeskyUnitTestTr(), UnitTestAxpy(), UnitTestDeterminant(), UnitTestDeterminantSign(), UnitTestEig(), UnitTestEigSp(), UnitTestFloorChol(), UnitTestInverse(), UnitTestNonsymmetricPower(), UnitTestRow(), UnitTestSimpleForMat(), UnitTestTridiagonalize(), and UnitTestTridiagonalizeAndQr().

56  {
57 start:
58  for (MatrixIndexT i = 0;i < M->NumRows();i++)
59  for (MatrixIndexT j = 0;j < M->NumCols();j++)
60  (*M)(i, j) = RandGauss();
61  if (M->NumRows() != 0 && M->Cond() > 100) {
62  printf("Condition number of random matrix large %f, trying again (this is normal)\n",
63  (float) M->Cond());
64  goto start;
65  }
66 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Real Cond() const
Returns condition number by computing Svd.
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ InitRandNonsingular() [2/2]

static void kaldi::InitRandNonsingular ( SpMatrix< Real > *  M)
static

Definition at line 69 of file matrix-lib-test.cc.

References SpMatrix< Real >::Cond(), rnnlm::i, rnnlm::j, PackedMatrix< Real >::NumRows(), and RandGauss().

69  {
70 start:
71  for (MatrixIndexT i = 0;i < M->NumRows();i++)
72  for (MatrixIndexT j = 0;j<=i;j++)
73  (*M)(i, j) = RandGauss();
74  if (M->NumRows() != 0 && M->Cond() > 100)
75  goto start;
76 }
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
MatrixIndexT NumRows() const
int32 MatrixIndexT
Definition: matrix-common.h:98
Real Cond() const
Returns maximum ratio of singular values.
Definition: sp-matrix.h:145

◆ InitRandomGmm()

void InitRandomGmm ( DiagGmm gmm_in)

Definition at line 27 of file diag-gmm-test.cc.

References DiagGmm::ComputeGconsts(), Exp(), rnnlm::i, rnnlm::j, DiagGmm::Perturb(), Rand(), RandGauss(), RandUniform(), DiagGmm::Resize(), VectorBase< Real >::Scale(), DiagGmm::SetInvVarsAndMeans(), DiagGmm::SetWeights(), and VectorBase< Real >::Sum().

Referenced by UnitTestDiagGmmGenerate(), UnitTestFmllrDiagGmm(), UnitTestFmllrDiagGmmDiagonal(), UnitTestFmllrDiagGmmOffset(), and UnitTestFmllrRaw().

27  {
28  int32 num_gauss = 10 + Rand() % 5;
29  int32 dim = 10 + Rand() % 10;
30  DiagGmm &gmm(*gmm_in);
31  gmm.Resize(num_gauss, dim);
32  Matrix<BaseFloat> inv_vars(num_gauss, dim),
33  means(num_gauss, dim);
34  Vector<BaseFloat> weights(num_gauss);
35  for (int32 i = 0; i < num_gauss; i++) {
36  for (int32 j = 0; j < dim; j++) {
37  inv_vars(i, j) = Exp(RandGauss() * (1.0 / (1 + j)));
38  means(i, j) = RandGauss() * (1.0 / (1 + j));
39  }
40  weights(i) = Exp(RandGauss());
41  }
42  weights.Scale(1.0 / weights.Sum());
43  gmm.SetWeights(weights);
44  gmm.SetInvVarsAndMeans(inv_vars, means);
45  gmm.Perturb(0.5 * RandUniform());
46  gmm.ComputeGconsts(); // this is unnecessary; computed in Perturb
47 }
double Exp(double x)
Definition: kaldi-math.h:83
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
Definition: kaldi-math.h:151
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
kaldi::int32 int32
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45

◆ IsLeafNode()

static bool kaldi::IsLeafNode ( const EventMap e)
static

Definition at line 354 of file event-map.cc.

References EventMap::GetChildren().

Referenced by GetTreeStructure(), and GetTreeStructureInternal().

354  {
355  std::vector<EventMap*> children;
356  e->GetChildren(&children);
357  return children.empty();
358 }

◆ IsLine()

bool IsLine ( const std::string &  line)

Returns true if "line" is free of
characters and unprintable characters, and does not contain leading or trailing whitespace.

Definition at line 154 of file text-utils.cc.

Referenced by ConvertStringToInteger(), and TestIsLine().

154  {
155  if (line.find('\n') != std::string::npos) return false;
156  if (line.empty()) return true;
157  if (isspace(*(line.begin()))) return false;
158  if (isspace(*(line.rbegin()))) return false;
159  std::string::const_iterator iter = line.begin(), end = line.end();
160  for (; iter != end; iter++)
161  if (!isprint(*iter)) return false;
162  return true;
163 }

◆ IsmoothStatsAmDiagGmm()

void IsmoothStatsAmDiagGmm ( const AccumAmDiagGmm src_stats,
double  tau,
AccumAmDiagGmm dst_stats 
)

Smooth "dst_stats" with "src_stats".

They don't have to be different.

Definition at line 358 of file ebw-diag-gmm.cc.

References AccumAmDiagGmm::GetAcc(), IsmoothStatsDiagGmm(), KALDI_ASSERT, and AccumAmDiagGmm::NumAccs().

Referenced by main(), and EbwWeightOptions::Register().

360  {
361  int num_pdfs = src_stats.NumAccs();
362  KALDI_ASSERT(num_pdfs == dst_stats->NumAccs());
363  for (int32 pdf = 0; pdf < num_pdfs; pdf++)
364  IsmoothStatsDiagGmm(src_stats.GetAcc(pdf), tau, &(dst_stats->GetAcc(pdf)));
365 }
kaldi::int32 int32
void IsmoothStatsDiagGmm(const AccumDiagGmm &src_stats, double tau, AccumDiagGmm *dst_stats)
I-Smooth the stats. src_stats and dst_stats do not have to be different.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsmoothStatsAmDiagGmmFromModel()

void IsmoothStatsAmDiagGmmFromModel ( const AmDiagGmm src_model,
double  tau,
AccumAmDiagGmm dst_stats 
)

This version of the I-smoothing function takes a model as input.

Definition at line 367 of file ebw-diag-gmm.cc.

References DiagGmmToStats(), AccumAmDiagGmm::GetAcc(), AmDiagGmm::GetPdf(), IsmoothStatsDiagGmm(), KALDI_ASSERT, kGmmAll, AccumAmDiagGmm::NumAccs(), and AmDiagGmm::NumPdfs().

Referenced by main(), and EbwWeightOptions::Register().

369  {
370  int num_pdfs = src_model.NumPdfs();
371  KALDI_ASSERT(num_pdfs == dst_stats->NumAccs());
372  for (int32 pdf = 0; pdf < num_pdfs; pdf++) {
373  AccumDiagGmm tmp_stats;
374  double occ = 1.0; // its value doesn't matter.
375  DiagGmmToStats(src_model.GetPdf(pdf), kGmmAll, occ, &tmp_stats);
376  IsmoothStatsDiagGmm(tmp_stats, tau, &(dst_stats->GetAcc(pdf)));
377  }
378 }
kaldi::int32 int32
void IsmoothStatsDiagGmm(const AccumDiagGmm &src_stats, double tau, AccumDiagGmm *dst_stats)
I-Smooth the stats. src_stats and dst_stats do not have to be different.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void DiagGmmToStats(const DiagGmm &gmm, GmmFlagsType flags, double state_occ, AccumDiagGmm *dst_stats)
Creates stats from the GMM. Resizes them as needed.

◆ IsmoothStatsDiagGmm()

void IsmoothStatsDiagGmm ( const AccumDiagGmm src_stats,
double  tau,
AccumDiagGmm dst_stats 
)

I-Smooth the stats. src_stats and dst_stats do not have to be different.

Definition at line 318 of file ebw-diag-gmm.cc.

References AccumDiagGmm::AddStatsForComponent(), VectorBase< Real >::CopyFromVec(), AccumDiagGmm::Dim(), AccumDiagGmm::Flags(), KALDI_ASSERT, kGmmMeans, kGmmVariances, AccumDiagGmm::mean_accumulator(), AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy(), VectorBase< Real >::Scale(), and AccumDiagGmm::variance_accumulator().

Referenced by IsmoothStatsAmDiagGmm(), IsmoothStatsAmDiagGmmFromModel(), EbwWeightOptions::Register(), and UnitTestEstimateMmieDiagGmm().

320  {
321  KALDI_ASSERT(src_stats.NumGauss() == dst_stats->NumGauss());
322  int32 dim = src_stats.Dim(), num_gauss = src_stats.NumGauss();
323  for (int32 g = 0; g < num_gauss; g++) {
324  double occ = src_stats.occupancy()(g);
325  if (occ != 0.0) { // can only do this for nonzero occupancies...
326  Vector<double> x_stats(dim), x2_stats(dim);
327  if (dst_stats->Flags() & kGmmMeans)
328  x_stats.CopyFromVec(src_stats.mean_accumulator().Row(g));
329  if (dst_stats->Flags() & kGmmVariances)
330  x2_stats.CopyFromVec(src_stats.variance_accumulator().Row(g));
331  x_stats.Scale(tau / occ);
332  x2_stats.Scale(tau / occ);
333  dst_stats->AddStatsForComponent(g, tau, x_stats, x2_stats);
334  }
335  }
336 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsPlausibleWord() [1/2]

static bool kaldi::IsPlausibleWord ( const WordBoundaryInfo info,
const TransitionModel tmodel,
const std::vector< int32 > &  transition_ids 
)
static

Definition at line 543 of file word-align-lattice.cc.

References rnnlm::i, TransitionModel::IsFinal(), TransitionModel::IsSelfLoop(), WordBoundaryInfo::kWordBeginAndEndPhone, WordBoundaryInfo::kWordBeginPhone, WordBoundaryInfo::kWordEndPhone, WordBoundaryInfo::reorder, TransitionModel::TransitionIdToPhone(), and WordBoundaryInfo::TypeOfPhone().

545  {
546  if (transition_ids.empty()) return false;
547  int32 first_phone = tmodel.TransitionIdToPhone(transition_ids.front()),
548  last_phone = tmodel.TransitionIdToPhone(transition_ids.back());
549  if ( (info.TypeOfPhone(first_phone) == WordBoundaryInfo::kWordBeginAndEndPhone
550  && first_phone == last_phone)
551  ||
552  (info.TypeOfPhone(first_phone) == WordBoundaryInfo::kWordBeginPhone &&
553  info.TypeOfPhone(last_phone) == WordBoundaryInfo::kWordEndPhone) ) {
554  if (! info.reorder) {
555  return (tmodel.IsFinal(transition_ids.back()));
556  } else {
557  int32 i = transition_ids.size() - 1;
558  while (i > 0 && tmodel.IsSelfLoop(transition_ids[i])) i--;
559  return tmodel.IsFinal(transition_ids[i]);
560  }
561  } else return false;
562 }
kaldi::int32 int32

◆ IsPlausibleWord() [2/2]

static bool kaldi::IsPlausibleWord ( const WordAlignLatticeLexiconInfo lexicon_info,
const TransitionModel tmodel,
int32  word_id,
const std::vector< int32 > &  transition_ids 
)
static

Definition at line 745 of file word-align-lattice-lexicon.cc.

References rnnlm::i, WordAlignLatticeLexiconInfo::IsValidEntry(), KALDI_ASSERT, KALDI_WARN, SplitToPhones(), and TransitionModel::TransitionIdToPhone().

Referenced by LatticeWordAligner::ComputationState::OutputArcForce(), and TestWordAlignedLattice().

748  {
749 
750  std::vector<std::vector<int32> > split_alignment; // Split into phones.
751  if (!SplitToPhones(tmodel, transition_ids, &split_alignment)) {
752  KALDI_WARN << "Could not split word into phones correctly (forced-out?)";
753  }
754  std::vector<int32> phones(split_alignment.size());
755  for (size_t i = 0; i < split_alignment.size(); i++) {
756  KALDI_ASSERT(!split_alignment[i].empty());
757  phones[i] = tmodel.TransitionIdToPhone(split_alignment[i][0]);
758  }
759  std::vector<int32> lexicon_entry;
760  lexicon_entry.push_back(word_id);
761  lexicon_entry.insert(lexicon_entry.end(), phones.begin(), phones.end());
762 
763  if (!lexicon_info.IsValidEntry(lexicon_entry)) {
764  std::ostringstream ostr;
765  for (size_t i = 0; i < lexicon_entry.size(); i++)
766  ostr << lexicon_entry[i] << ' ';
767  KALDI_WARN << "Invalid arc in aligned lattice (code error?) lexicon-entry is " << ostr.str();
768  return false;
769  } else {
770  return true;
771  }
772 }
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
Definition: hmm-utils.cc:723
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsReordered()

static bool kaldi::IsReordered ( const TransitionModel trans_model,
const std::vector< int32 > &  alignment 
)
static

Definition at line 625 of file hmm-utils.cc.

References rnnlm::i, TransitionModel::IsSelfLoop(), KALDI_ASSERT, and TransitionModel::TransitionIdToTransitionState().

Referenced by ConvertAlignmentInternal(), and SplitToPhones().

626  {
627  for (size_t i = 0; i + 1 < alignment.size(); i++) {
628  int32 tstate1 = trans_model.TransitionIdToTransitionState(alignment[i]),
629  tstate2 = trans_model.TransitionIdToTransitionState(alignment[i+1]);
630  if (tstate1 != tstate2) {
631  bool is_loop_1 = trans_model.IsSelfLoop(alignment[i]),
632  is_loop_2 = trans_model.IsSelfLoop(alignment[i+1]);
633  KALDI_ASSERT(!(is_loop_1 && is_loop_2)); // Invalid.
634  if (is_loop_1) return true; // Reordered. self-loop is last.
635  if (is_loop_2) return false; // Not reordered. self-loop is first.
636  }
637  }
638 
639  // Just one trans-state in whole sequence.
640  if (alignment.empty()) return false;
641  else {
642  bool is_loop_front = trans_model.IsSelfLoop(alignment.front()),
643  is_loop_back = trans_model.IsSelfLoop(alignment.back());
644  if (is_loop_front) return false; // Not reordered. Self-loop is first.
645  if (is_loop_back) return true; // Reordered. Self-loop is last.
646  return false; // We really don't know in this case but calling code should
647  // not care.
648  }
649 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsSorted()

bool kaldi::IsSorted ( const std::vector< T > &  vec)
inline

Returns true if the vector is sorted.

Definition at line 47 of file stl-utils.h.

Referenced by QuestionsForKey::Check(), DiscriminativeSupervisionSplitter::LatticeInfo::Check(), fst::CheckPhones(), PldaStats::Sort(), SplitEventMap::SplitEventMap(), TestIsSorted(), TestMergePairVectorSumming(), and Uniq().

47  {
48  typename std::vector<T>::const_iterator iter = vec.begin(), end = vec.end();
49  if (iter == end) return true;
50  while (1) {
51  typename std::vector<T>::const_iterator next_iter = iter;
52  ++next_iter;
53  if (next_iter == end) return true; // end of loop and nothing out of order
54  if (*next_iter < *iter) return false;
55  iter = next_iter;
56  }
57 }

◆ IsSortedAndUniq()

bool kaldi::IsSortedAndUniq ( const std::vector< T > &  vec)
inline

Returns true if the vector is sorted and contains each element only once.

Definition at line 63 of file stl-utils.h.

Referenced by AccumulateTreeStatsInfo::AccumulateTreeStatsInfo(), AddTransitionProbs(), AutomaticallyObtainQuestions(), RegressionTree::BuildTree(), BuildTree(), BuildTreeTwoLevel(), ConvolutionModel::Check(), ComputationGraphBuilder::Check(), Compiler::CompileBackwardFromSubmatLocations(), ExampleMergingConfig::ComputeDerived(), kaldi::nnet3::ComputeMatrixAccesses(), kaldi::nnet3::ComputeVariableAccesses(), ComputationRenumberer::CreateRenumbering(), FeatureTransformEstimateMulti::Estimate(), FilterStatsByKey(), ComputationLoopedOptimizer::FindActiveMatrices(), GenRandContextDependency(), GenRandContextDependencyLarge(), GenRandTopology(), GetDefaultTopology(), GetFullBiphoneStubMap(), ContextDependency::GetPdfInfo(), GetPdfsForPhones(), GetPhonesForPdfs(), kaldi::nnet3::time_height_convolution::GetRandomConvolutionIndexes(), GetStubMap(), SpliceComponent::Init(), TimeHeightConvolutionComponent::InitFromConfig(), KMeansClusterPhones(), LatticeActivePhones(), LatticeBoost(), main(), kaldi::nnet3::time_height_convolution::MakeComputation(), ObtainSetsOfPhones(), HmmTopology::Read(), ReadRootsFile(), ReadSharedPhonesList(), kaldi::nnet3::time_height_convolution::RegularizeTList(), DiagGmm::RemoveComponents(), FullGmm::RemoveComponents(), TestIsSortedAndUniq(), TrailingSilenceLength(), and TrainingGraphCompiler::TrainingGraphCompiler().

63  {
64  typename std::vector<T>::const_iterator iter = vec.begin(), end = vec.end();
65  if (iter == end) return true;
66  while (1) {
67  typename std::vector<T>::const_iterator next_iter = iter;
68  ++next_iter;
69  if (next_iter == end) return true; // end of loop and nothing out of order
70  if (*next_iter <= *iter) return false;
71  iter = next_iter;
72  }
73 }

◆ IsToken()

bool IsToken ( const std::string &  token)

Returns true if "token" is nonempty, and all characters are printable and whitespace-free.

Definition at line 105 of file text-utils.cc.

References rnnlm::i.

Referenced by ConvertStringToInteger(), RandomAccessTableReader< kaldi::TokenHolder >::HasKey(), RandomAccessTableReaderScriptImpl< Holder >::HasKeyInternal(), IsNotToken(), Nnet::ProcessComponentConfigLine(), SplitArgOnEquals(), TestIsToken(), TokenHolder::Write(), TokenVectorHolder::Write(), TableWriterArchiveImpl< Holder >::Write(), TableWriterScriptImpl< Holder >::Write(), TableWriterBothImpl< Holder >::Write(), and WriteScriptFile().

105  {
106  size_t l = token.length();
107  if (l == 0) return false;
108  for (size_t i = 0; i < l; i++) {
109  unsigned char c = token[i];
110  if ((!isprint(c) || isspace(c)) && (isascii(c) || c == (unsigned char)255))
111  return false;
112  // The "&& (isascii(c) || c == 255)" was added so that we won't reject
113  // non-ASCII characters such as French characters with accents [except for
114  // 255 which is "nbsp", a form of space].
115  }
116  return true;
117 }

◆ IsValidName()

bool IsValidName ( const std::string &  name)

Returns true if 'name' would be a valid name for a component or node in a nnet3Nnet.

This is a nonempty string beginning with A-Za-z_, and containing only '-', '_', '.', A-Z, a-z, or 0-9.

Definition at line 553 of file text-utils.cc.

References rnnlm::i.

Referenced by Nnet::AddComponent(), kaldi::nnet3::DescriptorTokenize(), ConfigLine::ParseLine(), Nnet::RemoveRedundantConfigLines(), and Nnet::SetNodeName().

553  {
554  if (name.size() == 0) return false;
555  for (size_t i = 0; i < name.size(); i++) {
556  if (i == 0 && !isalpha(name[i]) && name[i] != '_')
557  return false;
558  if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-' && name[i] != '.')
559  return false;
560  }
561  return true;
562 }

◆ JoinVectorToString()

void JoinVectorToString ( const std::vector< std::string > &  vec_in,
const char *  delim,
bool  omit_empty_strings,
std::string *  str_out 
)

Joins the elements of a vector of strings into a single string using "delim" as the delimiter.

If omit_empty_strings == true, any empty strings in the vector are skipped. A vector of empty strings results in an empty string on the output.

Definition at line 77 of file text-utils.cc.

References rnnlm::i.

Referenced by TestSplitStringToVector().

79  {
80  std::string tmp_str;
81  for (size_t i = 0; i < vec_in.size(); i++) {
82  if (!omit_empty_strings || !vec_in[i].empty()) {
83  tmp_str.append(vec_in[i]);
84  if (i < vec_in.size() - 1)
85  if (!omit_empty_strings || !vec_in[i+1].empty())
86  tmp_str.append(delim);
87  }
88  }
89  str_out->swap(tmp_str);
90 }

◆ KaldiGetStackTrace()

static std::string kaldi::KaldiGetStackTrace ( )
static

Definition at line 133 of file kaldi-error.cc.

References rnnlm::i.

Referenced by MessageLogger::LogMessage().

133  {
134  std::string ans;
135 #ifdef HAVE_EXECINFO_H
136  const size_t KALDI_MAX_TRACE_SIZE = 50;
137  const size_t KALDI_MAX_TRACE_PRINT = 50; // Must be even.
138  // Buffer for the trace.
139  void *trace[KALDI_MAX_TRACE_SIZE];
140  // Get the trace.
141  size_t size = backtrace(trace, KALDI_MAX_TRACE_SIZE);
142  // Get the trace symbols.
143  char **trace_symbol = backtrace_symbols(trace, size);
144  if (trace_symbol == NULL)
145  return ans;
146 
147  // Compose a human-readable backtrace string.
148  ans += "[ Stack-Trace: ]\n";
149  if (size <= KALDI_MAX_TRACE_PRINT) {
150  for (size_t i = 0; i < size; i++) {
151  ans += Demangle(trace_symbol[i]) + "\n";
152  }
153  } else { // Print out first+last (e.g.) 5.
154  for (size_t i = 0; i < KALDI_MAX_TRACE_PRINT / 2; i++) {
155  ans += Demangle(trace_symbol[i]) + "\n";
156  }
157  ans += ".\n.\n.\n";
158  for (size_t i = size - KALDI_MAX_TRACE_PRINT / 2; i < size; i++) {
159  ans += Demangle(trace_symbol[i]) + "\n";
160  }
161  if (size == KALDI_MAX_TRACE_SIZE)
162  ans += ".\n.\n.\n"; // Stack was too long, probably a bug.
163  }
164 
165  // We must free the array of pointers allocated by backtrace_symbols(),
166  // but not the strings themselves.
167  free(trace_symbol);
168 #endif // HAVE_EXECINFO_H
169  return ans;
170 }

◆ LatticeAcousticRescore()

void kaldi::LatticeAcousticRescore ( const TransitionModel trans_model,
const Matrix< BaseFloat > &  log_likes,
const std::vector< int32 > &  state_times,
Lattice lat 
)

Definition at line 31 of file lattice-rescore-mapped.cc.

References rnnlm::i, KALDI_ASSERT, KALDI_ERR, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and TransitionModel::TransitionIdToPdf().

Referenced by main().

34  {
35  kaldi::uint64 props = lat->Properties(fst::kFstProperties, false);
36  if (!(props & fst::kTopSorted))
37  KALDI_ERR << "Input lattice must be topologically sorted.";
38 
39  KALDI_ASSERT(!state_times.empty());
40  std::vector<std::vector<int32> > time_to_state(log_likes.NumRows());
41  for (size_t i = 0; i < state_times.size(); i++) {
42  KALDI_ASSERT(state_times[i] >= 0);
43  if (state_times[i] < log_likes.NumRows()) // end state may be past this..
44  time_to_state[state_times[i]].push_back(i);
45  else
46  KALDI_ASSERT(state_times[i] == log_likes.NumRows()
47  && "There appears to be lattice/feature mismatch.");
48  }
49 
50  for (int32 t = 0; t < log_likes.NumRows(); t++) {
51  for (size_t i = 0; i < time_to_state[t].size(); i++) {
52  int32 state = time_to_state[t][i];
53  for (fst::MutableArcIterator<Lattice> aiter(lat, state); !aiter.Done();
54  aiter.Next()) {
55  LatticeArc arc = aiter.Value();
56  int32 trans_id = arc.ilabel;
57  if (trans_id != 0) { // Non-epsilon input label on arc
58  int32 pdf_id = trans_model.TransitionIdToPdf(trans_id);
59  if (pdf_id > log_likes.NumCols())
60  KALDI_ERR << "Pdf-id " << pdf_id << " is out of the range of "
61  << "input log-likelihoods " << log_likes.NumCols()
62  << " (probably some kind of mismatch).";
63  BaseFloat ll = log_likes(t, pdf_id);
64  arc.weight.SetValue2(-ll + arc.weight.Value2());
65  aiter.SetValue(arc);
66  }
67  }
68  }
69  }
70 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ LatticeActivePhones() [1/2]

void kaldi::LatticeActivePhones ( const Lattice lat,
const TransitionModel trans,
const std::vector< int32 > &  sil_phones,
std::vector< std::set< int32 > > *  active_phones 
)

Given a lattice, and a transition model to map pdf-ids to phones, outputs for each frame the set of phones active on that frame.

If sil_phones (which must be sorted and uniq) is nonempty, it excludes phones in this list.

Definition at line 399 of file lattice-functions.cc.

References IsSortedAndUniq(), KALDI_ASSERT, LatticeStateTimes(), and TransitionModel::TransitionIdToPhone().

401  {
402  KALDI_ASSERT(IsSortedAndUniq(silence_phones));
403  vector<int32> state_times;
404  int32 num_states = lat.NumStates();
405  int32 max_time = LatticeStateTimes(lat, &state_times);
406  active_phones->clear();
407  active_phones->resize(max_time);
408  for (int32 state = 0; state < num_states; state++) {
409  int32 cur_time = state_times[state];
410  for (fst::ArcIterator<Lattice> aiter(lat, state); !aiter.Done();
411  aiter.Next()) {
412  const LatticeArc &arc = aiter.Value();
413  if (arc.ilabel != 0) { // Non-epsilon arc
414  int32 phone = trans.TransitionIdToPhone(arc.ilabel);
415  if (!std::binary_search(silence_phones.begin(),
416  silence_phones.end(), phone))
417  (*active_phones)[cur_time].insert(phone);
418  }
419  } // end looping over arcs
420  } // end looping over states
421 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ LatticeActivePhones() [2/2]

void kaldi::LatticeActivePhones ( const Lattice lat,
const TransitionModel trans,
const std::vector< int32 > &  sil_phones,
std::vector< std::set< int32 > > *  active_phones 
)

Given a lattice, and a transition model to map pdf-ids to phones, outputs for each frame the set of phones active on that frame.

If sil_phones (which must be sorted and uniq) is nonempty, it excludes phones in this list.

Definition at line 399 of file lattice-functions.cc.

References IsSortedAndUniq(), KALDI_ASSERT, LatticeStateTimes(), and TransitionModel::TransitionIdToPhone().

401  {
402  KALDI_ASSERT(IsSortedAndUniq(silence_phones));
403  vector<int32> state_times;
404  int32 num_states = lat.NumStates();
405  int32 max_time = LatticeStateTimes(lat, &state_times);
406  active_phones->clear();
407  active_phones->resize(max_time);
408  for (int32 state = 0; state < num_states; state++) {
409  int32 cur_time = state_times[state];
410  for (fst::ArcIterator<Lattice> aiter(lat, state); !aiter.Done();
411  aiter.Next()) {
412  const LatticeArc &arc = aiter.Value();
413  if (arc.ilabel != 0) { // Non-epsilon arc
414  int32 phone = trans.TransitionIdToPhone(arc.ilabel);
415  if (!std::binary_search(silence_phones.begin(),
416  silence_phones.end(), phone))
417  (*active_phones)[cur_time].insert(phone);
418  }
419  } // end looping over arcs
420  } // end looping over states
421 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ LatticeBoost()

bool LatticeBoost ( const TransitionModel trans,
const std::vector< int32 > &  alignment,
const std::vector< int32 > &  silence_phones,
BaseFloat  b,
BaseFloat  max_silence_error,
Lattice lat 
)

Boosts LM probabilities by b * [number of frame errors]; equivalently, adds -b*[number of frame errors] to the graph-component of the cost of each arc/path.

There is a frame error if a particular transition-id on a particular frame corresponds to a phone not matching transcription's alignment for that frame. This is used in "margin-inspired" discriminative training, esp. Boosted MMI. The TransitionModel is used to map transition-ids in the lattice input-side to phones; the phones appearing in "silence_phones" are treated specially in that we replace the frame error f (either zero or 1) for a frame, with the minimum of f or max_silence_error. For the normal recipe, max_silence_error would be zero. Returns true on success, false if there was some kind of mismatch. At input, silence_phones must be sorted and unique.

Definition at line 735 of file lattice-functions.cc.

References IsSortedAndUniq(), KALDI_ASSERT, KALDI_WARN, LatticeStateTimes(), TransitionModel::NumTransitionIds(), TopSortLatticeIfNeeded(), and TransitionModel::TransitionIdToPhone().

Referenced by DiscriminativeComputation::Compute(), NnetDiscriminativeUpdater::LatticeComputations(), and main().

740  {
742 
743  // get all stored properties (test==false means don't test if not known).
744  uint64 props = lat->Properties(fst::kFstProperties,
745  false);
746 
747  KALDI_ASSERT(IsSortedAndUniq(silence_phones));
748  KALDI_ASSERT(max_silence_error >= 0.0 && max_silence_error <= 1.0);
749  vector<int32> state_times;
750  int32 num_states = lat->NumStates();
751  int32 num_frames = LatticeStateTimes(*lat, &state_times);
752  KALDI_ASSERT(num_frames == static_cast<int32>(alignment.size()));
753  for (int32 state = 0; state < num_states; state++) {
754  int32 cur_time = state_times[state];
755  for (fst::MutableArcIterator<Lattice> aiter(lat, state); !aiter.Done();
756  aiter.Next()) {
757  LatticeArc arc = aiter.Value();
758  if (arc.ilabel != 0) { // Non-epsilon arc
759  if (arc.ilabel < 0 || arc.ilabel > trans.NumTransitionIds()) {
760  KALDI_WARN << "Lattice has out-of-range transition-ids: "
761  << "lattice/model mismatch?";
762  return false;
763  }
764  int32 phone = trans.TransitionIdToPhone(arc.ilabel),
765  ref_phone = trans.TransitionIdToPhone(alignment[cur_time]);
766  BaseFloat frame_error;
767  if (phone == ref_phone) {
768  frame_error = 0.0;
769  } else { // an error...
770  if (std::binary_search(silence_phones.begin(), silence_phones.end(), phone))
771  frame_error = max_silence_error;
772  else
773  frame_error = 1.0;
774  }
775  BaseFloat delta_cost = -b * frame_error; // negative cost if
776  // frame is wrong, to boost likelihood of arcs with errors on them.
777  // Add this cost to the graph part.
778  arc.weight.SetValue1(arc.weight.Value1() + delta_cost);
779  aiter.SetValue(arc);
780  }
781  }
782  }
783  // All we changed is the weights, so any properties that were
784  // known before, are still known, except for whether or not the
785  // lattice was weighted.
786  lat->SetProperties(props,
787  ~(fst::kWeighted|fst::kUnweighted));
788 
789  return true;
790 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
void TopSortLatticeIfNeeded(Lattice *lat)
Topologically sort the lattice if not already topologically sorted.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63

◆ LatticeForwardBackward()

BaseFloat LatticeForwardBackward ( const Lattice lat,
Posterior arc_post,
double *  acoustic_like_sum = NULL 
)

This function does the forward-backward over lattices and computes the posterior probabilities of the arcs.

It returns the total log-probability of the lattice. The Posterior quantities contain pairs of (transition-id, weight) on each frame. If the pointer "acoustic_like_sum" is provided, this value is set to the sum over the arcs, of the posterior of the arc times the acoustic likelihood [i.e. negated acoustic score] on that link. This is used in combination with other quantities to work out the objective function in MMI discriminative training.

Definition at line 314 of file lattice-functions.cc.

References ApproxEqual(), fst::ConvertToCost(), Exp(), KALDI_ASSERT, KALDI_ERR, KALDI_WARN, kLogZeroDouble, LatticeStateTimes(), LogAdd(), and MergePairVectorSumming().

Referenced by SingleUtteranceGmmDecoder::GetGaussianPosteriors(), LatticeForwardBackwardMmi(), main(), and TestWordAlignedLattice().

315  {
316  // Note, Posterior is defined as follows: Indexed [frame], then a list
317  // of (transition-id, posterior-probability) pairs.
318  // typedef std::vector<std::vector<std::pair<int32, BaseFloat> > > Posterior;
319  using namespace fst;
320  typedef Lattice::Arc Arc;
321  typedef Arc::Weight Weight;
322  typedef Arc::StateId StateId;
323 
324  if (acoustic_like_sum) *acoustic_like_sum = 0.0;
325 
326  // Make sure the lattice is topologically sorted.
327  if (lat.Properties(fst::kTopSorted, true) == 0)
328  KALDI_ERR << "Input lattice must be topologically sorted.";
329  KALDI_ASSERT(lat.Start() == 0);
330 
331  int32 num_states = lat.NumStates();
332  vector<int32> state_times;
333  int32 max_time = LatticeStateTimes(lat, &state_times);
334  std::vector<double> alpha(num_states, kLogZeroDouble);
335  std::vector<double> &beta(alpha); // we re-use the same memory for
336  // this, but it's semantically distinct so we name it differently.
337  double tot_forward_prob = kLogZeroDouble;
338 
339  post->clear();
340  post->resize(max_time);
341 
342  alpha[0] = 0.0;
343  // Propagate alphas forward.
344  for (StateId s = 0; s < num_states; s++) {
345  double this_alpha = alpha[s];
346  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
347  const Arc &arc = aiter.Value();
348  double arc_like = -ConvertToCost(arc.weight);
349  alpha[arc.nextstate] = LogAdd(alpha[arc.nextstate], this_alpha + arc_like);
350  }
351  Weight f = lat.Final(s);
352  if (f != Weight::Zero()) {
353  double final_like = this_alpha - (f.Value1() + f.Value2());
354  tot_forward_prob = LogAdd(tot_forward_prob, final_like);
355  KALDI_ASSERT(state_times[s] == max_time &&
356  "Lattice is inconsistent (final-prob not at max_time)");
357  }
358  }
359  for (StateId s = num_states-1; s >= 0; s--) {
360  Weight f = lat.Final(s);
361  double this_beta = -(f.Value1() + f.Value2());
362  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
363  const Arc &arc = aiter.Value();
364  double arc_like = -ConvertToCost(arc.weight),
365  arc_beta = beta[arc.nextstate] + arc_like;
366  this_beta = LogAdd(this_beta, arc_beta);
367  int32 transition_id = arc.ilabel;
368 
369  // The following "if" is an optimization to avoid un-needed exp().
370  if (transition_id != 0 || acoustic_like_sum != NULL) {
371  double posterior = Exp(alpha[s] + arc_beta - tot_forward_prob);
372 
373  if (transition_id != 0) // Arc has a transition-id on it [not epsilon]
374  (*post)[state_times[s]].push_back(std::make_pair(transition_id,
375  static_cast<kaldi::BaseFloat>(posterior)));
376  if (acoustic_like_sum != NULL)
377  *acoustic_like_sum -= posterior * arc.weight.Value2();
378  }
379  }
380  if (acoustic_like_sum != NULL && f != Weight::Zero()) {
381  double final_logprob = - ConvertToCost(f),
382  posterior = Exp(alpha[s] + final_logprob - tot_forward_prob);
383  *acoustic_like_sum -= posterior * f.Value2();
384  }
385  beta[s] = this_beta;
386  }
387  double tot_backward_prob = beta[0];
388  if (!ApproxEqual(tot_forward_prob, tot_backward_prob, 1e-8)) {
389  KALDI_WARN << "Total forward probability over lattice = " << tot_forward_prob
390  << ", while total backward probability = " << tot_backward_prob;
391  }
392  // Now combine any posteriors with the same transition-id.
393  for (int32 t = 0; t < max_time; t++)
394  MergePairVectorSumming(&((*post)[t]));
395  return tot_backward_prob;
396 }
fst::StdArc::StateId StateId
double Exp(double x)
Definition: kaldi-math.h:83
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
bool ApproxEqual(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2, float delta=kDelta)
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void MergePairVectorSumming(std::vector< std::pair< I, F > > *vec)
For a vector of pair<I, F> where I is an integer and F a floating-point or integer type...
Definition: stl-utils.h:288
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ LatticeForwardBackwardMmi()

BaseFloat LatticeForwardBackwardMmi ( const TransitionModel trans,
const Lattice lat,
const std::vector< int32 > &  num_ali,
bool  drop_frames,
bool  convert_to_pdf_ids,
bool  cancel,
Posterior arc_post 
)

This function can be used to compute posteriors for MMI, with a positive contribution for the numerator and a negative one for the denominator.

This function is not actually used in our normal MMI training recipes, where it's instead done using various command line programs that each do a part of the job. This function was written for use in neural-net MMI training.

Parameters
[in]transThe transition model. Used to map the transition-ids to phones or pdfs.
[in]latThe denominator lattice
[in]num_aliThe numerator alignment
[in]drop_framesIf "drop_frames" is true, it will not compute any posteriors on frames where the num and den have disjoint pdf-ids.
[in]convert_to_pdf_idsIf "convert_to_pdfs_ids" is true, it will convert the output to be at the level of pdf-ids, not transition-ids.
[in]cancelIf "cancel" is true, it will cancel out any positive and negative parts from the same transition-id (or pdf-id, if convert_to_pdf_ids == true).
[out]arc_postThe output MMI posteriors of transition-ids (or pdf-ids if convert_to_pdf_ids == true) at each frame i.e. the difference between the numerator and denominator posteriors.

It returns the forward-backward likelihood of the lattice.

Definition at line 1414 of file lattice-functions.cc.

References AlignmentToPosterior(), ConvertPosteriorToPdfs(), LatticeForwardBackward(), MergePosteriors(), and ScalePosterior().

Referenced by DiscriminativeComputation::ComputeObjfAndDeriv(), kaldi::nnet2::ExampleToPdfPost(), and NnetDiscriminativeUpdater::GetDiscriminativePosteriors().

1421  {
1422  // First compute the MMI posteriors.
1423 
1424  Posterior den_post;
1426  &den_post,
1427  NULL);
1428 
1429  Posterior num_post;
1430  AlignmentToPosterior(num_ali, &num_post);
1431 
1432  // Now negate the MMI posteriors and add the numerator
1433  // posteriors.
1434  ScalePosterior(-1.0, &den_post);
1435 
1436  if (convert_to_pdf_ids) {
1437  Posterior num_tmp;
1438  ConvertPosteriorToPdfs(tmodel, num_post, &num_tmp);
1439  num_tmp.swap(num_post);
1440  Posterior den_tmp;
1441  ConvertPosteriorToPdfs(tmodel, den_post, &den_tmp);
1442  den_tmp.swap(den_post);
1443  }
1444 
1445  MergePosteriors(num_post, den_post,
1446  cancel, drop_frames, post);
1447 
1448  return ans;
1449 }
float BaseFloat
Definition: kaldi-types.h:29
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
BaseFloat LatticeForwardBackward(const Lattice &lat, Posterior *post, double *acoustic_like_sum)
This function does the forward-backward over lattices and computes the posterior probabilities of the...
void AlignmentToPosterior(const std::vector< int32 > &ali, Posterior *post)
Convert an alignment to a posterior (with a scale of 1.0 on each entry).
Definition: posterior.cc:290
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.
Definition: posterior.cc:218
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322
int32 MergePosteriors(const Posterior &post1, const Posterior &post2, bool merge, bool drop_frames, Posterior *post)
Merge two sets of posteriors, which must have the same length.
Definition: posterior.cc:258

◆ LatticeForwardBackwardMpeVariants()

BaseFloat LatticeForwardBackwardMpeVariants ( const TransitionModel trans,
const std::vector< int32 > &  silence_phones,
const Lattice lat,
const std::vector< int32 > &  num_ali,
std::string  criterion,
bool  one_silence_class,
Posterior post 
)

This function implements either the MPFE (minimum phone frame error) or SMBR (state-level minimum bayes risk) forward-backward, depending on whether "criterion" is "mpfe" or "smbr".

It returns the MPFE criterion of SMBR criterion for this utterance, and outputs the posteriors (which may be positive or negative) into "post".

Parameters
[in]transThe transition model. Used to map the transition-ids to phones or pdfs.
[in]silence_phonesA list of integer ids of silence phones. The silence frames i.e. the frames where num_ali corresponds to a silence phones are treated specially. The behavior is determined by 'one_silence_class' being false (traditional behavior) or true. Usually in our setup, several phones including the silence, vocalized noise, non-spoken noise and unk are treated as "silence phones"
[in]latThe denominator lattice
[in]num_aliThe numerator alignment
[in]criterionThe objective function. Must be "mpfe" or "smbr" for MPFE (minimum phone frame error) or sMBR (state minimum bayes risk) training.
[in]one_silence_classDetermines how the silence frames are treated. Setting this to false gives the old traditional behavior, where the silence frames (according to num_ali) are treated as incorrect. However, this means that the insertions are not penalized by the objective. Setting this to true gives the new behaviour, where we treat silence as any other phone, except that all pdfs of silence phones are collapsed into a single class for the frame-error computation. This can possible reduce the insertions in the trained model. This is closer to the WER metric that we actually care about, since WER is generally computed after filtering out noises, but does penalize insertions.
[out]postThe "MBR posteriors" i.e. derivatives w.r.t to the pseudo log-likelihoods of states at each frame.

Definition at line 794 of file lattice-functions.cc.

References ApproxEqual(), fst::ConvertToCost(), Exp(), KALDI_ASSERT, KALDI_ERR, KALDI_ISNAN, kLogZeroDouble, LatticeStateTimes(), LogAdd(), MergePairVectorSumming(), TransitionModel::TransitionIdToPdf(), and TransitionModel::TransitionIdToPhone().

Referenced by DiscriminativeComputation::ComputeObjfAndDeriv(), kaldi::nnet2::ExampleToPdfPost(), NnetDiscriminativeUpdater::GetDiscriminativePosteriors(), and main().

801  {
802  using namespace fst;
803  typedef Lattice::Arc Arc;
804  typedef Arc::Weight Weight;
805  typedef Arc::StateId StateId;
806 
807  KALDI_ASSERT(criterion == "mpfe" || criterion == "smbr");
808  bool is_mpfe = (criterion == "mpfe");
809 
810  if (lat.Properties(fst::kTopSorted, true) == 0)
811  KALDI_ERR << "Input lattice must be topologically sorted.";
812  KALDI_ASSERT(lat.Start() == 0);
813 
814  int32 num_states = lat.NumStates();
815  vector<int32> state_times;
816  int32 max_time = LatticeStateTimes(lat, &state_times);
817  KALDI_ASSERT(max_time == static_cast<int32>(num_ali.size()));
818  std::vector<double> alpha(num_states, kLogZeroDouble),
819  alpha_smbr(num_states, 0), //forward variable for sMBR
820  beta(num_states, kLogZeroDouble),
821  beta_smbr(num_states, 0); //backward variable for sMBR
822 
823  double tot_forward_prob = kLogZeroDouble;
824  double tot_forward_score = 0;
825 
826  post->clear();
827  post->resize(max_time);
828 
829  alpha[0] = 0.0;
830  // First Pass Forward,
831  for (StateId s = 0; s < num_states; s++) {
832  double this_alpha = alpha[s];
833  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
834  const Arc &arc = aiter.Value();
835  double arc_like = -ConvertToCost(arc.weight);
836  alpha[arc.nextstate] = LogAdd(alpha[arc.nextstate], this_alpha + arc_like);
837  }
838  Weight f = lat.Final(s);
839  if (f != Weight::Zero()) {
840  double final_like = this_alpha - (f.Value1() + f.Value2());
841  tot_forward_prob = LogAdd(tot_forward_prob, final_like);
842  KALDI_ASSERT(state_times[s] == max_time &&
843  "Lattice is inconsistent (final-prob not at max_time)");
844  }
845  }
846  // First Pass Backward,
847  for (StateId s = num_states-1; s >= 0; s--) {
848  Weight f = lat.Final(s);
849  double this_beta = -(f.Value1() + f.Value2());
850  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
851  const Arc &arc = aiter.Value();
852  double arc_like = -ConvertToCost(arc.weight),
853  arc_beta = beta[arc.nextstate] + arc_like;
854  this_beta = LogAdd(this_beta, arc_beta);
855  }
856  beta[s] = this_beta;
857  }
858  // First Pass Forward-Backward Check
859  double tot_backward_prob = beta[0];
860  // may loose the condition somehow here 1e-6 (was 1e-8)
861  if (!ApproxEqual(tot_forward_prob, tot_backward_prob, 1e-6)) {
862  KALDI_ERR << "Total forward probability over lattice = " << tot_forward_prob
863  << ", while total backward probability = " << tot_backward_prob;
864  }
865 
866  alpha_smbr[0] = 0.0;
867  // Second Pass Forward, calculate forward for MPFE/SMBR
868  for (StateId s = 0; s < num_states; s++) {
869  double this_alpha = alpha[s];
870  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
871  const Arc &arc = aiter.Value();
872  double arc_like = -ConvertToCost(arc.weight);
873  double frame_acc = 0.0;
874  if (arc.ilabel != 0) {
875  int32 cur_time = state_times[s];
876  int32 phone = trans.TransitionIdToPhone(arc.ilabel),
877  ref_phone = trans.TransitionIdToPhone(num_ali[cur_time]);
878  bool phone_is_sil = std::binary_search(silence_phones.begin(),
879  silence_phones.end(),
880  phone),
881  ref_phone_is_sil = std::binary_search(silence_phones.begin(),
882  silence_phones.end(),
883  ref_phone),
884  both_sil = phone_is_sil && ref_phone_is_sil;
885  if (!is_mpfe) { // smbr.
886  int32 pdf = trans.TransitionIdToPdf(arc.ilabel),
887  ref_pdf = trans.TransitionIdToPdf(num_ali[cur_time]);
888  if (!one_silence_class) // old behavior
889  frame_acc = (pdf == ref_pdf && !phone_is_sil) ? 1.0 : 0.0;
890  else
891  frame_acc = (pdf == ref_pdf || both_sil) ? 1.0 : 0.0;
892  } else {
893  if (!one_silence_class) // old behavior
894  frame_acc = (phone == ref_phone && !phone_is_sil) ? 1.0 : 0.0;
895  else
896  frame_acc = (phone == ref_phone || both_sil) ? 1.0 : 0.0;
897  }
898  }
899  double arc_scale = Exp(alpha[s] + arc_like - alpha[arc.nextstate]);
900  alpha_smbr[arc.nextstate] += arc_scale * (alpha_smbr[s] + frame_acc);
901  }
902  Weight f = lat.Final(s);
903  if (f != Weight::Zero()) {
904  double final_like = this_alpha - (f.Value1() + f.Value2());
905  double arc_scale = Exp(final_like - tot_forward_prob);
906  tot_forward_score += arc_scale * alpha_smbr[s];
907  KALDI_ASSERT(state_times[s] == max_time &&
908  "Lattice is inconsistent (final-prob not at max_time)");
909  }
910  }
911  // Second Pass Backward, collect Mpe style posteriors
912  for (StateId s = num_states-1; s >= 0; s--) {
913  for (ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
914  const Arc &arc = aiter.Value();
915  double arc_like = -ConvertToCost(arc.weight),
916  arc_beta = beta[arc.nextstate] + arc_like;
917  double frame_acc = 0.0;
918  int32 transition_id = arc.ilabel;
919  if (arc.ilabel != 0) {
920  int32 cur_time = state_times[s];
921  int32 phone = trans.TransitionIdToPhone(arc.ilabel),
922  ref_phone = trans.TransitionIdToPhone(num_ali[cur_time]);
923  bool phone_is_sil = std::binary_search(silence_phones.begin(),
924  silence_phones.end(), phone),
925  ref_phone_is_sil = std::binary_search(silence_phones.begin(),
926  silence_phones.end(),
927  ref_phone),
928  both_sil = phone_is_sil && ref_phone_is_sil;
929  if (!is_mpfe) { // smbr.
930  int32 pdf = trans.TransitionIdToPdf(arc.ilabel),
931  ref_pdf = trans.TransitionIdToPdf(num_ali[cur_time]);
932  if (!one_silence_class) // old behavior
933  frame_acc = (pdf == ref_pdf && !phone_is_sil) ? 1.0 : 0.0;
934  else
935  frame_acc = (pdf == ref_pdf || both_sil) ? 1.0 : 0.0;
936  } else {
937  if (!one_silence_class) // old behavior
938  frame_acc = (phone == ref_phone && !phone_is_sil) ? 1.0 : 0.0;
939  else
940  frame_acc = (phone == ref_phone || both_sil) ? 1.0 : 0.0;
941  }
942  }
943  double arc_scale = Exp(beta[arc.nextstate] + arc_like - beta[s]);
944  // check arc_scale NAN,
945  // this is to prevent partial paths in Lattices
946  // i.e., paths don't survive to the final state
947  if (KALDI_ISNAN(arc_scale)) arc_scale = 0;
948  beta_smbr[s] += arc_scale * (beta_smbr[arc.nextstate] + frame_acc);
949 
950  if (transition_id != 0) { // Arc has a transition-id on it [not epsilon]
951  double posterior = Exp(alpha[s] + arc_beta - tot_forward_prob);
952  double acc_diff = alpha_smbr[s] + frame_acc + beta_smbr[arc.nextstate]
953  - tot_forward_score;
954  double posterior_smbr = posterior * acc_diff;
955  (*post)[state_times[s]].push_back(std::make_pair(transition_id,
956  static_cast<BaseFloat>(posterior_smbr)));
957  }
958  }
959  }
960 
961  //Second Pass Forward Backward check
962  double tot_backward_score = beta_smbr[0]; // Initial state id == 0
963  // may loose the condition somehow here 1e-5/1e-4
964  if (!ApproxEqual(tot_forward_score, tot_backward_score, 1e-4)) {
965  KALDI_ERR << "Total forward score over lattice = " << tot_forward_score
966  << ", while total backward score = " << tot_backward_score;
967  }
968 
969  // Output the computed posteriors
970  for (int32 t = 0; t < max_time; t++)
971  MergePairVectorSumming(&((*post)[t]));
972  return tot_forward_score;
973 }
fst::StdArc::StateId StateId
double Exp(double x)
Definition: kaldi-math.h:83
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
bool ApproxEqual(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2, float delta=kDelta)
double ConvertToCost(const LatticeWeightTpl< Float > &w)
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::StdArc::Weight Weight
double LogAdd(double x, double y)
Definition: kaldi-math.h:184
#define KALDI_ISNAN
Definition: kaldi-math.h:72
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void MergePairVectorSumming(std::vector< std::pair< I, F > > *vec)
For a vector of pair<I, F> where I is an integer and F a floating-point or integer type...
Definition: stl-utils.h:288
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ LatticeStateTimes() [1/2]

int32 kaldi::LatticeStateTimes ( const Lattice lat,
std::vector< int32 > *  times 
)

This function iterates over the states of a topologically sorted lattice and counts the time instance corresponding to each state.

The times are returned in a vector of integers 'times' which is resized to have a size equal to the number of states in the lattice. The function also returns the maximum time in the lattice (this will equal the number of frames in the file).

Definition at line 78 of file lattice-functions.cc.

References KALDI_ASSERT, and KALDI_ERR.

Referenced by DiscriminativeSupervision::Check(), DiscriminativeExampleSplitter::CollapseTransitionIds(), ComputeAcousticScoresMap(), DiscriminativeExampleSplitter::ComputeFrameInfo(), DiscriminativeSupervisionSplitter::ComputeLatticeScores(), DiscriminativeSupervisionSplitter::CreateRangeLattice(), GetLatticeTimeSpan(), LatticeActivePhones(), LatticeBoost(), NnetDiscriminativeUpdater::LatticeComputations(), LatticeForwardBackward(), LatticeForwardBackwardMpeVariants(), DiscriminativeComputation::LookupNnetOutput(), main(), DiscriminativeSupervisionSplitter::PrepareLattice(), ReplaceAcousticScoresFromMap(), and RescoreLattice().

78  {
79  if (!lat.Properties(fst::kTopSorted, true))
80  KALDI_ERR << "Input lattice must be topologically sorted.";
81  KALDI_ASSERT(lat.Start() == 0);
82  int32 num_states = lat.NumStates();
83  times->clear();
84  times->resize(num_states, -1);
85  (*times)[0] = 0;
86  for (int32 state = 0; state < num_states; state++) {
87  int32 cur_time = (*times)[state];
88  for (fst::ArcIterator<Lattice> aiter(lat, state); !aiter.Done();
89  aiter.Next()) {
90  const LatticeArc &arc = aiter.Value();
91 
92  if (arc.ilabel != 0) { // Non-epsilon input label on arc
93  // next time instance
94  if ((*times)[arc.nextstate] == -1) {
95  (*times)[arc.nextstate] = cur_time + 1;
96  } else {
97  KALDI_ASSERT((*times)[arc.nextstate] == cur_time + 1);
98  }
99  } else { // epsilon input label on arc
100  // Same time instance
101  if ((*times)[arc.nextstate] == -1)
102  (*times)[arc.nextstate] = cur_time;
103  else
104  KALDI_ASSERT((*times)[arc.nextstate] == cur_time);
105  }
106  }
107  }
108  return (*std::max_element(times->begin(), times->end()));
109 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ LatticeStateTimes() [2/2]

int32 kaldi::LatticeStateTimes ( const Lattice lat,
std::vector< int32 > *  times 
)

This function iterates over the states of a topologically sorted lattice and counts the time instance corresponding to each state.

The times are returned in a vector of integers 'times' which is resized to have a size equal to the number of states in the lattice. The function also returns the maximum time in the lattice (this will equal the number of frames in the file).

Definition at line 78 of file lattice-functions.cc.

References KALDI_ASSERT, and KALDI_ERR.

Referenced by DiscriminativeSupervision::Check(), DiscriminativeExampleSplitter::CollapseTransitionIds(), ComputeAcousticScoresMap(), DiscriminativeExampleSplitter::ComputeFrameInfo(), DiscriminativeSupervisionSplitter::ComputeLatticeScores(), DiscriminativeSupervisionSplitter::CreateRangeLattice(), GetLatticeTimeSpan(), LatticeActivePhones(), LatticeBoost(), NnetDiscriminativeUpdater::LatticeComputations(), LatticeForwardBackward(), LatticeForwardBackwardMpeVariants(), DiscriminativeComputation::LookupNnetOutput(), main(), DiscriminativeSupervisionSplitter::PrepareLattice(), ReplaceAcousticScoresFromMap(), and RescoreLattice().

78  {
79  if (!lat.Properties(fst::kTopSorted, true))
80  KALDI_ERR << "Input lattice must be topologically sorted.";
81  KALDI_ASSERT(lat.Start() == 0);
82  int32 num_states = lat.NumStates();
83  times->clear();
84  times->resize(num_states, -1);
85  (*times)[0] = 0;
86  for (int32 state = 0; state < num_states; state++) {
87  int32 cur_time = (*times)[state];
88  for (fst::ArcIterator<Lattice> aiter(lat, state); !aiter.Done();
89  aiter.Next()) {
90  const LatticeArc &arc = aiter.Value();
91 
92  if (arc.ilabel != 0) { // Non-epsilon input label on arc
93  // next time instance
94  if ((*times)[arc.nextstate] == -1) {
95  (*times)[arc.nextstate] = cur_time + 1;
96  } else {
97  KALDI_ASSERT((*times)[arc.nextstate] == cur_time + 1);
98  }
99  } else { // epsilon input label on arc
100  // Same time instance
101  if ((*times)[arc.nextstate] == -1)
102  (*times)[arc.nextstate] = cur_time;
103  else
104  KALDI_ASSERT((*times)[arc.nextstate] == cur_time);
105  }
106  }
107  }
108  return (*std::max_element(times->begin(), times->end()));
109 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ LatticeToString() [1/2]

std::string kaldi::LatticeToString ( const Lattice lat,
const fst::SymbolTable &  word_syms 
)

Definition at line 70 of file online2-tcp-nnet3-decode-faster.cc.

References fst::GetLinearSymbolSequence(), rnnlm::i, KALDI_WARN, and words.

Referenced by LatticeToString(), and main().

70  {
71  LatticeWeight weight;
72  std::vector<int32> alignment;
73  std::vector<int32> words;
74  GetLinearSymbolSequence(lat, &alignment, &words, &weight);
75 
76  std::ostringstream msg;
77  for (size_t i = 0; i < words.size(); i++) {
78  std::string s = word_syms.Find(words[i]);
79  if (s.empty()) {
80  KALDI_WARN << "Word-id " << words[i] << " not in symbol table.";
81  msg << "<#" << std::to_string(i) << "> ";
82  } else
83  msg << s << " ";
84  }
85  return msg.str();
86 }
int32 words[kMaxOrder]
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ LatticeToString() [2/2]

std::string kaldi::LatticeToString ( const CompactLattice clat,
const fst::SymbolTable &  word_syms 
)

Definition at line 102 of file online2-tcp-nnet3-decode-faster.cc.

References CompactLatticeShortestPath(), fst::ConvertLattice(), KALDI_WARN, and LatticeToString().

102  {
103  if (clat.NumStates() == 0) {
104  KALDI_WARN << "Empty lattice.";
105  return "";
106  }
107  CompactLattice best_path_clat;
108  CompactLatticeShortestPath(clat, &best_path_clat);
109 
110  Lattice best_path_lat;
111  ConvertLattice(best_path_clat, &best_path_lat);
112  return LatticeToString(best_path_lat, word_syms);
113 }
std::string LatticeToString(const CompactLattice &clat, const fst::SymbolTable &word_syms)
void CompactLatticeShortestPath(const CompactLattice &clat, CompactLattice *shortest_path)
A form of the shortest-path/best-path algorithm that&#39;s specially coded for CompactLattice.
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46

◆ Lcm()

I kaldi::Lcm ( m,
n 
)

Returns the least common multiple of two integers.

Will crash unless the inputs are positive.

Definition at line 318 of file kaldi-math.h.

References Gcd(), and KALDI_ASSERT.

Referenced by NnetSimpleComputationOptions::CheckAndFixConfigs(), DecodableNnetSimple::CheckAndFixConfigs(), LinearResample::GetNumOutputSamples(), SwitchingForwardingDescriptor::Modulus(), Nnet::Modulus(), BinarySumDescriptor::Modulus(), Descriptor::Modulus(), and UnitTestGcdLcmTpl().

318  {
319  KALDI_ASSERT(m > 0 && n > 0);
320  I gcd = Gcd(m, n);
321  return gcd * (m/gcd) * (n/gcd);
322 }
I Gcd(I m, I n)
Definition: kaldi-math.h:297
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ LevenshteinAlignment()

int32 LevenshteinAlignment ( const std::vector< T > &  a,
const std::vector< T > &  b,
eps_symbol,
std::vector< std::pair< T, T > > *  output 
)

Definition at line 130 of file edit-distance-inl.h.

References rnnlm::i, KALDI_ASSERT, rnnlm::n, and ReverseVector().

Referenced by main(), and TestLevenshteinAlignment().

133  {
134  // Check inputs:
135  {
136  KALDI_ASSERT(output != NULL);
137  for (size_t i = 0; i < a.size(); i++) KALDI_ASSERT(a[i] != eps_symbol);
138  for (size_t i = 0; i < b.size(); i++) KALDI_ASSERT(b[i] != eps_symbol);
139  }
140  output->clear();
141  // This is very memory-inefficiently implemented using a vector of vectors.
142  size_t M = a.size(), N = b.size();
143  size_t m, n;
144  std::vector<std::vector<int32> > e(M+1);
145  for (m = 0; m <=M; m++) e[m].resize(N+1);
146  for (n = 0; n <= N; n++)
147  e[0][n] = n;
148  for (m = 1; m <= M; m++) {
149  e[m][0] = e[m-1][0] + 1;
150  for (n = 1; n <= N; n++) {
151  int32 sub_or_ok = e[m-1][n-1] + (a[m-1] == b[n-1] ? 0 : 1);
152  int32 del = e[m-1][n] + 1; // assumes a == ref, b == hyp.
153  int32 ins = e[m][n-1] + 1;
154  e[m][n] = std::min(sub_or_ok, std::min(del, ins));
155  }
156  }
157  // get time-reversed output first: trace back.
158  m = M;
159  n = N;
160  while (m != 0 || n != 0) {
161  size_t last_m, last_n;
162  if (m == 0) {
163  last_m = m;
164  last_n = n-1;
165  } else if (n == 0) {
166  last_m = m-1;
167  last_n = n;
168  } else {
169  int32 sub_or_ok = e[m-1][n-1] + (a[m-1] == b[n-1] ? 0 : 1);
170  int32 del = e[m-1][n] + 1; // assumes a == ref, b == hyp.
171  int32 ins = e[m][n-1] + 1;
172  // choose sub_or_ok if all else equal.
173  if (sub_or_ok <= std::min(del, ins)) {
174  last_m = m-1;
175  last_n = n-1;
176  } else {
177  if (del <= ins) { // choose del over ins if equal.
178  last_m = m-1;
179  last_n = n;
180  } else {
181  last_m = m;
182  last_n = n-1;
183  }
184  }
185  }
186  T a_sym, b_sym;
187  a_sym = (last_m == m ? eps_symbol : a[last_m]);
188  b_sym = (last_n == n ? eps_symbol : b[last_n]);
189  output->push_back(std::make_pair(a_sym, b_sym));
190  m = last_m;
191  n = last_n;
192  }
193  ReverseVector(output);
194  return e[M][N];
195 }
kaldi::int32 int32
struct rnnlm::@11::@12 n
void ReverseVector(std::vector< T > *vec)
Reverses the contents of a vector.
Definition: stl-utils.h:264
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ LevenshteinEditDistance() [1/2]

int32 LevenshteinEditDistance ( const std::vector< T > &  a,
const std::vector< T > &  b 
)

Definition at line 30 of file edit-distance-inl.h.

References rnnlm::i, and rnnlm::n.

Referenced by GetEditsDualHyp(), GetEditsSingleHyp(), main(), TestEditDistance(), TestEditDistance2(), TestEditDistance2String(), TestEditDistanceString(), and TestLevenshteinAlignment().

31  {
32  // Algorithm:
33  // write A and B for the sequences, with elements a_0 ..
34  // let |A| = M and |B| = N be the lengths, and have
35  // elements a_0 ... a_{M-1} and b_0 ... b_{N-1}.
36  // We are computing the recursion
37  // E(m, n) = min( E(m-1, n-1) + (1-delta(a_{m-1}, b_{n-1})),
38  // E(m-1, n) + 1,
39  // E(m, n-1) + 1).
40  // where E(m, n) is defined for m = 0..M and n = 0..N and out-of-
41  // bounds quantities are considered to be infinity (i.e. the
42  // recursion does not visit them).
43 
44  // We do this computation using a vector e of size N+1.
45  // The outer iterations range over m = 0..M.
46 
47  int M = a.size(), N = b.size();
48  std::vector<int32> e(N+1);
49  std::vector<int32> e_tmp(N+1);
50  // initialize e.
51  for (size_t i = 0; i < e.size(); i++)
52  e[i] = i;
53  for (int32 m = 1; m <= M; m++) {
54  // computing E(m, .) from E(m-1, .)
55  // handle special case n = 0:
56  e_tmp[0] = e[0] + 1;
57 
58  for (int32 n = 1; n <= N; n++) {
59  int32 term1 = e[n-1] + (a[m-1] == b[n-1] ? 0 : 1);
60  int32 term2 = e[n] + 1;
61  int32 term3 = e_tmp[n-1] + 1;
62  e_tmp[n] = std::min(term1, std::min(term2, term3));
63  }
64  e = e_tmp;
65  }
66  return e.back();
67 }
kaldi::int32 int32
struct rnnlm::@11::@12 n

◆ LevenshteinEditDistance() [2/2]

int32 LevenshteinEditDistance ( const std::vector< T > &  ref,
const std::vector< T > &  hyp,
int32 ins,
int32 del,
int32 sub 
)

Definition at line 79 of file edit-distance-inl.h.

References rnnlm::i.

81  {
82  // temp sequence to remember error type and stats.
83  std::vector<error_stats> e(ref.size()+1);
84  std::vector<error_stats> cur_e(ref.size()+1);
85  // initialize the first hypothesis aligned to the reference at each
86  // position:[hyp_index =0][ref_index]
87  for (size_t i =0; i < e.size(); i ++) {
88  e[i].ins_num = 0;
89  e[i].sub_num = 0;
90  e[i].del_num = i;
91  e[i].total_cost = i;
92  }
93 
94  // for other alignments
95  for (size_t hyp_index = 1; hyp_index <= hyp.size(); hyp_index ++) {
96  cur_e[0] = e[0];
97  cur_e[0].ins_num++;
98  cur_e[0].total_cost++;
99  for (size_t ref_index = 1; ref_index <= ref.size(); ref_index ++) {
100  int32 ins_err = e[ref_index].total_cost + 1;
101  int32 del_err = cur_e[ref_index-1].total_cost + 1;
102  int32 sub_err = e[ref_index-1].total_cost;
103  if (hyp[hyp_index-1] != ref[ref_index-1])
104  sub_err++;
105 
106  if (sub_err < ins_err && sub_err < del_err) {
107  cur_e[ref_index] =e[ref_index-1];
108  if (hyp[hyp_index-1] != ref[ref_index-1])
109  cur_e[ref_index].sub_num++; // substitution error should be increased
110  cur_e[ref_index].total_cost = sub_err;
111  } else if (del_err < ins_err) {
112  cur_e[ref_index] = cur_e[ref_index-1];
113  cur_e[ref_index].total_cost = del_err;
114  cur_e[ref_index].del_num++; // deletion number is increased.
115  } else {
116  cur_e[ref_index] = e[ref_index];
117  cur_e[ref_index].total_cost = ins_err;
118  cur_e[ref_index].ins_num++; // insertion number is increased.
119  }
120  }
121  e = cur_e; // alternate for the next recursion.
122  }
123  size_t ref_index = e.size()-1;
124  *ins = e[ref_index].ins_num, *del =
125  e[ref_index].del_num, *sub = e[ref_index].sub_num;
126  return e[ref_index].total_cost;
127 }
kaldi::int32 int32

◆ LinearCgd< double >()

template int32 kaldi::LinearCgd< double > ( const LinearCgdOptions opts,
const SpMatrix< double > &  A,
const VectorBase< double > &  b,
VectorBase< double > *  x 
)

Referenced by LinearCgd().

◆ LinearCgd< float >()

template int32 kaldi::LinearCgd< float > ( const LinearCgdOptions opts,
const SpMatrix< float > &  A,
const VectorBase< float > &  b,
VectorBase< float > *  x 
)

Referenced by LinearCgd().

◆ LinearlyInterpolatePitch()

void kaldi::LinearlyInterpolatePitch ( Matrix< BaseFloat > *  mat)

Definition at line 252 of file interpolate-pitch.cc.

References rnnlm::i, and MatrixBase< Real >::NumRows().

Referenced by main().

252  {
253  int32 num_frames = mat->NumRows();
254  int i = 0;
255  Matrix<BaseFloat> &features = *mat;
256  while (i < num_frames) {
257  if(features(i, 1) == 0.0) {
258  int start = i - 1;
259  int end = i;
260  while( (features(end, 1)) == 0.0 && (end < num_frames))
261  end++;
262  BaseFloat end_value = -1, start_value = -1;
263  if (end < num_frames) end_value = features(end, 1);
264  if (start > 0) start_value = features(start, 1);
265 
266  if (start_value < 0 && end_value < 0) {
267  // the whole file is unvoiced -> just put an arbitrary value,
268  // it will all be normalized out anyway.
269  start_value = 1.0;
270  end_value = 1.0;
271  }
272  // If we don't have a value for one end of the range, i.e. at the start or
273  // end, set it to 0.9 times the pitch value that we have at the other end
274  // of the range. The reason we don't set it to that value itself, is that
275  // then over this segment we would have zero time-derivative, so if we
276  // took time derivatives we would have an artificial spike at zero.
277  if (start_value < 0.0) start_value = 0.9 * end_value;
278  if (end_value < 0.0) end_value = 0.9 * start_value;
279 
280  for(int k = start + 1; k < end; k++)
281  features(k, 1) = start_value +
282  (end_value - start_value) / (end - start) * (k - start);
283  i = end;
284  }
285  i++;
286  }
287 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ Log() [1/2]

double kaldi::Log ( double  x)
inline

Definition at line 100 of file kaldi-math.h.

Referenced by VectorBase< float >::ApplyLog(), VectorBase< float >::ApplyLogAndCopy(), VectorBase< float >::ApplyLogSoftMax(), VectorBase< float >::ApplySoftMax(), MatrixBase< float >::ApplySoftMax(), CompactLatticeNormalize(), CuMatrix< float >::CompObjfAndDeriv(), AmSgmm2::ComponentPosteriors(), SpectrogramComputer::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), PlpComputer::Compute(), PitchFrameInfo::ComputeBacktraces(), TransitionModel::ComputeDerivedOfProbs(), FullGmm::ComputeGconsts(), ComputeGconsts(), DiagGmm::ComputeGconsts(), NnetComputer::ComputeLastLayerDeriv(), ComputeLpc(), MleAmSgmm2Updater::ComputeMPrior(), AmSgmm2::ComputeNormalizersInternal(), DiscriminativeComputation::ConvertAnswersToLogLike(), CuVectorUnitTestApplyLog(), CuMatrixBase< float >::DiffXent(), DoRescalingUpdate(), EBWUpdateGaussian(), FbankComputer::FbankComputer(), FmllrInnerUpdate(), GetHmmAsFsa(), GetHmmAsFsaSimple(), GetLogLikeTest(), LogisticRegression::GetObjfAndGrad(), OnlineProcessPitch::GetRawLogPitchFeature(), Rbm::InitData(), TransitionModel::InitializeProbs(), SpMatrix< float >::Invert(), MatrixBase< float >::Invert(), KaldiAssertFailure_(), kaldi::nnet2::KlDivergence(), kaldi::nnet3::KlDivergence(), NnetDiscriminativeUpdater::LatticeComputations(), MatrixBase< float >::Log(), Log1p(), AmSgmm2::LogLikelihood(), SpMatrix< float >::LogPosDefDet(), LogSub(), VectorBase< float >::LogSumExp(), MatrixBase< float >::LogSumExp(), main(), TransitionModel::MapUpdate(), TransitionModel::MapUpdateShared(), DiagGmm::Merge(), DiagGmm::merged_components_logdet(), MfccComputer::MfccComputer(), SoftmaxComponent::MixUp(), TransitionModel::MleUpdate(), TransitionModel::MleUpdateShared(), PushSpecialClass::ModifyFst(), PitchInterpolator::MultiplyObsProb(), OnlinePaSource::OnlinePaSource(), PlpComputer::PlpComputer(), ProcessPovFeatures(), ProcessWindow(), LogSoftmaxComponent::Propagate(), RandGauss(), SpectrogramComputer::SpectrogramComputer(), VectorBase< float >::SumLog(), TakeLogOfPitch(), PushSpecialClass::TestAccuracy(), UnitTestCuDiffXent(), UnitTestDeterminantSign(), UnitTestDiagGmm(), UnitTestEig(), UnitTestFullGmm(), UnitTestLogAddSub(), UnitTestLogSpeed(), UnitTestTrain(), MlltAccs::Update(), OnlineProcessPitch::UpdateNormalizationStats(), MleAmSgmm2Updater::UpdateSubstateWeights(), and VectorToPosteriorEntry().

100 { return log(x); }

◆ Log() [2/2]

float kaldi::Log ( float  x)
inline

Definition at line 101 of file kaldi-math.h.

101 { return logf(x); }

◆ Log1p() [1/2]

double kaldi::Log1p ( double  x)
inline

Definition at line 104 of file kaldi-math.h.

Referenced by Log1p(), LogAdd(), MatrixBase< float >::SoftHinge(), and UnitTestSoftHinge().

104 { return log1p(x); }

◆ Log1p() [2/2]

float kaldi::Log1p ( float  x)
inline

Definition at line 105 of file kaldi-math.h.

References Log(), and Log1p().

105 { return log1pf(x); }

◆ LogAdd() [1/2]

double kaldi::LogAdd ( double  x,
double  y 
)
inline

Definition at line 184 of file kaldi-math.h.

References Exp(), and Log1p().

Referenced by ComputeCompactLatticeAlphas(), ComputeCompactLatticeBetas(), MinimumBayesRisk::EditDistance(), FullGmm::GaussianSelection(), DiagGmm::GaussianSelection(), FullGmm::GaussianSelectionPreselect(), DiagGmm::GaussianSelectionPreselect(), GetLogLikeTest(), LogisticRegression::GetLogPosteriors(), fst::InputDeterminizeSingleState(), GrammarFstPreparer::InsertEpsilonsForState(), LatticeForwardBackward(), LatticeForwardBackwardMpeVariants(), LogAddOrMax(), and UnitTestLogAddSub().

184  {
185  double diff;
186 
187  if (x < y) {
188  diff = x - y;
189  x = y;
190  } else {
191  diff = y - x;
192  }
193  // diff is negative. x is now the larger one.
194 
195  if (diff >= kMinLogDiffDouble) {
196  double res;
197  res = x + Log1p(Exp(diff));
198  return res;
199  } else {
200  return x; // return the larger one.
201  }
202 }
float Log1p(float x)
Definition: kaldi-math.h:105
float Exp(float x)
Definition: kaldi-math.h:85
static const double kMinLogDiffDouble
Definition: kaldi-math.h:124

◆ LogAdd() [2/2]

float kaldi::LogAdd ( float  x,
float  y 
)
inline

Definition at line 206 of file kaldi-math.h.

References Exp(), and Log1p().

206  {
207  float diff;
208 
209  if (x < y) {
210  diff = x - y;
211  x = y;
212  } else {
213  diff = y - x;
214  }
215  // diff is negative. x is now the larger one.
216 
217  if (diff >= kMinLogDiffFloat) {
218  float res;
219  res = x + Log1p(Exp(diff));
220  return res;
221  } else {
222  return x; // return the larger one.
223  }
224 }
float Log1p(float x)
Definition: kaldi-math.h:105
float Exp(float x)
Definition: kaldi-math.h:85
static const float kMinLogDiffFloat
Definition: kaldi-math.h:125

◆ LogAddOrMax()

static double kaldi::LogAddOrMax ( bool  viterbi,
double  a,
double  b 
)
inlinestatic

Definition at line 444 of file lattice-functions.cc.

References LogAdd().

Referenced by ComputeLatticeAlphasAndBetas().

444  {
445  if (viterbi)
446  return std::max(a, b);
447  else
448  return LogAdd(a, b);
449 }
double LogAdd(double x, double y)
Definition: kaldi-math.h:184

◆ LogSub() [1/2]

double kaldi::LogSub ( double  x,
double  y 
)
inline

Definition at line 228 of file kaldi-math.h.

References Exp(), KALDI_ERR, KALDI_ISNAN, kLogZeroDouble, and Log().

Referenced by UnitTestLogAddSub().

228  {
229  if (y >= x) { // Throws exception if y>=x.
230  if (y == x)
231  return kLogZeroDouble;
232  else
233  KALDI_ERR << "Cannot subtract a larger from a smaller number.";
234  }
235 
236  double diff = y - x; // Will be negative.
237  double res = x + Log(1.0 - Exp(diff));
238 
239  // res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision
240  if (KALDI_ISNAN(res))
241  return kLogZeroDouble;
242  return res;
243 }
float Exp(float x)
Definition: kaldi-math.h:85
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ISNAN
Definition: kaldi-math.h:72
float Log(float x)
Definition: kaldi-math.h:101
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ LogSub() [2/2]

float kaldi::LogSub ( float  x,
float  y 
)
inline

Definition at line 247 of file kaldi-math.h.

References Exp(), KALDI_ERR, KALDI_ISNAN, kLogZeroDouble, kLogZeroFloat, and Log().

247  {
248  if (y >= x) { // Throws exception if y>=x.
249  if (y == x)
250  return kLogZeroDouble;
251  else
252  KALDI_ERR << "Cannot subtract a larger from a smaller number.";
253  }
254 
255  float diff = y - x; // Will be negative.
256  float res = x + Log(1.0f - Exp(diff));
257 
258  // res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision
259  if (KALDI_ISNAN(res))
260  return kLogZeroFloat;
261  return res;
262 }
float Exp(float x)
Definition: kaldi-math.h:85
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ISNAN
Definition: kaldi-math.h:72
const float kLogZeroFloat
Definition: kaldi-math.h:128
float Log(float x)
Definition: kaldi-math.h:101
const double kLogZeroDouble
Definition: kaldi-math.h:129

◆ LongestSentenceLength() [1/2]

int32 LongestSentenceLength ( const Lattice lat)

This function returns the number of words in the longest sentence in a CompactLattice (i.e.

the the maximum of any path, of the count of olabels on that path).

Definition at line 1452 of file lattice-functions.cc.

References KALDI_ASSERT, KALDI_ERR, and LatticeWeightTpl< BaseFloat >::Zero().

Referenced by LongestSentenceLength(), and SentenceLevelConfidence().

1452  {
1453  typedef Lattice::Arc Arc;
1454  typedef Arc::Label Label;
1455  typedef Arc::StateId StateId;
1456 
1457  if (lat.Properties(fst::kTopSorted, true) == 0) {
1458  Lattice lat_copy(lat);
1459  if (!TopSort(&lat_copy))
1460  KALDI_ERR << "Was not able to topologically sort lattice (cycles found?)";
1461  return LongestSentenceLength(lat_copy);
1462  }
1463  std::vector<int32> max_length(lat.NumStates(), 0);
1464  int32 lattice_max_length = 0;
1465  for (StateId s = 0; s < lat.NumStates(); s++) {
1466  int32 this_max_length = max_length[s];
1467  for (fst::ArcIterator<Lattice> aiter(lat, s); !aiter.Done(); aiter.Next()) {
1468  const Arc &arc = aiter.Value();
1469  bool arc_has_word = (arc.olabel != 0);
1470  StateId nextstate = arc.nextstate;
1471  KALDI_ASSERT(static_cast<size_t>(nextstate) < max_length.size());
1472  if (arc_has_word) {
1473  // A lattice should ideally not have cycles anyway; a cycle with a word
1474  // on is something very bad.
1475  KALDI_ASSERT(nextstate > s && "Lattice has cycles with words on.");
1476  max_length[nextstate] = std::max(max_length[nextstate],
1477  this_max_length + 1);
1478  } else {
1479  max_length[nextstate] = std::max(max_length[nextstate],
1480  this_max_length);
1481  }
1482  }
1483  if (lat.Final(s) != LatticeWeight::Zero())
1484  lattice_max_length = std::max(lattice_max_length, max_length[s]);
1485  }
1486  return lattice_max_length;
1487 }
fst::StdArc::StateId StateId
kaldi::int32 int32
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 LongestSentenceLength(const CompactLattice &clat)
This function returns the number of words in the longest sentence in a CompactLattice, i.e.
fst::StdArc::Label Label
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ LongestSentenceLength() [2/2]

int32 LongestSentenceLength ( const CompactLattice lat)

This function returns the number of words in the longest sentence in a CompactLattice, i.e.

the the maximum of any path, of the count of labels on that path... note, in CompactLattice, the ilabels and olabels are identical because it is an acceptor.

Definition at line 1489 of file lattice-functions.cc.

References KALDI_ASSERT, KALDI_ERR, LongestSentenceLength(), and CompactLatticeWeightTpl< WeightType, IntType >::Zero().

1489  {
1490  typedef CompactLattice::Arc Arc;
1491  typedef Arc::Label Label;
1492  typedef Arc::StateId StateId;
1493 
1494  if (clat.Properties(fst::kTopSorted, true) == 0) {
1495  CompactLattice clat_copy(clat);
1496  if (!TopSort(&clat_copy))
1497  KALDI_ERR << "Was not able to topologically sort lattice (cycles found?)";
1498  return LongestSentenceLength(clat_copy);
1499  }
1500  std::vector<int32> max_length(clat.NumStates(), 0);
1501  int32 lattice_max_length = 0;
1502  for (StateId s = 0; s < clat.NumStates(); s++) {
1503  int32 this_max_length = max_length[s];
1504  for (fst::ArcIterator<CompactLattice> aiter(clat, s);
1505  !aiter.Done(); aiter.Next()) {
1506  const Arc &arc = aiter.Value();
1507  bool arc_has_word = (arc.ilabel != 0); // note: olabel == ilabel.
1508  // also note: for normal CompactLattice, e.g. as produced by
1509  // determinization, all arcs will have nonzero labels, but the user might
1510  // decide to remplace some of the labels with zero for some reason, and we
1511  // want to support this.
1512  StateId nextstate = arc.nextstate;
1513  KALDI_ASSERT(static_cast<size_t>(nextstate) < max_length.size());
1514  KALDI_ASSERT(nextstate > s && "CompactLattice has cycles");
1515  if (arc_has_word)
1516  max_length[nextstate] = std::max(max_length[nextstate],
1517  this_max_length + 1);
1518  else
1519  max_length[nextstate] = std::max(max_length[nextstate],
1520  this_max_length);
1521  }
1522  if (clat.Final(s) != CompactLatticeWeight::Zero())
1523  lattice_max_length = std::max(lattice_max_length, max_length[s]);
1524  }
1525  return lattice_max_length;
1526 }
fst::StdArc::StateId StateId
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
int32 LongestSentenceLength(const CompactLattice &clat)
This function returns the number of words in the longest sentence in a CompactLattice, i.e.
fst::StdArc::Label Label
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ MachineIsLittleEndian()

int kaldi::MachineIsLittleEndian ( )
inline

Definition at line 83 of file kaldi-utils.h.

References Sleep().

Referenced by SphinxMatrixHolder< kFeatDim >::Read(), ReadHtk(), SphinxMatrixHolder< kFeatDim >::Write(), WriteHtk(), and WriteSphinx().

83  {
84  int check = 1;
85  return (*reinterpret_cast<char*>(&check) != 0);
86 }

◆ MakeEventPair()

std::pair<EventKeyType, EventValueType> kaldi::MakeEventPair ( EventKeyType  k,
EventValueType  v 
)
inline

Definition at line 62 of file event-map.h.

References EventTypeToString(), ReadEventType(), and WriteEventType().

Referenced by ShareEventMapLeaves(), and TestShareEventMapLeaves().

62  {
63  return std::pair<EventKeyType, EventValueType>(k, v);
64 }

◆ MakeLatticeFromLinear()

void kaldi::MakeLatticeFromLinear ( const std::vector< int32 > &  ali,
const std::vector< int32 > &  words,
BaseFloat  lm_cost,
BaseFloat  ac_cost,
Lattice lat_out 
)

Definition at line 27 of file linear-to-nbest.cc.

References rnnlm::i.

Referenced by main().

31  {
33  typedef LatticeArc::Weight Weight;
34  typedef LatticeArc::Label Label;
35  lat_out->DeleteStates();
36  StateId cur_state = lat_out->AddState(); // will be 0.
37  lat_out->SetStart(cur_state);
38  for (size_t i = 0; i < ali.size() || i < words.size(); i++) {
39  Label ilabel = (i < ali.size() ? ali[i] : 0);
40  Label olabel = (i < words.size() ? words[i] : 0);
41  StateId next_state = lat_out->AddState();
42  lat_out->AddArc(cur_state,
43  LatticeArc(ilabel, olabel, Weight::One(), next_state));
44  cur_state = next_state;
45  }
46  lat_out->SetFinal(cur_state, Weight(lm_cost, ac_cost));
47 }
int32 words[kMaxOrder]
fst::StdArc::StateId StateId
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
fst::StdArc::Label Label
fst::StdArc::Weight Weight

◆ MakeTrivialAcceptor()

static fst::VectorFst<fst::StdArc>* kaldi::MakeTrivialAcceptor ( int32  label)
inlinestatic

This utility function, used in GetHTransducer(), creates an FSA (finite state acceptor, i.e.

an FST with ilabels equal to olabels) with a single successful path, with a single label on it.

Definition at line 239 of file hmm-utils.cc.

Referenced by GetHTransducer().

239  {
240  typedef fst::StdArc Arc;
241  typedef Arc::Weight Weight;
242  fst::VectorFst<Arc> *ans = new fst::VectorFst<Arc>;
243  ans->AddState();
244  ans->AddState();
245  ans->SetStart(0);
246  ans->SetFinal(1, Weight::One());
247  ans->AddArc(0, Arc(label, label, Weight::One(), 1));
248  return ans;
249 }
fst::StdArc StdArc
fst::StdArc::Weight Weight

◆ MapAmDiagGmmUpdate()

void MapAmDiagGmmUpdate ( const MapDiagGmmOptions config,
const AccumAmDiagGmm am_diag_gmm_acc,
GmmFlagsType  flags,
AmDiagGmm am_gmm,
BaseFloat obj_change_out,
BaseFloat count_out 
)

Maximum A Posteriori update.

Definition at line 237 of file mle-am-diag-gmm.cc.

References AmDiagGmm::Dim(), AccumAmDiagGmm::Dim(), AccumAmDiagGmm::GetAcc(), AmDiagGmm::GetPdf(), rnnlm::i, KALDI_ASSERT, MapDiagGmmUpdate(), AccumAmDiagGmm::NumAccs(), and AmDiagGmm::NumPdfs().

Referenced by main().

242  {
243  KALDI_ASSERT(am_gmm != NULL && am_diag_gmm_acc.Dim() == am_gmm->Dim() &&
244  am_diag_gmm_acc.NumAccs() == am_gmm->NumPdfs());
245  if (obj_change_out != NULL) *obj_change_out = 0.0;
246  if (count_out != NULL) *count_out = 0.0;
247  BaseFloat tmp_obj_change, tmp_count;
248  BaseFloat *p_obj = (obj_change_out != NULL) ? &tmp_obj_change : NULL,
249  *p_count = (count_out != NULL) ? &tmp_count : NULL;
250 
251  for (int32 i = 0; i < am_diag_gmm_acc.NumAccs(); i++) {
252  MapDiagGmmUpdate(config, am_diag_gmm_acc.GetAcc(i), flags,
253  &(am_gmm->GetPdf(i)), p_obj, p_count);
254 
255  if (obj_change_out != NULL) *obj_change_out += tmp_obj_change;
256  if (count_out != NULL) *count_out += tmp_count;
257  }
258 }
void MapDiagGmmUpdate(const MapDiagGmmOptions &config, const AccumDiagGmm &diag_gmm_acc, GmmFlagsType flags, DiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
Maximum A Posteriori estimation of the model.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ MapCygwinPath()

std::string kaldi::MapCygwinPath ( const std::string &  filename)

Definition at line 82 of file kaldi-cygwin-io-inl.h.

References KALDI_ERR, MapCygwinPathNoTmp(), and prefixp().

Referenced by UnitTestNativeFilename().

82  {
83  // /tmp[/....]
84  if (filename != "/tmp" && !prefixp("/tmp/", filename)) {
85  return MapCygwinPathNoTmp(filename);
86  }
87  char *tmpdir = std::getenv("TMP");
88  if (tmpdir == nullptr)
89  tmpdir = std::getenv("TEMP");
90  if (tmpdir == nullptr) {
91  KALDI_ERR << "Unable to resolve path '" << filename
92  << "' - unable to find temporary directory. Set TMP.";
93  return filename;
94  }
95  // Map the value of tmpdir again, as cygwin environment actually may contain
96  // unix-style paths.
97  return MapCygwinPathNoTmp(std::string(tmpdir) + filename.substr(4));
98 }
#define KALDI_ERR
Definition: kaldi-error.h:147
static std::string MapCygwinPathNoTmp(const std::string &filename)
static bool prefixp(const std::string &pfx, const std::string &str)

◆ MapCygwinPathNoTmp()

static std::string kaldi::MapCygwinPathNoTmp ( const std::string &  filename)
static

Definition at line 52 of file kaldi-cygwin-io-inl.h.

References KALDI_ERR, KALDI_WARN, and prefixp().

Referenced by MapCygwinPath().

52  {
53  // UNC(?), relative, native Windows and empty paths are ok already.
54  if (prefixp("//", filename) || !prefixp("/", filename))
55  return filename;
56 
57  // /dev/...
58  if (filename == "/dev/null")
59  return "\\\\.\\nul";
60  if (prefixp("/dev/", filename)) {
61  KALDI_ERR << "Unable to resolve path '" << filename
62  << "' - only have /dev/null here.";
63  return "\\\\.\\invalid";
64  }
65 
66  // /cygdrive/?[/....]
67  int preflen = cygprefix.size();
68  if (prefixp(cygprefix, filename)
69  && filename.size() >= preflen + 1 && isalpha(filename[preflen])
70  && (filename.size() == preflen + 1 || filename[preflen + 1] == '/')) {
71  return std::string() + filename[preflen] + ':' +
72  (filename.size() > preflen + 1 ? filename.substr(preflen + 1) : "/");
73  }
74 
75  KALDI_WARN << "Unable to resolve path '" << filename
76  << "' - cannot map unix prefix. "
77  << "Will go on, but breakage will likely ensue.";
78  return filename;
79 }
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
static std::string cygprefix("/cygdrive/")
static bool prefixp(const std::string &pfx, const std::string &str)

◆ MapDiagGmmUpdate()

void MapDiagGmmUpdate ( const MapDiagGmmOptions config,
const AccumDiagGmm diag_gmm_acc,
GmmFlagsType  flags,
DiagGmm gmm,
BaseFloat obj_change_out,
BaseFloat count_out 
)

Maximum A Posteriori estimation of the model.

Definition at line 410 of file mle-diag-gmm.cc.

References DiagGmm::ComputeGconsts(), MatrixBase< Real >::CopyRowFromVec(), DiagGmmNormal::CopyToDiagGmm(), DiagGmm::Dim(), AccumDiagGmm::Dim(), AccumDiagGmm::Flags(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, kGmmMeans, kGmmVariances, AccumDiagGmm::mean_accumulator(), MapDiagGmmOptions::mean_tau, DiagGmmNormal::means_, MlObjective(), DiagGmm::NumGauss(), AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy(), MatrixBase< Real >::Row(), VectorBase< Real >::Scale(), AccumDiagGmm::variance_accumulator(), MapDiagGmmOptions::variance_tau, DiagGmmNormal::vars_, MapDiagGmmOptions::weight_tau, and DiagGmmNormal::weights_.

Referenced by MapAmDiagGmmUpdate(), and AccumDiagGmm::Resize().

415  {
416  KALDI_ASSERT(gmm != NULL);
417 
418  if (flags & ~diag_gmm_acc.Flags())
419  KALDI_ERR << "Flags in argument do not match the active accumulators";
420 
421  KALDI_ASSERT(diag_gmm_acc.NumGauss() == gmm->NumGauss() &&
422  diag_gmm_acc.Dim() == gmm->Dim());
423 
424  int32 num_gauss = gmm->NumGauss();
425  double occ_sum = diag_gmm_acc.occupancy().Sum();
426 
427  // remember the old objective function value
428  gmm->ComputeGconsts();
429  BaseFloat obj_old = MlObjective(*gmm, diag_gmm_acc);
430 
431  // allocate the gmm in normal representation; all parameters of this will be
432  // updated, but only the flagged ones will be transferred back to gmm
433  DiagGmmNormal ngmm(*gmm);
434 
435  for (int32 i = 0; i < num_gauss; i++) {
436  double occ = diag_gmm_acc.occupancy()(i);
437 
438  // First update the weight. The weight_tau is a tau for the
439  // whole state.
440  ngmm.weights_(i) = (occ + ngmm.weights_(i) * config.weight_tau) /
441  (occ_sum + config.weight_tau);
442 
443 
444  if (occ > 0.0 && (flags & kGmmMeans)) {
445  // Update the Gaussian mean.
446  Vector<double> old_mean(ngmm.means_.Row(i));
447  Vector<double> mean(diag_gmm_acc.mean_accumulator().Row(i));
448  mean.Scale(1.0 / (occ + config.mean_tau));
449  mean.AddVec(config.mean_tau / (occ + config.mean_tau), old_mean);
450  ngmm.means_.CopyRowFromVec(mean, i);
451  }
452 
453  if (occ > 0.0 && (flags & kGmmVariances)) {
454  // Computing the variance around the updated mean; this is:
455  // E( (x - mu)^2 ) = E( x^2 - 2 x mu + mu^2 ) =
456  // E(x^2) + mu^2 - 2 mu E(x).
457  Vector<double> old_var(ngmm.vars_.Row(i));
458  Vector<double> var(diag_gmm_acc.variance_accumulator().Row(i));
459  var.Scale(1.0 / occ);
460  var.AddVec2(1.0, ngmm.means_.Row(i));
461  SubVector<double> mean_acc(diag_gmm_acc.mean_accumulator(), i),
462  mean(ngmm.means_, i);
463  var.AddVecVec(-2.0 / occ, mean_acc, mean, 1.0);
464  // now var is E(x^2) + m^2 - 2 mu E(x).
465  // Next we do the appropriate weighting usnig the tau value.
466  var.Scale(occ / (config.variance_tau + occ));
467  var.AddVec(config.variance_tau / (config.variance_tau + occ), old_var);
468  // Now write to the model.
469  ngmm.vars_.Row(i).CopyFromVec(var);
470  }
471  }
472 
473  // Copy to natural/exponential representation.
474  ngmm.CopyToDiagGmm(gmm, flags);
475 
476  gmm->ComputeGconsts(); // or MlObjective will fail.
477  BaseFloat obj_new = MlObjective(*gmm, diag_gmm_acc);
478 
479  if (obj_change_out)
480  *obj_change_out = (obj_new - obj_old);
481 
482  if (count_out) *count_out = occ_sum;
483 }
BaseFloat MlObjective(const DiagGmm &gmm, const AccumDiagGmm &diag_gmm_acc)
Calc using the DiagGMM exponential form.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ MapPhone()

static int32 kaldi::MapPhone ( const std::vector< int32 > &  phone_map,
int32  phone 
)
static

Definition at line 26 of file tree-accu.cc.

References KALDI_ERR.

Referenced by AccumulateTreeStats().

27  {
28  if (phone == 0 || phone_map.empty()) return phone;
29  else if (phone < 0 || phone >= phone_map.size()) {
30  KALDI_ERR << "Out-of-range phone " << phone << " bad --phone-map option?";
31  }
32  return phone_map[phone];
33 }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ MapSymbols()

static void kaldi::MapSymbols ( const WordAlignLatticeLexiconInfo lexicon_info,
CompactLattice lat 
)
static

Testing code; map word symbols in the lattice "lat" using the equivalence-classes obtained from the lexicon, using the function EquivalenceClassOf in the lexicon_info object.

Definition at line 912 of file word-align-lattice-lexicon.cc.

References WordAlignLatticeLexiconInfo::EquivalenceClassOf(), and KALDI_ASSERT.

Referenced by TestWordAlignedLattice().

913  {
915  for (StateId s = 0; s < lat->NumStates(); s++) {
916  for (fst::MutableArcIterator<CompactLattice> aiter(lat, s);
917  !aiter.Done(); aiter.Next()) {
918  CompactLatticeArc arc (aiter.Value());
919  KALDI_ASSERT(arc.ilabel == arc.olabel);
920  arc.ilabel = lexicon_info.EquivalenceClassOf(arc.ilabel);
921  arc.olabel = arc.ilabel;
922  aiter.SetValue(arc);
923  }
924  }
925 }
fst::StdArc::StateId StateId
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ MatrixUnitSpeedTest()

static void kaldi::MatrixUnitSpeedTest ( )
static

Definition at line 257 of file matrix-lib-speed-test.cc.

257  {
258  UnitTestRealFftSpeed<Real>();
259  UnitTestSplitRadixRealFftSpeed<Real>();
260  UnitTestSvdSpeed<Real>();
261  UnitTestAddMatMatSpeed<Real>();
262  UnitTestAddRowSumMatSpeed<Real>();
263  UnitTestAddColSumMatSpeed<Real>();
264  UnitTestAddVecToRowsSpeed<Real>();
265  UnitTestAddVecToColsSpeed<Real>();
266 }

◆ MatrixUnitTest()

static void kaldi::MatrixUnitTest ( bool  full_test)
static

Definition at line 4592 of file matrix-lib-test.cc.

References KALDI_LOG, and UnitTestAddVecCross().

4592  {
4593  UnitTestLinearCgd<Real>();
4594  UnitTestGeneralMatrix<BaseFloat>();
4595  UnitTestTridiagonalize<Real>();
4596  UnitTestTridiagonalizeAndQr<Real>();
4597  UnitTestAddMatSmat<Real>();
4598  UnitTestFloorChol<Real>();
4599  UnitTestFloorUnit<Real>();
4600  UnitTestAddMat2Sp<Real>();
4601  UnitTestLbfgs<Real>();
4602  // UnitTestSvdBad<Real>(); // test bug in Jama SVD code.
4603  UnitTestCompressedMatrix<Real>();
4604  UnitTestCompressedMatrix2<Real>();
4605  UnitTestExtractCompressedMatrix<Real>();
4606  UnitTestResize<Real>();
4607  UnitTestResizeCopyDataDifferentStrideType<Real>();
4608  UnitTestNonsymmetricPower<Real>();
4609  UnitTestEigSymmetric<Real>();
4610  KALDI_LOG << " Point A";
4611  UnitTestComplexPower<Real>();
4612  UnitTestEig<Real>();
4613  UnitTestEigSp<Real>();
4614  // commenting these out for now-- they test the speed, but take a while.
4615  // UnitTestSplitRadixRealFftSpeed<Real>();
4616  // UnitTestRealFftSpeed<Real>(); // won't exit!/
4617  UnitTestComplexFt<Real>();
4618  KALDI_LOG << " Point B";
4619  UnitTestComplexFft2<Real>();
4620  UnitTestComplexFft<Real>();
4621  UnitTestSplitRadixComplexFft<Real>();
4622  UnitTestSplitRadixComplexFft2<Real>();
4623  UnitTestDct<Real>();
4624  UnitTestRealFft<Real>();
4625  KALDI_LOG << " Point C";
4626  UnitTestSplitRadixRealFft<Real>();
4627  UnitTestSvd<Real>();
4628  UnitTestSvdNodestroy<Real>();
4629  UnitTestSvdJustvec<Real>();
4630  UnitTestSpAddDiagVec<Real, float>();
4631  UnitTestSpAddDiagVec<Real, double>();
4632  UnitTestSpAddVecVec<Real>();
4633  UnitTestSpInvert<Real>();
4634  KALDI_LOG << " Point D";
4635  UnitTestTpInvert<Real>();
4636  UnitTestIo<Real>();
4637  UnitTestIoCross<Real>();
4638  UnitTestHtkIo<Real>();
4639  UnitTestScale<Real>();
4640  UnitTestTrace<Real>();
4641  KALDI_LOG << " Point E";
4642  CholeskyUnitTestTr<Real>();
4643  UnitTestAxpy<Real>();
4644  UnitTestSimple<Real>();
4645  UnitTestMmul<Real>();
4646  UnitTestMmulSym<Real>();
4647  UnitTestVecmul<Real>();
4648  UnitTestInverse<Real>();
4649  UnitTestMulElements<Real>();
4650  UnitTestDotprod<Real>();
4651  // UnitTestSvdVariants<Real>();
4652  UnitTestPower<Real>();
4653  UnitTestPowerAbs<Real>();
4654  UnitTestHeaviside<Real>();
4655  UnitTestCopySp<Real>();
4656  UnitTestDeterminant<Real>();
4657  KALDI_LOG << " Point F";
4658  UnitTestDeterminantSign<Real>();
4659  UnitTestSger<Real>();
4660  UnitTestAddOuterProductPlusMinus<Real>();
4661  UnitTestTraceProduct<Real>();
4662  UnitTestTransposeScatter<Real>();
4663  UnitTestRankNUpdate<Real>();
4664  UnitTestSpVec<Real>();
4665  UnitTestLimitCondInvert<Real>();
4666  KALDI_LOG << " Point G";
4667  UnitTestLimitCond<Real>();
4668  UnitTestMat2Vec<Real>();
4669  UnitTestFloorCeiling<Real>();
4670  KALDI_LOG << " Point H";
4671  UnitTestCopyRowsAndCols<Real>();
4672  UnitTestSpliceRows<Real>();
4673  UnitTestAddSp<Real>();
4674  UnitTestRemoveRow<Real>();
4675  UnitTestRow<Real>();
4676  UnitTestSubvector<Real>();
4677  UnitTestRange<Real>();
4678  UnitTestSimpleForVec<Real>();
4679  UnitTestSetRandn<Real>();
4680  UnitTestSetRandUniform<Real>();
4681  UnitTestVectorMax<Real>();
4682  UnitTestVectorMin<Real>();
4683  UnitTestSimpleForMat<Real>();
4684  UnitTestTanh<Real>();
4685  UnitTestSigmoid<Real>();
4686  UnitTestSoftHinge<Real>();
4687  UnitTestNorm<Real>();
4688  UnitTestCopyCols<Real>();
4689  UnitTestCopyRows<Real>();
4690  UnitTestCopyToRows<Real>();
4691  UnitTestAddRows<Real>();
4692  UnitTestAddToRows<Real>();
4693  UnitTestMul<Real>();
4694  KALDI_LOG << " Point I";
4695  UnitTestSolve<Real>();
4696  UnitTestAddMat2<Real>();
4697  UnitTestSymAddMat2<Real>();
4698  UnitTestAddMatSelf<Real>();
4699  UnitTestMaxMin<Real>();
4700  UnitTestInnerProd<Real>();
4701  UnitTestApplyExpSpecial<Real>();
4702  UnitTestScaleDiag<Real>();
4703  UnitTestSetDiag<Real>();
4704  UnitTestSetRandn<Real>();
4705  KALDI_LOG << " Point J";
4706  UnitTestTraceSpSpLower<Real>();
4707  UnitTestTranspose<Real>();
4708  UnitTestAddVec2Sp<Real>();
4709  UnitTestAddVecToRows<Real>();
4710  UnitTestAddVecToCols<Real>();
4712  UnitTestTp2Sp<Real>();
4713  UnitTestTp2<Real>();
4714  UnitTestAddDiagMat2<Real>();
4715  UnitTestAddDiagMatMat<Real>();
4716  // UnitTestOrthogonalizeRows<Real>();
4717  UnitTestTopEigs<Real>();
4718  UnitTestRandCategorical<Real>();
4719  UnitTestTridiag<Real>();
4720  UnitTestTridiag<Real>();
4721  // SlowMatMul<Real>();
4722  UnitTestAddDiagVecMat<Real>();
4723  UnitTestAddMatDiagVec<Real>();
4724  UnitTestAddMatMatElements<Real>();
4725  UnitTestAddMatMatNans<Real>();
4726  UnitTestAddToDiagMatrix<Real>();
4727  UnitTestAddToDiag<Real>();
4728  UnitTestMaxAbsEig<Real>();
4729  UnitTestMax2<Real>();
4730  UnitTestPca<Real>(full_test);
4731  UnitTestPca2<Real>(full_test);
4732  UnitTestAddVecVec<Real>();
4733  UnitTestReplaceValue<Real>();
4734  // The next one is slow. The upshot is that Eig is up to ten times faster
4735  // than SVD.
4736  // UnitTestSvdSpeed<Real>();
4737  KALDI_LOG << " Point K";
4738  UnitTestTriVecSolver<Real>();
4739 }
void UnitTestAddVecCross()
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ MaxAbsolute()

BaseFloat kaldi::MaxAbsolute ( const Vector< BaseFloat > &  vector)

Definition at line 52 of file wav-reverberate.cc.

References VectorBase< Real >::Max(), and VectorBase< Real >::Min().

52  {
53  return std::max(std::abs(vector.Max()), std::abs(vector.Min()));
54 }
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.

◆ MaybeDoSanityCheck() [1/2]

void MaybeDoSanityCheck ( const KwsLexicographicFst index_transducer)

Definition at line 325 of file kws-functions.cc.

References DifferenceWrapper(), fst::GetLinearSymbolSequence(), GetVerboseLevel(), rnnlm::i, KALDI_VLOG, and KALDI_WARN.

Referenced by DoFactorMerging(), main(), and MaybeDoSanityCheck().

325  {
327  if (GetVerboseLevel() < 2) return;
328  KwsLexicographicFst temp_transducer;
329  ShortestPath(index_transducer, &temp_transducer);
330  std::vector<Label> isymbols, osymbols;
331  KwsLexicographicWeight weight;
332  GetLinearSymbolSequence(temp_transducer, &isymbols, &osymbols, &weight);
333  std::ostringstream os;
334  for (size_t i = 0; i < isymbols.size(); i++)
335  os << isymbols[i] << ' ';
336  BaseFloat best_cost = weight.Value1().Value();
337  KALDI_VLOG(3) << "Best path: " << isymbols.size() << " isymbols " << ", "
338  << osymbols.size() << " osymbols, isymbols are " << os.str()
339  << ", best cost is " << best_cost;
340 
341  // Now get second-best path. This will exclude the best path, which
342  // will generally correspond to the empty word sequence (there will
343  // be isymbols and osymbols anyway though, because of the utterance-id
344  // having been encoded as an osymbol (and later, the EncodeFst turning it
345  // into a transducer).
346  KwsLexicographicFst difference_transducer;
347  DifferenceWrapper(index_transducer, temp_transducer, &difference_transducer);
348  ShortestPath(difference_transducer, &temp_transducer);
349 
350  GetLinearSymbolSequence(temp_transducer, &isymbols, &osymbols, &weight);
351  std::ostringstream os2;
352  for (size_t i = 0; i < isymbols.size(); i++)
353  os2 << isymbols[i] << ' ';
354  BaseFloat second_best_cost = weight.Value1().Value();
355  KALDI_VLOG(3) << "Second-best path: " << isymbols.size()
356  << " isymbols " << ", "
357  << osymbols.size() << " osymbols, isymbols are " << os2.str()
358  << ", second-best cost is " << second_best_cost;
359  if (second_best_cost < -0.01) {
360  KALDI_WARN << "Negative second-best cost found " << second_best_cost;
361  }
362 }
int32 GetVerboseLevel()
Get verbosity level, usually set via command line &#39;–verbose=&#39; switch.
Definition: kaldi-error.h:60
static void DifferenceWrapper(const fst::VectorFst< Arc > &fst1, const fst::VectorFst< Arc > &fst2, fst::VectorFst< Arc > *difference)
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
fst::VectorFst< KwsLexicographicArc > KwsLexicographicFst
Definition: kaldi-kws.h:46
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Label Label
StdLStdLStdWeight KwsLexicographicWeight
Definition: kaldi-kws.h:44
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ MaybeDoSanityCheck() [2/2]

void MaybeDoSanityCheck ( const KwsProductFst product_transducer)

Definition at line 365 of file kws-functions.cc.

References GetVerboseLevel(), and MaybeDoSanityCheck().

365  {
366  if (GetVerboseLevel() < 2) return;
367