1 // -*- C++ -*- 2 /** 3 * @brief Krawtchouk polynomial factory 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 #ifndef OPENTURNS_KRAWTCHOUKFACTORY_HXX 22 #define OPENTURNS_KRAWTCHOUKFACTORY_HXX 23 24 #include "openturns/OrthogonalUniVariatePolynomialFactory.hxx" 25 26 BEGIN_NAMESPACE_OPENTURNS 27 28 29 30 /** 31 * @class KrawtchoukFactory 32 * 33 * Krawtchouk polynomial factory 34 */ 35 36 class OT_API KrawtchoukFactory 37 : public OrthogonalUniVariatePolynomialFactory 38 { 39 CLASSNAME 40 public: 41 42 43 /** Default constructor: (1, 0.5) order Krawtchouk polynomial associated with the default Binomial() = Binomial(1, 0.5) distribution which is equal to the Bernoulli(0.5) distribution */ 44 KrawtchoukFactory(); 45 46 /** Parameter constructor: (n, p) is the order of the Krawtchouk polynomial, associated with the Binomial(n, p) distribution */ 47 KrawtchoukFactory(const UnsignedInteger n, 48 const Scalar p); 49 50 /** Virtual constructor */ 51 KrawtchoukFactory * clone() const override; 52 53 /** Calculate the coefficients of recurrence a0n, a1n, a2n such that 54 Pn+1(x) = (a0n * x + a1n) * Pn(x) + a2n * Pn-1(x) */ 55 Coefficients getRecurrenceCoefficients(const UnsignedInteger n) const override; 56 57 /** N accessor */ 58 UnsignedInteger getN() const; 59 60 /** P accessor */ 61 Scalar getP() const; 62 63 /** String converter */ 64 String __repr__() const override; 65 66 /** Method save() stores the object through the StorageManager */ 67 void save(Advocate & adv) const override; 68 69 /** Method load() reloads the object from the StorageManager */ 70 void load(Advocate & adv) override; 71 72 private: 73 /* First parameter of the Krawtchouk polynomial */ 74 UnsignedInteger n_; 75 /* Second parameter of the Krawtchouk polynomial */ 76 Scalar p_; 77 78 } ; /* class KrawtchoukFactory */ 79 80 81 END_NAMESPACE_OPENTURNS 82 83 #endif /* OPENTURNS_KRAWTCHOUKFACTORY_HXX */ 84