20 #ifndef KALDI_FSTEXT_RAND_FST_H_ 21 #define KALDI_FSTEXT_RAND_FST_H_ 26 #include <fst/fstlib.h> 27 #include <fst/fst-decl.h> 49 weight_multiplier = 0.25;
60 VectorFst<Arc> *
fst =
new VectorFst<Arc>();
65 std::vector<StateId> all_states;
66 for (
size_t i = 0;
i < (
size_t)opts.n_states;
i++) {
67 StateId this_state = fst->AddState();
68 if (
i == 0) fst->SetStart(
i);
69 all_states.push_back(this_state);
72 for (
size_t j = 0;
j < (
size_t)opts.n_final;
j++) {
73 StateId
id = all_states[
kaldi::Rand() % opts.n_states];
75 fst->SetFinal(
id, weight);
78 for (
size_t i = 0;
i < (
size_t)opts.n_arcs;
i++) {
82 start_state = all_states[
kaldi::Rand() % opts.n_states];
83 a.nextstate = all_states[
kaldi::Rand() % opts.n_states];
85 start_state = all_states[
kaldi::Rand() % (opts.n_states-1)];
86 a.nextstate = start_state + 1 + (
kaldi::Rand() % (opts.n_states-start_state-1));
92 fst->AddArc(start_state, a);
98 assert(fst->Properties(kAcyclic,
true) & kAcyclic);
99 if (fst->Start() == kNoStateId && !opts.allow_empty) {
112 VectorFst<Arc> *
fst =
new VectorFst<Arc>();
117 std::vector<StateId> all_states;
118 for (
size_t i = 0;
i < (
size_t)opts.n_states;
i++) {
119 StateId this_state = fst->AddState();
120 if (
i == 0) fst->SetStart(
i);
121 all_states.push_back(this_state);
124 for (
size_t j = 0;
j < (
size_t)opts.n_final;
j++) {
125 StateId
id = all_states[
kaldi::Rand() % opts.n_states];
127 fst->SetFinal(
id, weight);
130 for (
size_t i = 0;
i < (
size_t)opts.n_arcs;
i++) {
134 start_state = all_states[
kaldi::Rand() % opts.n_states];
135 a.nextstate = all_states[
kaldi::Rand() % opts.n_states];
137 start_state = all_states[
kaldi::Rand() % (opts.n_states-1)];
138 a.nextstate = start_state + 1 + (
kaldi::Rand() % (opts.n_states-start_state-1));
144 fst->AddArc(start_state, a);
150 assert(fst->Properties(kAcyclic,
true) & kAcyclic);
151 if (fst->Start() == kNoStateId && !opts.allow_empty) {
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
VectorFst< Arc > * RandPairFst(RandFstOptions opts=RandFstOptions())
Returns a random FST.
VectorFst< Arc > * RandFst(RandFstOptions opts=RandFstOptions())
Returns a random FST.
int Rand(struct RandomState *state)
fst::StdArc::Weight Weight