ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
NormalRandom.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Normal Random Distribution Header File
18
19Author: Alex Reynolds
20*/
21#ifndef NORMAL_RANDOM_HPP
22#define NORMAL_RANDOM_HPP
23
24#include <random>
25
26#include "data_management/GraphTreeObject.h"
27#include "data_management/DataIO.hpp"
28
29namespace modelspace {
30
31 /**
32 * @brief Class to generate random numbers according to normal distribution
33 *
34 * This function generates a random normal distribution draw according to
35 * the mt19937 engine and a std::normal_distribution. It produces random
36 * numbers according to the mean, std, and seed set in the constructor. Mean
37 * and std may be modified via standard setters mean and std.
38 */
39 template<typename T>
40 class NormalRandom : clockwerk::GraphTreeObject {
41 public:
42 /// @brief Constructor for the normal random distribution
43 /// @param mean The mean for the distribution
44 /// @param std The standard deviation of the distribution
45 /// @param seed Seed for the RNG -- Defaults to zero
46 NormalRandom(T set_mean, T set_std, unsigned int seed = 0);
47 ~NormalRandom() {}
48
49 T operator () ();
50
51 /// @brief The mean of the random output. Can be get/set
52 clockwerk::DataIO<T> mean = clockwerk::DataIO<T>(this, "mean");
53
54 /// @brief The standard deviation of the random output. Can be get/set
55 clockwerk::DataIO<T> std = clockwerk::DataIO<T>(this, "std");
56 protected:
57 std::mt19937 _engine;
58 std::normal_distribution<double> _distribution;
59 };
60
61 template <typename T>
62 NormalRandom<T>::NormalRandom(T set_mean, T set_std, unsigned int seed)
63 : _engine{seed}, _distribution(0, 1.0) {
64 mean(set_mean);
65 std(set_std);
66 }
67
68 template <typename T>
69 T NormalRandom<T>::operator () () {
70 // Calculate our distribution as
71 // val = mean + rng*seed
72 // Where we
73
74 return mean() + _distribution(_engine)*std();
75 }
76
77}
78
79#endif
Class for inter-object communication.
Definition DataIO.hpp:46
Base class for object organization.
Definition GraphTreeObject.h:87
Class to generate random numbers according to normal distribution.
Definition NormalRandom.hpp:40
NormalRandom(T set_mean, T set_std, unsigned int seed=0)
Constructor for the normal random distribution.
Definition NormalRandom.hpp:62
clockwerk::DataIO< T > std
The standard deviation of the random output. Can be get/set.
Definition NormalRandom.hpp:55
clockwerk::DataIO< T > mean
The mean of the random output. Can be get/set.
Definition NormalRandom.hpp:52
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18