Commit 1c069df0 authored by Dan Povey's avatar Dan Povey
Browse files

trunk: Update svn:ignore properties and .gitignore; make various minor changes...

trunk: Update svn:ignore properties and .gitignore; make various minor changes to address test failures on FreeBSD.

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@4572 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent fa7abd2b
......@@ -536,6 +536,7 @@ src/lmbin/arpa-to-const-arpa
/src/nnet2bin/nnet-train-parallel
/src/nnet2bin/nnet-train-simple
/src/nnet2bin/nnet-train-transitions
/src/nnet2bin/nnet-relabel-egs
/src/nnet2bin/raw-nnet-concat
/src/nnet2bin/raw-nnet-info
......
......@@ -204,14 +204,10 @@ void UnitTestAssertFunc() { // Testing Assert** *functions
float f1 = Rand() % 10000 + 1, f2 = Rand() % 20 + 1;
float tmp1 = f1 * f2;
float tmp2 = (1/f1 + 1/f2);
float tmp3 = (1/(f1 - 1.0) + 1/(f2 - 1.0));
float tmp4 = (1/(f1 + 1.0) + 1/(f2 + 1.0));
float add = f1 + f2;
float addeql = tmp1 * tmp2, addgeq = tmp1 * tmp3, addleq = tmp1 * tmp4;
float addeql = tmp1 * tmp2;
float thresh = 0.00001;
AssertEqual(add, addeql, thresh); // test AssertEqual()
AssertGeq(addgeq, add, thresh); // test AsserGeq()
AssertLeq(addleq, add, thresh); // test AsserLeq()
}
}
......
......@@ -222,35 +222,24 @@ inline float LogSub(float x, float y) {
return res;
}
// return (a == b)
/// return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
static inline bool ApproxEqual(float a, float b,
float relative_tolerance = 0.001) {
// a==b handles infinities.
if (a==b) return true;
float diff = std::abs(a-b);
if (diff == std::numeric_limits<float>::infinity()
|| diff!=diff) return false; // diff is +inf or nan.
|| diff != diff) return false; // diff is +inf or nan.
return (diff <= relative_tolerance*(std::abs(a)+std::abs(b)));
}
// assert (a == b)
/// assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
static inline void AssertEqual(float a, float b,
float relative_tolerance = 0.001) {
// a==b handles infinities.
KALDI_ASSERT(ApproxEqual(a, b, relative_tolerance));
}
// assert (a>=b)
static inline void AssertGeq(float a, float b,
float relative_tolerance = 0.001) {
KALDI_ASSERT(a-b >= -relative_tolerance * (std::abs(a)+std::abs(b)));
}
// assert (a<=b)
static inline void AssertLeq(float a, float b,
float relative_tolerance = 0.001) {
KALDI_ASSERT(a-b <= -relative_tolerance * (std::abs(a)+std::abs(b)));
}
// RoundUpToNearestPowerOfTwo does the obvious thing. It crashes if n <= 0.
int32 RoundUpToNearestPowerOfTwo(int32 n);
......
// fstext/remove-eps-local-inl.h
// Copyright 2009-2011 Microsoft Corporation
// 2014 Johns Hopkins University (author: Daniel Povey
// See ../../COPYING for clarification regarding multiple authors
//
......@@ -32,7 +33,8 @@ struct ReweightPlusDefault {
};
struct ReweightPlusLogArc {
inline TropicalWeight operator () (const TropicalWeight &a, const TropicalWeight &b) {
inline TropicalWeight operator () (const TropicalWeight &a,
const TropicalWeight &b) {
LogWeight a_log(a.Value()), b_log(b.Value());
return TropicalWeight(Plus(a_log, b_log).Value());
}
......@@ -62,8 +64,10 @@ class RemoveEpsLocalClass {
private:
MutableFst<Arc> *fst_;
StateId non_coacc_state_; // use this to delete arcs: make it nextstate
vector<StateId> num_arcs_in_;
vector<StateId> num_arcs_out_;
vector<StateId> num_arcs_in_; // The number of arcs into the state, plus one
// if it's the start state.
vector<StateId> num_arcs_out_; // The number of arcs out of the state, plus
// one if it's a final state.
ReweightPlus reweight_plus_;
bool CanCombineArcs(const Arc &a, const Arc &b, Arc *c) {
......@@ -308,7 +312,8 @@ void RemoveEpsLocal(MutableFst<Arc> *fst) {
void RemoveEpsLocalSpecial(MutableFst<StdArc> *fst) {
RemoveEpsLocalClass<StdArc, ReweightPlusLogArc> c(fst); // work gets done in initializer.
// work gets done in initializer.
RemoveEpsLocalClass<StdArc, ReweightPlusLogArc> c(fst);
}
} // end namespace fst.
......
......@@ -158,9 +158,12 @@ static void TestRemoveEpsLocalSpecial() {
FstPrinter<LogArc> fstprinter(logfst2, NULL, NULL, NULL, false, true);
fstprinter.Print(&std::cout, "standard output");
}
#ifndef _MSC_VER
assert(IsStochasticFst(logfst2, kDelta*10));
#endif
if (ApproxEqual(ShortestDistance(*logfst), ShortestDistance(logfst2))) {
// make sure we preserved stochasticity in cases where doing so was
// possible... if the log-semiring total weight changed, then it is
// not possible so don't assert this.
assert(IsStochasticFst(logfst2, kDelta*10));
}
delete logfst;
}
......@@ -168,7 +171,7 @@ static void TestRemoveEpsLocalSpecial() {
int main() {
using namespace fst;
for (int i = 0;i < 10;i++) {
for (int i = 0; i < 10; i++) {
TestRemoveEpsLocal<fst::StdArc>();
TestRemoveEpsLocalSpecial();
}
......
// fstext/remove-eps-local.h
// Copyright 2009-2011 Microsoft Corporation
// 2014 Johns Hopkins University (author: Daniel Povey)
// See ../../COPYING for clarification regarding multiple authors
//
......@@ -35,11 +36,14 @@ namespace fst {
/// into one.
/// The algorithm preserves equivalence and stochasticity in the given semiring.
/// If you want to preserve stochasticity in a different semiring (e.g. log),
/// For that, use RemoveEpsLocalSpecial, which only words for StdArc but which
/// preserves stochasticity in the LogArc sense. The reason that we can't
/// then use RemoveEpsLocalSpecial, which only words for StdArc but which
/// preserves stochasticity, where possible (*) in the LogArc sense. The reason that we can't
/// just cast to a different semiring is that in that case we would no longer
/// be able to guarantee equivalence in the original semiring (this arises from
/// what happens when we combine identical arcs).
/// (*) by "where possible".. there are situations where we wouldn't be able to
/// preserve stochasticity in the LogArc sense while maintaining equivalence in
/// the StdArc sense, so in these situations we maintain equivalence.
template<class Arc>
void RemoveEpsLocal(MutableFst<Arc> *fst);
......
......@@ -79,8 +79,8 @@ void TestComponentAcc(const DiagGmm &gmm, const Matrix<BaseFloat> &feats) {
"component removal during Update() call (this is normal)";
return;
} else {
AssertGeq(loglike1, loglike0, 1.0e-6);
AssertGeq(loglike2, loglike0, 1.0e-6);
KALDI_ASSERT(loglike1 >= loglike0 - (std::abs(loglike1)+std::abs(loglike0))*1.0e-06);
KALDI_ASSERT(loglike2 >= loglike0 - (std::abs(loglike2)+std::abs(loglike0))*1.0e-06);
}
}
......
......@@ -82,8 +82,8 @@ void TestComponentAcc(const FullGmm &gmm, const Matrix<BaseFloat> &feats) {
"component removal during Update() call (this is normal)";
return;
} else {
AssertGeq(loglike1, loglike0, 1.0e-6);
AssertGeq(loglike2, loglike0, 1.0e-6);
KALDI_ASSERT(loglike1 >= loglike0 - (std::abs(loglike1)+std::abs(loglike0))*1.0e-06);
KALDI_ASSERT(loglike2 >= loglike0 - (std::abs(loglike2)+std::abs(loglike0))*1.0e-06);
}
}
......@@ -370,11 +370,11 @@ UnitTestEstimateFullGmm() {
double prec_m = 1e-3;
double prec_v = 1e-3;
for (int32 d = 0; d < dim; d++) {
KALDI_ASSERT(ApproxEqual(means.Row(0)(d), ngmm.means_.Row(0)(d), prec_m));
KALDI_ASSERT(ApproxEqual(gmm->means_invcovars().Row(0)(d), rgmm.means_invcovars().Row(0)(d), prec_v));
KALDI_ASSERT(std::abs(means.Row(0)(d) - ngmm.means_.Row(0)(d)) < prec_m);
KALDI_ASSERT(std::abs(gmm->means_invcovars().Row(0)(d) - rgmm.means_invcovars().Row(0)(d)) < prec_v);
for (int32 d2 = d; d2 < dim; ++d2) {
KALDI_ASSERT(ApproxEqual(covar(d, d2), ngmm.vars_[0](d, d2), prec_v));
KALDI_ASSERT(ApproxEqual(gmm->inv_covars()[0](d, d2), rgmm.inv_covars()[0](d, d2), prec_v));
KALDI_ASSERT(std::abs(covar(d, d2) - ngmm.vars_[0](d, d2)) < prec_v);
KALDI_ASSERT(std::abs(gmm->inv_covars()[0](d, d2) - rgmm.inv_covars()[0](d, d2)) < prec_v);
}
}
KALDI_LOG << "OK";
......
......@@ -23,9 +23,12 @@ namespace kaldi {
void UnitTestPldaEstimation(int32 dim) {
int32 num_classes = 4000 + Rand() % 10;
Matrix<double> between_proj(dim, dim);
between_proj.SetRandn();
while (between_proj.Cond() > 100)
between_proj.SetRandn();
Matrix<double> within_proj(dim, dim);
within_proj.SetRandn();
while (within_proj.Cond() > 100)
within_proj.SetRandn();
Vector<double> global_mean(dim);
global_mean.SetRandn();
......
......@@ -1423,7 +1423,7 @@ Real MatrixBase<Real>::Cond() const {
min = std::min((Real)std::abs(singular_values(i)), min); max = std::max((Real)std::abs(singular_values(i)), max);
}
if (min > 0) return max/min;
else return 1.0e+100;
else return std::numeric_limits<Real>::infinity();
}
template<typename Real>
......
......@@ -372,7 +372,8 @@ class MatrixBase {
void TestUninitialized() const; // This function is designed so that if any element
// if the matrix is uninitialized memory, valgrind will complain.
/// returns condition number by computing Svd. Works even if cols > rows.
/// Returns condition number by computing Svd. Works even if cols > rows.
/// Returns infinity if all singular values are zero.
Real Cond() const;
/// Returns true if matrix is Symmetric.
......
......@@ -89,7 +89,8 @@ void TestMultiSgmmEst(const std::vector<AmSgmm*> &models,
}
}
KALDI_LOG << "LL = " << loglike << "; LL1 = " << loglike1;
AssertGeq(loglike1, loglike, 1e-6);
KALDI_ASSERT(loglike1 >= loglike - (std::abs(loglike1)+std::abs(loglike))*1.0e-06);
DeletePointers(&accs);
DeletePointers(&new_models);
......
......@@ -351,7 +351,7 @@ void RegtreeMllrDiagGmmAccs::Update(const RegressionTree &regtree,
<< ((obj_new - obj_old)/regclass_stats[rclass_index]->beta_)
<< " over " << regclass_stats[rclass_index]->beta_
<< " frames.";
AssertGeq(obj_new, obj_old, 1e-5);
KALDI_ASSERT(obj_new >= obj_old - (std::abs(obj_new)+std::abs(obj_old))*1.0e-05);
tot_t += regclass_stats[rclass_index]->beta_;
tot_auxf_impr += obj_new - obj_old;
}
......@@ -378,7 +378,7 @@ void RegtreeMllrDiagGmmAccs::Update(const RegressionTree &regtree,
KALDI_LOG << "MLLR: base-class " << (bclass_index)
<< ": Auxiliary function impr per frame is "
<< ((obj_new-obj_old)/baseclass_stats_[bclass_index]->beta_);
AssertGeq(obj_new, obj_old, 1e-5);
KALDI_ASSERT(obj_new >= obj_old - (std::abs(obj_new)+std::abs(obj_old))*1.0e-05);
tot_t += baseclass_stats_[bclass_index]->beta_;
tot_auxf_impr += obj_new - obj_old;
} else {
......
......@@ -304,7 +304,9 @@ static void TestRefineClusters() {
BaseFloat points_objf = SumClusterableObjf(points),
clust_objf_before = SumClusterableObjf(clusters),
clust_objf_after;
AssertGeq(points_objf, clust_objf_before);
KALDI_ASSERT(points_objf >= clust_objf_before -
(std::abs(points_objf)+std::abs(clust_objf_before))*0.001);
RefineClustersOptions cfg;
cfg.num_iters = 10000; // very large.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment