1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// weight_test.h 2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License"); 4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License. 5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at 6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// http://www.apache.org/licenses/LICENSE-2.0 8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software 10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS, 11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and 13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License. 14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc. 16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: riley@google.com (Michael Riley) 17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// 18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// \file 19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Regression test for Fst weights. 20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <cstdlib> 22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <ctime> 23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/expectation-weight.h> 25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/float-weight.h> 26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/random-weight.h> 27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include "./weight-tester.h" 28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_int32(seed, -1, "random seed"); 30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_int32(repeat, 100000, "number of test repetitions"); 31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::TropicalWeight; 33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::TropicalWeightGenerator; 34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::TropicalWeightTpl; 35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::TropicalWeightGenerator_; 36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LogWeight; 38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LogWeightGenerator; 39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LogWeightTpl; 40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LogWeightGenerator_; 41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::MinMaxWeight; 43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::MinMaxWeightGenerator; 44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::MinMaxWeightTpl; 45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::MinMaxWeightGenerator_; 46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::StringWeight; 48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::StringWeightGenerator; 49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::GallicWeight; 51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::GallicWeightGenerator; 52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LexicographicWeight; 54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::LexicographicWeightGenerator; 55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::ProductWeight; 57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::ProductWeightGenerator; 58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 59f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::PowerWeight; 60f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::PowerWeightGenerator; 61f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::SignedLogWeightTpl; 63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::SignedLogWeightGenerator_; 64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::ExpectationWeight; 66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::SparsePowerWeight; 68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::SparsePowerWeightGenerator; 69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::STRING_LEFT; 71f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::STRING_RIGHT; 72f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 73f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonusing fst::WeightTester; 74f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 75f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate <class T> 76f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonvoid TestTemplatedWeights(int repeat, int seed) { 77f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeightGenerator_<T> tropical_generator(seed); 78f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<TropicalWeightTpl<T>, TropicalWeightGenerator_<T> > 79f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_tester(tropical_generator); 80f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_tester.Test(repeat); 81f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 82f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogWeightGenerator_<T> log_generator(seed); 83f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<LogWeightTpl<T>, LogWeightGenerator_<T> > 84f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_tester(log_generator); 85f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_tester.Test(repeat); 86f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 87f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson MinMaxWeightGenerator_<T> minmax_generator(seed); 88f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<MinMaxWeightTpl<T>, MinMaxWeightGenerator_<T> > 89f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson minmax_tester(minmax_generator); 90f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson minmax_tester.Test(repeat); 91f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 92f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson SignedLogWeightGenerator_<T> signedlog_generator(seed); 93f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<SignedLogWeightTpl<T>, SignedLogWeightGenerator_<T> > 94f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson signedlog_tester(signedlog_generator); 95f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson signedlog_tester.Test(repeat); 96f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} 97f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 98f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonint main(int argc, char **argv) { 99f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson std::set_new_handler(FailedNewHandler); 100dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin SET_FLAGS(argv[0], &argc, &argv, true); 101f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 102f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson int seed = FLAGS_seed >= 0 ? FLAGS_seed : time(0); 103f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LOG(INFO) << "Seed = " << seed; 104f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 105f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TestTemplatedWeights<float>(FLAGS_repeat, seed); 106f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TestTemplatedWeights<double>(FLAGS_repeat, seed); 107f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FLAGS_fst_weight_parentheses = "()"; 108f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TestTemplatedWeights<float>(FLAGS_repeat, seed); 109f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TestTemplatedWeights<double>(FLAGS_repeat, seed); 110f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FLAGS_fst_weight_parentheses = ""; 111f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 112f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson // Make sure type names for templated weights are consistent 113f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson CHECK(TropicalWeight::Type() == "tropical"); 114f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson CHECK(TropicalWeightTpl<double>::Type() != TropicalWeightTpl<float>::Type()); 115f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson CHECK(LogWeight::Type() == "log"); 116f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson CHECK(LogWeightTpl<double>::Type() != LogWeightTpl<float>::Type()); 117f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeightTpl<double> w(15.0); 118f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeight tw(15.0); 119f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 120f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson StringWeightGenerator<int> left_string_generator(seed); 121f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<StringWeight<int>, StringWeightGenerator<int> > 122f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson left_string_tester(left_string_generator); 123f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson left_string_tester.Test(FLAGS_repeat); 124f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 125f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson StringWeightGenerator<int, STRING_RIGHT> right_string_generator(seed); 126f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<StringWeight<int, STRING_RIGHT>, 127f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson StringWeightGenerator<int, STRING_RIGHT> > 128f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson right_string_tester(right_string_generator); 129f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson right_string_tester.Test(FLAGS_repeat); 130f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 131f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef GallicWeight<int, TropicalWeight> TropicalGallicWeight; 132f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef GallicWeightGenerator<int, TropicalWeightGenerator> 133f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalGallicWeightGenerator; 134f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 135f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalGallicWeightGenerator tropical_gallic_generator(seed); 136f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<TropicalGallicWeight, TropicalGallicWeightGenerator> 137f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_gallic_tester(tropical_gallic_generator); 138f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_gallic_tester.Test(FLAGS_repeat); 139f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 140f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeight<TropicalWeight, TropicalWeight> TropicalProductWeight; 141f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeightGenerator<TropicalWeightGenerator, 142f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeightGenerator> TropicalProductWeightGenerator; 143f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 144f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalProductWeightGenerator tropical_product_generator(seed); 145f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<TropicalProductWeight, TropicalProductWeightGenerator> 146f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_product_weight_tester(tropical_product_generator); 147f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_product_weight_tester.Test(FLAGS_repeat); 148f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 149f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef PowerWeight<TropicalWeight, 3> TropicalCubeWeight; 150f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef PowerWeightGenerator<TropicalWeightGenerator, 3> 151f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalCubeWeightGenerator; 152f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 153f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalCubeWeightGenerator tropical_cube_generator(seed); 154f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<TropicalCubeWeight, TropicalCubeWeightGenerator> 155f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_cube_weight_tester(tropical_cube_generator); 156f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_cube_weight_tester.Test(FLAGS_repeat); 157f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 158f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeight<TropicalWeight, TropicalProductWeight> 159f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson SecondNestedProductWeight; 160f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeightGenerator<TropicalWeightGenerator, 161f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalProductWeightGenerator> SecondNestedProductWeightGenerator; 162f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 163f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson SecondNestedProductWeightGenerator second_nested_product_generator(seed); 164f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<SecondNestedProductWeight, SecondNestedProductWeightGenerator> 165f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson second_nested_product_weight_tester(second_nested_product_generator); 166f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson second_nested_product_weight_tester.Test(FLAGS_repeat); 167f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 168f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson // This only works with fst_weight_parentheses = "()" 169f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeight<TropicalProductWeight, TropicalWeight> 170f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FirstNestedProductWeight; 171f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeightGenerator<TropicalProductWeightGenerator, 172f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeightGenerator> FirstNestedProductWeightGenerator; 173f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 174f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FirstNestedProductWeightGenerator first_nested_product_generator(seed); 175f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<FirstNestedProductWeight, FirstNestedProductWeightGenerator> 176f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson first_nested_product_weight_tester(first_nested_product_generator); 177f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 178f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef PowerWeight<FirstNestedProductWeight, 3> NestedProductCubeWeight; 179f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef PowerWeightGenerator<FirstNestedProductWeightGenerator, 3> 180f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson NestedProductCubeWeightGenerator; 181f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 182f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson NestedProductCubeWeightGenerator nested_product_cube_generator(seed); 183f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<NestedProductCubeWeight, NestedProductCubeWeightGenerator> 184f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson nested_product_cube_weight_tester(nested_product_cube_generator); 185f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 186f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef SparsePowerWeight<NestedProductCubeWeight, 187f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson size_t > SparseNestedProductCubeWeight; 188f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef SparsePowerWeightGenerator<NestedProductCubeWeightGenerator, 189f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson size_t, 3> SparseNestedProductCubeWeightGenerator; 190f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 191f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson SparseNestedProductCubeWeightGenerator 192f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson sparse_nested_product_cube_generator(seed); 193f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<SparseNestedProductCubeWeight, 194f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson SparseNestedProductCubeWeightGenerator> 195f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson sparse_nested_product_cube_weight_tester( 196f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson sparse_nested_product_cube_generator); 197f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 198f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef SparsePowerWeight<LogWeight, size_t > LogSparsePowerWeight; 199f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef SparsePowerWeightGenerator<LogWeightGenerator, 200f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson size_t, 3> LogSparsePowerWeightGenerator; 201f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 202f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogSparsePowerWeightGenerator 203f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_sparse_power_weight_generator(seed); 204f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<LogSparsePowerWeight, 205f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogSparsePowerWeightGenerator> 206f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_sparse_power_weight_tester( 207f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_sparse_power_weight_generator); 208f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 209f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ExpectationWeight<LogWeight, LogWeight> 210f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogExpectWeight; 211f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeightGenerator<LogWeightGenerator, LogWeightGenerator, 212f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogExpectWeight> LogLogExpectWeightGenerator; 213f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 214f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogExpectWeightGenerator log_log_expect_weight_generator(seed); 215f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<LogLogExpectWeight, LogLogExpectWeightGenerator> 216f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_log_expect_weight_tester(log_log_expect_weight_generator); 217f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 218f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ExpectationWeight<LogWeight, LogSparsePowerWeight> 219f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogSparseExpectWeight; 220f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef ProductWeightGenerator< 221f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogWeightGenerator, 222f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogSparsePowerWeightGenerator, 223f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogSparseExpectWeight> LogLogSparseExpectWeightGenerator; 224f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 225f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson LogLogSparseExpectWeightGenerator log_logsparse_expect_weight_generator(seed); 226f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<LogLogSparseExpectWeight, LogLogSparseExpectWeightGenerator> 227f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_logsparse_expect_weight_tester(log_logsparse_expect_weight_generator); 228f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 229f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson // Test all product weight I/O with parentheses 230f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FLAGS_fst_weight_parentheses = "()"; 231f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson first_nested_product_weight_tester.Test(FLAGS_repeat); 232f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson nested_product_cube_weight_tester.Test(FLAGS_repeat); 233f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_sparse_power_weight_tester.Test(1); 234f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson sparse_nested_product_cube_weight_tester.Test(1); 235f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_product_weight_tester.Test(5); 236f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson second_nested_product_weight_tester.Test(5); 237f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_gallic_tester.Test(5); 238f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_cube_weight_tester.Test(5); 239f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson FLAGS_fst_weight_parentheses = ""; 240f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_sparse_power_weight_tester.Test(1); 241f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_log_expect_weight_tester.Test(1, false); // disables division 242f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson log_logsparse_expect_weight_tester.Test(1, false); 243f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 244f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef LexicographicWeight<TropicalWeight, TropicalWeight> 245f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalLexicographicWeight; 246f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson typedef LexicographicWeightGenerator<TropicalWeightGenerator, 247f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalWeightGenerator> TropicalLexicographicWeightGenerator; 248f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 249f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalLexicographicWeightGenerator tropical_lexicographic_generator(seed); 250f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson WeightTester<TropicalLexicographicWeight, 251f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson TropicalLexicographicWeightGenerator> 252f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_lexicographic_tester(tropical_lexicographic_generator); 253f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson tropical_lexicographic_tester.Test(FLAGS_repeat); 254f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 255f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson cout << "PASS" << endl; 256f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson 257f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson return 0; 258f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson} 259