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);
31  WeightedSampler<std::mt19937> sampler(&rng);
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 }
static int runAllTests(TestResult &result)
static std::mt19937 rng
Fast sampling without replacement.
Definition: Half.h:150
TEST(WeightedSampler, sampleWithoutReplacement)
traits
Definition: chartTesting.h:28
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
std::vector< size_t > sampleWithoutReplacement(size_t numSamples, const std::vector< double > &weights)
int main()
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


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:50:25