vnl_sample.h

来自「InsightToolkit-1.4.0(有大量的优化算法程序)」· C头文件 代码 · 共 48 行

H
48
字号
// This is vxl/vnl/vnl_sample.h
#ifndef vnl_sample_h_
#define vnl_sample_h_
#ifdef VCL_NEEDS_PRAGMA_INTERFACE
#pragma interface
#endif
//:
//  \file
//  \brief easy ways to sample from various probability distributions

//: re-seed the random number generator.
void vnl_sample_reseed();

//: re-seed the random number generator given a seed.
void vnl_sample_reseed(int seed);

//: uniform on [a, b)
double vnl_sample_uniform(double a, double b);

//: two independent samples from a standard normal distribution.
void vnl_sample_normal_2(double *x, double *y);

//: Normal distribution with given mean and standard deviation
double vnl_sample_normal(double mean, double sigma);

// P(X = k) = [kth term in binomial expansion of (p + (1-p))^n]
//int vnl_sample_binomial(int n, int k, double p);

// ----------------------------------------

//: handy function to fill a range of values.
template <class I>
inline void vnl_sample_uniform(I begin, I end, double a, double b)
{
  for (I p=begin; p!=end; ++p)
    (*p) = vnl_sample_uniform(a, b);
}

//: handy function to fill a range of values.
template <class I>
inline void vnl_sample_normal(I begin, I end, double mean, double sigma)
{
  for (I p=begin; p!=end; ++p)
    (*p) = vnl_sample_normal(mean, sigma);
}

#endif // vnl_sample_h_

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?