NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Random/beta.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#ifndef NUMCPP_NO_USE_BOOST
31
32#include <algorithm>
33#include <string>
34
35#include "boost/random/beta_distribution.hpp"
36
39#include "NumCpp/Core/Shape.hpp"
40#include "NumCpp/NdArray.hpp"
42
43namespace nc::random
44{
45 namespace detail
46 {
47 //============================================================================
48 // Method Description:
60 template<typename dtype, typename GeneratorType = std::mt19937>
62 {
64
65 if (inAlpha < 0)
66 {
67 THROW_INVALID_ARGUMENT_ERROR("input alpha must be greater than zero.");
68 }
69
70 if (inBeta < 0)
71 {
72 THROW_INVALID_ARGUMENT_ERROR("input beta must be greater than zero.");
73 }
74
75 boost::random::beta_distribution<dtype> dist(inAlpha, inBeta);
76 return dist(generator);
77 }
78
79 //============================================================================
80 // Method Description:
94 template<typename dtype, typename GeneratorType = std::mt19937>
96 {
98
99 if (inAlpha < 0)
100 {
101 THROW_INVALID_ARGUMENT_ERROR("input alpha must be greater than zero.");
102 }
103
104 if (inBeta < 0)
105 {
106 THROW_INVALID_ARGUMENT_ERROR("input beta must be greater than zero.");
107 }
108
110
111 boost::random::beta_distribution<dtype> dist(inAlpha, inBeta);
112
113 std::for_each(returnArray.begin(),
114 returnArray.end(),
115 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
116
117 return returnArray;
118 }
119 } // namespace detail
120
121 //============================================================================
122 // Method Description:
133 template<typename dtype>
138
139 //============================================================================
140 // Method Description:
153 template<typename dtype>
158} // namespace nc::random
159
160#endif // #ifndef NUMCPP_NO_USE_BOOST
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
dtype beta(GeneratorType &generator, dtype inAlpha, dtype inBeta)
Definition Random/beta.hpp:61
Definition Random/bernoulli.hpp:41
dtype beta(dtype inAlpha, dtype inBeta)
Definition Random/beta.hpp:134
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59