File indexing completed on 2025-01-18 09:12:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/AnnealingUtility.hpp"
0012
0013 #include <iostream>
0014 #include <vector>
0015
0016 namespace Acts::Test {
0017
0018 BOOST_AUTO_TEST_CASE(annealing_tool_singleChi2_tests) {
0019 std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0020 AnnealingUtility::Config config;
0021 config.setOfTemperatures = temperatures;
0022 AnnealingUtility annealingTool(config);
0023
0024 AnnealingUtility::State state;
0025
0026
0027
0028
0029 double chi2 = config.cutOff + 3.14;
0030
0031
0032 double previousWeight = 1.;
0033
0034 std::cout << "Check weight decrease:" << std::endl;
0035 for (auto temp : temperatures) {
0036 double weight = annealingTool.getWeight(state, chi2);
0037
0038 bool hasDecreased = weight < previousWeight;
0039
0040 BOOST_CHECK(hasDecreased);
0041
0042 previousWeight = weight;
0043 annealingTool.anneal(state);
0044
0045 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0046 << std::endl;
0047 }
0048
0049
0050 BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0051
0052
0053 state = AnnealingUtility::State();
0054
0055 BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0056 BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0057
0058
0059
0060
0061 chi2 = config.cutOff - 3.14;
0062
0063
0064 previousWeight = 0.;
0065
0066 std::cout << "Check weight increase:" << std::endl;
0067 for (auto temp : temperatures) {
0068 double weight = annealingTool.getWeight(state, chi2);
0069
0070 bool hasIncreased = weight > previousWeight;
0071
0072 BOOST_CHECK(hasIncreased);
0073
0074 previousWeight = weight;
0075 annealingTool.anneal(state);
0076
0077 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0078 << std::endl;
0079 }
0080
0081
0082 state = AnnealingUtility::State();
0083
0084
0085
0086
0087 chi2 = config.cutOff;
0088
0089
0090 previousWeight = 0.5;
0091
0092 std::cout << "Check weight insensitivity:" << std::endl;
0093 for (auto temp : temperatures) {
0094 double weight = annealingTool.getWeight(state, chi2);
0095
0096 bool hasNotChanged = weight == previousWeight;
0097
0098 BOOST_CHECK(hasNotChanged);
0099
0100 previousWeight = weight;
0101 annealingTool.anneal(state);
0102
0103 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0104 << std::endl;
0105 }
0106 }
0107
0108 BOOST_AUTO_TEST_CASE(annealing_tool_multiChi2_tests) {
0109
0110 std::vector<double> allChi2{1.3, 4.5, 8.4, 0.4, 10.3, 12.3,
0111 3.5, 5.8, 11.0, 1.1, 3.5, 6.7};
0112
0113 std::vector<double> temperatures{64., 16., 4., 2., 1.5, 1.};
0114 AnnealingUtility::Config config;
0115 config.setOfTemperatures = {64., 16., 4., 2., 1.5, 1.};
0116 AnnealingUtility annealingTool(config);
0117
0118 AnnealingUtility::State state;
0119
0120
0121
0122
0123 double chi2 = config.cutOff + 5.;
0124
0125
0126 double previousWeight = 1.;
0127
0128 std::cout << "Check weight decrease:" << std::endl;
0129 for (auto temp : temperatures) {
0130 double weight = annealingTool.getWeight(state, chi2, allChi2);
0131
0132 bool hasDecreased = weight < previousWeight;
0133
0134 BOOST_CHECK(hasDecreased);
0135
0136 previousWeight = weight;
0137 annealingTool.anneal(state);
0138
0139 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0140 << std::endl;
0141 }
0142
0143
0144 BOOST_CHECK_EQUAL(state.equilibriumReached, true);
0145
0146
0147 state = AnnealingUtility::State();
0148
0149 BOOST_CHECK_EQUAL(state.currentTemperatureIndex, 0u);
0150 BOOST_CHECK_EQUAL(state.equilibriumReached, false);
0151
0152
0153
0154
0155 chi2 = 1.234;
0156
0157
0158 previousWeight = 0.;
0159
0160 std::cout << "Check weight increase:" << std::endl;
0161 for (auto temp : temperatures) {
0162 double weight = annealingTool.getWeight(state, chi2, allChi2);
0163
0164 bool hasIncreased = weight > previousWeight;
0165
0166 BOOST_CHECK(hasIncreased);
0167
0168 previousWeight = weight;
0169 annealingTool.anneal(state);
0170
0171 std::cout << "\tTemperature: " << temp << ", weight: " << weight
0172 << std::endl;
0173 }
0174 }
0175
0176 }