36 std::vector<int32> parents;
38 KALDI_ASSERT(a && parents.size() == 1 && parents[0] == 0);
43 std::vector<int32> parents;
48 std::vector<EventMap*> tvec;
57 std::vector<int32> parents;
60 && parents[1] == 2 && parents[2] == 2);
66 std::map<ValueType, EventMap*> tmap;
67 tmap[0] = C0c; tmap[1] = C1d;
70 std::vector<ValueType> vec;
81 for (
size_t i = 0;
i < 100;
i++) {
82 size_t nElems =
Rand() % 10;
83 std::map<ValueType, AnswerType> init_map;
84 for (
size_t i = 0;
i < nElems;
i++) {
89 for (
size_t i = 0;
i < 10;
i++) {
91 vec.push_back(std::make_pair(key, (ValueType)
i));
94 if (init_map.count(i) == 0) {
97 bool b = T3.
Map(vec, &ans);
111 for (
size_t p = 0; p < 20; p++) {
113 size_t size =
Rand() % 20;
114 event_vec.resize(size);
115 for (
size_t i = 0;
i < size;
i++) {
116 event_vec[
i].first =
Rand() % 10 + (
i > 0 ? event_vec[
i-1].first : 0);
117 event_vec[
i].second =
Rand() % 20;
122 const char *filename =
"tmpf";
123 Output ko(filename, binary);
124 std::ostream &outfile = ko.
Stream();
130 Input ki(filename, &binary_in);
131 std::istream &infile = ki.
Stream();
133 evec2.push_back(std::pair<EventKeyType, EventValueType>(1, 1));
153 }
else if (f < 0.666) {
154 float nonnull_prob = 0.3;
155 float expected_table_size = 3.0;
159 std::vector<EventMap*> table(table_size);
160 for (
size_t t = 0; t < (
size_t)table_size; t++) {
162 else table[t] = NULL;
168 std::set<EventValueType> yes_set;
169 for (
size_t i = 0;
i < 5;
i++) yes_set.insert(
Rand() % max_val);
170 std::vector<EventValueType> yes_vec;
179 for (
size_t p = 0; p < 20; p++) {
181 int32 num_keys = 1 + (
Rand() % (max_key - 1));
182 std::set<EventKeyType> key_set;
184 while (key_set.size() < (
size_t)num_keys) key_set.insert( (
Rand() % (2*max_key)) - 5);
185 std::vector<EventKeyType> key_vec;
189 std::ostringstream str_out;
194 std::cout <<
"Random map is: "<<str_out.str()<<
'\n';
197 std::istringstream str_in(str_out.str());
200 std::ostringstream str2_out;
212 std::vector<EventKeyType> keys;
217 std::vector<EventAnswerType> all_answers;
218 em->
MultiMap(empty_event, &all_answers);
220 std::vector<EventMap*> new_leaves;
221 std::vector<EventAnswerType> mapping;
222 for (
size_t i = 0;
i < all_answers.size();
i++) {
225 new_leaves.resize(ans + 1, NULL);
226 mapping.resize(ans + 1, no_ans);
228 if (
Rand() % 2 == 0) map_to = -1;
229 else map_to =
Rand() % 20;
231 mapping[ans] = map_to;
234 *pruned_em = mapped_em->
Prune();
235 for (
size_t i = 0;
i < new_leaves.size();
i++)
236 delete new_leaves[
i];
239 for (
int32 key = 1; key <= 2; key++) {
240 if (
Rand() % 2 == 0) {
242 event.push_back(std::make_pair(key, value));
246 if (em->
Map(event, &answer)) {
248 if (pruned_em == NULL) ret =
false;
249 else ret = pruned_em->Map(event, &answer2);
253 if (mapped_ans == -1) {
255 KALDI_LOG <<
"Answer was correctly pruned away.";
257 KALDI_LOG <<
"Answer was not pruned away [but this is not required]";
261 KALDI_LOG <<
"Answers match " << answer <<
" -> " << answer2;
271 std::vector<EventKeyType> keys;
277 unordered_set<EventKeyType> mapped_keys;
278 unordered_map<EventKeyType,EventKeyType> value_map;
279 if (
Rand() % 2 == 0) mapped_keys.insert(1);
280 if (
Rand() % 2 == 0) mapped_keys.insert(2);
284 value_map[v] = (v + v_offset) %
kMaxVal;
290 for (
int32 key = 1; key <= 2; key++) {
291 if (
Rand() % 2 == 0) {
293 event.push_back(std::make_pair(key, value));
295 if (mapped_keys.count(key) == 0) mapped_value = value;
296 else mapped_value = value_map[value];
297 mapped_event.push_back(std::make_pair(key, mapped_value));
301 if (em->
Map(event, &answer)) {
302 bool ret = mapped_em->
Map(mapped_event, &answer2);
319 using namespace kaldi;
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. ...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CopySetToVector(const std::set< T > &s, std::vector< T > *v)
Copies the elements of a set to a vector.
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
void TestEventTypeIo(bool binary)
virtual EventAnswerType MaxResult() const
virtual bool Map(const EventType &event, EventAnswerType *ans) const
void TestEventMapIo(bool binary)
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
virtual bool Map(const EventType &event, EventAnswerType *ans) const =0
int32 RandPoisson(float lambda, struct RandomState *state)
static EventMap * Read(std::istream &is, bool binary)
a Read function that reads an arbitrary EventMap; also works for NULL pointers.
void WriteEventType(std::ostream &os, bool binary, const EventType &evec)
std::vector< std::pair< EventKeyType, EventValueType > > EventType
int32 EventKeyType
Things of type EventKeyType can take any value.
void ReadEventType(std::istream &is, bool binary, EventType *evec)
virtual EventMap * MapValues(const unordered_set< EventKeyType > &keys_to_map, const unordered_map< EventValueType, EventValueType > &value_map) const =0
virtual EventMap * Copy(const std::vector< EventMap *> &new_leaves) const =0
int Rand(struct RandomState *state)
A class that is capable of representing a generic mapping from EventType (which is a vector of (key...
#define KALDI_ASSERT(cond)
int32 EventAnswerType
As far as the event-map code itself is concerned, things of type EventAnswerType may take any value e...
void TestEventMapMapValues()
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
virtual EventMap * Prune() const =0
EventMap * RandomEventMap(const std::vector< EventKeyType > &keys)
virtual void MultiMap(const EventType &event, std::vector< EventAnswerType > *ans) const =0
virtual void Write(std::ostream &os, bool binary)=0
Write to stream.