STIR 6.4.0
GeneralisedPoissonNoiseGenerator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2017, University College London
3 This file is part of STIR.
4
5 SPDX-License-Identifier: Apache-2.0
6
7 See STIR/LICENSE.txt for details
8*/
9
16
17#include "stir/ProjData.h"
18
19#include <boost/random/mersenne_twister.hpp>
20#include <boost/random/variate_generator.hpp>
21#include <algorithm>
22#include <functional>
23// boost::serialization::make_array was moved in boost 1.64
24#if BOOST_VERSION == 106400
25# include <boost/serialization/array_wrapper.hpp>
26#endif
27
28START_NAMESPACE_STIR
29
44{
45 // try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
46 typedef boost::mt19937 base_generator_type;
47 typedef base_generator_type::result_type poisson_result_type;
48
49public:
51 GeneralisedPoissonNoiseGenerator(const float scaling_factor = 1.0F, const bool preserve_mean = false);
52
54 void seed(unsigned int);
55
57 float generate_random(const float mu);
58
59 template <int num_dimensions, class elemTout, class elemTin>
61 {
62 std::transform(array_in.begin_all(),
63 array_in.end_all(),
64 array_out.begin_all(),
65 std::bind(generate_scaled_poisson_random, std::placeholders::_1, this->scaling_factor, this->preserve_mean));
66 }
67
68 void generate_random(ProjData& output_projdata, const ProjData& input_projdata);
69
70private:
71 static base_generator_type generator;
72 const float scaling_factor;
73 const bool preserve_mean;
74
75 static unsigned int generate_poisson_random(const float mu);
76 static float generate_scaled_poisson_random(const float mu, const float scaling_factor, const bool preserve_mean);
77};
78
79END_NAMESPACE_STIR
Declaration of class stir::ProjData.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
full_iterator begin_all()
start value for iterating through all elements in the array, see full_iterator
Definition Array.inl:213
full_iterator end_all()
end value for iterating through all elements in the array, see full_iterator
Definition Array.inl:185
void seed(unsigned int)
The seed value for the random number generator.
Definition GeneralisedPoissonNoiseGenerator.cxx:42
GeneralisedPoissonNoiseGenerator(const float scaling_factor=1.0F, const bool preserve_mean=false)
Constructor intialises the andom number generator with a fixed seed.
Definition GeneralisedPoissonNoiseGenerator.cxx:34
float generate_random(const float mu)
generate a random number according to a distribution with mean mu
Definition GeneralisedPoissonNoiseGenerator.cxx:107
The (abstract) base class for the projection data.
Definition ProjData.h:105