Skip to content

Commit 0ef1205

Browse files
committed
Adding push-special-test.cc which had been missing, and change some names of functions in ClusterableItf.
git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@1511 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
1 parent c61c633 commit 0ef1205

9 files changed

Lines changed: 95 additions & 16 deletions

File tree

src/TODO

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
=====
88
dan's TODO:
9-
Read()->ReadNew in clusterable-classes.h, and Read_ -> Read
9+
10+
put informative text in local/score.sh RE how to see results.
1011

1112
change on-disk formats to make memory mapping easier?
1213
address roundoff issues RE lattice generation?

src/fstext/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TESTFILES = determinize-star-test \
1515
context-fst-test factor-test table-matcher-test fstext-utils-test \
1616
remove-eps-local-test rescale-test lattice-weight-test \
1717
determinize-lattice-test lattice-utils-test deterministic-fst-test \
18-
determinize-lattice-pruned-test
18+
determinize-lattice-pruned-test push-special-test
1919

2020
OBJFILES = push-special.o
2121

src/fstext/push-special-test.cc

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// fstext/push-special-test.cc
2+
3+
// Copyright 2009-2011 Microsoft Corporation
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12+
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13+
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
14+
// MERCHANTABLITY OR NON-INFRINGEMENT.
15+
// See the Apache 2 License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
19+
#include "fstext/push-special.h"
20+
#include "fstext/rand-fst.h"
21+
#include "fstext/fstext-utils.h"
22+
23+
namespace fst
24+
{
25+
26+
27+
// Don't instantiate with log semiring, as RandEquivalent may fail.
28+
static void TestPushSpecial() {
29+
typedef StdArc Arc;
30+
typedef Arc::Label Label;
31+
typedef Arc::StateId StateId;
32+
typedef Arc::Weight Weight;
33+
34+
VectorFst<Arc> *fst = RandFst<StdArc>();
35+
36+
{
37+
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
38+
fstprinter.Print(&std::cout, "standard output");
39+
}
40+
41+
VectorFst<Arc> fst_copy(*fst);
42+
43+
float delta = kDelta;
44+
PushSpecial(&fst_copy, delta);
45+
46+
Weight min, max;
47+
float delta_dontcare = 0.1;
48+
IsStochasticFstInLog(fst_copy, delta_dontcare, &min, &max);
49+
// the per-state normalizers are allowed to deviate from the average by delta
50+
// up and down, so the difference from the min to max weight should be 2*delta
51+
// or less. We give it a bit of wiggle room (->2.5) due to numerical roundoff.
52+
53+
54+
{
55+
FstPrinter<Arc> fstprinter(fst_copy, NULL, NULL, NULL, false, true);
56+
fstprinter.Print(&std::cout, "standard output");
57+
}
58+
KALDI_LOG << "Min value is " << min.Value() << ", max value is " << max.Value();
59+
60+
// below, should be <= delta but different pieces of code compute this in this
61+
// part vs. push-special, so the roundoff may be different.
62+
KALDI_ASSERT(std::abs(min.Value() - max.Value()) <= 1.2 * delta);
63+
64+
KALDI_ASSERT(RandEquivalent(*fst, fst_copy,
65+
5/*paths*/, 0.01/*delta*/, rand()/*seed*/, 100/*path length-- max?*/));
66+
delete fst;
67+
}
68+
69+
70+
} // namespace fst
71+
72+
int main() {
73+
kaldi::g_kaldi_verbose_level = 4;
74+
using namespace fst;
75+
for (int i = 0; i < 25; i++) {
76+
TestPushSpecial();
77+
}
78+
}

