@@ -89,7 +89,7 @@ TEST(TreeStructuredParzenEstimatorTest, MinimizationTest)
89
89
TreeStructuredParzenEstimator estimator (
90
90
TreeStructuredParzenEstimator::Direction::MINIMIZE, k_trials_num / 2 , sample_mean,
91
91
sample_stddev);
92
-
92
+
93
93
for (int64_t trial = 0 ; trial < k_trials_num; trial++) {
94
94
const TreeStructuredParzenEstimator::Input input = estimator.get_next_input ();
95
95
const double score = quadratic_function (input);
@@ -114,7 +114,7 @@ TEST(TreeStructuredParzenEstimatorTest, SingleDimensionTest)
114
114
TreeStructuredParzenEstimator estimator (
115
115
TreeStructuredParzenEstimator::Direction::MAXIMIZE, k_trials_num / 2 , sample_mean,
116
116
sample_stddev);
117
-
117
+
118
118
for (int64_t trial = 0 ; trial < k_trials_num; trial++) {
119
119
const TreeStructuredParzenEstimator::Input input = estimator.get_next_input ();
120
120
const double score = linear_function (input);
@@ -132,7 +132,7 @@ TEST(TreeStructuredParzenEstimatorTest, EmptyTrials)
132
132
133
133
TreeStructuredParzenEstimator estimator (
134
134
TreeStructuredParzenEstimator::Direction::MAXIMIZE, 10 , sample_mean, sample_stddev);
135
-
135
+
136
136
// Should not crash when getting input without any trials
137
137
const TreeStructuredParzenEstimator::Input input = estimator.get_next_input ();
138
138
EXPECT_EQ (input.size (), 2u );
@@ -145,11 +145,11 @@ TEST(TreeStructuredParzenEstimatorTest, SingleTrial)
145
145
146
146
TreeStructuredParzenEstimator estimator (
147
147
TreeStructuredParzenEstimator::Direction::MAXIMIZE, 0 , sample_mean, sample_stddev);
148
-
148
+
149
149
// Add one trial
150
150
const TreeStructuredParzenEstimator::Input first_input{1.0 , 1.0 };
151
151
estimator.add_trial ({first_input, 1.0 });
152
-
152
+
153
153
// Should be able to get next input
154
154
const TreeStructuredParzenEstimator::Input next_input = estimator.get_next_input ();
155
155
EXPECT_EQ (next_input.size (), 2u );
@@ -160,10 +160,10 @@ TEST(TreeStructuredParzenEstimatorTest, LogGaussianPdf)
160
160
TreeStructuredParzenEstimator::Input input{1.0 , 2.0 };
161
161
TreeStructuredParzenEstimator::Input mu{1.0 , 2.0 };
162
162
TreeStructuredParzenEstimator::Input sigma{1.0 , 1.0 };
163
-
163
+
164
164
double log_pdf = TreeStructuredParzenEstimator::log_gaussian_pdf (input, mu, sigma);
165
165
EXPECT_NEAR (log_pdf, -1.8378770664093453 , 1e-6 ); // Expected value calculated manually
166
-
166
+
167
167
// Test with different sigma
168
168
TreeStructuredParzenEstimator::Input sigma2{0.5 , 0.5 };
169
169
log_pdf = TreeStructuredParzenEstimator::log_gaussian_pdf (input, mu, sigma2);
@@ -177,18 +177,18 @@ TEST(TreeStructuredParzenEstimatorTest, DifferentSampleStddev)
177
177
178
178
TreeStructuredParzenEstimator estimator (
179
179
TreeStructuredParzenEstimator::Direction::MAXIMIZE, 10 , sample_mean, sample_stddev);
180
-
180
+
181
181
// Add some trials
182
182
for (int i = 0 ; i < 5 ; ++i) {
183
183
TreeStructuredParzenEstimator::Input input{0.1 * i, 0.01 * i, 1.0 * i};
184
184
estimator.add_trial ({input, static_cast <double >(i)});
185
185
}
186
-
186
+
187
187
// Get next input and verify it's within reasonable bounds
188
188
const TreeStructuredParzenEstimator::Input next_input = estimator.get_next_input ();
189
- EXPECT_NEAR (next_input[0 ], 0.0 , 2.0 ); // stddev = 1.0
190
- EXPECT_NEAR (next_input[1 ], 0.0 , 0.2 ); // stddev = 0.1
191
- EXPECT_NEAR (next_input[2 ], 0.0 , 20.0 ); // stddev = 10.0
189
+ EXPECT_NEAR (next_input[0 ], 0.0 , 2.0 ); // stddev = 1.0
190
+ EXPECT_NEAR (next_input[1 ], 0.0 , 0.2 ); // stddev = 0.1
191
+ EXPECT_NEAR (next_input[2 ], 0.0 , 20.0 ); // stddev = 10.0
192
192
}
193
193
194
194
TEST (TreeStructuredParzenEstimatorTest, ComputeLogLikelihoodRatio)
@@ -198,17 +198,17 @@ TEST(TreeStructuredParzenEstimatorTest, ComputeLogLikelihoodRatio)
198
198
199
199
TreeStructuredParzenEstimator estimator (
200
200
TreeStructuredParzenEstimator::Direction::MAXIMIZE, 0 , sample_mean, sample_stddev);
201
-
201
+
202
202
// Add some trials
203
203
for (int i = 0 ; i < 10 ; ++i) {
204
204
TreeStructuredParzenEstimator::Input input{0.1 * i, 0.1 * i};
205
205
estimator.add_trial ({input, static_cast <double >(i)});
206
206
}
207
-
207
+
208
208
// Test likelihood ratio for a point
209
209
TreeStructuredParzenEstimator::Input test_point{0.5 , 0.5 };
210
210
double ratio = estimator.compute_log_likelihood_ratio (test_point);
211
-
211
+
212
212
// The exact value depends on the random sampling, but we can check it's finite
213
213
EXPECT_TRUE (std::isfinite (ratio));
214
214
}
0 commit comments