From c834704d89f322a38da6f2f80a450a31205ae29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sun, 7 Jan 2024 10:21:49 +0100 Subject: [PATCH] core: Add functions to calculate mean for Weibull distribution --- src/core/model/random-variable-stream.cc | 14 ++++++++++++++ src/core/model/random-variable-stream.h | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/model/random-variable-stream.cc b/src/core/model/random-variable-stream.cc index 4364419ea..699f98242 100644 --- a/src/core/model/random-variable-stream.cc +++ b/src/core/model/random-variable-stream.cc @@ -612,6 +612,20 @@ WeibullRandomVariable::GetBound() const return m_bound; } +double +WeibullRandomVariable::GetMean(double scale, double shape) +{ + NS_LOG_FUNCTION(scale << shape); + return scale * std::tgamma(1 + (1 / shape)); +} + +double +WeibullRandomVariable::GetMean() const +{ + NS_LOG_FUNCTION(this); + return GetMean(m_scale, m_shape); +} + double WeibullRandomVariable::GetValue(double scale, double shape, double bound) { diff --git a/src/core/model/random-variable-stream.h b/src/core/model/random-variable-stream.h index 7ddb6f9e7..01bffd629 100644 --- a/src/core/model/random-variable-stream.h +++ b/src/core/model/random-variable-stream.h @@ -862,6 +862,19 @@ class WeibullRandomVariable : public RandomVariableStream */ double GetBound() const; + /** + * \brief Returns the mean value for the Weibull distribution returned by this RNG stream. + * \return The mean value for the Weibull distribution returned by this RNG stream. + */ + double GetMean() const; + + /** + * \copydoc GetMean() + * \param [in] scale Scale parameter for the Weibull distribution. + * \param [in] shape Shape parameter for the Weibull distribution. + */ + static double GetMean(double scale, double shape); + /** * \copydoc GetValue() * \param [in] scale Scale parameter for the Weibull distribution.