src/itf/clusterable-itf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Clusterable {
6565
/// Read data from a stream and return the corresponding object (const
6666
/// function; it's a class member because we need access to the vtable
6767
/// so generic code can read derived types).
68-
virtual Clusterable* Read(std::istream &os, bool binary) const = 0;
68+
virtual Clusterable* ReadNew(std::istream &os, bool binary) const = 0;
6969

7070
virtual ~Clusterable() {}
7171

src/sgmm/sgmm-clusterable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void SgmmClusterable::Write(std::ostream &os, bool binary) const {
184184
y_.Write(os, binary);
185185
}
186186

187-
Clusterable *SgmmClusterable::Read(std::istream &is, bool binary) const {
187+
Clusterable *SgmmClusterable::ReadNew(std::istream &is, bool binary) const {
188188
SgmmClusterable *ans = new SgmmClusterable(sgmm_, H_);
189189
ans->gamma_.Read(is, binary);
190190
ans->y_.Read(is, binary);

src/sgmm/sgmm-clusterable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SgmmClusterable: public Clusterable {
6363
virtual Clusterable *Copy() const;
6464
virtual void Scale(BaseFloat f);
6565
virtual void Write(std::ostream &os, bool binary) const;
66-
virtual Clusterable *Read(std::istream &is, bool binary) const;
66+
virtual Clusterable *ReadNew(std::istream &is, bool binary) const;
6767
virtual ~SgmmClusterable() {}
6868

6969
const Vector<double> &gamma () const { return gamma_; }

src/tree/build-tree-utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void ReadBuildTreeStats(std::istream &is, bool binary, const Clusterable &exampl
5252
ReadEventType(is, binary, &((*stats)[i].first));
5353
bool nonNull;
5454
ReadBasicType(is, binary, &nonNull);
55-
if (nonNull) (*stats)[i].second = example.Read(is, binary);
55+
if (nonNull) (*stats)[i].second = example.ReadNew(is, binary);
5656
else (*stats)[i].second = NULL;
5757
}
5858
}

src/tree/clusterable-classes.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ void ScalarClusterable::Write(std::ostream &os, bool binary) const {
104104
WriteBasicType(os, binary, count_);
105105
}
106106

107-
Clusterable* ScalarClusterable::Read(std::istream &is, bool binary) const {
107+
Clusterable* ScalarClusterable::ReadNew(std::istream &is, bool binary) const {
108108
ScalarClusterable *sc = new ScalarClusterable();
109-
sc->Read_(is, binary);
109+
sc->Read(is, binary);
110110
return sc;
111111
}
112112

113-
void ScalarClusterable::Read_(std::istream &is, bool binary) {
113+
void ScalarClusterable::Read(std::istream &is, bool binary) {
114114
ExpectToken(is, binary, "SCL");
115115
ReadBasicType(is, binary, &x_);
116116
ReadBasicType(is, binary, &x2_);
@@ -175,13 +175,13 @@ void GaussClusterable::Write(std::ostream &os, bool binary) const {
175175
stats_.Write(os, binary);
176176
}
177177

178-
Clusterable* GaussClusterable::Read(std::istream &is, bool binary) const {
178+
Clusterable* GaussClusterable::ReadNew(std::istream &is, bool binary) const {
179179
GaussClusterable *gc = new GaussClusterable();
180-
gc->Read_(is, binary);
180+
gc->Read(is, binary);
181181
return gc;
182182
}
183183

184-
void GaussClusterable::Read_(std::istream &is, bool binary) {
184+
void GaussClusterable::Read(std::istream &is, bool binary) {
185185
ExpectToken(is, binary, "GCL"); // magic string.
186186
ReadBasicType(is, binary, &count_);
187187
ReadBasicType(is, binary, &var_floor_);

src/tree/clusterable-classes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ScalarClusterable: public Clusterable {
4848

4949
// Function to write data to stream. Will organize input later [more complex]
5050
virtual void Write(std::ostream &os, bool binary) const;
51-
virtual Clusterable* Read(std::istream &is, bool binary) const;
51+
virtual Clusterable* ReadNew(std::istream &is, bool binary) const;
5252

5353
std::string Info(); // For debugging.
5454
BaseFloat Mean() { return (count_ != 0 ? x_/count_ : 0.0); }
@@ -57,7 +57,7 @@ class ScalarClusterable: public Clusterable {
5757
BaseFloat x2_;
5858
BaseFloat count_;
5959

60-
void Read_(std::istream &is, bool binary);
60+
void Read(std::istream &is, bool binary);
6161
};
6262

6363

@@ -83,7 +83,7 @@ class GaussClusterable: public Clusterable {
8383
virtual Clusterable *Copy() const;
8484
virtual void Scale(BaseFloat f);
8585
virtual void Write(std::ostream &os, bool binary) const;
86-
virtual Clusterable *Read(std::istream &is, bool binary) const;
86+
virtual Clusterable *ReadNew(std::istream &is, bool binary) const;
8787
virtual ~GaussClusterable() {}
8888

8989
BaseFloat count() const { return count_; }
@@ -95,7 +95,7 @@ class GaussClusterable: public Clusterable {
9595
Matrix<double> stats_; // two rows: sum, then sum-squared.
9696
double var_floor_; // should be common for all objects created.
9797

98-
void Read_(std::istream &is, bool binary);
98+
void Read(std::istream &is, bool binary);
9999
};
100100

101101
/// @} end of "addtogroup clustering_group"

0 commit comments

Comments
 (0)