Aracılığıyla paylaş


normal_distribution Sınıfı

Normal bir dağıtım oluşturur.

Sözdizimi

template<class RealType = double>
class normal_distribution
   {
public:
   // types
   typedef RealType result_type;
   struct param_type;

   // constructors and reset functions
   explicit normal_distribution(result_type mean = 0.0, result_type stddev = 1.0);
   explicit normal_distribution(const param_type& parm);
   void reset();

   // generating functions
   template <class URNG>
   result_type operator()(URNG& gen);
   template <class URNG>
   result_type operator()(URNG& gen, const param_type& parm);

   // property functions
   result_type mean() const;
   result_type stddev() const;
   param_type param() const;
   void param(const param_type& parm);
   result_type min() const;
   result_type max() const;
   };

Parametreler

RealType
Kayan nokta sonuç türü varsayılan olarak olarak doublegösterilir. Olası türler için bkz <. rastgele>.

Açıklamalar

Sınıf şablonu, kullanıcı tarafından belirtilen tam sayı türünde değerler üreten bir dağıtımı açıklar veya sağlanmayan bir tür double , Normal Dağıtıma göre dağıtılır. Aşağıdaki tabloda, tek tek üyeler hakkındaki makalelere bağlantılar yer alır.

normal_distribution
param_type

özellik işlevleri mean() ve stddev() sırasıyla ortalama ve stddev depolanan dağıtım parametrelerinin değerlerini döndürür.

Özellik üyesi param() depolanan dağıtım parametresi paketini ayarlar veya döndürür param_type .

min() ve max() üye işlevleri sırasıyla mümkün olan en küçük sonucu ve mümkün olan en büyük sonucu döndürür.

reset() Üye işlevi önbelleğe alınmış değerleri atar, böylece bir sonraki çağrısının sonucu, çağrıdan operator() önce altyapıdan alınan hiçbir değere bağımlı olmaz.

operator() Üye işlevleri, geçerli parametre paketinden veya belirtilen parametre paketinden ÜRNG altyapısını temel alarak bir sonraki oluşturulan değeri döndürür.

Dağıtım sınıfları ve üyeleri hakkında daha fazla bilgi için bkz <. rastgele>.

Normal dağıtım hakkında ayrıntılı bilgi için Normal Dağıtım Wolfram MathWorld makalesine bakın.

Örnek

// compile with: /EHsc /W4
#include <random>
#include <iostream>
#include <iomanip>
#include <string>
#include <map>

using namespace std;

void test(const double m, const double s, const int samples) {

    // uncomment to use a non-deterministic seed
    //    random_device rd;
    //    mt19937 gen(rd());
    mt19937 gen(1701);

    normal_distribution<> distr(m, s);

    cout << endl;
    cout << "min() == " << distr.min() << endl;
    cout << "max() == " << distr.max() << endl;
    cout << "m() == " << fixed << setw(11) << setprecision(10) << distr.mean() << endl;
    cout << "s() == " << fixed << setw(11) << setprecision(10) << distr.stddev() << endl;

    // generate the distribution as a histogram
    map<double, int> histogram;
    for (int i = 0; i < samples; ++i) {
        ++histogram[distr(gen)];
    }

    // print results
    cout << "Distribution for " << samples << " samples:" << endl;
    int counter = 0;
    for (const auto& elem : histogram) {
        cout << fixed << setw(11) << ++counter << ": "
            << setw(14) << setprecision(10) << elem.first << endl;
    }
    cout << endl;
}

int main()
{
    double m_dist = 1;
    double s_dist = 1;
    int samples = 10;

    cout << "Use CTRL-Z to bypass data entry and run using default values." << endl;
    cout << "Enter a floating point value for the 'mean' distribution parameter: ";
    cin >> m_dist;
    cout << "Enter a floating point value for the 'stddev' distribution parameter (must be greater than zero): ";
    cin >> s_dist;
    cout << "Enter an integer value for the sample count: ";
    cin >> samples;

    test(m_dist, s_dist, samples);
}
Use CTRL-Z to bypass data entry and run using default values.
Enter a floating point value for the 'mean' distribution parameter: 0
Enter a floating point value for the 'stddev' distribution parameter (must be greater than zero): 1
Enter an integer value for the sample count: 10

min() == -1.79769e+308
max() == 1.79769e+308
m() == 0.0000000000
s() == 1.0000000000
Distribution for 10 samples:
    1: -0.8845823965
    2: -0.1995761116
    3: -0.1162665130
    4: -0.0685154932
    5: 0.0403741461
    6: 0.1591327792
    7: 1.0414389924
    8: 1.5876269426
    9: 1.6362637713
    10: 2.7821317338

Gereksinimler

Üst bilgi:<rastgele>

Ad alanı: std

normal_distribution::normal_distribution

Dağıtımı oluşturur.

explicit normal_distribution(result_type mean = 0.0, result_type stddev = 1.0);
explicit normal_distribution(const param_type& parm);

Parametreler

demek
mean Dağıtım parametresi.

stddev
stddev Dağıtım parametresi.

parm
Dağılımı oluşturmak için kullanılan parametre yapısı.

Açıklamalar

Önkoşul: 0.0 < stddev

İlk oluşturucu, depolanan mean değeri ortalamayı ve depolanan stddev değeri stddev değerini tutan bir nesne oluşturur.

İkinci oluşturucu, depolanan parametreleri parm'den başlatılan bir nesne oluşturur. Üye işlevini çağırarak param() mevcut bir dağıtımın geçerli parametrelerini alabilir ve ayarlayabilirsiniz.

normal_distribution::p aram_type

Dağıtımın parametrelerini depolar.

struct param_type {
   typedef normal_distribution<result_type> distribution_type;
   param_type(result_type mean = 0.0, result_type stddev = 1.0);
   result_type mean() const;
   result_type stddev() const;

   bool operator==(const param_type& right) const;
   bool operator!=(const param_type& right) const;
   };

Parametreler

demek
mean Dağıtım parametresi.

stddev
stddev Dağıtım parametresi.

Sağ
param_type Karşılaştırmak için kullanılan yapı.

Açıklamalar

Önkoşul: 0.0 < stddev

Bu yapı, örnek oluşturma sırasında dağıtımın sınıf oluşturucusunun, mevcut bir dağıtımın param() depolanmış parametrelerini ayarlamak için üye işlevine operator() geçirilebilir ve depolanan parametrelerin yerine kullanılacaktır.

Ayrıca bkz.

<rastgele>