在MATLAB中定义自己的概率密度函数 [英] Defining your own probability density function in MATLAB

查看:780
本文介绍了在MATLAB中定义自己的概率密度函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在MATLAB或Octave中定义您自己的概率密度函数并使用它 用于生成随机数?

Is it possible to define your own probability density function in MATLAB or Octave and use it for generating random numbers?

MATLAB和Octave具有默认函数,例如rand,内置randn以从均匀分布或正态分布中随机抽取点,但是似乎没有关于如何定义我自己的概率密度函数的文档.

MATLAB and Octave have default functions like rand, randn built in to draw points at random from a uniform, or normal distributions but there seems to be no documentation of how to define my very own proability density function.

推荐答案

从任意随机分布中采样并不总是那么简单.对于众所周知的发行版,有一些技巧可以实现它们,并且大多数都如Oli所说的那样在stats工具箱中实现.

Sampling from an arbitrary random distribution is not always trivial. For well known distributions there are tricks to implement them and most of them are implemented in stats toolbox as Oli said.

如果您感兴趣的发行形式很困难,那么有很多采样算法可以为您提供帮助,例如拒绝采样,切片采样, Metropolis-Hastings算法.

If your distribution of interest is of difficult form, there are many sampling algorithms that may help you, such as, rejection sampling, slice sampling, Metropolis–Hastings algorithm.

如果您的分布是离散的,或者可以很好地由离散分布近似,那么您可以使用randsamp进行多项式采样.

If your distribution is discrete, or can be approximated by a discrete distribution fairly well, then you can just do multinomial sampling using randsamp.

这篇关于在MATLAB中定义自己的概率密度函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