mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
logistic.hpp
Go to the documentation of this file.
1 /** \file logistic.hpp
2  * \brief The logistic function
3  *
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  * \ingroup gen_math_files
7  *
8  */
9 
10 //***********************************************************************//
11 // Copyright 2015, 2016, 2017 Jared R. Males (jaredmales@gmail.com)
12 //
13 // This file is part of mxlib.
14 //
15 // mxlib is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 // mxlib is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
27 //***********************************************************************//
28 
29 #ifndef __logistic_hpp__
30 #define __logistic_hpp__
31 
32 namespace mx
33 {
34 
35 namespace math
36 {
37 
38 namespace func
39 {
40 
41 
42 
43 ///Return the logistic function parameter for a specified rise time
44 /** The logistic function is
45  * \f[
46  * f(t) = \frac{1}{1 + e^{-a(t-t_0)}}
47  * \f]
48  * The parameter \f$ a \f$ controls how fast the function rises. Here it is specified by the
49  * value \f$ f(t_{1/2}) = x\f$, where \f$ 0 < x < 1 \f$.
50  *
51  *
52  * \returns the value of a
53  *
54  * \tparam floatT is the floating point type of the arguments and the returned value.
55  *
56  * \ingroup gen_math_logistic
57  */
58 template<typename floatT>
59 floatT logistic_param( floatT x, ///< [in] the value at which the rise time is specified.
60  floatT thalf ///< [in] half the rise time, or the time after 0 when f(t) = x.
61  )
62 {
63  return -log( 1.0/x - 1)/thalf;
64 }
65 
66 ///Return the value of the logistic function
67 /** The logistic function is
68  * \f[
69  * f(t) = \frac{1}{1 + e^{-a(t-t_0)}}
70  * \f]
71  *
72  * \param t [input] the argument.
73  * \param t0 [input] [optional] the center of the curve, defaults to 0.
74  * \param a [input] [optional] the exponent parameter, defaults to 1.
75  *
76  * \returns the value of the logistic function at t
77  *
78  * \tparam floatT is the floating point type of the arguments and the returned value.
79  *
80  * \ingroup gen_math_logistic
81  */
82 template<typename floatT>
83 floatT logistic(floatT t, floatT t0 = 0, floatT a = 1)
84 {
85  return 1.0/(1.0 + exp( -a*(t-t0)));
86 }
87 
88 
89 
90 } //namespace func
91 } //namespace math
92 } //namespace mx
93 
94 #endif //__logistic_hpp__
95 
floatT logistic(floatT t, floatT t0=0, floatT a=1)
Return the value of the logistic function.
Definition: logistic.hpp:83
floatT logistic_param(floatT x, floatT thalf)
Return the logistic function parameter for a specified rise time.
Definition: logistic.hpp:59
The mxlib c++ namespace.
Definition: mxError.hpp:107