NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
nonCentralChiSquared.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/non_central_chi_squared_distribution.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
56  template<typename dtype>
57  dtype nonCentralChiSquared(dtype inK = 1, dtype inLambda = 1)
58  {
60 
61  if (inK <= 0)
62  {
63  THROW_INVALID_ARGUMENT_ERROR("input k must be greater than zero.");
64  }
65 
66  if (inLambda <= 0)
67  {
68  THROW_INVALID_ARGUMENT_ERROR("input lambda must be greater than zero.");
69  }
70 
71  boost::random::non_central_chi_squared_distribution<dtype> dist(inK, inLambda);
72  return dist(generator_);
73  }
74 
75  //============================================================================
76  // Method Description:
88  template<typename dtype>
89  NdArray<dtype> nonCentralChiSquared(const Shape& inShape, dtype inK = 1, dtype inLambda = 1)
90  {
92 
93  if (inK <= 0)
94  {
95  THROW_INVALID_ARGUMENT_ERROR("input k must be greater than zero.");
96  }
97 
98  if (inLambda <= 0)
99  {
100  THROW_INVALID_ARGUMENT_ERROR("input lambda must be greater than zero.");
101  }
102 
103  NdArray<dtype> returnArray(inShape);
104 
105  boost::random::non_central_chi_squared_distribution<dtype> dist(inK, inLambda);
106 
107  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
108  [&dist](dtype& value) -> void
109  {
110  value = dist(generator_);
111  });
112 
113  return returnArray;
114  }
115  } // namespace random
116 } // namespace nc
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:57
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1434
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
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090