testWeightedSampler.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 
22 
23 #include <random>
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 TEST(WeightedSampler, sampleWithoutReplacement) {
29  vector<double> weights{1, 2, 3, 4, 3, 2, 1};
30  std::mt19937 rng(42);
32  auto samples = sampler.sampleWithoutReplacement(5, weights);
33  EXPECT_LONGS_EQUAL(5, samples.size());
34 }
35 
36 //******************************************************************************
37 int main() {
38  TestResult tr;
39  return TestRegistry::runAllTests(tr);
40 }
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
rng
static std::mt19937 rng
Definition: timeFactorOverhead.cpp:31
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
TestHarness.h
main
int main()
Definition: testWeightedSampler.cpp:37
gtsam::WeightedSampler
Definition: WeightedSampler.h:37
WeightedSampler.h
Fast sampling without replacement.
gtsam::WeightedSampler::sampleWithoutReplacement
std::vector< size_t > sampleWithoutReplacement(size_t numSamples, const std::vector< double > &weights)
Definition: WeightedSampler.h:48
samples
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set samples
Definition: gnuplot_common_settings.hh:32
TEST
TEST(WeightedSampler, sampleWithoutReplacement)
Definition: testWeightedSampler.cpp:28
TestResult
Definition: TestResult.h:26
gtsam
traits
Definition: SFMdata.h:40
std
Definition: BFloat16.h:88


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:56