Type2LargestValueRV.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 2001, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** Reliability module developed by:                                   **
00020 **   Terje Haukaas (haukaas@ce.berkeley.edu)                          **
00021 **   Armen Der Kiureghian (adk@ce.berkeley.edu)                       **
00022 **                                                                    **
00023 ** ****************************************************************** */
00024                                                                         
00025 // $Revision: 1.6 $
00026 // $Date: 2003/03/04 00:44:36 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/domain/distributions/Type2LargestValueRV.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <Type2LargestValueRV.h>
00035 #include <GammaRV.h>
00036 #include <math.h>
00037 #include <string.h>
00038 #include <classTags.h>
00039 #include <OPS_Globals.h>
00040 
00041 Type2LargestValueRV::Type2LargestValueRV(int passedTag, 
00042                  double passedMean,
00043                  double passedStdv,
00044                  double passedStartValue)
00045 :RandomVariable(passedTag, RANDOM_VARIABLE_type2largestvalue)
00046 {
00047         tag = passedTag ;
00048         setParameters(passedMean,passedStdv);
00049         startValue = passedStartValue;
00050 }
00051 Type2LargestValueRV::Type2LargestValueRV(int passedTag, 
00052                  double passedParameter1,
00053                  double passedParameter2,
00054                  double passedParameter3,
00055                  double passedParameter4,
00056                  double passedStartValue)
00057 :RandomVariable(passedTag, RANDOM_VARIABLE_type2largestvalue)
00058 {
00059         tag = passedTag ;
00060         u = passedParameter1;
00061         k = passedParameter2;
00062         startValue = passedStartValue;
00063 }
00064 Type2LargestValueRV::Type2LargestValueRV(int passedTag, 
00065                  double passedMean,
00066                  double passedStdv)
00067 :RandomVariable(passedTag, RANDOM_VARIABLE_type2largestvalue)
00068 {
00069         tag = passedTag ;
00070         setParameters(passedMean,passedStdv);
00071         startValue = getMean();
00072 }
00073 Type2LargestValueRV::Type2LargestValueRV(int passedTag, 
00074                  double passedParameter1,
00075                  double passedParameter2,
00076                  double passedParameter3,
00077                  double passedParameter4)
00078 :RandomVariable(passedTag, RANDOM_VARIABLE_type2largestvalue)
00079 {
00080         tag = passedTag ;
00081         u = passedParameter1;
00082         k = passedParameter2;
00083         startValue = getMean();
00084 }
00085 
00086 
00087 Type2LargestValueRV::~Type2LargestValueRV()
00088 {
00089 }
00090 
00091 
00092 void
00093 Type2LargestValueRV::Print(OPS_Stream &s, int flag)
00094 {
00095 }
00096 
00097 
00098 double
00099 Type2LargestValueRV::getPDFvalue(double rvValue)
00100 {
00101         double result;
00102         if ( 0.0 < rvValue ) {
00103                 result = k/u * pow(u/rvValue,k+1) * exp(-pow(u/rvValue,k));
00104         }
00105         else {
00106                 result = 0.0;
00107         }
00108         return result;
00109 }
00110 
00111 
00112 double
00113 Type2LargestValueRV::getCDFvalue(double rvValue)
00114 {
00115         double result;
00116         if ( 0.0 < rvValue ) {
00117                 result = exp(-pow(u/rvValue,k));
00118         }
00119         else {
00120                 result = 0.0;
00121         }
00122         return result;
00123 }
00124 
00125 
00126 double
00127 Type2LargestValueRV::getInverseCDFvalue(double probValue)
00128 {
00129         return u * pow((-log(probValue)),(-1.0/k));
00130 }
00131 
00132 
00133 const char *
00134 Type2LargestValueRV::getType()
00135 {
00136         return "TYPE2LARGESTVALUE";
00137 }
00138 
00139 
00140 double 
00141 Type2LargestValueRV::getMean()
00142 {
00143         double result;
00144         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00145         result = u * aGammaRV->gammaFunction(1.0-1.0/k);
00146         delete aGammaRV;
00147         return result;
00148 }
00149 
00150 
00151 
00152 double 
00153 Type2LargestValueRV::getStdv()
00154 {
00155         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00156         double a = aGammaRV->gammaFunction(1.0-2.0/k);
00157         double b = aGammaRV->gammaFunction(1.0-1.0/k);
00158         delete aGammaRV;
00159         double result = u*sqrt(a-b*b);
00160         return result;
00161 }
00162 
00163 
00164 double 
00165 Type2LargestValueRV::getStartValue()
00166 {
00167         return startValue;
00168 }
00169 
00170 double Type2LargestValueRV::getParameter1()  {return u;}
00171 double Type2LargestValueRV::getParameter2()  {return k;}
00172 double Type2LargestValueRV::getParameter3()  {opserr<<"No such parameter in r.v. #"<<tag<<endln; return 0.0;}
00173 double Type2LargestValueRV::getParameter4()  {opserr<<"No such parameter in r.v. #"<<tag<<endln; return 0.0;}
00174 
00175 
00176 
00177 void
00178 Type2LargestValueRV::setParameters(double mean, double stdv)
00179 {
00180         double cov = stdv/mean;
00181         double xk = 1.5;
00182         function131(xk, cov,mean);
00183 }
00184 
00185 
00186 void
00187 Type2LargestValueRV::function131(double xk, double cov, double mean)
00188 {
00189         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00190         xk = xk + 1.0;
00191         double x1 = 1.0 - 1.0/xk;
00192         double x2 = 1.0 - 2.0/xk;
00193         double gm1 = aGammaRV->gammaFunction(x1);
00194         double gm2 = aGammaRV->gammaFunction(x2);
00195         delete aGammaRV;
00196         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00197         if (cov-vy < 0.0) 
00198                 function131(xk,cov,mean);
00199         else if (cov-vy == 0.0) 
00200                 function134(xk,cov,mean);
00201         else 
00202                 function132(xk,cov,mean);
00203 }
00204 void
00205 Type2LargestValueRV::function132(double xk, double cov, double mean)
00206 {
00207         xk = xk - 0.1;
00208         double x1 = 1.0 - 1.0/xk;
00209         double x2 = 1.0 - 2.0/xk;
00210         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00211         double gm1 = aGammaRV->gammaFunction(x1);
00212         double gm2 = aGammaRV->gammaFunction(x2);
00213         delete aGammaRV;
00214         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00215         if (cov-vy < 0.0) 
00216                 function133(xk,cov,mean);
00217         else if (cov-vy == 0.0) 
00218                 function134(xk,cov,mean);
00219         else 
00220                 function132(xk,cov,mean);
00221 }
00222 void
00223 Type2LargestValueRV::function133(double xk, double cov, double mean)
00224 {
00225         xk = xk + 0.01;
00226         double x1 = 1.0 - 1.0/xk;
00227         double x2 = 1.0 - 2.0/xk;
00228         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00229         double gm1 = aGammaRV->gammaFunction(x1);
00230         double gm2 = aGammaRV->gammaFunction(x2);
00231         delete aGammaRV;
00232         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00233         if (cov-vy < 0.0) 
00234                 function133(xk,cov,mean);
00235         else if (cov-vy == 0.0) 
00236                 function134(xk,cov,mean);
00237         else 
00238                 function134(xk,cov,mean);
00239 
00240 
00241 }
00242 void
00243 Type2LargestValueRV::function134(double xk, double gm1, double mean)
00244 {
00245         u = mean/gm1;
00246         k = xk;
00247 }

Generated on Mon Oct 23 15:05:26 2006 for OpenSees by doxygen 1.5.0