1 // -*- C++ -*-
2 /**
3 * @brief WeibullMin distribution with mu and sigma as parameters
4 *
5 * Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
6 *
7 * This library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 #include <cmath>
23 #include "openturns/WeibullMaxFactory.hxx"
24 #include "openturns/SquareMatrix.hxx"
25 #include "openturns/SpecFunc.hxx"
26 #include "openturns/WeibullMaxMuSigma.hxx"
27 #include "openturns/WeibullMinMuSigma.hxx"
28 #include "openturns/PersistentObjectFactory.hxx"
29
30 BEGIN_NAMESPACE_OPENTURNS
31
32 CLASSNAMEINIT(WeibullMaxMuSigma)
33 static const Factory<WeibullMaxMuSigma> Factory_WeibullMaxMuSigma;
34
35 /* Default constructor */
WeibullMaxMuSigma()36 WeibullMaxMuSigma::WeibullMaxMuSigma()
37 : DistributionParametersImplementation()
38 , mu_(1.0)
39 , sigma_(1.0)
40 , gamma_(0.)
41 {
42 // Nothing to do
43 }
44
WeibullMaxMuSigma(const Scalar mu,const Scalar sigma,const Scalar gamma)45 WeibullMaxMuSigma::WeibullMaxMuSigma(const Scalar mu, const Scalar sigma, const Scalar gamma)
46 : DistributionParametersImplementation()
47 , mu_(mu)
48 , sigma_(sigma)
49 , gamma_(gamma)
50 {
51 if (!(sigma > 0.0)) throw InvalidArgumentException(HERE) << "sigma must be > 0, here sigma=" << sigma;
52 if (!(mu < gamma)) throw InvalidArgumentException(HERE) << "mu must be lesser than gamma, here mu=" << mu << " and gamma=" << gamma;
53 }
54
55 /* Virtual constructor */
clone() const56 WeibullMaxMuSigma * WeibullMaxMuSigma::clone() const
57 {
58 return new WeibullMaxMuSigma(*this);
59 }
60
61 /* Comparison operator */
operator ==(const WeibullMaxMuSigma & other) const62 Bool WeibullMaxMuSigma::operator ==(const WeibullMaxMuSigma & other) const
63 {
64 return (this == &other);
65 }
66
67
68 /* Build a distribution based on a set of native parameters */
getDistribution() const69 Distribution WeibullMaxMuSigma::getDistribution() const
70 {
71 Point newParameters(3);
72 newParameters[0] = mu_;
73 newParameters[1] = sigma_;
74 newParameters[2] = gamma_;
75
76 Point nativeParameters(operator()(newParameters));
77
78 return WeibullMaxFactory().build(nativeParameters);
79 }
80
81
82 /* Compute jacobian / native parameters */
gradient() const83 Matrix WeibullMaxMuSigma::gradient() const
84 {
85 Point newParameters(3);
86 newParameters[0] = mu_;
87 newParameters[1] = sigma_;
88 newParameters[2] = gamma_;
89
90 Matrix nativeParametersGradient(WeibullMinMuSigma(-mu_, sigma_, -gamma_).gradient());
91 nativeParametersGradient(0, 0) *= -1.0;//dbeta/dmu
92 nativeParametersGradient(0, 1) *= -1.0;//dalpha/dmu
93 return nativeParametersGradient;
94 }
95
96
97 /* Conversion operator */
operator ()(const Point & inP) const98 Point WeibullMaxMuSigma::operator () (const Point & inP) const
99 {
100 Point inP2(inP);
101 inP2[0] *= -1;//mu
102 inP2[2] *= -1;// gamma
103 Point nativeParameters(WeibullMinMuSigma().operator()(inP2));
104 nativeParameters[2] *= -1;// gamma
105 return nativeParameters;
106 }
107
108
inverse(const Point & inP) const109 Point WeibullMaxMuSigma::inverse(const Point & inP) const
110 {
111 Point inP2(inP);
112 inP2[2] *= -1;// gamma
113 Point muSigmaParameters(WeibullMinMuSigma().inverse(inP2));
114 muSigmaParameters[0] *= -1;// mu
115 muSigmaParameters[2] *= -1;// gamma
116 return muSigmaParameters;
117 }
118
119
120 /* Parameters value and description accessor */
setValues(const Point & inP)121 void WeibullMaxMuSigma::setValues(const Point & inP)
122 {
123 if (inP.getDimension() != 3) throw InvalidArgumentException(HERE) << "the given point must have dimension=3, here dimension=" << inP.getDimension();
124 mu_ = inP[0];
125 sigma_ = inP[1];
126 gamma_ = inP[2];
127 }
128
getValues() const129 Point WeibullMaxMuSigma::getValues() const
130 {
131 Point point(3);
132 point[0] = mu_;
133 point[1] = sigma_;
134 point[2] = gamma_;
135 return point;
136 }
137
getDescription() const138 Description WeibullMaxMuSigma::getDescription() const
139 {
140 Description description(3);
141 description[0] = "mu";
142 description[1] = "sigma";
143 description[2] = "gamma";
144 return description;
145 }
146
147 /* String converter */
__repr__() const148 String WeibullMaxMuSigma::__repr__() const
149 {
150 OSS oss(true);
151 oss << "class=" << GetClassName()
152 << " name=" << getName()
153 << " mu=" << mu_
154 << " sigma=" << sigma_
155 << " gamma=" << gamma_;
156 return oss;
157 }
158
159
__str__(const String &) const160 String WeibullMaxMuSigma::__str__(const String & ) const
161 {
162 OSS oss(false);
163 oss << getClassName() << "(mu = " << mu_ << ", sigma = " << sigma_ << ", gamma = " << gamma_ << ")";
164 return oss;
165 }
166
save(Advocate & adv) const167 void WeibullMaxMuSigma::save(Advocate & adv) const
168 {
169 DistributionParametersImplementation::save(adv);
170 adv.saveAttribute( "mu_", mu_ );
171 adv.saveAttribute( "sigma_", sigma_ );
172 adv.saveAttribute( "gamma_", gamma_ );
173 }
174
load(Advocate & adv)175 void WeibullMaxMuSigma::load(Advocate & adv)
176 {
177 DistributionParametersImplementation::load(adv);
178 adv.loadAttribute( "mu_", mu_ );
179 adv.loadAttribute( "sigma_", sigma_ );
180 adv.loadAttribute( "gamma_", gamma_ );
181 }
182
183 END_NAMESPACE_OPENTURNS
184