[gnumeric] Rayleigh distribution: add cdf and inverse cdf functions.



commit 2193644f91dcca2abe0bd88c7d99b8d6c053e0e1
Author: Morten Welinder <terra gnome org>
Date:   Sat Dec 5 14:43:13 2015 -0500

    Rayleigh distribution: add cdf and inverse cdf functions.

 ChangeLog    |    5 +++++
 src/sf-dpq.c |   45 ++++++++++++++++++++++++++++++++++-----------
 src/sf-dpq.h |    2 ++
 3 files changed, 41 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3b5ed07..6d1f120 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-05  Morten Welinder  <terra gnome org>
+
+       * src/sf-dpq.c (prayleigh, qrayleigh): New functions.
+       (drayleigh): Define in terms of dweibull.
+
 2015-12-03  Morten Welinder  <terra gnome org>
 
        * src/sf-dpq.c (discpfuncinverter): Fix problem at left edge of
diff --git a/src/sf-dpq.c b/src/sf-dpq.c
index adf3f89..6cfe6a9 100644
--- a/src/sf-dpq.c
+++ b/src/sf-dpq.c
@@ -639,18 +639,41 @@ qhyper (gnm_float p, gnm_float NR, gnm_float NB, gnm_float n,
 gnm_float
 drayleigh (gnm_float x, gnm_float scale, gboolean give_log)
 {
-       if (scale <= 0)
-               return gnm_nan;
+       return dweibull (x, 2, M_SQRT2gnum * scale, give_log);
+}
 
-       if (x <= 0)
-               return R_D__0;
-       else {
-               gnm_float p = dnorm (x, 0, scale, give_log);
-               gnm_float f = M_SQRT_2PI * x / scale;
-               return give_log
-                       ? p + gnm_log (f)
-                       : p * f;
-       }
+/* ------------------------------------------------------------------------ */
+/**
+ * prayleigh:
+ * @x: observation
+ * @scale: scale parameter
+ * @lower_tail: if %TRUE, the lower tail of the distribution is considered.
+ * @log_p: if %TRUE, log of the result will be returned instead
+ *
+ * Returns: cumulative density of the Rayleigh distribution.
+ */
+
+gnm_float
+prayleigh (gnm_float x, gnm_float scale, gboolean lower_tail, gboolean log_p)
+{
+       return pweibull (x, 2, M_SQRT2gnum * scale, lower_tail, log_p);
+}
+
+
+/**
+ * qrayleigh:
+ * @p: probability
+ * @scale: scale parameter
+ * @lower_tail: if %TRUE, the lower tail of the distribution is considered.
+ * @log_p: if %TRUE, log of the result will be returned instead
+ *
+ * Returns: the observation with cumulative probability @p for the
+ * Rayleigh distribution.
+ */
+gnm_float
+qrayleigh (gnm_float p, gnm_float scale, gboolean lower_tail, gboolean log_p)
+{
+       return qweibull (p, 2, M_SQRT2gnum * scale, lower_tail, log_p);
 }
 
 /* ------------------------------------------------------------------------ */
diff --git a/src/sf-dpq.h b/src/sf-dpq.h
index b9ed62a..0a0498a 100644
--- a/src/sf-dpq.h
+++ b/src/sf-dpq.h
@@ -45,6 +45,8 @@ gnm_float qhyper (gnm_float p, gnm_float r, gnm_float b, gnm_float n, gboolean l
 /* Rayleigh distribution  */
 
 gnm_float drayleigh (gnm_float x, gnm_float scale, gboolean give_log);
+gnm_float prayleigh (gnm_float x, gnm_float scale, gboolean lower_tail, gboolean log_p);
+gnm_float qrayleigh (gnm_float p, gnm_float scale, gboolean lower_tail, gboolean log_p);
 
 /* ------------------------------------------------------------------------- */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]