NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
nonCentralChiSquared.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #ifndef NO_USE_BOOST
31 
34 #include "NumCpp/Core/Shape.hpp"
35 #include "NumCpp/NdArray.hpp"
37 
38 #include "boost/random/non_central_chi_squared_distribution.hpp"
39 
40 #include <algorithm>
41 #include <string>
42 
43 namespace nc
44 {
45  namespace random
46  {
47  //============================================================================
48  // Method Description:
59  template<typename dtype>
60  dtype nonCentralChiSquared(dtype inK = 1, dtype inLambda = 1)
61  {
63 
64  if (inK <= 0)
65  {
66  THROW_INVALID_ARGUMENT_ERROR("input k must be greater than zero.");
67  }
68 
69  if (inLambda <= 0)
70  {
71  THROW_INVALID_ARGUMENT_ERROR("input lambda must be greater than zero.");
72  }
73 
74  boost::random::non_central_chi_squared_distribution<dtype> dist(inK, inLambda);
75  return dist(generator_);
76  }
77 
78  //============================================================================
79  // Method Description:
92  template<typename dtype>
93  NdArray<dtype> nonCentralChiSquared(const Shape& inShape, dtype inK = 1, dtype inLambda = 1)
94  {
96 
97  if (inK <= 0)
98  {
99  THROW_INVALID_ARGUMENT_ERROR("input k must be greater than zero.");
100  }
101 
102  if (inLambda <= 0)
103  {
104  THROW_INVALID_ARGUMENT_ERROR("input lambda must be greater than zero.");
105  }
106 
107  NdArray<dtype> returnArray(inShape);
108 
109  boost::random::non_central_chi_squared_distribution<dtype> dist(inK, inLambda);
110 
111  std::for_each(returnArray.begin(), returnArray.end(),
112  [&dist](dtype& value) -> void
113  {
114  value = dist(generator_);
115  });
116 
117  return returnArray;
118  }
119  } // namespace random
120 } // namespace nc
121 
122 #endif // #ifndef NO_USE_BOOST
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
generator.hpp
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
NdArray.hpp
nc::random::nonCentralChiSquared
dtype nonCentralChiSquared(dtype inK=1, dtype inLambda=1)
Definition: nonCentralChiSquared.hpp:60
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1431
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087