Doxygen 1.9.1
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.2 (development)
tsgDreamCorePDF.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Miroslav Stoyanov
3  *
4  * This file is part of
5  * Toolkit for Adaptive Stochastic Modeling And Non-Intrusive ApproximatioN: TASMANIAN
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
12  * and the following disclaimer in the documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * UT-BATTELLE, LLC AND THE UNITED STATES GOVERNMENT MAKE NO REPRESENTATIONS AND DISCLAIM ALL WARRANTIES, BOTH EXPRESSED AND IMPLIED.
25  * THERE ARE NO EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE ANY PATENT,
26  * COPYRIGHT, TRADEMARK, OR OTHER PROPRIETARY RIGHTS, OR THAT THE SOFTWARE WILL ACCOMPLISH THE INTENDED RESULTS OR THAT THE SOFTWARE OR ITS USE WILL NOT RESULT IN INJURY OR DAMAGE.
27  * THE USER ASSUMES RESPONSIBILITY FOR ALL LIABILITIES, PENALTIES, FINES, CLAIMS, CAUSES OF ACTION, AND COSTS AND EXPENSES, CAUSED BY, RESULTING FROM OR ARISING OUT OF,
28  * IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE.
29  */
30 
31 #ifndef __TASMANIAN_DREAM_CORE_PDF_HPP
32 #define __TASMANIAN_DREAM_CORE_PDF_HPP
33 
43 #include "tsgDreamEnumerates.hpp"
44 
45 namespace TasDREAM{
46 
49 
84 template<TypeDistribution distribution, TypeSamplingForm form = regform, typename... Params>
85 double getDensity(double x, Params... params){
86  std::vector<typename std::tuple_element<0, std::tuple<Params...>>::type> ParameterArray = {params...};
87  if (form == regform){
88  if (distribution == dist_gaussian){
89  return std::exp(-0.5 * (x - ParameterArray[0]) * (x - ParameterArray[0]) / ParameterArray[1]);
90  }else if (distribution == dist_exponential){
91  return std::exp(-ParameterArray[1] * (x - ParameterArray[0]));
92  }else if (distribution == dist_beta){
93  return std::pow(x - ParameterArray[0], ParameterArray[2] - 1.0) * std::pow(ParameterArray[1] - x, ParameterArray[3] - 1.0);
94  }else if (distribution == dist_gamma){
95  return std::pow(x - ParameterArray[0], ParameterArray[1] - 1.0) * std::exp(- ParameterArray[2] * (x - ParameterArray[0]));
96  }else{ // uniform
97  return 1.0;
98  }
99  }else{
100  if (distribution == dist_gaussian){
101  return -0.5 * (x - ParameterArray[0]) * (x - ParameterArray[0]) / ParameterArray[1];
102  }else if (distribution == dist_exponential){
103  return -ParameterArray[1] * (x - ParameterArray[0]);
104  }else if (distribution == dist_beta){
105  return std::log(x - ParameterArray[0]) * (ParameterArray[2] - 1.0) + std::log(ParameterArray[1] - x) * (ParameterArray[3] - 1.0);
106  }else if (distribution == dist_gamma){
107  return std::log(x - ParameterArray[0]) * (ParameterArray[1] - 1.0) - ParameterArray[2] * (x - ParameterArray[0]);
108  }else{ // uniform
109  return 0.0;
110  }
111  }
112 }
113 
114 }
115 
116 
117 #endif
TypeDistribution
Indicates a specific probability distribution for the associated function.
Definition: tsgDreamEnumerates.hpp:102
TypeSamplingForm
Describes whether sampling should be done with the regular or logarithm form of the probability densi...
Definition: tsgDreamEnumerates.hpp:90
@ dist_gaussian
Gaussian or Normal distribution defined by mean and variance.
Definition: tsgDreamEnumerates.hpp:107
@ dist_exponential
Exponential distribution (i.e., special case of the Gamma distribution).
Definition: tsgDreamEnumerates.hpp:110
@ dist_beta
Beta distribution, corresponds to Gauss-Jacobi sparse grid rule TasGrid::rule_gaussjacobi.
Definition: tsgDreamEnumerates.hpp:113
@ dist_gamma
Gamma distribution, corresponds to Gauss-Laguerre sparse grid rule TasGrid::rule_gausslaguerre.
Definition: tsgDreamEnumerates.hpp:116
@ regform
Use the standard form for the probability density.
Definition: tsgDreamEnumerates.hpp:92
double getDensity(double x, Params... params)
Returns the unscaled probability density of distribution (defined by params) at the point x.
Definition: tsgDreamCorePDF.hpp:85
Encapsulates the Tasmanian DREAM module.
Definition: TasmanianDREAM.hpp:80
The enumerated types used in the DREAM module.